Blame SOURCES/0150-RHBZ-1253913-fix-startup-msg.patch

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