/[baselayout]/trunk/src/runscript.c
Gentoo

Diff of /trunk/src/runscript.c

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

Revision 2634 Revision 2638
41static char **providelist = NULL; 41static char **providelist = NULL;
42static char **types = NULL; 42static char **types = NULL;
43static char **restart_services = NULL; 43static char **restart_services = NULL;
44static char **need_services = NULL; 44static char **need_services = NULL;
45static char **env = NULL; 45static char **env = NULL;
46static char *mycmd = NULL;
47static char *myarg1 = NULL;
48static char *myarg2 = NULL;
49static char *tmp = NULL; 46static char *tmp = NULL;
50static char *softlevel = NULL; 47static char *softlevel = NULL;
51static bool sighup = false; 48static bool sighup = false;
52static char *ibsave = NULL; 49static char *ibsave = NULL;
53static bool in_background = false; 50static bool in_background = false;
67{ 64{
68 void *lib_handle = NULL; 65 void *lib_handle = NULL;
69 66
70 lib_handle = dlopen (SELINUX_LIB, RTLD_NOW | RTLD_GLOBAL); 67 lib_handle = dlopen (SELINUX_LIB, RTLD_NOW | RTLD_GLOBAL);
71 if (lib_handle) { 68 if (lib_handle) {
69 /*
72 /* FIXME: the below code generates the warning 70 * FIXME: the below code generates the warning
73 ISO C forbids assignment between function pointer and 'void *' 71 * ISO C forbids assignment between function pointer and 'void *'
74 which sucks ass 72 * which sucks ass
75http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html */ 73 * http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html
74 */
76 selinux_run_init_old = dlsym (lib_handle, "selinux_runscript"); 75 selinux_run_init_old = dlsym (lib_handle, "selinux_runscript");
77 selinux_run_init_new = dlsym (lib_handle, "selinux_runscript2"); 76 selinux_run_init_new = dlsym (lib_handle, "selinux_runscript2");
78 77
79 /* Use new run_init if it rc_exists, else fall back to old */ 78 /* Use new run_init if it rc_exists, else fall back to old */
80 if (selinux_run_init_new) 79 if (selinux_run_init_new)
214 rc_strlist_free (restart_services); 213 rc_strlist_free (restart_services);
215 if (need_services) 214 if (need_services)
216 rc_strlist_free (need_services); 215 rc_strlist_free (need_services);
217 if (tmplist) 216 if (tmplist)
218 rc_strlist_free (tmplist); 217 rc_strlist_free (tmplist);
219 if (mycmd)
220 free (mycmd);
221 if (myarg1)
222 free (myarg1);
223 if (myarg2)
224 free (myarg2);
225 if (ibsave) 218 if (ibsave)
226 free (ibsave); 219 free (ibsave);
227 220
228 if (in_control ()) { 221 if (in_control ()) {
229 if (rc_service_state (applet, rc_service_stopping)) { 222 if (rc_service_state (applet, rc_service_stopping)) {
271 264
272 /* We need to disable our child signal handler now so we block 265 /* We need to disable our child signal handler now so we block
273 until our script returns. */ 266 until our script returns. */
274 signal (SIGCHLD, NULL); 267 signal (SIGCHLD, NULL);
275 268
276 pid = fork(); 269 pid = vfork();
277 270
278 if (pid == -1) 271 if (pid == -1)
279 eerrorx ("%s: fork: %s", service, strerror (errno)); 272 eerrorx ("%s: vfork: %s", service, strerror (errno));
280 if (pid == 0) { 273 if (pid == 0) {
281 mycmd = rc_xstrdup (service);
282 myarg1 = rc_xstrdup (arg1);
283 if (arg2)
284 myarg2 = rc_xstrdup (arg2);
285
286 if (rc_exists (RC_SVCDIR "runscript.sh")) { 274 if (rc_exists (RC_SVCDIR "runscript.sh")) {
287 execl (RC_SVCDIR "runscript.sh", mycmd, mycmd, myarg1, myarg2, 275 execl (RC_SVCDIR "runscript.sh", service, service, arg1, arg2,
288 (char *) NULL); 276 (char *) NULL);
289 eerrorx ("%s: exec `" RC_SVCDIR "runscript.sh': %s", 277 eerror ("%s: exec `" RC_SVCDIR "runscript.sh': %s",
290 service, strerror (errno)); 278 service, strerror (errno));
279 _exit (EXIT_FAILURE);
291 } else { 280 } else {
292 execl (RC_LIBDIR "sh/runscript.sh", mycmd, mycmd, myarg1, myarg2, 281 execl (RC_LIBDIR "sh/runscript.sh", service, service, arg1, arg2,
293 (char *) NULL); 282 (char *) NULL);
294 eerrorx ("%s: exec `" RC_LIBDIR "sh/runscript.sh': %s", 283 eerror ("%s: exec `" RC_LIBDIR "sh/runscript.sh': %s",
295 service, strerror (errno)); 284 service, strerror (errno));
285 _exit (EXIT_FAILURE);
296 } 286 }
297 } 287 }
298 288
299 do { 289 do {
300 if (waitpid (pid, &status, 0) < 0) { 290 if (waitpid (pid, &status, 0) < 0) {

Legend:
Removed from v.2634  
changed lines
  Added in v.2638

  ViewVC Help
Powered by ViewVC 1.1.20