Silence get_pid(), OpenRC will give the process some time to create the PID file and the first get__pid() call may fail.

This commit is contained in:
Christian Ruppert 2012-09-12 21:00:20 +02:00
parent 3863c11be5
commit a06072b395
2 changed files with 9 additions and 7 deletions

View File

@ -38,7 +38,7 @@
"Disable color output", \ "Disable color output", \
"Display software version", \ "Display software version", \
"Run verbosely", \ "Run verbosely", \
"Run quietly" "Run quietly (Does not affect errors)"
#define case_RC_COMMON_getopt_case_C setenv ("EINFO_COLOR", "NO", 1); #define case_RC_COMMON_getopt_case_C setenv ("EINFO_COLOR", "NO", 1);
#define case_RC_COMMON_getopt_case_h usage (EXIT_SUCCESS); #define case_RC_COMMON_getopt_case_h usage (EXIT_SUCCESS);

View File

@ -305,7 +305,7 @@ parse_schedule(const char *string, int timeout)
} }
static pid_t static pid_t
get_pid(const char *pidfile) get_pid(const char *pidfile, bool quiet)
{ {
FILE *fp; FILE *fp;
pid_t pid; pid_t pid;
@ -314,12 +314,14 @@ get_pid(const char *pidfile)
return -1; return -1;
if ((fp = fopen(pidfile, "r")) == NULL) { if ((fp = fopen(pidfile, "r")) == NULL) {
eerror("%s: fopen `%s': %s", applet, pidfile, strerror(errno)); if(!quiet)
eerror("%s: fopen `%s': %s", applet, pidfile, strerror(errno));
return -1; return -1;
} }
if (fscanf(fp, "%d", &pid) != 1) { if (fscanf(fp, "%d", &pid) != 1) {
eerror("%s: no pid found in `%s'", applet, pidfile); if(!quiet)
eerror("%s: no pid found in `%s'", applet, pidfile);
fclose(fp); fclose(fp);
return -1; return -1;
} }
@ -413,7 +415,7 @@ run_stop_schedule(const char *exec, const char *const *argv,
} }
if (pidfile) { if (pidfile) {
pid = get_pid(pidfile); pid = get_pid(pidfile, false);
if (pid == -1) if (pid == -1)
return 0; return 0;
} }
@ -1079,7 +1081,7 @@ start_stop_daemon(int argc, char **argv)
} }
if (pidfile) if (pidfile)
pid = get_pid(pidfile); pid = get_pid(pidfile, false);
else else
pid = 0; pid = 0;
@ -1352,7 +1354,7 @@ start_stop_daemon(int argc, char **argv)
alive = true; alive = true;
} else { } else {
if (pidfile) { if (pidfile) {
pid = get_pid(pidfile); pid = get_pid(pidfile, true);
if (pid == -1) { if (pid == -1) {
eerrorx("%s: did not " eerrorx("%s: did not "
"create a valid" "create a valid"