chiark / gitweb /
Add -f option, to fork after a successful locking.
authorSimon Tatham <anakin@pobox.com>
Sat, 7 May 2016 15:58:07 +0000 (16:58 +0100)
committerMatthew Vernon <matthew@debian.org>
Sat, 21 May 2016 18:03:35 +0000 (19:03 +0100)
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>
xtrlock.c
xtrlock.man

index 7598560463f3ea104da3c34d3d8d342daee5d111..6117c6fadbc596805a9f6f32fded1fb5ae0c07b2 100644 (file)
--- 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) {
index 7a869a6636c5a782fd413f85cf58b400a172bbb2..e211bd538acf230d033cbc64b0ad83343cc29612 100644 (file)
@@ -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