summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2016-05-07 16:58:07 +0100
committerMatthew Vernon <matthew@debian.org>2016-05-21 19:03:35 +0100
commiteb50973552a62e49274cfeeddf31245739c8f47e (patch)
tree3a9579994403c216d446836eb6fb3835a1e013fc
parent7331fbf2792a5ace5fab0ff6cff4390e05a82961 (diff)
Add -f option, to fork after a successful locking.
This permits a chain of commands of the form 'xtrlock -f && suspend', where 'suspend' is whatever CLI command suspends your particular laptop environment, so that when you unsuspend you then have to unlock the xtrlock. Without this option, you have to run xtrlock in the background, and then either include a bodgy sleep to try to avoid the suspend command winning the race, or else find a way to test by some X-related means that the locking has happened. Signed-off-by: Simon Tatham <anakin@pobox.com>
-rw-r--r--xtrlock.c33
-rw-r--r--xtrlock.man6
2 files changed, 31 insertions, 8 deletions
diff --git a/xtrlock.c b/xtrlock.c
index 7598560..6117c6f 100644
--- a/xtrlock.c
+++ b/xtrlock.c
@@ -81,19 +81,27 @@ int main(int argc, char **argv){
Cursor cursor;
Pixmap csr_source,csr_mask;
XColor csr_fg, csr_bg, dummy, black;
- int ret, screen, blank = 0;
+ int ret, screen, blank = 0, fork_after = 0;
#ifdef SHADOW_PWD
struct spwd *sp;
#endif
struct timeval tv;
int tvt, gs;
- if ((argc == 2) && (strcmp(argv[1], "-b") == 0)) {
- blank = 1;
- } else if (argc > 1) {
- fprintf(stderr,"xtrlock (version %s); usage: xtrlock [-b]\n",
- program_version);
- exit(1);
+ while (argc > 1) {
+ if ((strcmp(argv[1], "-b") == 0)) {
+ blank = 1;
+ argc--;
+ argv++;
+ } else if ((strcmp(argv[1], "-f") == 0)) {
+ fork_after = 1;
+ argc--;
+ argv++;
+ } else {
+ fprintf(stderr,"xtrlock (version %s); usage: xtrlock [-b] [-f]\n",
+ program_version);
+ exit(1);
+ }
}
errno=0; pw= getpwuid(getuid());
@@ -208,6 +216,17 @@ int main(int argc, char **argv){
exit(1);
}
+ if (fork_after) {
+ pid_t pid = fork();
+ if (pid < 0) {
+ fprintf(stderr,"xtrlock (version %s): cannot fork: %s\n",
+ program_version, strerror(errno));
+ exit(1);
+ } else if (pid > 0) {
+ exit(0);
+ }
+ }
+
for (;;) {
XNextEvent(display,&ev);
switch (ev.type) {
diff --git a/xtrlock.man b/xtrlock.man
index 7a869a6..e211bd5 100644
--- a/xtrlock.man
+++ b/xtrlock.man
@@ -2,7 +2,7 @@
.SH NAME
xtrlock \- Lock X display until password supplied, leaving windows visible
.SH SYNOPSIS
-.B xtrlock [-b]
+.B xtrlock [-b] [-f]
.SH DESCRIPTION
.B xtrlock
locks the X server till the user enters their password at the keyboard.
@@ -30,6 +30,10 @@ touching a key (Shift, for example) or the mouse.
.TP
\fB\-b\fR
blank the screen as well as displaying the padlock
+.TP
+\fB\-f\fR
+fork after locking is complete, and return success from the parent
+process
.SH X RESOURCES, CONFIGURATION
None.
.SH BUGS