/[baselayout]/trunk/src/rc.h
Gentoo

Contents of /trunk/src/rc.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2665 - (show annotations) (download) (as text)
Fri Apr 27 11:24:05 2007 UTC (6 years, 11 months ago) by uberlord
File MIME type: text/x-chdr
File size: 7368 byte(s)
env-update now respects COLON_SEPARATED and SPACE_SEPARATED env.d values, #176198.
1 /*
2 rc.h
3 Header file for external applications to get RC information.
4 Copyright 2007 Gentoo Foundation
5 Released under the GPLv2
6 */
7
8 #ifndef __RC_H__
9 #define __RC_H__
10
11 #ifdef __GNUC__
12 # define SENTINEL __attribute__ ((__sentinel__))
13 #endif
14
15 #include <sys/types.h>
16 #include <stdbool.h>
17
18 /* Special level names */
19 #define RC_LEVEL_SYSINIT "sysinit"
20 #define RC_LEVEL_BOOT "boot"
21 #define RC_LEVEL_SINGLE "single"
22 #define RC_LEVEL_SHUTDOWN "shutdown"
23 #define RC_LEVEL_REBOOT "reboot"
24 #define RC_LEVEL_DEFAULT "default"
25
26 typedef enum
27 {
28 rc_service_started,
29 rc_service_stopped,
30 rc_service_starting,
31 rc_service_stopping,
32 rc_service_inactive,
33 rc_service_wasinactive,
34 rc_service_coldplugged,
35 rc_service_failed,
36 rc_service_scheduled,
37 rc_service_crashed
38 } rc_service_state_t;
39
40 char *rc_resolve_service (const char *service);
41 bool rc_service_exists (const char *service);
42 bool rc_service_in_runlevel (const char *service, const char *runlevel);
43 bool rc_service_state (const char *service, rc_service_state_t state);
44 bool rc_mark_service (const char *service, rc_service_state_t state);
45 pid_t rc_stop_service (const char *service);
46 pid_t rc_start_service (const char *service);
47 int rc_waitpid (pid_t pid);
48 void rc_schedule_start_service (const char *service,
49 const char *service_to_start);
50 char **rc_services_scheduled_by (const char *service);
51 void rc_schedule_clear (const char *service);
52 bool rc_wait_service (const char *service);
53 bool rc_get_service_option (const char *service, const char *option,
54 char *value);
55 bool rc_set_service_option (const char *service, const char *option,
56 const char *value);
57 void rc_set_service_daemon (const char *service, const char *exec,
58 const char *name, const char *pidfile,
59 bool started);
60 bool rc_service_started_daemon (const char *service, const char *exec,
61 int indx);
62
63 bool rc_allow_plug (char *service);
64
65 char *rc_get_runlevel (void);
66 void rc_set_runlevel (const char *runlevel);
67 bool rc_runlevel_exists (const char *runlevel);
68 char **rc_get_runlevels (void);
69 bool rc_runlevel_starting (void);
70 bool rc_runlevel_stopping (void);
71 bool rc_service_add (const char *runlevel, const char *service);
72 bool rc_service_delete (const char *runlevel, const char *service);
73 char **rc_services_in_runlevel (const char *runlevel);
74 char **rc_services_in_state (rc_service_state_t state);
75 char **rc_services_scheduled (const char *service);
76
77 /* Find pids based on criteria - free the pointer returned after use */
78 pid_t *rc_find_pids (const char *exec, const char *cmd,
79 uid_t uid, pid_t pid);
80 /* Checks that all daemons started with start-stop-daemon by the service
81 are still running. If so, return false otherwise true.
82 You should check that the service has been started before calling this. */
83 bool rc_service_daemons_crashed (const char *service);
84
85 /* Dependency tree structs and functions. */
86 typedef struct rc_deptype
87 {
88 char *type;
89 char **services;
90 struct rc_deptype *next;
91 } rc_deptype_t;
92
93 typedef struct rc_depinfo
94 {
95 char *service;
96 rc_deptype_t *depends;
97 struct rc_depinfo *next;
98 } rc_depinfo_t;
99
100
101 /* Options for rc_dep_depends and rc_order_services.
102 When changing runlevels, you should use RC_DEP_START and RC_DEP_STOP for
103 the start and stop lists as we tweak the provided services for this. */
104 #define RC_DEP_TRACE 0x01
105 #define RC_DEP_STRICT 0x02
106 #define RC_DEP_START 0x04
107 #define RC_DEP_STOP 0x08
108
109 int rc_update_deptree (bool force);
110 rc_depinfo_t *rc_load_deptree (void);
111 rc_depinfo_t *rc_get_depinfo (rc_depinfo_t *deptree, const char *service);
112 rc_deptype_t *rc_get_deptype (rc_depinfo_t *depinfo, const char *type);
113 char **rc_get_depends (rc_depinfo_t *deptree, char **types,
114 char **services, const char *runlevel, int options);
115 /* List all the services that should be started, in order, the the
116 given runlevel, including sysinit and boot services where
117 approriate.
118 If reboot, shutdown or single are given then we list all the services
119 we that we need to shutdown in order. */
120 char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
121 int options);
122
123 void rc_free_deptree (rc_depinfo_t *deptree);
124
125 /* Plugin handler
126 For each plugin loaded we will call it's _name_hook with the below
127 enum and either the runlevel name or service name. For example
128 int _splash_hook (rc_hook_t hook, const char *name);
129 Plugins are called when rc does something. This does not indicate an
130 end result and the plugin should use the above functions to query things
131 like service status.
132 The service hooks have extra ones - now and done. This is because after
133 start_in we may start other services before we start the service in
134 question. now shows we really will start the service now and done shows
135 when we have done it as may start scheduled services at this point. */
136 typedef enum
137 {
138 rc_hook_runlevel_stop_in = 1,
139 rc_hook_runlevel_stop_out = 4,
140 rc_hook_runlevel_start_in = 5,
141 rc_hook_runlevel_start_out = 8,
142 /* We reserved a few numbers if we need rc_runlevel_stop_now and done */
143 rc_hook_abort = 99,
144 /* We send the abort if an init script requests we abort and drop
145 * into single user mode if system not fully booted */
146 rc_hook_service_stop_in = 101,
147 rc_hook_service_stop_now,
148 rc_hook_service_stop_done,
149 rc_hook_service_stop_out,
150 rc_hook_service_start_in,
151 rc_hook_service_start_now,
152 rc_hook_service_start_done,
153 rc_hook_service_start_out
154 } rc_hook_t;
155
156 /* Plugins should write FOO=BAR to this fd to set any environment variables
157 * they wish. At this time we only support the setting of one env var. */
158 extern FILE *rc_environ_fd;
159
160 /* RC utility functions.
161 Although not directly related to RC in general, they are used by RC
162 itself and the supporting applications. */
163 void *rc_xcalloc (size_t n, size_t size);
164 void *rc_xmalloc (size_t size);
165 void *rc_xrealloc (void *ptr, size_t size);
166 char *rc_xstrdup (const char *str);
167
168 /* Concat paths adding '/' if needed. */
169 char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL;
170
171 bool rc_is_env (const char *variable, const char *value);
172 bool rc_exists (const char *pathname);
173 bool rc_is_file (const char *pathname);
174 bool rc_is_link (const char *pathname);
175 bool rc_is_dir (const char *pathname);
176 bool rc_is_exec (const char *pathname);
177
178 #define RC_LS_INITD 0x01
179 char **rc_ls_dir (char **list, const char *dir, int options);
180
181 bool rc_rm_dir (const char *pathname, bool top);
182
183 /* Config file functions */
184 char **rc_get_list (char **list, const char *file);
185 char **rc_get_config (char **list, const char *file);
186 char *rc_get_config_entry (char **list, const char *entry);
187
188 /* Make an environment list which filters out all unwanted values
189 and loads it up with our RC config */
190 char **rc_filter_env (void);
191 char **rc_config_env (char **env);
192
193 /* Handy functions for dealing with string arrays of char ** */
194 char **rc_strlist_add (char **list, const char *item);
195 char **rc_strlist_addu (char **list, const char *item);
196 char **rc_strlist_addsort (char **list, const char *item);
197 char **rc_strlist_addsortc (char **list, const char *item);
198 char **rc_strlist_addsortu (char **list, const char *item);
199 char **rc_strlist_delete (char **list, const char *item);
200 char **rc_strlist_join (char **this, char **that);
201 void rc_strlist_reverse (char **list);
202 void rc_strlist_free (char **list);
203
204 #endif

  ViewVC Help
Powered by ViewVC 1.1.20