Blame SOURCES/0042-UP-fix-signal-handling.patch

38852f
---
38852f
 libmultipath/file.c        |    4 +-
38852f
 libmultipath/lock.c        |    9 ----
38852f
 libmultipath/lock.h        |    1 
38852f
 libmultipath/log_pthread.c |   22 -----------
38852f
 libmultipath/waiter.c      |    2 -
38852f
 multipathd/cli_handlers.c  |    4 +-
38852f
 multipathd/main.c          |   90 ++++++++++++++++++++-------------------------
38852f
 multipathd/main.h          |    3 +
38852f
 multipathd/uxlsnr.c        |   21 +++++++---
38852f
 multipathd/uxlsnr.h        |    3 +
38852f
 10 files changed, 65 insertions(+), 94 deletions(-)
38852f
38852f
Index: multipath-tools-130222/libmultipath/file.c
38852f
===================================================================
38852f
--- multipath-tools-130222.orig/libmultipath/file.c
38852f
+++ multipath-tools-130222/libmultipath/file.c
38852f
@@ -98,7 +98,7 @@ lock_file(int fd, char *file_name)
38852f
 	sigaddset(&set, SIGALRM);
38852f
 
38852f
 	sigaction(SIGALRM, &act, &oldact);
38852f
-	sigprocmask(SIG_UNBLOCK, &set, &oldset);
38852f
+	pthread_sigmask(SIG_UNBLOCK, &set, &oldset);
38852f
 
38852f
 	alarm(FILE_TIMEOUT);
38852f
 	err = fcntl(fd, F_SETLKW, &lock);
38852f
@@ -112,7 +112,7 @@ lock_file(int fd, char *file_name)
38852f
 			condlog(0, "%s is locked. Giving up.", file_name);
38852f
 	}
38852f
 
38852f
-	sigprocmask(SIG_SETMASK, &oldset, NULL);
38852f
+	pthread_sigmask(SIG_SETMASK, &oldset, NULL);
38852f
 	sigaction(SIGALRM, &oldact, NULL);
38852f
 	return err;
38852f
 }
38852f
Index: multipath-tools-130222/libmultipath/lock.c
38852f
===================================================================
38852f
--- multipath-tools-130222.orig/libmultipath/lock.c
38852f
+++ multipath-tools-130222/libmultipath/lock.c
38852f
@@ -1,16 +1,7 @@
38852f
 #include <pthread.h>
38852f
-#include <signal.h>
38852f
 #include "lock.h"
38852f
 #include <stdio.h>
38852f
 
38852f
-void block_signal (int signum, sigset_t *old)
38852f
-{
38852f
-	sigset_t set;
38852f
-	sigemptyset(&set);
38852f
-	sigaddset(&set, signum);
38852f
-	pthread_sigmask(SIG_BLOCK, &set, old);
38852f
-}
38852f
-
38852f
 void cleanup_lock (void * data)
38852f
 {
38852f
 	unlock ((*(struct mutex_lock *)data));
38852f
Index: multipath-tools-130222/libmultipath/lock.h
38852f
===================================================================
38852f
--- multipath-tools-130222.orig/libmultipath/lock.h
38852f
+++ multipath-tools-130222/libmultipath/lock.h
38852f
@@ -29,6 +29,5 @@ struct mutex_lock {
38852f
 #endif
38852f
 
38852f
 void cleanup_lock (void * data);
38852f
-void block_signal(int signum, sigset_t *old);
38852f
 
38852f
 #endif /* _LOCK_H */
38852f
Index: multipath-tools-130222/libmultipath/log_pthread.c
38852f
===================================================================
38852f
--- multipath-tools-130222.orig/libmultipath/log_pthread.c
38852f
+++ multipath-tools-130222/libmultipath/log_pthread.c
38852f
@@ -22,26 +22,13 @@ pthread_cond_t logev_cond;
38852f
 
38852f
 int logq_running;
38852f
 
38852f
-static void
38852f
-sigusr1 (int sig)
38852f
-{
38852f
-	pthread_mutex_lock(&logq_lock);
38852f
-	log_reset("multipathd");
38852f
-	pthread_mutex_unlock(&logq_lock);
38852f
-}
38852f
-
38852f
 void log_safe (int prio, const char * fmt, va_list ap)
38852f
 {
38852f
-	sigset_t old;
38852f
-
38852f
 	if (log_thr == (pthread_t)0) {
38852f
 		syslog(prio, fmt, ap);
38852f
 		return;
38852f
 	}
38852f
 
38852f
-	block_signal(SIGUSR1, &old;;
38852f
-	block_signal(SIGHUP, NULL);
38852f
-
38852f
 	pthread_mutex_lock(&logq_lock);
38852f
 	log_enqueue(prio, fmt, ap);
38852f
 	pthread_mutex_unlock(&logq_lock);
38852f
@@ -49,8 +36,6 @@ void log_safe (int prio, const char * fm
38852f
 	pthread_mutex_lock(&logev_lock);
38852f
 	pthread_cond_signal(&logev_cond);
38852f
 	pthread_mutex_unlock(&logev_lock);
38852f
-
38852f
-	pthread_sigmask(SIG_SETMASK, &old, NULL);
38852f
 }
38852f
 
38852f
 void log_thread_flush (void)
38852f
@@ -81,15 +66,8 @@ static void flush_logqueue (void)
38852f
 
38852f
 static void * log_thread (void * et)
38852f
 {
38852f
-	struct sigaction sig;
38852f
 	int running;
38852f
 
38852f
-	sig.sa_handler = sigusr1;
38852f
-	sigemptyset(&sig.sa_mask);
38852f
-	sig.sa_flags = 0;
38852f
-	if (sigaction(SIGUSR1, &sig, NULL) < 0)
38852f
-		logdbg(stderr, "Cannot set signal handler");
38852f
-
38852f
 	pthread_mutex_lock(&logev_lock);
38852f
 	logq_running = 1;
38852f
 	pthread_mutex_unlock(&logev_lock);
38852f
Index: multipath-tools-130222/libmultipath/waiter.c
38852f
===================================================================
38852f
--- multipath-tools-130222.orig/libmultipath/waiter.c
38852f
+++ multipath-tools-130222/libmultipath/waiter.c
38852f
@@ -157,8 +157,6 @@ void *waitevent (void *et)
38852f
 	waiter = (struct event_thread *)et;
38852f
 	pthread_cleanup_push(free_waiter, et);
38852f
 
38852f
-	block_signal(SIGUSR1, NULL);
38852f
-	block_signal(SIGHUP, NULL);
38852f
 	while (1) {
38852f
 		r = waiteventloop(waiter);
38852f
 
38852f
Index: multipath-tools-130222/multipathd/cli_handlers.c
38852f
===================================================================
38852f
--- multipath-tools-130222.orig/multipathd/cli_handlers.c
38852f
+++ multipath-tools-130222/multipathd/cli_handlers.c
38852f
@@ -939,8 +939,8 @@ int
38852f
 cli_shutdown (void * v, char ** reply, int * len, void * data)
38852f
 {
38852f
 	condlog(3, "shutdown (operator)");
38852f
-
38852f
-	return exit_daemon(0);
38852f
+	exit_daemon();
38852f
+	return 0;
38852f
 }
38852f
 
38852f
 int
38852f
Index: multipath-tools-130222/multipathd/main.c
38852f
===================================================================
38852f
--- multipath-tools-130222.orig/multipathd/main.c
38852f
+++ multipath-tools-130222/multipathd/main.c
38852f
@@ -17,6 +17,7 @@
38852f
 #include <limits.h>
38852f
 #include <linux/oom.h>
38852f
 #include <libudev.h>
38852f
+#include <semaphore.h>
38852f
 #include <mpath_persist.h>
38852f
 
38852f
 /*
38852f
@@ -52,6 +53,7 @@
38852f
 #include <wwids.h>
38852f
 #include <pgpolicies.h>
38852f
 #include <uevent.h>
38852f
+#include <log.h>
38852f
 
38852f
 #include "main.h"
38852f
 #include "pidfile.h"
38852f
@@ -81,13 +83,11 @@ struct mpath_event_param
38852f
 
38852f
 unsigned int mpath_mx_alloc_len;
38852f
 
38852f
-pthread_cond_t exit_cond = PTHREAD_COND_INITIALIZER;
38852f
-pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER;
38852f
-
38852f
 int logsink;
38852f
 enum daemon_status running_state;
38852f
 pid_t daemon_pid;
38852f
 
38852f
+static sem_t exit_sem;
38852f
 /*
38852f
  * global copy of vecs for use in sig handlers
38852f
  */
38852f
@@ -838,9 +838,6 @@ out:
38852f
 static void *
38852f
 ueventloop (void * ap)
38852f
 {
38852f
-	block_signal(SIGUSR1, NULL);
38852f
-	block_signal(SIGHUP, NULL);
38852f
-
38852f
 	if (uevent_listen())
38852f
 		condlog(0, "error starting uevent listener");
38852f
 
38852f
@@ -850,9 +847,6 @@ ueventloop (void * ap)
38852f
 static void *
38852f
 uevqloop (void * ap)
38852f
 {
38852f
-	block_signal(SIGUSR1, NULL);
38852f
-	block_signal(SIGHUP, NULL);
38852f
-
38852f
 	if (uevent_dispatch(&uev_trigger, ap))
38852f
 		condlog(0, "error starting uevent dispatcher");
38852f
 
38852f
@@ -861,9 +855,6 @@ uevqloop (void * ap)
38852f
 static void *
38852f
 uxlsnrloop (void * ap)
38852f
 {
38852f
-	block_signal(SIGUSR1, NULL);
38852f
-	block_signal(SIGHUP, NULL);
38852f
-
38852f
 	if (cli_init())
38852f
 		return NULL;
38852f
 
38852f
@@ -913,18 +904,10 @@ uxlsnrloop (void * ap)
38852f
 	return NULL;
38852f
 }
38852f
 
38852f
-int
38852f
-exit_daemon (int status)
38852f
+void
38852f
+exit_daemon (void)
38852f
 {
38852f
-	if (status != 0)
38852f
-		fprintf(stderr, "bad exit status. see daemon.log\n");
38852f
-
38852f
-	if (running_state != DAEMON_SHUTDOWN) {
38852f
-		pthread_mutex_lock(&exit_mutex);
38852f
-		pthread_cond_signal(&exit_cond);
38852f
-		pthread_mutex_unlock(&exit_mutex);
38852f
-	}
38852f
-	return status;
38852f
+	sem_post(&exit_sem);
38852f
 }
38852f
 
38852f
 const char *
38852f
@@ -1287,7 +1270,6 @@ checkerloop (void *ap)
38852f
 	struct path *pp;
38852f
 	int count = 0;
38852f
 	unsigned int i;
38852f
-	sigset_t old;
38852f
 
38852f
 	mlockall(MCL_CURRENT | MCL_FUTURE);
38852f
 	vecs = (struct vectors *)ap;
38852f
@@ -1301,7 +1283,6 @@ checkerloop (void *ap)
38852f
 	}
38852f
 
38852f
 	while (1) {
38852f
-		block_signal(SIGHUP, &old;;
38852f
 		pthread_cleanup_push(cleanup_lock, &vecs->lock);
38852f
 		lock(vecs->lock);
38852f
 		pthread_testcancel();
38852f
@@ -1325,7 +1306,6 @@ checkerloop (void *ap)
38852f
 		}
38852f
 
38852f
 		lock_cleanup_pop(vecs->lock);
38852f
-		pthread_sigmask(SIG_SETMASK, &old, NULL);
38852f
 		sleep(1);
38852f
 	}
38852f
 	return NULL;
38852f
@@ -1485,36 +1465,56 @@ signal_set(int signo, void (*func) (int)
38852f
 		return (osig.sa_handler);
38852f
 }
38852f
 
38852f
+void
38852f
+handle_signals(void)
38852f
+{
38852f
+	if (reconfig_sig && running_state == DAEMON_RUNNING) {
38852f
+		condlog(2, "reconfigure (signal)");
38852f
+		pthread_cleanup_push(cleanup_lock,
38852f
+				&gvecs->lock);
38852f
+		lock(gvecs->lock);
38852f
+		pthread_testcancel();
38852f
+		reconfigure(gvecs);
38852f
+		lock_cleanup_pop(gvecs->lock);
38852f
+	}
38852f
+	if (log_reset_sig) {
38852f
+		condlog(2, "reset log (signal)");
38852f
+		pthread_mutex_lock(&logq_lock);
38852f
+		log_reset("multipathd");
38852f
+		pthread_mutex_unlock(&logq_lock);
38852f
+	}
38852f
+	reconfig_sig = 0;
38852f
+	log_reset_sig = 0;
38852f
+}
38852f
+
38852f
 static void
38852f
 sighup (int sig)
38852f
 {
38852f
-	condlog(2, "reconfigure (SIGHUP)");
38852f
-
38852f
-	if (running_state != DAEMON_RUNNING)
38852f
-		return;
38852f
-
38852f
-	reconfigure(gvecs);
38852f
-
38852f
-#ifdef _DEBUG_
38852f
-	dbg_free_final(NULL);
38852f
-#endif
38852f
+	reconfig_sig = 1;
38852f
 }
38852f
 
38852f
 static void
38852f
 sigend (int sig)
38852f
 {
38852f
-	exit_daemon(0);
38852f
+	exit_daemon();
38852f
 }
38852f
 
38852f
 static void
38852f
 sigusr1 (int sig)
38852f
 {
38852f
-	condlog(3, "SIGUSR1 received");
38852f
+	log_reset_sig = 1;
38852f
 }
38852f
 
38852f
 static void
38852f
 signal_init(void)
38852f
 {
38852f
+	sigset_t set;
38852f
+
38852f
+	sigemptyset(&set);
38852f
+	sigaddset(&set, SIGHUP);
38852f
+	sigaddset(&set, SIGUSR1);
38852f
+	pthread_sigmask(SIG_BLOCK, &set, NULL);
38852f
+
38852f
 	signal_set(SIGHUP, sighup);
38852f
 	signal_set(SIGUSR1, sigusr1);
38852f
 	signal_set(SIGINT, sigend);
38852f
@@ -1587,10 +1587,11 @@ child (void * param)
38852f
 	struct vectors * vecs;
38852f
 	struct multipath * mpp;
38852f
 	int i;
38852f
-	sigset_t set;
38852f
 	int rc, pid_rc;
38852f
 
38852f
 	mlockall(MCL_CURRENT | MCL_FUTURE);
38852f
+	sem_init(&exit_sem, 0, 0);
38852f
+	signal_init();
38852f
 
38852f
 	setup_thread_attr(&misc_attr, 64 * 1024, 1);
38852f
 	setup_thread_attr(&waiter_attr, 32 * 1024, 1);
38852f
@@ -1650,7 +1651,6 @@ child (void * param)
38852f
 	if (!vecs)
38852f
 		exit(1);
38852f
 
38852f
-	signal_init();
38852f
 	setscheduler();
38852f
 	set_oom_adj();
38852f
 
38852f
@@ -1693,25 +1693,17 @@ child (void * param)
38852f
 	}
38852f
 	pthread_attr_destroy(&misc_attr);
38852f
 
38852f
-	pthread_mutex_lock(&exit_mutex);
38852f
 	/* Startup complete, create logfile */
38852f
 	pid_rc = pidfile_create(DEFAULT_PIDFILE, daemon_pid);
38852f
 	/* Ignore errors, we can live without */
38852f
 
38852f
 	running_state = DAEMON_RUNNING;
38852f
-	pthread_cond_wait(&exit_cond, &exit_mutex);
38852f
-	/* Need to block these to avoid deadlocking */
38852f
-	sigemptyset(&set);
38852f
-	sigaddset(&set, SIGTERM);
38852f
-	sigaddset(&set, SIGINT);
38852f
-	pthread_sigmask(SIG_BLOCK, &set, NULL);
38852f
 
38852f
 	/*
38852f
 	 * exit path
38852f
 	 */
38852f
+	while(sem_wait(&exit_sem) != 0); /* Do nothing */
38852f
 	running_state = DAEMON_SHUTDOWN;
38852f
-	pthread_sigmask(SIG_UNBLOCK, &set, NULL);
38852f
-	block_signal(SIGHUP, NULL);
38852f
 	lock(vecs->lock);
38852f
 	if (conf->queue_without_daemon == QUE_NO_DAEMON_OFF)
38852f
 		vector_foreach_slot(vecs->mpvec, mpp, i)
38852f
Index: multipath-tools-130222/multipathd/main.h
38852f
===================================================================
38852f
--- multipath-tools-130222.orig/multipathd/main.h
38852f
+++ multipath-tools-130222/multipathd/main.h
38852f
@@ -16,7 +16,7 @@ struct prin_resp;
38852f
 
38852f
 extern pid_t daemon_pid;
38852f
 
38852f
-int exit_daemon(int);
38852f
+void exit_daemon(void);
38852f
 const char * daemon_status(void);
38852f
 int reconfigure (struct vectors *);
38852f
 int ev_add_path (struct path *, struct vectors *);
38852f
@@ -35,5 +35,6 @@ int mpath_pr_event_handle(struct path *p
38852f
 void * mpath_pr_event_handler_fn (void * );
38852f
 int update_map_pr(struct multipath *mpp);
38852f
 void * mpath_pr_event_handler_fn (void * pathp );
38852f
+void handle_signals(void);
38852f
 
38852f
 #endif /* MAIN_H */
38852f
Index: multipath-tools-130222/multipathd/uxlsnr.c
38852f
===================================================================
38852f
--- multipath-tools-130222.orig/multipathd/uxlsnr.c
38852f
+++ multipath-tools-130222/multipathd/uxlsnr.c
38852f
@@ -8,6 +8,7 @@
38852f
 /*
38852f
  * A simple domain socket listener
38852f
  */
38852f
+#define _GNU_SOURCE
38852f
 #include <stdio.h>
38852f
 #include <stdlib.h>
38852f
 #include <unistd.h>
38852f
@@ -19,20 +20,21 @@
38852f
 #include <sys/socket.h>
38852f
 #include <sys/un.h>
38852f
 #include <sys/poll.h>
38852f
-
38852f
+#include <signal.h>
38852f
 #include <checkers.h>
38852f
-
38852f
 #include <memory.h>
38852f
 #include <debug.h>
38852f
 #include <vector.h>
38852f
 #include <structs.h>
38852f
+#include <structs_vec.h>
38852f
 #include <uxsock.h>
38852f
 #include <defaults.h>
38852f
 
38852f
+#include "main.h"
38852f
 #include "cli.h"
38852f
 #include "uxlsnr.h"
38852f
 
38852f
-#define SLEEP_TIME 5000
38852f
+struct timespec sleep_time = {5, 0};
38852f
 
38852f
 struct client {
38852f
 	int fd;
38852f
@@ -42,6 +44,8 @@ struct client {
38852f
 static struct client *clients;
38852f
 static unsigned num_clients;
38852f
 struct pollfd *polls;
38852f
+volatile sig_atomic_t reconfig_sig = 0;
38852f
+volatile sig_atomic_t log_reset_sig = 0;
38852f
 
38852f
 /*
38852f
  * handle a new client joining
38852f
@@ -104,6 +108,7 @@ void * uxsock_listen(int (*uxsock_trigge
38852f
 	int rlen;
38852f
 	char *inbuf;
38852f
 	char *reply;
38852f
+	sigset_t mask;
38852f
 
38852f
 	ux_sock = ux_socket_listen(DEFAULT_SOCKET);
38852f
 
38852f
@@ -115,7 +120,9 @@ void * uxsock_listen(int (*uxsock_trigge
38852f
 	pthread_cleanup_push(uxsock_cleanup, NULL);
38852f
 
38852f
 	polls = (struct pollfd *)MALLOC(0);
38852f
-
38852f
+	pthread_sigmask(SIG_SETMASK, NULL, &mask);
38852f
+	sigdelset(&mask, SIGHUP);
38852f
+	sigdelset(&mask, SIGUSR1);
38852f
 	while (1) {
38852f
 		struct client *c;
38852f
 		int i, poll_count;
38852f
@@ -132,11 +139,13 @@ void * uxsock_listen(int (*uxsock_trigge
38852f
 		}
38852f
 
38852f
 		/* most of our life is spent in this call */
38852f
-		poll_count = poll(polls, i, SLEEP_TIME);
38852f
+		poll_count = ppoll(polls, i, &sleep_time, &mask);
38852f
 
38852f
 		if (poll_count == -1) {
38852f
-			if (errno == EINTR)
38852f
+			if (errno == EINTR) {
38852f
+				handle_signals();
38852f
 				continue;
38852f
+			}
38852f
 
38852f
 			/* something went badly wrong! */
38852f
 			condlog(0, "poll");
38852f
Index: multipath-tools-130222/multipathd/uxlsnr.h
38852f
===================================================================
38852f
--- multipath-tools-130222.orig/multipathd/uxlsnr.h
38852f
+++ multipath-tools-130222/multipathd/uxlsnr.h
38852f
@@ -4,5 +4,8 @@
38852f
 void * uxsock_listen(int (*uxsock_trigger)
38852f
 			(char *, char **, int *, void *),
38852f
 			void * trigger_data);
38852f
+
38852f
+extern volatile sig_atomic_t reconfig_sig;
38852f
+extern volatile sig_atomic_t log_reset_sig;
38852f
 #endif
38852f