diff --git a/main.c b/main.c index 31056bc..6ef63be 100644 --- a/main.c +++ b/main.c @@ -107,6 +107,8 @@ int main(int argc, char **argv) { int try = 0, root_user = 1; uid_t owner; userinfo_t *u = &user; + int sigusr1recieved = 0; + sigset_t sigusr1; oldvt = oldsysrq = oldprintk = vt.nr = vt.fd = -1; vt.ios = NULL; @@ -121,9 +123,14 @@ int main(int argc, char **argv) { setup_signal(SIGQUIT, sa_handler_exit); setup_signal(SIGHUP, SIG_IGN); setup_signal(SIGINT, SIG_IGN); - setup_signal(SIGUSR1, SIG_IGN); + if (options->staggered != 1) { + setup_signal(SIGUSR1, SIG_IGN); + } setup_signal(SIGUSR2, SIG_IGN); + sigemptyset(&sigusr1); + sigaddset(&sigusr1, SIGUSR1); + vt_init(); vt_get_current(&oldvt, &owner); @@ -186,6 +193,13 @@ int main(int argc, char **argv) { locked = 1; + if (options->staggered == 1) { + sigprocmask(SIG_BLOCK,&sigusr1,NULL); + sigwait(&sigusr1, &sigusr1recieved); + sigprocmask(SIG_UNBLOCK,&sigusr1,NULL); + fflush(vt.ios); + } + while (locked) { if (!root_user && try >= (u == &root ? 1 : 3)) { u = u == &root ? &user : &root; diff --git a/options.c b/options.c index 6ec3634..72ed11c 100644 --- a/options.c +++ b/options.c @@ -28,7 +28,7 @@ static options_t _options; const options_t *options = (const options_t*) &_options; void print_usage() { - printf("usage: physlock [-dhLlmsv] [-p MSG]\n"); + printf("usage: physlock [-dhLlmsvw] [-p MSG]\n"); } void print_version() { @@ -45,8 +45,9 @@ void parse_options(int argc, char **argv) { _options.disable_sysrq = 0; _options.lock_switch = -1; _options.mute_kernel_messages = 0; + _options.staggered = 0; - while ((opt = getopt(argc, argv, "dhLlmp:sv")) != -1) { + while ((opt = getopt(argc, argv, "dhLlmp:svw")) != -1) { switch (opt) { case '?': print_usage(); @@ -75,6 +76,9 @@ void parse_options(int argc, char **argv) { case 'v': print_version(); exit(0); + case 'w': + _options.staggered = 1; + break; } } } diff --git a/physlock.1 b/physlock.1 index 32e8547..1b73f10 100644 --- a/physlock.1 +++ b/physlock.1 @@ -49,6 +49,14 @@ Disable SysRq mechanism while physlock is running. .TP .B \-v Print version information to standard output and exit. +.TP +.B \-w +Wait until a SIGUSR1 signal is received to prompt for authentication. +Useful if the first authentication attempt always fails +due to bad input buffering in the virtual terminal. +.BI WARNING: +When using this option, ensure that some external program sends a SIGUSR1 +signal to physlock. Otherwise, you will be locked out of your session. .SH AUTHORS .TP Bert Muennich diff --git a/physlock.h b/physlock.h index 0eb42ee..5f5570d 100644 --- a/physlock.h +++ b/physlock.h @@ -54,6 +54,7 @@ typedef struct options_s { int disable_sysrq; int lock_switch; int mute_kernel_messages; + int staggered; const char *prompt; } options_t;