Add missing includes for remember_wwid
Benjamin Marzinski
maintainerPATCH 1/2 Add missing includes for remember_wwid
My previous commit (0245b3ac6e34dee1ab039bba71806bc35c286ab8) caused a warning on compile, since it didn't include the wwids.h file in main.c
--- multipathd/main.c | 1 + 1 file changed, 1 insertion(+)
multipathd/main.c +1 -0
@@ -60,6 +60,7 @@#include "cli_handlers.h" #include "lock.h" #include "waiter.h" +#include "wwids.h" #define FILE_NAME_SIZE 256#define CMDSIZE 160
Signature · 1 line
1.8.2
Benjamin Marzinski
maintainerPATCH 2/2 simplify multipath signal handlers
This patch changes how multipath's signal handlers work. Instead of having sighup and sigusr1 acquire locks and call functions directly, they now both simply set atomic variables. These two signals are blocked in child(), and all other threads inherit this sigmask. The only place in all the multipath code that doesn't block these signals is now the ppoll() call by the uxlsnr thread. When it is interrupted by a signal, the uxlsnr thread does the actual processing work.
Instead of sigend using mutex locks and condition variables to tell the child() function to exit, it now uses a signal_handler safe semaphore that child() waits on and exit_daemon() increments.
--- libmultipath/lock.c | 9 ----- libmultipath/lock.h | 1 - libmultipath/log_pthread.c | 22 ------------ libmultipath/waiter.c | 2 -- multipathd/cli_handlers.c | 4 +-- multipathd/main.c | 90 +++++++++++++++++++++------------------------- multipathd/main.h | 3 +- multipathd/uxlsnr.c | 21 +++++++---- multipathd/uxlsnr.h | 3 ++ 9 files changed, 63 insertions(+), 92 deletions(-)
libmultipath/lock.c +0 -9
@@ -1,16 +1,7 @@#include <pthread.h> -#include <signal.h> #include "lock.h" #include <stdio.h> -void block_signal (int signum,sigset_t *old) -{ -sigset_t set; -sigemptyset (&set); -sigaddset (&set, signum); -pthread_sigmask (SIG_BLOCK , &set, old); -} -void cleanup_lock (void * data) {unlock ((*(struct mutex_lock *)data));
libmultipath/lock.h +0 -1
@@ -29,6 +29,5 @@ struct mutex_lock {#endif void cleanup_lock (void * data); -void block_signal (int signum,sigset_t *old);#endif /* _LOCK_H */
libmultipath/log_pthread.c +0 -22
@@ -22,26 +22,13 @@ pthread_cond_t logev_cond;int logq_running; -static void -sigusr1 (int sig) -{ -pthread_mutex_lock (&logq_lock); -log_reset ("multipathd" ); -pthread_mutex_unlock (&logq_lock); -} -void log_safe (int prio,const char * fmt,va_list ap) { -sigset_t old; -if (log_thr == (pthread_t )0 ) {syslog (prio, fmt, ap);return ; } -block_signal (SIGUSR1 , &old); -block_signal (SIGHUP ,NULL ); -pthread_mutex_lock (&logq_lock);log_enqueue (prio, fmt, ap);pthread_mutex_unlock (&logq_lock);
@@ -49,8 +36,6 @@ void log_safe (int prio, const char * fmt, va_list ap)pthread_mutex_lock (&logev_lock);pthread_cond_signal (&logev_cond);pthread_mutex_unlock (&logev_lock); - -pthread_sigmask (SIG_SETMASK , &old,NULL ); }void log_thread_flush (void )
@@ -81,15 +66,8 @@ static void flush_logqueue (void)static void *log_thread (void * et) { -struct sigaction sig;int running; - sig.sa_handler = sigusr1; -sigemptyset (&sig.sa_mask); - sig.sa_flags =0 ; -if (sigaction (SIGUSR1 , &sig,NULL ) <0 ) -logdbg (stderr,"Cannot set signal handler" ); -pthread_mutex_lock (&logev_lock); logq_running =1 ;pthread_mutex_unlock (&logev_lock);
libmultipath/waiter.c +0 -2
@@ -157,8 +157,6 @@ void *waitevent (void *et) waiter = (struct event_thread *)et;pthread_cleanup_push (free_waiter, et); -block_signal (SIGUSR1 ,NULL ); -block_signal (SIGHUP ,NULL );while (1 ) { r =waiteventloop (waiter);
multipathd/cli_handlers.c +2 -2
@@ -939,8 +939,8 @@ int cli_shutdown (void * v, char ** reply, int * len, void * data) {condlog (3 ,"shutdown (operator)" ); - -return exit_daemon (0 ); +exit_daemon (); +return 0 ; }int
multipathd/main.c +41 -49
210 lines not on this page · raw message
multipathd/main.h +2 -1
@@ -16,7 +16,7 @@ struct prin_resp;extern pid_t daemon_pid; -int exit_daemon (int ); +void exit_daemon (void );const char *daemon_status (void );int reconfigure (struct vectors *);int ev_add_path (struct path *,struct vectors *);
@@ -35,5 +35,6 @@ int mpath_pr_event_handle(struct path *pp);void *mpath_pr_event_handler_fn (void * );int update_map_pr (struct multipath *mpp);void *mpath_pr_event_handler_fn (void * pathp ); +void handle_signals (void );#endif /* MAIN_H */
multipathd/uxlsnr.c +15 -6
@@ -8,6 +8,7 @@/* * A simple domain socket listener */ +#define _GNU_SOURCE#include <stdio.h> #include <stdlib.h> #include <unistd.h>
@@ -19,20 +20,21 @@#include <sys/socket.h> #include <sys/un.h> #include <sys/poll.h> - +#include <signal.h> #include <checkers.h> -#include <memory.h> #include <debug.h> #include <vector.h> #include <structs.h> +#include <structs_vec.h> #include <uxsock.h> #include <defaults.h> +#include "main.h" #include "cli.h" #include "uxlsnr.h" -#define SLEEP_TIME 5000 +struct timespec sleep_time = {5 ,0 };struct client {int fd;
@@ -42,6 +44,8 @@ struct client {static struct client *clients;static unsigned num_clients;struct pollfd *polls; +volatile sig_atomic_t reconfig_sig =0 ; +volatile sig_atomic_t log_reset_sig =0 ;/* * handle a new client joining
@@ -104,6 +108,7 @@ void * uxsock_listen(int (*uxsock_trigger)(char *, char **, int *, void *),int rlen;char *inbuf;char *reply; +sigset_t mask; ux_sock =ux_socket_listen (DEFAULT_SOCKET );
@@ -115,7 +120,9 @@ void * uxsock_listen(int (*uxsock_trigger)(char *, char **, int *, void *),pthread_cleanup_push (uxsock_cleanup,NULL ); polls = (struct pollfd *)MALLOC (0 ); - +sigprocmask (SIG_SETMASK ,NULL , &mask); +sigdelset (&mask,SIGHUP ); +sigdelset (&mask,SIGUSR1 );while (1 ) {struct client *c;int i, poll_count;
@@ -132,11 +139,13 @@ void * uxsock_listen(int (*uxsock_trigger)(char *, char **, int *, void *), }/* most of our life is spent in this call */ - poll_count =poll (polls, i,SLEEP_TIME ); + poll_count =ppoll (polls, i, &sleep_time, &mask);if (poll_count ==-1 ) { -if (errno ==EINTR ) +if (errno ==EINTR ) { +handle_signals ();continue ; + }/* something went badly wrong! */ condlog (0 ,"poll" );
multipathd/uxlsnr.h +3 -0
@@ -4,5 +4,8 @@void *uxsock_listen (int (*uxsock_trigger) (char *,char **,int *,void *),void * trigger_data); + +extern volatile sig_atomic_t reconfig_sig; +extern volatile sig_atomic_t log_reset_sig;#endif
Signature · 1 line
1.8.2
Re: [PATCH 2/2] simplify multipath signal handlers
multipathd/uxlsnr.c void * uxsock_listen(int (*uxsock_trigger)(char *, char **, int *, void *), · line 123
Quoted 1 line · Benjamin Marzinski
multipathd/uxlsnr.c +1
-0+sigprocmask (SIG_SETMASK ,NULL , &mask);
Not sure this is relevant on Linux, but the POSIX specs require to use pthread_sigmask() in multithreaded programs instead of sigprocmask() (see also http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_sigmask.html). Otherwise this patch looks fine to me.
Bart.