From 12aff8638653798a38e4712cafa46e1ef409b7a8 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 21 Aug 2022 11:37:24 +0100 Subject: [PATCH] prefork-interp: kill and fresh modes Signed-off-by: Ian Jackson --- cprogs/prefork-interp.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cprogs/prefork-interp.c b/cprogs/prefork-interp.c index d87e8f8..918083e 100644 --- a/cprogs/prefork-interp.c +++ b/cprogs/prefork-interp.c @@ -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; } -- 2.30.2