}
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 }
};
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");
}
static __attribute__((noreturn))
-void become_setup(int sfd, int fake_pair[2],
+void become_setup(int sfd, int lockfd, int fake_pair[2],
int watcher_stdin, int watcher_stderr) {
+ close(lockfd);
close(fake_pair[0]);
int call_fd = fake_pair[1];
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; }
pid_t setup_pid = fork();
if (setup_pid == (pid_t)-1) diee("fork for spawn setup");
- if (!setup_pid) become_setup(sfd, fake_pair,
+ if (!setup_pid) become_setup(sfd, lockfd, fake_pair,
watcher_stdin[1], watcher_stderr[0]);
close(fake_pair[1]);
close(sfd);