2016-04-22 02:27:49 +00:00
|
|
|
---
|
|
|
|
multipathd/main.c | 38 +++++++++++++++++++++++++++++---------
|
|
|
|
1 file changed, 29 insertions(+), 9 deletions(-)
|
|
|
|
|
|
|
|
Index: multipath-tools-130222/multipathd/main.c
|
|
|
|
===================================================================
|
|
|
|
--- multipath-tools-130222.orig/multipathd/main.c
|
|
|
|
+++ multipath-tools-130222/multipathd/main.c
|
|
|
|
@@ -87,6 +87,7 @@ unsigned int mpath_mx_alloc_len;
|
|
|
|
int logsink;
|
|
|
|
enum daemon_status running_state;
|
|
|
|
pid_t daemon_pid;
|
|
|
|
+pid_t parent_pid = -1;
|
|
|
|
|
|
|
|
static sem_t exit_sem;
|
|
|
|
/*
|
2016-07-22 20:20:02 +00:00
|
|
|
@@ -1705,6 +1706,12 @@ sigusr2 (int sig)
|
2016-04-22 02:27:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
+sigalrm (int sig)
|
|
|
|
+{
|
|
|
|
+ exit(0);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void
|
|
|
|
signal_init(void)
|
|
|
|
{
|
|
|
|
sigset_t set;
|
2016-07-22 20:20:02 +00:00
|
|
|
@@ -1807,6 +1814,9 @@ child (void * param)
|
2016-04-22 02:27:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
running_state = DAEMON_START;
|
|
|
|
+ pid_rc = pidfile_create(DEFAULT_PIDFILE, daemon_pid);
|
|
|
|
+ if (parent_pid > 0)
|
|
|
|
+ kill(parent_pid, SIGALRM);
|
|
|
|
|
|
|
|
condlog(2, "--------start up--------");
|
|
|
|
condlog(2, "read " DEFAULT_CONFIGFILE);
|
2016-07-22 20:20:02 +00:00
|
|
|
@@ -1898,8 +1908,6 @@ child (void * param)
|
2016-04-22 02:27:49 +00:00
|
|
|
}
|
|
|
|
pthread_attr_destroy(&misc_attr);
|
|
|
|
|
|
|
|
- /* Startup complete, create logfile */
|
|
|
|
- pid_rc = pidfile_create(DEFAULT_PIDFILE, daemon_pid);
|
|
|
|
update_timestamp(1);
|
|
|
|
/* Ignore errors, we can live without */
|
|
|
|
|
2016-07-22 20:20:02 +00:00
|
|
|
@@ -1979,7 +1987,10 @@ daemonize(void)
|
2016-04-22 02:27:49 +00:00
|
|
|
{
|
|
|
|
int pid;
|
|
|
|
int dev_null_fd;
|
|
|
|
+ struct sigaction oldsig;
|
|
|
|
|
|
|
|
+ oldsig.sa_handler = signal_set(SIGALRM, sigalrm);
|
|
|
|
+ parent_pid = getpid();
|
|
|
|
if( (pid = fork()) < 0){
|
|
|
|
fprintf(stderr, "Failed first fork : %s\n", strerror(errno));
|
|
|
|
return -1;
|
2016-07-22 20:20:02 +00:00
|
|
|
@@ -1987,10 +1998,13 @@ daemonize(void)
|
2016-04-22 02:27:49 +00:00
|
|
|
else if (pid != 0)
|
|
|
|
return pid;
|
|
|
|
|
|
|
|
+ signal_set(SIGALRM, oldsig.sa_handler);
|
|
|
|
setsid();
|
|
|
|
|
|
|
|
- if ( (pid = fork()) < 0)
|
|
|
|
+ if ( (pid = fork()) < 0) {
|
|
|
|
fprintf(stderr, "Failed second fork : %s\n", strerror(errno));
|
|
|
|
+ goto fail;
|
|
|
|
+ }
|
|
|
|
else if (pid != 0)
|
|
|
|
_exit(0);
|
|
|
|
|
2016-07-22 20:20:02 +00:00
|
|
|
@@ -2001,30 +2015,34 @@ daemonize(void)
|
2016-04-22 02:27:49 +00:00
|
|
|
if (dev_null_fd < 0){
|
|
|
|
fprintf(stderr, "cannot open /dev/null for input & output : %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
- _exit(0);
|
|
|
|
+ goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(STDIN_FILENO);
|
|
|
|
if (dup(dev_null_fd) < 0) {
|
|
|
|
fprintf(stderr, "cannot dup /dev/null to stdin : %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
- _exit(0);
|
|
|
|
+ goto fail;
|
|
|
|
}
|
|
|
|
close(STDOUT_FILENO);
|
|
|
|
if (dup(dev_null_fd) < 0) {
|
|
|
|
fprintf(stderr, "cannot dup /dev/null to stdout : %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
- _exit(0);
|
|
|
|
+ goto fail;
|
|
|
|
}
|
|
|
|
close(STDERR_FILENO);
|
|
|
|
if (dup(dev_null_fd) < 0) {
|
|
|
|
fprintf(stderr, "cannot dup /dev/null to stderr : %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
- _exit(0);
|
|
|
|
+ goto fail;
|
|
|
|
}
|
|
|
|
close(dev_null_fd);
|
|
|
|
daemon_pid = getpid();
|
|
|
|
return 0;
|
|
|
|
+
|
|
|
|
+fail:
|
|
|
|
+ kill(parent_pid, SIGALRM);
|
|
|
|
+ _exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-07-22 20:20:02 +00:00
|
|
|
@@ -2103,10 +2121,12 @@ main (int argc, char *argv[])
|
2016-04-22 02:27:49 +00:00
|
|
|
if (err < 0)
|
|
|
|
/* error */
|
|
|
|
exit(1);
|
|
|
|
- else if (err > 0)
|
|
|
|
+ else if (err > 0) {
|
|
|
|
+ /* wait up to 3 seconds for the child to start */
|
|
|
|
+ sleep(3);
|
|
|
|
/* parent dies */
|
|
|
|
exit(0);
|
|
|
|
- else
|
|
|
|
+ } else
|
|
|
|
/* child lives */
|
|
|
|
return (child(NULL));
|
|
|
|
}
|