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

Diff of /trunk/src/runscript.c

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

Revision 3048 Revision 3049
11#include <sys/select.h> 11#include <sys/select.h>
12#include <sys/types.h> 12#include <sys/types.h>
13#include <sys/ioctl.h> 13#include <sys/ioctl.h>
14#include <sys/param.h> 14#include <sys/param.h>
15#include <sys/stat.h> 15#include <sys/stat.h>
16#include <sys/wait.h>
17#include <dlfcn.h> 16#include <dlfcn.h>
18#include <errno.h> 17#include <errno.h>
19#include <fcntl.h> 18#include <fcntl.h>
20#include <getopt.h> 19#include <getopt.h>
21#include <libgen.h> 20#include <libgen.h>
130 129
131 case SIGCHLD: 130 case SIGCHLD:
132 if (signal_pipe[1] > -1) { 131 if (signal_pipe[1] > -1) {
133 if (write (signal_pipe[1], &sig, sizeof (sig)) == -1) 132 if (write (signal_pipe[1], &sig, sizeof (sig)) == -1)
134 eerror ("%s: send: %s", service, strerror (errno)); 133 eerror ("%s: send: %s", service, strerror (errno));
135 } else { 134 } else
136 wait (0); 135 rc_waitpid (-1);
137 }
138 break; 136 break;
139 137
140 case SIGWINCH: 138 case SIGWINCH:
141 if (master_tty >= 0) { 139 if (master_tty >= 0) {
142 ioctl (fileno (stdout), TIOCGWINSZ, &ws); 140 ioctl (fileno (stdout), TIOCGWINSZ, &ws);
354 } 352 }
355 353
356 return (ret); 354 return (ret);
357} 355}
358 356
359static int wait_pid (pid_t pid)
360{
361 int status = 0;
362 pid_t savedpid = pid;
363 int retval = -1;
364
365 errno = 0;
366 while ((pid = waitpid (savedpid, &status, 0)) > 0) {
367 if (pid == savedpid)
368 retval = WIFEXITED (status) ? WEXITSTATUS (status) : EXIT_FAILURE;
369 }
370
371 return (retval);
372}
373
374static bool svc_exec (const char *arg1, const char *arg2) 357static bool svc_exec (const char *arg1, const char *arg2)
375{ 358{
376 bool execok; 359 bool execok;
377 int fdout = fileno (stdout); 360 int fdout = fileno (stdout);
378 struct termios tt; 361 struct termios tt;
417 if (slave_tty >= 0) { 400 if (slave_tty >= 0) {
418 /* Hmmm, this shouldn't work in a vfork, but it does which is 401 /* Hmmm, this shouldn't work in a vfork, but it does which is
419 * good for us */ 402 * good for us */
420 close (master_tty); 403 close (master_tty);
421 404
422 dup2 (fileno (stdin), 0);
423 dup2 (slave_tty, 1); 405 dup2 (slave_tty, 1);
424 dup2 (slave_tty, 2); 406 dup2 (slave_tty, 2);
425 if (slave_tty > 2) 407 if (slave_tty > 2)
426 close (slave_tty); 408 close (slave_tty);
427 } 409 }
455 break; 437 break;
456 } 438 }
457 } 439 }
458 440
459 if (s > 0) { 441 if (s > 0) {
460 /* Only SIGCHLD signals come down this pipe */
461 if (FD_ISSET (signal_pipe[0], &rset))
462 break;
463
464 if (master_tty >= 0 && FD_ISSET (master_tty, &rset)) { 442 if (master_tty >= 0 && FD_ISSET (master_tty, &rset)) {
465 bytes = read (master_tty, buffer, RC_LINEBUFFER); 443 bytes = read (master_tty, buffer, RC_LINEBUFFER);
466 write_prefix (buffer, bytes, &prefixed); 444 write_prefix (buffer, bytes, &prefixed);
467 } 445 }
446
447 /* Only SIGCHLD signals come down this pipe */
448 if (FD_ISSET (signal_pipe[0], &rset))
449 break;
468 } 450 }
469 } 451 }
470 452
471 free (buffer); 453 free (buffer);
472 close (signal_pipe[0]); 454 close (signal_pipe[0]);
477 signal (SIGWINCH, SIG_IGN); 459 signal (SIGWINCH, SIG_IGN);
478 close (master_tty); 460 close (master_tty);
479 master_tty = -1; 461 master_tty = -1;
480 } 462 }
481 463
482 execok = wait_pid (service_pid) == 0 ? true : false; 464 execok = rc_waitpid (service_pid) == 0 ? true : false;
483 service_pid = 0; 465 service_pid = 0;
484 466
485 return (execok); 467 return (execok);
486} 468}
487 469
648 if (! rc_runlevel_starting ()) { 630 if (! rc_runlevel_starting ()) {
649 STRLIST_FOREACH (use_services, svc, i) 631 STRLIST_FOREACH (use_services, svc, i)
650 if (rc_service_state (svc) & RC_SERVICE_STOPPED) { 632 if (rc_service_state (svc) & RC_SERVICE_STOPPED) {
651 pid_t pid = rc_service_start (svc); 633 pid_t pid = rc_service_start (svc);
652 if (! rc_env_bool ("RC_PARALLEL")) 634 if (! rc_env_bool ("RC_PARALLEL"))
653 wait_pid (pid); 635 rc_waitpid (pid);
654 } 636 }
655 } 637 }
656 638
657 /* Now wait for them to start */ 639 /* Now wait for them to start */
658 services = rc_deptree_depends (deptree, types_nua, svcl, 640 services = rc_deptree_depends (deptree, types_nua, svcl,
855 if (svcs & RC_SERVICE_STARTED || 837 if (svcs & RC_SERVICE_STARTED ||
856 svcs & RC_SERVICE_INACTIVE) 838 svcs & RC_SERVICE_INACTIVE)
857 { 839 {
858 pid_t pid = rc_service_stop (svc); 840 pid_t pid = rc_service_stop (svc);
859 if (! rc_env_bool ("RC_PARALLEL")) 841 if (! rc_env_bool ("RC_PARALLEL"))
860 wait_pid (pid); 842 rc_waitpid (pid);
861 rc_strlist_add (&tmplist, svc); 843 rc_strlist_add (&tmplist, svc);
862 } 844 }
863 } 845 }
864 } 846 }
865 rc_strlist_free (services); 847 rc_strlist_free (services);

Legend:
Removed from v.3048  
changed lines
  Added in v.3049

  ViewVC Help
Powered by ViewVC 1.1.20