Skip to content

Commit

Permalink
Merge pull request #1 from tstsrt/master
Browse files Browse the repository at this point in the history
Fix issue xyb3rt#97 with very basic signal handling
  • Loading branch information
menglishca authored Jul 27, 2020
2 parents 4fbacee + e688b42 commit fb36937
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
16 changes: 15 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();
Expand Down Expand Up @@ -75,6 +76,9 @@ void parse_options(int argc, char **argv) {
case 'v':
print_version();
exit(0);
case 'w':
_options.staggered = 1;
break;
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions physlock.1
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ber.t at gmx.com>
Expand Down
1 change: 1 addition & 0 deletions physlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit fb36937

Please sign in to comment.