]> git.saurik.com Git - apple/launchd.git/blame - launchd/src/lists.h
launchd-106.tar.gz
[apple/launchd.git] / launchd / src / lists.h
CommitLineData
e91b9f68
A
1/*
2 * Copyright (c) 1999-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License."
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24/*
25 * bootstrap -- fundamental service initiator and port server
26 * Mike DeMoney, NeXT, Inc.
27 * Copyright, 1990. All rights reserved.
28 *
29 * lists.h -- interface to list routines
30 */
31
32#include <sys/types.h>
33#include <mach/mach.h>
34#include <mach/boolean.h>
35#include <servers/bootstrap_defs.h>
36
37#include <bsm/audit.h>
38
39#ifndef NULL
40#define NULL ((void *)0)
41#endif NULL
42
43typedef struct bootstrap bootstrap_info_t;
44typedef struct service service_t;
45typedef struct server server_t;
46
47/* Bootstrap info */
48struct bootstrap {
49 bootstrap_info_t *next; /* list of all bootstraps */
50 bootstrap_info_t *prev;
51 bootstrap_info_t *parent;
52 bootstrap_info_t *deactivate; /* list being deactivated */
53 mach_port_name_t bootstrap_port;
54 mach_port_name_t requestor_port;
55 unsigned int ref_count;
56};
57
58/* Service types */
59typedef enum {
60 DECLARED, /* Declared in config file */
61 REGISTERED /* Registered dynamically */
62} servicetype_t;
63
64struct service {
65 service_t *next; /* list of all services */
66 service_t *prev;
67 name_t name; /* service name */
68 mach_port_name_t port; /* service port,
69 may have all rights if inactive */
70 bootstrap_info_t *bootstrap; /* bootstrap port(s) used at this
71 * level. */
72 boolean_t isActive; /* server is running */
73 servicetype_t servicetype; /* Declared, Registered, or Machport */
74 server_t *server; /* server, declared services only */
75};
76
77/* Server types */
78typedef enum {
79 SERVER, /* Launchable server */
80 RESTARTABLE, /* Restartable server */
81 DEMAND, /* Restartable server - on demand */
82 MACHINIT, /* mach_init doesn't get launched. */
83} servertype_t;
84
85#define NULL_SERVER NULL
86#define ACTIVE TRUE
87
88struct server {
89 server_t *next; /* list of all servers */
90 server_t *prev;
91 servertype_t servertype;
92 cmd_t cmd; /* server command to exec */
93 uid_t uid; /* uid to exec server with */
94 auditinfo_t auinfo; /* server's audit information */
95 mach_port_t port; /* server's priv bootstrap port */
96 mach_port_t task_port; /* server's task port */
97 pid_t pid; /* server's pid */
98 int activity; /* count of checkins/registers this instance */
99 int active_services;/* count of active services */
100 bootstrap_info_t *bootstrap; /* bootstrap context */
101};
102
103#define NO_PID (-1)
104
105extern void init_lists(void);
106
107extern server_t *new_server(
108 bootstrap_info_t *bootstrap,
109 const char *cmd,
110 uid_t uid,
111 servertype_t servertype,
112 auditinfo_t auinfo);
113
114extern service_t *new_service(
115 bootstrap_info_t *bootstrap,
116 const char *name,
117 mach_port_t serviceport,
118 boolean_t isActive,
119 servicetype_t servicetype,
120 server_t *serverp);
121
122extern bootstrap_info_t *new_bootstrap(
123 bootstrap_info_t *parent,
124 mach_port_name_t bootstrapport,
125 mach_port_name_t requestorport);
126
127extern server_t *lookup_server_by_port(mach_port_t port);
128extern server_t *lookup_server_by_task_port(mach_port_t port);
129extern void setup_server(server_t *serverp);
130extern void delete_server(server_t *serverp);
131extern boolean_t active_server(server_t *serverp);
132extern boolean_t useless_server(server_t *serverp);
133
134extern void delete_service(service_t *servicep);
135extern service_t *lookup_service_by_name(bootstrap_info_t *bootstrap, name_t name);
136extern service_t *lookup_service_by_port(mach_port_t port);
137extern service_t *lookup_service_by_server(server_t *serverp);
138
139extern bootstrap_info_t *lookup_bootstrap_by_port(mach_port_t port);
140extern bootstrap_info_t *lookup_bootstrap_by_req_port(mach_port_t port);
141extern void deactivate_bootstrap(bootstrap_info_t *bootstrap);
142extern void deallocate_bootstrap(bootstrap_info_t *bootstrap);
143extern boolean_t active_bootstrap(bootstrap_info_t *bootstrap);
144
145extern void *ckmalloc(unsigned nbytes);
146
147extern bootstrap_info_t bootstraps; /* head of list of bootstrap ports */
148extern server_t servers; /* head of list of all servers */
149extern service_t services; /* head of list of all services */
150extern unsigned nservices; /* number of services in list */
151
152#define FIRST(q) ((q).next)
153#define NEXT(qe) ((qe)->next)
154#define PREV(qe) ((qe)->prev)
155#define IS_END(qe, q) ((qe) == &(q))