aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-05-06 16:37:52 +0200
committerMattias Andrée <maandree@operamail.com>2014-05-06 16:37:52 +0200
commitdc9887834f0ca7d5e369096ceaa7aeb75ff308f7 (patch)
tree7cab38c4f8265dff1ef4ad161af9c37da88a1eff
parentadd foreach_linked_list_node (diff)
downloadmds-dc9887834f0ca7d5e369096ceaa7aeb75ff308f7.tar.gz
mds-dc9887834f0ca7d5e369096ceaa7aeb75ff308f7.tar.bz2
mds-dc9887834f0ca7d5e369096ceaa7aeb75ff308f7.tar.xz
add xsigaction
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/libmdsserver/util.c26
-rw-r--r--src/libmdsserver/util.h13
-rw-r--r--src/mds-server.c24
-rw-r--r--src/mds.c9
4 files changed, 53 insertions, 19 deletions
diff --git a/src/libmdsserver/util.c b/src/libmdsserver/util.c
index c4606e8..81793ae 100644
--- a/src/libmdsserver/util.c
+++ b/src/libmdsserver/util.c
@@ -22,6 +22,7 @@
#include <unistd.h>
#include <limits.h>
#include <string.h>
+#include <signal.h>
/**
@@ -80,3 +81,28 @@ void reexec_server(int argc, char** argv, int reexeced)
execv(readlink_buf, reexec_args);
}
+
+/**
+ * Set up a signal trap.
+ * This function should only be used for common mds
+ * signals, and this function may choose to add
+ * additional behaviour depending on the signal, such
+ * as blocking other signals.
+ *
+ * @param signo The signal to trap
+ * @param function The function to run when the signal is caught
+ * @return Zero on success, -1 on error
+ */
+int xsigaction(int signo, void (*function)(int signo))
+{
+ struct sigaction action;
+ sigset_t sigset;
+
+ sigemptyset(&sigset);
+ action.sa_handler = function;
+ action.sa_mask = sigset;
+ action.sa_flags = 0;
+
+ return sigaction(signo, &action, NULL);
+}
+
diff --git a/src/libmdsserver/util.h b/src/libmdsserver/util.h
index 4f505db..8bfaa71 100644
--- a/src/libmdsserver/util.h
+++ b/src/libmdsserver/util.h
@@ -37,6 +37,19 @@ char* getenv_nonempty(const char* var);
*/
void reexec_server(int argc, char** argv, int reexeced);
+/**
+ * Set up a signal trap.
+ * This function should only be used for common mds
+ * signals, and this function may choose to add
+ * additional behaviour depending on the signal, such
+ * as blocking other signals.
+ *
+ * @param signo The signal to trap
+ * @param function The function to run when the signal is caught
+ * @return Zero on success, -1 on error
+ */
+int xsigaction(int signo, void (*function)(int signo));
+
#endif
diff --git a/src/mds-server.c b/src/mds-server.c
index d3ef424..e0ef547 100644
--- a/src/mds-server.c
+++ b/src/mds-server.c
@@ -268,23 +268,13 @@ int main(int argc_, char** argv_)
/* Make the server update without all slaves dying on SIGUSR1. */
- {
- struct sigaction action;
- sigset_t sigset;
-
- sigemptyset(&sigset);
- action.sa_handler = sigusr1_trap;
- action.sa_mask = sigset;
- action.sa_flags = 0;
-
- if (sigaction(SIGUSR1, &action, NULL) < 0)
- {
- perror(*argv);
- fd_table_destroy(&client_map, NULL, NULL);
- linked_list_destroy(&client_list);
- return 1;
- }
- }
+ if (xsigaction(SIGUSR1, sigusr1_trap) < 0)
+ {
+ perror(*argv);
+ fd_table_destroy(&client_map, NULL, NULL);
+ linked_list_destroy(&client_list);
+ return 1;
+ }
/* Create mutex and condition for slave counter. */
diff --git a/src/mds.c b/src/mds.c
index 6a8b3f8..88fe598 100644
--- a/src/mds.c
+++ b/src/mds.c
@@ -19,6 +19,7 @@
#include <libmdsserver/config.h>
#include <libmdsserver/macros.h>
+#include <libmdsserver/util.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -107,6 +108,10 @@ int main(int argc_, char** argv_)
return 1;
}
+ /* Set up to ignore SIGUSR1, used in mds for re-exec, but we cannot re-exec. */
+ if (xsigaction(SIGUSR1, SIG_IGN) < 0)
+ perror(*argv);
+
/* Create directory for socket files, PID files and such. */
if (create_directory_root(MDS_RUNTIME_ROOT_DIRECTORY))
return 1;
@@ -227,8 +232,8 @@ int main(int argc_, char** argv_)
/* Start master server and respawn it if it crashes. */
rc = spawn_and_respawn_server(fd);
-
- done:
+
+ done:
/* Shutdown, close and remove the socket. */
if (fd != -1)
{