]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - command.c
com_term(): Ignore SIGTERM.
[paraslash.git] / command.c
index bb276a89b4acebf391a0875d8f81e1033d2130de..00d2c5a61ada8fdcedfad2989e43844265ca46d5 100644 (file)
--- a/command.c
+++ b/command.c
@@ -21,8 +21,8 @@
 #include "net.h"
 #include "server.h"
 #include "list.h"
-#include "send.h"
 #include "sched.h"
+#include "send.h"
 #include "vss.h"
 #include "daemon.h"
 #include "fd.h"
@@ -78,7 +78,7 @@ static char *vss_status_tohuman(unsigned int flags)
  */
 static char *vss_get_status_flags(unsigned int flags)
 {
-       char *msg = para_malloc(5 * sizeof(char));
+       char *msg = alloc(5 * sizeof(char));
 
        msg[0] = (flags & VSS_PLAYING)? 'P' : '_';
        msg[1] = (flags & VSS_NOMORE)? 'O' : '_';
@@ -630,6 +630,13 @@ EXPORT_SERVER_CMD_HANDLER(ll);
 static int com_term(__a_unused struct command_context *cc,
                __a_unused struct lls_parse_result *lpr)
 {
+       /*
+        * The server catches SIGTERM and propagates this signal to all its
+        * children. We are about to exit anyway, but we'd leak tons of memory
+        * if being terminated by the signal. So we ignore the signal here and
+        * terminate via the normal exit path, deallocating all memory.
+        */
+       para_sigaction(SIGTERM, SIG_IGN);
        kill(getppid(), SIGTERM);
        return 1;
 }
@@ -871,7 +878,7 @@ static int run_command(struct command_context *cc, struct iovec *iov)
        for (i = 0; p < end; i++)
                p += strlen(p) + 1;
        argc = i;
-       argv = para_malloc((argc + 1) * sizeof(char *));
+       argv = arr_alloc(argc + 1, sizeof(char *));
        for (i = 0, p = iov->iov_base; p < end; i++) {
                argv[i] = para_strdup(p);
                p += strlen(p) + 1;
@@ -926,7 +933,7 @@ int handle_connect(int fd)
        int ret;
        unsigned char rand_buf[APC_CHALLENGE_SIZE + 2 * SESSION_KEY_LEN];
        unsigned char challenge_hash[HASH2_SIZE];
-       char *command = NULL, *buf = para_malloc(HANDSHAKE_BUFSIZE) /* must be on the heap */;
+       char *command = NULL, *buf = alloc(HANDSHAKE_BUFSIZE) /* must be on the heap */;
        size_t numbytes;
        struct command_context cc_struct = {.u = NULL}, *cc = &cc_struct;
        struct iovec iov;