From e70cd4a4d54f6b6af8f7dda06554f7cfb44af4ec Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 18 Nov 2011 20:39:00 +0100 Subject: agetty: release the terminal for 5s upon a SIGQUIT Upon SIGQUIT, close everything and wait 5 seconds before exiting, so that the tty remains unattached for some time, leaving an opportunity for another tool to grab the device. Upon next startup, agetty will simply loop trying to grab the device again until the other tool releases it. --- term-utils/agetty.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/term-utils/agetty.c b/term-utils/agetty.c index 5fb9ab1..2039c24 100644 --- a/term-utils/agetty.c +++ b/term-utils/agetty.c @@ -303,6 +303,7 @@ static ssize_t append(char *dest, size_t len, const char *sep, const char *src) static void check_username (const char* nm); static void login_options_to_argv(char *argv[], int *argc, char *str, char *username); static int plymouth_command(const char* arg); +static void sig_quit(int sig); static void reload_agettys(void); /* Fake hostname for ut_host specified on command line. */ @@ -369,6 +370,9 @@ int main(int argc, char **argv) if (options.delay) sleep(options.delay); + /* now we want to be able to release the tty on demand */ + signal(SIGQUIT, sig_quit); + debug("calling open_tty\n"); /* Open the tty as standard { input, output, error }. */ @@ -2559,3 +2563,18 @@ static void reload_agettys(void) errx(EXIT_FAILURE, _("--reload is unsupported on your system")); #endif } + +/* Upon SIGQUIT, close everything and wait 5 seconds before exiting, so that + * the tty remains unattached for some time, leaving an opportunity for another + * tool to grab the device. Upon next startup, agetty will simply loop trying + * to grab the device again until the other tool releases it. + */ +static void sig_quit(int sig) +{ + signal(sig, SIG_DFL); + close(2); + close(1); + close(0); + sleep(5); + exit(0); +} -- 1.7.12.1