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

Diff of /trunk/src/runscript.c

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

Revision 2657 Revision 2659
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
36static char *applet = NULL; 38static char *applet = NULL;
37static char *exclusive = NULL; 39static char *exclusive = NULL;
38static char *mtime_test = NULL; 40static char *mtime_test = NULL;
39static rc_depinfo_t *deptree = NULL; 41static rc_depinfo_t *deptree = NULL;
51static char *ibsave = NULL; 53static char *ibsave = NULL;
52static bool in_background = false; 54static bool in_background = false;
53static rc_hook_t hook_out = 0; 55static rc_hook_t hook_out = 0;
54static pid_t service_pid = 0; 56static pid_t service_pid = 0;
55static char *prefix = NULL; 57static char *prefix = NULL;
56 58static bool prefix_locked = false;
57/* Pipes for prefixed output */
58 59
59extern char **environ; 60extern char **environ;
60 61
61#ifdef __linux__ 62#ifdef __linux__
62static void (*selinux_run_init_old) (void); 63static void (*selinux_run_init_old) (void);
201 free (cold); 202 free (cold);
202} 203}
203 204
204static void cleanup (void) 205static 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]);

Legend:
Removed from v.2657  
changed lines
  Added in v.2659

  ViewVC Help
Powered by ViewVC 1.1.20