chiark / gitweb /
prefork-interp: kill and fresh modes
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Aug 2022 10:37:24 +0000 (11:37 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Aug 2022 20:21:10 +0000 (21:21 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
cprogs/prefork-interp.c

index d87e8f82c87950ec6484a6a6816dd96a94c7ab3f..918083e321af6b48f69b7a5c2ccc5e46c5b54e4b 100644 (file)
@@ -269,13 +269,20 @@ void fusagemessage(FILE *f) {
 }
 
 static int laundering;
+static int mode;
 static int max_sockets = 100; // maximum entries in the run dir is 2x this
 
 static struct stat initial_stab;
 
+#define MODE_NORMAL 0
+#define MODE_KILL   'k'
+#define MODE_FRESH  'f'
+
 const struct cmdinfo cmdinfos[]= {
   PREFORK_CMDINFOS
-  { 0, 'U',   0,                    .iassignto= &laundering,    .arg= 'U' },
+  { 0,         'U',   0,    .iassignto= &laundering,    .arg= 'U'         },
+  { "kill",     0,    0,    .iassignto= &mode,          .arg= MODE_KILL   },
+  { 0,         'f',   0,    .iassignto= &mode,          .arg= MODE_FRESH  },
   { 0 }
 };
 
@@ -599,6 +606,8 @@ static FILE *connect_existing(void) {
   int r;
   int fd = -1;
 
+  if (mode != MODE_NORMAL) return 0;
+
   fd = socket(AF_UNIX, SOCK_STREAM, 0);
   if (fd==-1) diee("socket() for client");
 
@@ -733,6 +742,16 @@ static void connect_or_spawn(void) {
   preclean();
 
   int lockfd = acquire_lock();
+
+  if (mode == MODE_KILL) {
+    r= unlink(socket_path);
+    if (r && errno != ENOENT) diee("remove socket %s", socket_path);
+
+    r= unlink(lock_path);
+    if (r) diee("rmeove lock %s", lock_path);
+    _exit(0);
+  }
+
   call_sock = connect_existing();
   if (call_sock) { close(lockfd); return; }