File resume_hybernate.patch of Package physlock
From e688b425399d12ba5e58138ade9956d0f586f3c4 Mon Sep 17 00:00:00 2001
From: ninad <ninadhuilgol@gmail.com>
Date: Tue, 9 Jun 2020 18:52:55 +0530
Subject: [PATCH] Fix issue #97 with very basic signal handling
---
main.c | 16 +++++++++++++++-
options.c | 8 ++++++--
physlock.1 | 8 ++++++++
physlock.h | 1 +
4 files changed, 30 insertions(+), 3 deletions(-)
--- main.c
+++ main.c 2024-09-11 11:29:08.248580547 +0000
@@ -137,6 +137,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;
cmdpid = -1;
@@ -152,9 +154,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);
@@ -221,6 +228,13 @@ int main(int argc, char **argv) {
locked = !options->no_auth;
+ 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;
--- options.c
+++ options.c 2024-09-11 11:32:08.333282851 +0000
@@ -28,7 +28,7 @@ static options_t _options;
const options_t *options = (const options_t*) &_options;
void print_usage() {
- printf("usage: physlock [-dhLlmsbanv] [-p MSG]\n");
+ printf("usage: physlock [-dhLlmsbanvw] [-p MSG]\n");
}
void print_version() {
@@ -45,9 +45,10 @@ void parse_options(int argc, char **argv
_options.disable_sysrq = 0;
_options.lock_switch = -1;
_options.mute_kernel_messages = 0;
+ _options.staggered = 0;
_options.no_auth = 0;
- while ((opt = getopt(argc, argv, "dhLlmnp:svb:a:")) != -1) {
+ while ((opt = getopt(argc, argv, "dhLlmnp:svb:a:w")) != -1) {
switch (opt) {
case '?':
print_usage();
@@ -85,6 +86,9 @@ void parse_options(int argc, char **argv
case 'v':
print_version();
exit(0);
+ case 'w':
+ _options.staggered = 1;
+ break;
}
}
}
--- physlock.1
+++ physlock.1 2024-09-11 11:29:08.248580547 +0000
@@ -62,6 +62,14 @@ Disable SysRq mechanism while physlock i
.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>
--- physlock.h
+++ physlock.h 2024-09-11 11:30:24.051192128 +0000
@@ -55,6 +55,7 @@ typedef struct options_s {
int lock_switch;
int mute_kernel_messages;
int no_auth;
+ int staggered;
const char *prompt;
const char *command_before;
const char *command_after;