Never leave the socket if the server dies by SIGTERM.
--- a/execute.c Thu Apr 05 23:59:50 2007 +0200
+++ b/execute.c Fri Apr 06 00:06:23 2007 +0200
@@ -16,8 +16,6 @@
#include "msg.h"
#include "main.h"
-static void program_signal();
-
/* Returns errorlevel */
static int run_parent(int fd_read_filename, int pid)
{
--- a/server.c Thu Apr 05 23:59:50 2007 +0200
+++ b/server.c Fri Apr 06 00:06:23 2007 +0200
@@ -15,6 +15,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
+#include <signal.h>
#include <stdio.h>
@@ -54,6 +55,25 @@
static int max_descriptors;
+static void sigterm_handler(int n)
+{
+ /* path will be initialized for sure, before installing the handler */
+ unlink(path);
+ exit(1);
+}
+
+static void install_sigterm_handler()
+{
+ struct sigaction act;
+
+ act.sa_handler = sigterm_handler;
+ /* Reset the mask */
+ memset(&act.sa_mask,0,sizeof(act.sa_mask));
+ act.sa_flags = 0;
+
+ sigaction(SIGTERM, &act, NULL);
+}
+
static int get_max_descriptors()
{
const int MARGIN = 5; /* stdin, stderr, listen socket, and whatever */
@@ -110,6 +130,8 @@
if (res == -1)
error("Error listening.");
+ install_sigterm_handler();
+
notify_parent(notify_fd);
server_loop(ls);