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

Contents of /trunk/src/rc.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2569 - (show annotations) (download) (as text)
Tue Apr 10 11:24:58 2007 UTC (11 years, 6 months ago) by uberlord
File MIME type: text/x-chdr
File size: 6535 byte(s)
Fix indentation
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 typedef enum
132 {
133 rc_hook_runlevel_stop_in = 1,
134 rc_hook_runlevel_stop_out,
135 rc_hook_runlevel_start_in,
136 rc_hook_runlevel_start_out,
137 rc_hook_service_stop_in,
138 rc_hook_service_stop_out,
139 rc_hook_service_start_in,
140 rc_hook_service_start_out
141 } rc_hook_t;
142
143 /* RC utility functions.
144 Although not directly related to RC in general, they are used by RC
145 itself and the supporting applications. */
146 void *rc_xcalloc (size_t n, size_t size);
147 void *rc_xmalloc (size_t size);
148 void *rc_xrealloc (void *ptr, size_t size);
149 char *rc_xstrdup (const char *str);
150
151 /* Concat paths adding '/' if needed. */
152 char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL;
153
154 bool rc_is_env (const char *variable, const char *value);
155 bool rc_exists (const char *pathname);
156 bool rc_is_file (const char *pathname);
157 bool rc_is_link (const char *pathname);
158 bool rc_is_dir (const char *pathname);
159 bool rc_is_exec (const char *pathname);
160
161 #define RC_LS_INITD 0x01
162 char **rc_ls_dir (char **list, const char *dir, int options);
163
164 bool rc_rm_dir (const char *pathname, bool top);
165
166 /* Config file functions */
167 char **rc_get_list (char **list, const char *file);
168 char **rc_get_config (char **list, const char *file);
169 char *rc_get_config_entry (char **list, const char *entry);
170
171 /* Make an environment list which filters out all unwanted values
172 and loads it up with our RC config */
173 char **rc_filter_env (void);
174 char **rc_config_env (char **env);
175
176 /* Handy functions for dealing with string arrays of char ** */
177 char **rc_strlist_add (char **list, const char *item);
178 char **rc_strlist_addsort (char **list, const char *item);
179 char **rc_strlist_addsortc (char **list, const char *item);
180 char **rc_strlist_delete (char **list, const char *item);
181 void rc_strlist_reverse (char **list);
182 void rc_strlist_free (char **list);
183
184 #endif

  ViewVC Help
Powered by ViewVC 1.1.20