From 52ea48e47a75e98b33a95a237dbf84f3eb0c59c4 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 28 Nov 2015 19:54:54 +0100 Subject: Rip out inittab and init script handling --- askconsole.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 askconsole.c (limited to 'askconsole.c') diff --git a/askconsole.c b/askconsole.c new file mode 100644 index 0000000..703024e --- /dev/null +++ b/askconsole.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2015 Matthias Schiffer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "procd.h" + +#include +#include + +#include +#include + + +static void askconsole(struct uloop_process *proc) { + char *const ask[] = { + "/sbin/askfirst", + "/bin/ash", + "--login", + NULL, + }; + + pid_t p; + + proc->pid = fork(); + if (!proc->pid) { + p = setsid(); + + fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) & ~O_NONBLOCK); + + ioctl(STDIN_FILENO, TIOCSCTTY, 1); + tcsetpgrp(STDIN_FILENO, p); + + execvp(ask[0], ask); + ERROR("Failed to execute %s\n", ask[0]); + exit(-1); + } + + if (proc->pid > 0) { + DEBUG(4, "Launched askconsole, pid=%d\n", + (int) proc->pid); + uloop_process_add(proc); + } +} + +static void child_exit(struct uloop_process *proc, int ret) +{ + DEBUG(4, "pid:%d\n", proc->pid); + askconsole(proc); +} + +void procd_askconsole(void) { + struct uloop_process *proc = malloc(sizeof(*proc)); + proc->cb = child_exit; + askconsole(proc); +} -- cgit v1.2.3