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

Contents of /trunk/src/rc.h

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20