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