/[baselayout]/trunk/src/start-stop-daemon.c
Gentoo

Diff of /trunk/src/start-stop-daemon.c

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

Revision 2676 Revision 2698
498 { "exec", 1, NULL, 'x'}, 498 { "exec", 1, NULL, 'x'},
499 { "stdout", 1, NULL, '1'}, 499 { "stdout", 1, NULL, '1'},
500 { "stderr", 1, NULL, '2'}, 500 { "stderr", 1, NULL, '2'},
501 { NULL, 0, NULL, 0} 501 { NULL, 0, NULL, 0}
502 }; 502 };
503 int c; 503 int opt;
504 bool start = false; 504 bool start = false;
505 bool stop = false; 505 bool stop = false;
506 bool oknodo = false; 506 bool oknodo = false;
507 bool test = false; 507 bool test = false;
508 bool quiet = false; 508 bool quiet = false;
539 539
540 if ((env = getenv ("SSD_NICELEVEL"))) 540 if ((env = getenv ("SSD_NICELEVEL")))
541 if (sscanf (env, "%d", &nicelevel) != 1) 541 if (sscanf (env, "%d", &nicelevel) != 1)
542 eerror ("%s: invalid nice level `%s' (SSD_NICELEVEL)", progname, env); 542 eerror ("%s: invalid nice level `%s' (SSD_NICELEVEL)", progname, env);
543 543
544 while ((c = getopt_long (argc, argv, 544 while ((opt = getopt_long (argc, argv,
545 "KN:R:Sbc:d:g:mn:op:qs:tu:r:vx:1:2:", 545 "KN:R:Sbc:d:g:mn:op:qs:tu:r:vx:1:2:",
546 longopts, (int *) 0)) != -1) 546 longopts, (int *) 0)) != -1)
547 switch (c) { 547 switch (opt) {
548 case 'K': /* --stop */ 548 case 'K': /* --stop */
549 stop = true; 549 stop = true;
550 break; 550 break;
551 551
552 case 'N': /* --nice */ 552 case 'N': /* --nice */
960 /* Wait a little bit and check that process is still running 960 /* Wait a little bit and check that process is still running
961 We do this as some badly written daemons fork and then barf */ 961 We do this as some badly written daemons fork and then barf */
962 if (START_WAIT > 0) { 962 if (START_WAIT > 0) {
963 struct timeval stopat; 963 struct timeval stopat;
964 struct timeval now; 964 struct timeval now;
965 bool retestpid = false;
965 966
966 if (gettimeofday (&stopat, NULL) != 0) 967 if (gettimeofday (&stopat, NULL) != 0)
967 eerrorx ("%s: gettimeofday: %s", progname, strerror (errno)); 968 eerrorx ("%s: gettimeofday: %s", progname, strerror (errno));
968 969
969 stopat.tv_usec += START_WAIT; 970 stopat.tv_usec += START_WAIT;
989 their pidfile a LONG time later. */ 990 their pidfile a LONG time later. */
990 if (background) { 991 if (background) {
991 if (kill (pid, 0) == 0) 992 if (kill (pid, 0) == 0)
992 alive = true; 993 alive = true;
993 } else { 994 } else {
994 if (pidfile && rc_exists (pidfile)) { 995 if (pidfile) {
995 if (do_stop (NULL, NULL, pidfile, uid, 0, true, false, true) > 0) 996 /* The pidfile may not have been written yet - give it some time */
997 if (get_pid (pidfile, true) == -1) {
996 alive = true; 998 alive = true;
999 retestpid = true;
1000 } else {
1001 retestpid = false;
1002 if (do_stop (NULL, NULL, pidfile, uid, 0,
1003 true, false, true) > 0)
1004 alive = true;
1005 }
997 } else { 1006 } else {
998 if (do_stop (exec, cmd, NULL, uid, 0, true, false, true) > 0) 1007 if (do_stop (exec, cmd, NULL, uid, 0, true, false, true)
1008 > 0)
999 alive = true; 1009 alive = true;
1000 } 1010 }
1001 } 1011 }
1002 1012
1003 if (! alive) 1013 if (! alive)
1004 eerrorx ("%s: %s died", progname, exec); 1014 eerrorx ("%s: %s died", progname, exec);
1005 1015
1006 if (timercmp (&now, &stopat, >)) 1016 if (timercmp (&now, &stopat, >))
1007 break; 1017 break;
1008 } 1018 }
1019
1020 if (retestpid) {
1021 if (do_stop (NULL, NULL, pidfile, uid, 0, true,
1022 false, true) < 1)
1023 eerrorx ("%s: %s died", progname, exec);
1024 }
1009 } 1025 }
1010 1026
1011 if (svcname) 1027 if (svcname)
1012 rc_set_service_daemon (svcname, exec, cmd, pidfile, true); 1028 rc_set_service_daemon (svcname, exec, cmd, pidfile, true);
1013 1029

Legend:
Removed from v.2676  
changed lines
  Added in v.2698

  ViewVC Help
Powered by ViewVC 1.1.20