]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Use para_sigaction() in command handlers.
authorAndre Noll <maan@systemlinux.org>
Mon, 6 Apr 2009 16:41:37 +0000 (18:41 +0200)
committerAndre Noll <maan@systemlinux.org>
Mon, 6 Apr 2009 16:41:37 +0000 (18:41 +0200)
This allows to get rid of an ugly hack for solaris. The patch also adds checks
for whether the signals were reset sucessfully in the command handler and
aborts early on errors.

command.c

index d08a71818cfb437c5cd6c02a13d6a7c2f3e56893..ca08ed729a9f6d65ae34ccacfc931e5bdea6dec8 100644 (file)
--- a/command.c
+++ b/command.c
@@ -30,6 +30,8 @@
 #include "user_list.h"
 #include "server_command_list.h"
 #include "afs_command_list.h"
 #include "user_list.h"
 #include "server_command_list.h"
 #include "afs_command_list.h"
+#include "sched.h"
+#include "signal.h"
 
 /** Commands including options must be shorter than this. */
 #define MAX_COMMAND_LEN 32768
 
 /** Commands including options must be shorter than this. */
 #define MAX_COMMAND_LEN 32768
@@ -42,15 +44,8 @@ extern int mmd_mutex;
 extern struct misc_meta_data *mmd;
 extern struct sender senders[];
 
 extern struct misc_meta_data *mmd;
 extern struct sender senders[];
 
-static void dummy(int s)
+static void dummy(__a_unused int s)
 {
 {
-       /*
-        * At least on Solaris, SIGUSR1 is one-shot, i.e. the signal action is
-        * restored to the default state once the signal handler has been
-        * called.
-        */
-       if (s == SIGUSR1)
-               signal(SIGUSR1, dummy);
 }
 
 static void mmd_dup(struct misc_meta_data *new_mmd)
 }
 
 static void mmd_dup(struct misc_meta_data *new_mmd)
@@ -113,7 +108,7 @@ static char *get_status(struct misc_meta_data *nmmd)
        char *status, *flags; /* vss status info */
        char *ut = uptime_str();
        long offset = (nmmd->offset + 500) / 1000;
        char *status, *flags; /* vss status info */
        char *ut = uptime_str();
        long offset = (nmmd->offset + 500) / 1000;
-       struct timeval now;
+       struct timeval current_time;
        struct tm mtime_tm;
 
        /* report real status */
        struct tm mtime_tm;
 
        /* report real status */
@@ -123,7 +118,7 @@ static char *get_status(struct misc_meta_data *nmmd)
                localtime_r(&nmmd->mtime, &mtime_tm);
                strftime(mtime, 29, "%b %d %Y", &mtime_tm);
        }
                localtime_r(&nmmd->mtime, &mtime_tm);
                strftime(mtime, 29, "%b %d %Y", &mtime_tm);
        }
-       gettimeofday(&now, NULL);
+       gettimeofday(&current_time, NULL);
        ret = make_message(
                "%s: %zu\n" /* file size */
                "%s: %s\n" /* mtime */
        ret = make_message(
                "%s: %zu\n" /* file size */
                "%s: %s\n" /* mtime */
@@ -146,8 +141,8 @@ static char *get_status(struct misc_meta_data *nmmd)
                        (long unsigned)nmmd->stream_start.tv_sec,
                        (long unsigned)nmmd->stream_start.tv_usec,
                status_item_list[SI_CURRENT_TIME],
                        (long unsigned)nmmd->stream_start.tv_sec,
                        (long unsigned)nmmd->stream_start.tv_usec,
                status_item_list[SI_CURRENT_TIME],
-                       (long unsigned)now.tv_sec,
-                       (long unsigned)now.tv_usec,
+                       (long unsigned)current_time.tv_sec,
+                       (long unsigned)current_time.tv_usec,
 
                nmmd->afd.verbose_ls_output
 
 
                nmmd->afd.verbose_ls_output
 
@@ -318,7 +313,9 @@ int com_stat(int fd, int argc, char * const * argv)
        struct misc_meta_data tmp, *nmmd = &tmp;
        char *s;
 
        struct misc_meta_data tmp, *nmmd = &tmp;
        char *s;
 
-       signal(SIGUSR1, dummy);
+       ret = para_sigaction(SIGUSR1, dummy);
+       if (ret < 0)
+               return ret;
 
        if (argc > 1)
                num = atoi(argv[1]);
 
        if (argc > 1)
                num = atoi(argv[1]);
@@ -655,6 +652,24 @@ out:
 
 }
 
 
 }
 
+static int reset_signals(void)
+{
+       int ret = para_sigaction(SIGCHLD, SIG_IGN);
+
+       if (ret < 0)
+               return ret;
+       ret = para_sigaction(SIGINT, SIG_DFL);
+       if (ret < 0)
+               return ret;
+       ret = para_sigaction(SIGTERM, SIG_DFL);
+       if (ret < 0)
+               return ret;
+       ret = para_sigaction(SIGHUP, SIG_DFL);
+       if (ret < 0)
+               return ret;
+       return 1;
+}
+
 /**
  * Perform user authentication and execute a command.
  *
 /**
  * Perform user authentication and execute a command.
  *
@@ -694,11 +709,9 @@ __noreturn void handle_connect(int fd, const char *peername)
        char *p, *command = NULL;
        size_t numbytes;
 
        char *p, *command = NULL;
        size_t numbytes;
 
-       signal(SIGCHLD, SIG_IGN);
-       signal(SIGINT, SIG_DFL);
-       signal(SIGTERM, SIG_DFL);
-       signal(SIGHUP, SIG_DFL);
-
+       ret = reset_signals();
+       if (ret < 0)
+               goto err_out;
        /* we need a blocking fd here as recv() might return EAGAIN otherwise. */
        ret = mark_fd_blocking(fd);
        if (ret < 0)
        /* we need a blocking fd here as recv() might return EAGAIN otherwise. */
        ret = mark_fd_blocking(fd);
        if (ret < 0)