summaryrefslogtreecommitdiff
path: root/xtrlock.c
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 /xtrlock.c
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>
Diffstat (limited to 'xtrlock.c')
-rw-r--r--xtrlock.c33
1 files changed, 26 insertions, 7 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) {