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

Contents of /trunk/src/rc.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2582 - (show annotations) (download) (as text)
Thu Apr 12 13:18:52 2007 UTC (11 years, 4 months ago) by uberlord
File MIME type: text/x-chdr
File size: 6909 byte(s)
Style updates
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 void rc_schedule_start_service (const char *service,
48 const char *service_to_start);
49 char **rc_services_scheduled_by (const char *service);
50 void rc_schedule_clear (const char *service);
51 bool rc_wait_service (const char *service);
52 bool rc_get_service_option (const char *service, const char *option,
53 char *value);
54 bool rc_set_service_option (const char *service, const char *option,
55 const char *value);
56 void rc_set_service_daemon (const char *service, const char *exec,
57 const char *name, const char *pidfile,
58 bool started);
59 bool rc_service_started_daemon (const char *service, const char *exec,
60 int indx);
61
62 bool rc_allow_plug (char *service);
63
64 char *rc_get_runlevel (void);
65 void rc_set_runlevel (const char *runlevel);
66 bool rc_runlevel_exists (const char *runlevel);
67 char **rc_get_runlevels (void);
68 bool rc_runlevel_starting (void);
69 bool rc_runlevel_stopping (void);
70 bool rc_service_add (const char *runlevel, const char *service);
71 bool rc_service_delete (const char *runlevel, const char *service);
72 char **rc_services_in_runlevel (const char *runlevel);
73 char **rc_services_in_state (rc_service_state_t state);
74 char **rc_services_scheduled (const char *service);
75
76 /* Find pids based on criteria - free the pointer returned after use */
77 pid_t *rc_find_pids (const char *exec, const char *cmd,
78 uid_t uid, pid_t pid);
79 /* Checks that all daemons started with start-stop-daemon by the service
80 are still running. If so, return false otherwise true.
81 You should check that the service has been started before calling this. */
82 bool rc_service_daemons_crashed (const char *service);
83
84 /* Dependency tree structs and functions. */
85 typedef struct rc_deptype
86 {
87 char *type;
88 char **services;
89 struct rc_deptype *next;
90 } rc_deptype_t;
91
92 typedef struct rc_depinfo
93 {
94 char *service;
95 rc_deptype_t *depends;
96 struct rc_depinfo *next;
97 } rc_depinfo_t;
98
99
100 /* Options for rc_dep_depends and rc_order_services.
101 When changing runlevels, you should use RC_DEP_START and RC_DEP_STOP for
102 the start and stop lists as we tweak the provided services for this. */
103 #define RC_DEP_TRACE 0x01
104 #define RC_DEP_STRICT 0x02
105 #define RC_DEP_START 0x04
106 #define RC_DEP_STOP 0x08
107
108 int rc_update_deptree (bool force);
109 rc_depinfo_t *rc_load_deptree (void);
110 rc_depinfo_t *rc_get_depinfo (rc_depinfo_t *deptree, const char *service);
111 rc_deptype_t *rc_get_deptype (rc_depinfo_t *depinfo, const char *type);
112 char **rc_get_depends (rc_depinfo_t *deptree, char **types,
113 char **services, const char *runlevel, int options);
114 /* List all the services that should be started, in order, the the
115 given runlevel, including sysinit and boot services where
116 approriate.
117 If reboot, shutdown or single are given then we list all the services
118 we that we need to shutdown in order. */
119 char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
120 int options);
121
122 void rc_free_deptree (rc_depinfo_t *deptree);
123
124 /* Plugin handler
125 For each plugin loaded we will call it's _name_hook with the below
126 enum and either the runlevel name or service name. For example
127 int _splash_hook (rc_hook_t hook, const char *name);
128 Plugins are called when rc does something. This does not indicate an
129 end result and the plugin should use the above functions to query things
130 like service status.
131 The service hooks have extra ones - now and done. This is because after
132 start_in we may start other services before we start the service in
133 question. now shows we really will start the service now and done shows
134 when we have done it as may start scheduled services at this point. */
135 typedef enum
136 {
137 rc_hook_runlevel_stop_in = 1,
138 rc_hook_runlevel_stop_out = 4,
139 rc_hook_runlevel_start_in = 5,
140 rc_hook_runlevel_start_out = 8,
141 /* We reserved a few numbers if we need rc_runlevel_stop_now and done */
142 rc_hook_service_stop_in = 101,
143 rc_hook_service_stop_now,
144 rc_hook_service_stop_done,
145 rc_hook_service_stop_out,
146 rc_hook_service_start_in,
147 rc_hook_service_start_now,
148 rc_hook_service_start_done,
149 rc_hook_service_start_out
150 } rc_hook_t;
151
152 /* RC utility functions.
153 Although not directly related to RC in general, they are used by RC
154 itself and the supporting applications. */
155 void *rc_xcalloc (size_t n, size_t size);
156 void *rc_xmalloc (size_t size);
157 void *rc_xrealloc (void *ptr, size_t size);
158 char *rc_xstrdup (const char *str);
159
160 /* Concat paths adding '/' if needed. */
161 char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL;
162
163 bool rc_is_env (const char *variable, const char *value);
164 bool rc_exists (const char *pathname);
165 bool rc_is_file (const char *pathname);
166 bool rc_is_link (const char *pathname);
167 bool rc_is_dir (const char *pathname);
168 bool rc_is_exec (const char *pathname);
169
170 #define RC_LS_INITD 0x01
171 char **rc_ls_dir (char **list, const char *dir, int options);
172
173 bool rc_rm_dir (const char *pathname, bool top);
174
175 /* Config file functions */
176 char **rc_get_list (char **list, const char *file);
177 char **rc_get_config (char **list, const char *file);
178 char *rc_get_config_entry (char **list, const char *entry);
179
180 /* Make an environment list which filters out all unwanted values
181 and loads it up with our RC config */
182 char **rc_filter_env (void);
183 char **rc_config_env (char **env);
184
185 /* Handy functions for dealing with string arrays of char ** */
186 char **rc_strlist_add (char **list, const char *item);
187 char **rc_strlist_addsort (char **list, const char *item);
188 char **rc_strlist_addsortc (char **list, const char *item);
189 char **rc_strlist_addsortu (char **list, const char *item);
190 char **rc_strlist_delete (char **list, const char *item);
191 void rc_strlist_reverse (char **list);
192 void rc_strlist_free (char **list);
193
194 #endif

  ViewVC Help
Powered by ViewVC 1.1.20