| … | |
… | |
| 30 | #include "rc-plugin.h" |
30 | #include "rc-plugin.h" |
| 31 | #include "strlist.h" |
31 | #include "strlist.h" |
| 32 | |
32 | |
| 33 | #define RCSCRIPT_HELP RC_LIBDIR "/sh/rc-help.sh" |
33 | #define RCSCRIPT_HELP RC_LIBDIR "/sh/rc-help.sh" |
| 34 | #define SELINUX_LIB RC_LIBDIR "/runscript_selinux.so" |
34 | #define SELINUX_LIB RC_LIBDIR "/runscript_selinux.so" |
|
|
35 | |
|
|
36 | #define PREFIX_LOCK RC_SVCDIR "/prefix.lock" |
| 35 | |
37 | |
| 36 | static char *applet = NULL; |
38 | static char *applet = NULL; |
| 37 | static char *exclusive = NULL; |
39 | static char *exclusive = NULL; |
| 38 | static char *mtime_test = NULL; |
40 | static char *mtime_test = NULL; |
| 39 | static rc_depinfo_t *deptree = NULL; |
41 | static rc_depinfo_t *deptree = NULL; |
| … | |
… | |
| 51 | static char *ibsave = NULL; |
53 | static char *ibsave = NULL; |
| 52 | static bool in_background = false; |
54 | static bool in_background = false; |
| 53 | static rc_hook_t hook_out = 0; |
55 | static rc_hook_t hook_out = 0; |
| 54 | static pid_t service_pid = 0; |
56 | static pid_t service_pid = 0; |
| 55 | static char *prefix = NULL; |
57 | static char *prefix = NULL; |
| 56 | |
58 | static bool prefix_locked = false; |
| 57 | /* Pipes for prefixed output */ |
|
|
| 58 | |
59 | |
| 59 | extern char **environ; |
60 | extern char **environ; |
| 60 | |
61 | |
| 61 | #ifdef __linux__ |
62 | #ifdef __linux__ |
| 62 | static void (*selinux_run_init_old) (void); |
63 | static void (*selinux_run_init_old) (void); |
| … | |
… | |
| 201 | free (cold); |
202 | free (cold); |
| 202 | } |
203 | } |
| 203 | |
204 | |
| 204 | static void cleanup (void) |
205 | static void cleanup (void) |
| 205 | { |
206 | { |
|
|
207 | if (prefix_locked) |
|
|
208 | unlink (PREFIX_LOCK); |
|
|
209 | |
| 206 | /* Flush our buffered output if any */ |
210 | /* Flush our buffered output if any */ |
| 207 | eclose (); |
211 | eclose (); |
| 208 | |
212 | |
| 209 | if (hook_out) |
213 | if (hook_out) |
| 210 | rc_plugin_run (hook_out, applet); |
214 | rc_plugin_run (hook_out, applet); |
| … | |
… | |
| 379 | break; |
383 | break; |
| 380 | } |
384 | } |
| 381 | } else if (retval) { |
385 | } else if (retval) { |
| 382 | ssize_t nr; |
386 | ssize_t nr; |
| 383 | |
387 | |
|
|
388 | /* Wait until we get a lock */ |
|
|
389 | while (true) { |
|
|
390 | struct timeval tv; |
|
|
391 | |
|
|
392 | if (mkfifo (PREFIX_LOCK, 0700) == 0) { |
|
|
393 | prefix_locked = true; |
|
|
394 | break; |
|
|
395 | } |
|
|
396 | |
|
|
397 | if (errno != EEXIST) |
|
|
398 | eerror ("mkfifo `%s': %s\n", PREFIX_LOCK, strerror (errno)); |
|
|
399 | tv.tv_sec = 0; |
|
|
400 | tv.tv_usec = 20000; |
|
|
401 | select (0, NULL, NULL, NULL, &tv); |
|
|
402 | } |
|
|
403 | |
| 384 | if (FD_ISSET (stdout_pipes[0], &fds)) { |
404 | if (FD_ISSET (stdout_pipes[0], &fds)) { |
| 385 | if ((nr = read (stdout_pipes[0], buffer, |
405 | if ((nr = read (stdout_pipes[0], buffer, |
| 386 | sizeof (buffer))) <= 0) |
406 | sizeof (buffer))) <= 0) |
| 387 | stdout_done = true; |
407 | stdout_done = true; |
| 388 | else |
408 | else |
| … | |
… | |
| 396 | stderr_done = true; |
416 | stderr_done = true; |
| 397 | else |
417 | else |
| 398 | write_prefix (fileno (stderr), buffer, nr, |
418 | write_prefix (fileno (stderr), buffer, nr, |
| 399 | &stderr_prefix_shown); |
419 | &stderr_prefix_shown); |
| 400 | } |
420 | } |
|
|
421 | |
|
|
422 | /* Clear the lock */ |
|
|
423 | unlink (PREFIX_LOCK); |
|
|
424 | prefix_locked = false; |
| 401 | } |
425 | } |
| 402 | } |
426 | } |
| 403 | |
427 | |
| 404 | /* Done now, so close the pipes */ |
428 | /* Done now, so close the pipes */ |
| 405 | close(stdout_pipes[0]); |
429 | close(stdout_pipes[0]); |