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

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