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

Diff of /trunk/src/rc.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2979 Revision 2980
28#define RC_LEVEL_SYSINIT "sysinit" 28#define RC_LEVEL_SYSINIT "sysinit"
29#define RC_LEVEL_SINGLE "single" 29#define RC_LEVEL_SINGLE "single"
30#define RC_LEVEL_SHUTDOWN "shutdown" 30#define RC_LEVEL_SHUTDOWN "shutdown"
31#define RC_LEVEL_REBOOT "reboot" 31#define RC_LEVEL_REBOOT "reboot"
32 32
33/*! @name rc_ls_dir options */ 33/*! Return the current runlevel.
34/*! Ensure that an init.d service exists for each file returned */ 34 * @return the current runlevel */
35#define RC_LS_INITD 0x01 35char *rc_runlevel_get (void);
36
37/*! Checks if the runlevel exists or not
38 * @param runlevel to check
39 * @return true if the runlevel exists, otherwise false */
40bool rc_runlevel_exists (const char *runlevel);
41
42/*! Return a NULL terminated list of runlevels
43 * @return a NULL terminated list of runlevels */
44char **rc_runlevel_list (void);
45
46/*! Set the runlevel.
47 * This just changes the stored runlevel and does not start or stop any services.
48 * @param runlevel to store */
49bool rc_runlevel_set (const char *runlevel);
50
51/*! Is the runlevel starting?
52 * @return true if yes, otherwise false */
53bool rc_runlevel_starting (void);
54
55/*! Is the runlevel stopping?
56 * @return true if yes, otherwise false */
57bool rc_runlevel_stopping (void);
36 58
37/*! @name RC 59/*! @name RC
38 * A service can be given as a full path or just its name. 60 * A service can be given as a full path or just its name.
39 * If its just a name then we try to resolve the service to a full path. 61 * If its just a name then we try to resolve the service to a full path.
40 * This should allow the use if local init.d directories in the future. */ 62 * This should allow the use if local init.d directories in the future. */
57 RC_SERVICE_FAILED = 0x0200, 79 RC_SERVICE_FAILED = 0x0200,
58 RC_SERVICE_SCHEDULED = 0x0400, 80 RC_SERVICE_SCHEDULED = 0x0400,
59 RC_SERVICE_WASINACTIVE = 0x0800, 81 RC_SERVICE_WASINACTIVE = 0x0800,
60} rc_service_state_t; 82} rc_service_state_t;
61 83
84/*! Add the service to the runlevel
85 * @param runlevel to add to
86 * @param service to add
87 * @return true if successful, otherwise false */
88bool rc_service_add (const char *runlevel, const char *service);
89
90/*! Remove the service from the runlevel
91 * @param runlevel to remove from
92 * @param service to remove
93 * @return true if sucessful, otherwise false */
94bool rc_service_delete (const char *runlevel, const char *service);
95
62/*! Save the arguments to find a running daemon 96/*! Save the arguments to find a running daemon
63 * @param service to save arguments for 97 * @param service to save arguments for
64 * @param exec that we started 98 * @param exec that we started
65 * @param name of the process (optional) 99 * @param name of the process (optional)
66 * @param pidfile of the process (optional) 100 * @param pidfile of the process (optional)
95/*! Lists the extra options a service has 129/*! Lists the extra options a service has
96 * @param service to load the options from 130 * @param service to load the options from
97 * @return NULL terminated string list of options */ 131 * @return NULL terminated string list of options */
98char **rc_service_options (const char *service); 132char **rc_service_options (const char *service);
99 133
134/*! Check if the service is allowed to be hot/cold plugged
135 * @param service to check
136 * @return true if allowed, otherwise false */
137bool rc_service_plugable (char *service);
138
139/*! Resolves a service name to its full path.
140 * @param service to check
141 * @return pointer to full path of service */
142char *rc_service_resolve (const char *service);
143
144/*! Schedule a service to be started when another service starts
145 * @param service that starts the scheduled service when started
146 * @param service_to_start service that will be started */
147bool rc_service_schedule_start (const char *service,
148 const char *service_to_start);
149/*! Return a NULL terminated list of services that are scheduled to start
150 * when the given service has started
151 * @param service to check
152 * @return NULL terminated list of services scheduled to start */
153char **rc_services_scheduled_by (const char *service);
154
155/*! Clear the list of services scheduled to be started by this service
156 * @param service to clear */
157void rc_service_schedule_clear (const char *service);
158
159/*! Checks if a service in in a state
160 * @param service to check
161 * @return state of the service */
162rc_service_state_t rc_service_state (const char *service);
163
164/*! Start a service
165 * @param service to start
166 * @return pid of the service starting process */
167pid_t rc_service_start (const char *service);
168
169/*! Stop a service
170 * @param service to stop
171 * @return pid of service stopping process */
172pid_t rc_service_stop (const char *service);
173
174/*! Check if the service started the daemon
175 * @param service to check
176 * @param exec to check
177 * @param indx of the daemon (optional - 1st daemon, 2nd daemon, etc)
178 * @return true if started by this service, otherwise false */
179bool rc_service_started_daemon (const char *service, const char *exec,
180 int indx);
181
100/*! Return a saved value for a service 182/*! Return a saved value for a service
101 * @param service to check 183 * @param service to check
102 * @param option to load 184 * @param option to load
103 * @return saved value */ 185 * @return saved value */
104char *rc_service_value_get (const char *service, const char *option); 186char *rc_service_value_get (const char *service, const char *option);
109 * @param value of the option 191 * @param value of the option
110 * @return true if saved, otherwise false */ 192 * @return true if saved, otherwise false */
111bool rc_service_value_set (const char *service, const char *option, 193bool rc_service_value_set (const char *service, const char *option,
112 const char *value); 194 const char *value);
113 195
114/*! Resolves a service name to its full path.
115 * @param service to check
116 * @return pointer to full path of service */
117char *rc_service_resolve (const char *service);
118
119/*! Schedule a service to be started when another service starts
120 * @param service that starts the scheduled service when started
121 * @param service_to_start service that will be started */
122bool rc_service_schedule_start (const char *service,
123 const char *service_to_start);
124/*! Return a NULL terminated list of services that are scheduled to start
125 * when the given service has started
126 * @param service to check
127 * @return NULL terminated list of services scheduled to start */
128char **rc_services_scheduled_by (const char *service);
129
130/*! Clear the list of services scheduled to be started by this service
131 * @param service to clear */
132void rc_service_schedule_clear (const char *service);
133
134/*! Checks if a service in in a state
135 * @param service to check
136 * @return state of the service */
137rc_service_state_t rc_service_state (const char *service);
138
139/*! Start a service
140 * @param service to start
141 * @return pid of the service starting process */
142pid_t rc_service_start (const char *service);
143
144/*! Stop a service
145 * @param service to stop
146 * @return pid of service stopping process */
147pid_t rc_service_stop (const char *service);
148
149/*! Wait for a service to finish 196/*! Wait for a service to finish
150 * @param service to wait for 197 * @param service to wait for
151 * @return true if service finished before timeout, otherwise false */ 198 * @return true if service finished before timeout, otherwise false */
152bool rc_service_wait (const char *service); 199bool rc_service_wait (const char *service);
153
154/*! Check if the service started the daemon
155 * @param service to check
156 * @param exec to check
157 * @param indx of the daemon (optional - 1st daemon, 2nd daemon, etc)
158 * @return true if started by this service, otherwise false */
159bool rc_service_started_daemon (const char *service, const char *exec,
160 int indx);
161
162/*! Check if the service is allowed to be hot/cold plugged
163 * @param service to check
164 * @return true if allowed, otherwise false */
165bool rc_service_plugable (char *service);
166
167/*! Return the current runlevel.
168 * @return the current runlevel */
169char *rc_runlevel_get (void);
170
171/*! Set the runlevel.
172 * This just changes the stored runlevel and does not start or stop any services.
173 * @param runlevel to store */
174bool rc_runlevel_set (const char *runlevel);
175
176/*! Checks if the runlevel exists or not
177 * @param runlevel to check
178 * @return true if the runlevel exists, otherwise false */
179bool rc_runlevel_exists (const char *runlevel);
180
181/*! Return a NULL terminated list of runlevels
182 * @return a NULL terminated list of runlevels */
183char **rc_runlevel_list (void);
184
185/*! Is the runlevel starting?
186 * @return true if yes, otherwise false */
187bool rc_runlevel_starting (void);
188/*! Is the runlevel stopping?
189 * @return true if yes, otherwise false */
190bool rc_runlevel_stopping (void);
191
192/*! Add the service to the runlevel
193 * @param runlevel to add to
194 * @param service to add
195 * @return true if successful, otherwise false */
196bool rc_service_add (const char *runlevel, const char *service);
197
198/*! Remove the service from the runlevel
199 * @param runlevel to remove from
200 * @param service to remove
201 * @return true if sucessful, otherwise false */
202bool rc_service_delete (const char *runlevel, const char *service);
203 200
204/*! List the services in a runlevel 201/*! List the services in a runlevel
205 * @param runlevel to list 202 * @param runlevel to list
206 * @return NULL terminated list of services */ 203 * @return NULL terminated list of services */
207char **rc_services_in_runlevel (const char *runlevel); 204char **rc_services_in_runlevel (const char *runlevel);
346 343
347/*! Plugins should write FOO=BAR to this fd to set any environment 344/*! Plugins should write FOO=BAR to this fd to set any environment
348 * variables they wish. Variables should be separated by NULLs. */ 345 * variables they wish. Variables should be separated by NULLs. */
349extern FILE *rc_environ_fd; 346extern FILE *rc_environ_fd;
350 347
348/*! @name Configuration */
349/*! Return a NULL terminated list of non comment lines from a file. */
350char **rc_config_list (const char *file);
351
352/*! Return a NULL terminated list of key=value lines from a file. */
353char **rc_config_load (const char *file);
354
355/*! Return the value of the entry from a key=value list. */
356char *rc_config_value (char **list, const char *entry);
357
358/*! Return a NULL terminated string list of variables allowed through
359 * from the current environemnt. */
360char **rc_filter_env (void);
361
362/*! Return a NULL terminated string list of enviroment variables made from
363 * our configuration files. */
364char **rc_make_env (void);
365
366/*! @name String List functions
367 * Handy functions for dealing with string arrays of char **.
368 * It's safe to assume that any function here that uses char ** is a string
369 * list that can be manipulated with the below functions. Every string list
370 * should be released with a call to rc_strlist_free.*/
371
372/*! Duplicate the item, add it to end of the list and return a pointer to it.
373 * @param list to add the item too
374 * @param item to add.
375 * @return pointer to newly added item */
376char *rc_strlist_add (char ***list, const char *item);
377
378/*! If the item does not exist in the list, duplicate it, add it to the
379 * list and then return a pointer to it.
380 * @param list to add the item too
381 * @param item to add.
382 * @return pointer to newly added item */
383char *rc_strlist_addu (char ***list, const char *item);
384
385/*! Duplicate the item, add it to the list at the point based on locale and
386 * then return a pointer to it.
387 * @param list to add the item too
388 * @param item to add.
389 * @return pointer to newly added item */
390char *rc_strlist_addsort (char ***list, const char *item);
391
392/*! Duplicate the item, add it to the list at the point based on C locale and
393 * then return a pointer to it.
394 * @param list to add the item too
395 * @param item to add.
396 * @return pointer to newly added item */
397char *rc_strlist_addsortc (char ***list, const char *item);
398
399/*! If the item does not exist in the list, duplicate it, add it to the
400 * list based on locale and then return a pointer to it.
401 * @param list to add the item too
402 * @param item to add.
403 * @return pointer to newly added item */
404char *rc_strlist_addsortu (char ***list, const char *item);
405
406/*! Free the item and remove it from the list. Return 0 on success otherwise -1.
407 * @param list to add the item too
408 * @param item to add.
409 * @return true on success, otherwise false */
410bool rc_strlist_delete (char ***list, const char *item);
411
412/*! Moves the contents of list2 onto list1, so list2 is effectively emptied.
413 * Returns a pointer to the last item on the new list.
414 * @param list1 to append to
415 * @param list2 to move from
416 * @return pointer to the last item on the list */
417char *rc_strlist_join (char ***list1, char **list2);
418
419/*! Reverses the contents of the list.
420 * @param list to reverse */
421void rc_strlist_reverse (char **list);
422
423/*! Frees each item on the list and the list itself.
424 * @param list to free */
425void rc_strlist_free (char **list);
426
351/*! @name Memory Allocation 427/*! @name Memory Allocation
352 * Ensure that if we cannot allocate the memory then we exit */ 428 * Ensure that if we cannot allocate the memory then we exit */
353/*@{*/ 429/*@{*/
354 430
355/*! Allocate a block of memory 431/*! Allocate a block of memory
410/*! Check if the file is marked executable or not 486/*! Check if the file is marked executable or not
411 * @param pathname to check 487 * @param pathname to check
412 * @return true if it's marked executable, otherwise false */ 488 * @return true if it's marked executable, otherwise false */
413bool rc_is_exec (const char *pathname); 489bool rc_is_exec (const char *pathname);
414 490
491/*! @name rc_ls_dir options */
492/*! Ensure that an init.d service exists for each file returned */
493#define RC_LS_INITD 0x01
494
415/*! Return a NULL terminted sorted list of the contents of the directory 495/*! Return a NULL terminted sorted list of the contents of the directory
416 * @param dir to list 496 * @param dir to list
417 * @param options any options to apply 497 * @param options any options to apply
418 * @return NULL terminated list */ 498 * @return NULL terminated list */
419char **rc_ls_dir (const char *dir, int options); 499char **rc_ls_dir (const char *dir, int options);
422 * @param pathname to remove 502 * @param pathname to remove
423 * @param top remove the top level directory too 503 * @param top remove the top level directory too
424 * @return true if successful, otherwise false */ 504 * @return true if successful, otherwise false */
425bool rc_rm_dir (const char *pathname, bool top); 505bool rc_rm_dir (const char *pathname, bool top);
426 506
427/*! @name Configuration */
428/*! Return a NULL terminated list of non comment lines from a file. */
429char **rc_get_list (const char *file);
430
431/*! Return a NULL terminated list of key=value lines from a file. */
432char **rc_get_config (const char *file);
433
434/*! Return the value of the entry from a key=value list. */
435char *rc_get_config_entry (char **list, const char *entry);
436
437/*! Return a NULL terminated string list of variables allowed through
438 * from the current environemnt. */
439char **rc_filter_env (void);
440
441/*! Return a NULL terminated string list of enviroment variables made from
442 * our configuration files. */
443char **rc_make_env (void);
444
445/*! @name String List functions
446 * Handy functions for dealing with string arrays of char **.
447 * It's safe to assume that any function here that uses char ** is a string
448 * list that can be manipulated with the below functions. Every string list
449 * should be released with a call to rc_strlist_free.*/
450
451/*! Duplicate the item, add it to end of the list and return a pointer to it.
452 * @param list to add the item too
453 * @param item to add.
454 * @return pointer to newly added item */
455char *rc_strlist_add (char ***list, const char *item);
456
457/*! If the item does not exist in the list, duplicate it, add it to the
458 * list and then return a pointer to it.
459 * @param list to add the item too
460 * @param item to add.
461 * @return pointer to newly added item */
462char *rc_strlist_addu (char ***list, const char *item);
463
464/*! Duplicate the item, add it to the list at the point based on locale and
465 * then return a pointer to it.
466 * @param list to add the item too
467 * @param item to add.
468 * @return pointer to newly added item */
469char *rc_strlist_addsort (char ***list, const char *item);
470
471/*! Duplicate the item, add it to the list at the point based on C locale and
472 * then return a pointer to it.
473 * @param list to add the item too
474 * @param item to add.
475 * @return pointer to newly added item */
476char *rc_strlist_addsortc (char ***list, const char *item);
477
478/*! If the item does not exist in the list, duplicate it, add it to the
479 * list based on locale and then return a pointer to it.
480 * @param list to add the item too
481 * @param item to add.
482 * @return pointer to newly added item */
483char *rc_strlist_addsortu (char ***list, const char *item);
484
485/*! Free the item and remove it from the list. Return 0 on success otherwise -1.
486 * @param list to add the item too
487 * @param item to add.
488 * @return true on success, otherwise false */
489bool rc_strlist_delete (char ***list, const char *item);
490
491/*! Moves the contents of list2 onto list1, so list2 is effectively emptied.
492 * Returns a pointer to the last item on the new list.
493 * @param list1 to append to
494 * @param list2 to move from
495 * @return pointer to the last item on the list */
496char *rc_strlist_join (char ***list1, char **list2);
497
498/*! Reverses the contents of the list.
499 * @param list to reverse */
500void rc_strlist_reverse (char **list);
501
502/*! Frees each item on the list and the list itself.
503 * @param list to free */
504void rc_strlist_free (char **list);
505
506#endif 507#endif

Legend:
Removed from v.2979  
changed lines
  Added in v.2980

  ViewVC Help
Powered by ViewVC 1.1.20