rc.h

Go to the documentation of this file.
00001 
00010 #ifndef __RC_H__
00011 #define __RC_H__
00012 
00013 #ifdef __GNUC__
00014 #  define GCC_VERSION (__GNUC__ * 1000 + __GNUC__MINOR)
00015 #  if (GCC_VERSION >= 3005)
00016 #    define SENTINEL __attribute__ ((__sentinel__))
00017 #  endif
00018 #endif
00019 #ifndef SENTINEL
00020 #  define SENTINEL
00021 #endif
00022 
00023 #include <sys/types.h>
00024 #include <stdbool.h>
00025 #include <stdio.h>
00026 
00028 #define RC_LEVEL_SYSINIT    "sysinit"
00029 #define RC_LEVEL_SINGLE     "single"
00030 #define RC_LEVEL_SHUTDOWN   "shutdown"
00031 #define RC_LEVEL_REBOOT     "reboot"
00032 
00035 #define RC_LS_INITD     0x01
00036 
00043 typedef enum
00044 {
00045         rc_service_started,
00046         rc_service_stopped,
00047         rc_service_starting,
00048         rc_service_stopping,
00049         rc_service_inactive,
00050         rc_service_wasinactive,
00051         rc_service_coldplugged,
00052         rc_service_failed,
00053         rc_service_scheduled,
00054         rc_service_crashed
00055 } rc_service_state_t;
00056 
00060 char *rc_resolve_service (const char *service);
00064 bool rc_service_exists (const char *service);
00065 
00069 char **rc_service_options (const char *service);
00070 
00075 char *rc_service_description (const char *service, const char *option);
00076 
00081 bool rc_service_in_runlevel (const char *service, const char *runlevel);
00082 
00087 bool rc_service_state (const char *service, rc_service_state_t state);
00088 
00093 bool rc_mark_service (const char *service, rc_service_state_t state);
00094 
00098 pid_t rc_stop_service (const char *service);
00099 
00103 pid_t rc_start_service (const char *service);
00104 
00108 int rc_waitpid (pid_t pid); 
00109 
00113 void rc_schedule_start_service (const char *service,
00114                                                                 const char *service_to_start);
00119 char **rc_services_scheduled_by (const char *service);
00120 
00123 void rc_schedule_clear (const char *service);
00124 
00128 bool rc_wait_service (const char *service);
00129 
00134 char *rc_get_service_option (const char *service, const char *option);
00140 bool rc_set_service_option (const char *service, const char *option,
00141                                                         const char *value);
00148 void rc_set_service_daemon (const char *service, const char *exec,
00149                                                         const char *name, const char *pidfile,
00150                                                         bool started);
00156 bool rc_service_started_daemon (const char *service, const char *exec,
00157                                                                 int indx);
00158 
00162 bool rc_allow_plug (char *service);
00163 
00166 char *rc_get_runlevel (void);
00170 void rc_set_runlevel (const char *runlevel);
00171 
00175 bool rc_runlevel_exists (const char *runlevel);
00176 
00179 char **rc_get_runlevels (void);
00180 
00183 bool rc_runlevel_starting (void);
00186 bool rc_runlevel_stopping (void);
00187 
00192 bool rc_service_add (const char *runlevel, const char *service);
00197 bool rc_service_delete (const char *runlevel, const char *service);
00201 char **rc_services_in_runlevel (const char *runlevel);
00205 char **rc_services_in_state (rc_service_state_t state);
00209 char **rc_services_scheduled (const char *service);
00210 
00220 pid_t *rc_find_pids (const char *exec, const char *cmd,
00221                                          uid_t uid, pid_t pid);
00226 bool rc_service_daemons_crashed (const char *service);
00227 
00232 #define RC_DEP_TRACE    0x01
00233 
00234 #define RC_DEP_STRICT   0x02
00235 
00236 #define RC_DEP_START    0x04
00237 
00238 #define RC_DEP_STOP     0x08
00239 
00245 typedef struct rc_deptype
00246 {
00248         char *type;
00250         char **services;
00252         struct rc_deptype *next;
00253 } rc_deptype_t;
00254 
00256 typedef struct rc_depinfo
00257 {
00259         char *service;
00261         rc_deptype_t *depends;
00263         struct rc_depinfo *next;
00264 } rc_depinfo_t;
00265 
00271 int rc_update_deptree (bool force);
00275 rc_depinfo_t *rc_load_deptree (void);
00280 rc_depinfo_t *rc_get_depinfo (rc_depinfo_t *deptree, const char *service);
00285 rc_deptype_t *rc_get_deptype (rc_depinfo_t *depinfo, const char *type);
00286 char **rc_get_depends (rc_depinfo_t *deptree, char **types,
00287                                            char **services, const char *runlevel, int options);
00295 char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
00296                                                   int options);
00299 void rc_free_deptree (rc_depinfo_t *deptree);
00300 
00314 typedef enum
00315 {
00316         rc_hook_runlevel_stop_in = 1,
00317         rc_hook_runlevel_stop_out = 4,
00318         rc_hook_runlevel_start_in = 5,
00319         rc_hook_runlevel_start_out = 8,
00322         rc_hook_abort = 99,
00323         rc_hook_service_stop_in = 101,
00324         rc_hook_service_stop_now,
00325         rc_hook_service_stop_done,
00326         rc_hook_service_stop_out,
00327         rc_hook_service_start_in,
00328         rc_hook_service_start_now,
00329         rc_hook_service_start_done,
00330         rc_hook_service_start_out
00331 } rc_hook_t;
00332 
00337 int rc_plugin_hook (rc_hook_t hook, const char *name);
00338 
00341 extern FILE *rc_environ_fd;
00342 
00349 void *rc_xmalloc (size_t size);
00354 void *rc_xrealloc (void *ptr, size_t size);
00358 char *rc_xstrdup (const char *str);
00369 char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL;
00374 bool rc_is_env (const char *variable, const char *value);
00378 bool rc_exists (const char *pathname);
00382 bool rc_is_file (const char *pathname);
00386 bool rc_is_link (const char *pathname);
00390 bool rc_is_dir (const char *pathname);
00394 bool rc_is_exec (const char *pathname);
00395 
00400 char **rc_ls_dir (const char *dir, int options);
00401 
00406 bool rc_rm_dir (const char *pathname, bool top);
00407 
00410 char **rc_get_list (const char *file);
00412 char **rc_get_config (const char *file);
00414 char *rc_get_config_entry (char **list, const char *entry);
00415 
00418 char **rc_filter_env (void);
00421 char **rc_make_env (void);
00422 
00432 char *rc_strlist_add (char ***list, const char *item);
00438 char *rc_strlist_addu (char ***list, const char *item);
00444 char *rc_strlist_addsort (char ***list, const char *item);
00450 char *rc_strlist_addsortc (char ***list, const char *item);
00456 char *rc_strlist_addsortu (char ***list, const char *item);
00461 int rc_strlist_delete (char ***list, const char *item);
00467 char *rc_strlist_join (char ***list1, char **list2);
00470 void rc_strlist_reverse (char **list);
00473 void rc_strlist_free (char **list);
00474 
00475 #endif

Generated on Tue Sep 25 16:24:20 2007 for rc by  doxygen 1.5.3