X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=slock.c;h=a00fbb9a8f37bbca4d40b04ed40cba525d183781;hb=a7afade1701a809f6a33b53525d59dd29b38d381;hp=a0ffed07e0cd321c2a5fcceda98fe9d10ca6f3d0;hpb=b02c4d452a7942d4be3c69e6f98dafd35a2e4e78;p=slock.git diff --git a/slock.c b/slock.c index a0ffed0..a00fbb9 100644 --- a/slock.c +++ b/slock.c @@ -23,6 +23,8 @@ #include #endif +#include "util.h" + enum { INIT, INPUT, @@ -46,15 +48,14 @@ static Bool failure = False; static Bool rr; static int rrevbase; static int rrerrbase; -static char *argv0; static void die(const char *errstr, ...) { va_list ap; + fputs("slock: ", stderr); va_start(ap, errstr); - fprintf(stderr, "%s: ", argv0); vfprintf(stderr, errstr, ap); va_end(ap); exit(1); @@ -136,7 +137,7 @@ readpw(Display *dpy, const char *pws) * timeout. */ while (running && !XNextEvent(dpy, &ev)) { if (ev.type == KeyPress) { - buf[0] = 0; + explicit_bzero(&buf, sizeof(buf)); num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0); if (IsKeypadKey(ksym)) { if (ksym == XK_KP_Enter) @@ -162,14 +163,16 @@ readpw(Display *dpy, const char *pws) XBell(dpy, 100); failure = True; } + explicit_bzero(&passwd, sizeof(passwd)); len = 0; break; case XK_Escape: + explicit_bzero(&passwd, sizeof(passwd)); len = 0; break; case XK_BackSpace: if (len) - --len; + passwd[len--] = 0; break; default: if (num && !iscntrl((int)buf[0]) && (len + num < sizeof(passwd))) { @@ -256,7 +259,7 @@ lockscreen(Display *dpy, int screen) usleep(1000); } if (!len) { - fprintf(stderr, "unable to grab mouse pointer for screen %d\n", screen); + fprintf(stderr, "slock: unable to grab mouse pointer for screen %d\n", screen); } else { for (len = 1000; len; len--) { if (XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess) { @@ -266,7 +269,7 @@ lockscreen(Display *dpy, int screen) } usleep(1000); } - fprintf(stderr, "unable to grab keyboard for screen %d\n", screen); + fprintf(stderr, "slock: unable to grab keyboard for screen %d\n", screen); } /* grabbing one of the inputs failed */ running = 0; @@ -274,16 +277,27 @@ lockscreen(Display *dpy, int screen) return NULL; } -int -main(int argc, char **argv) +static void +usage(void) { + fprintf(stderr, "usage: slock [-v|POST_LOCK_CMD]\n"); + exit(1); +} + +int +main(int argc, char **argv) { #ifndef HAVE_BSD_AUTH const char *pws; #endif Display *dpy; int screen; - argv0 = argv[0], argc--, argv++; + if ((argc >= 2) && !strcmp("-v", argv[1])) + die("version %s, © 2006-2016 slock engineers\n", VERSION); + + /* treat first argument starting with a '-' as option */ + if ((argc >= 2) && argv[1][0] == '-') + usage(); #ifdef __linux__ dontkillme(); @@ -317,11 +331,11 @@ main(int argc, char **argv) return 1; } - if (argc >= 1 && fork() == 0) { + if (argc >= 2 && fork() == 0) { if (dpy) close(ConnectionNumber(dpy)); - execvp(argv[0], argv); - die("execvp %s failed: %s\n", argv[0], strerror(errno)); + execvp(argv[1], argv+1); + die("execvp %s failed: %s\n", argv[1], strerror(errno)); } /* Everything is now blank. Now wait for the correct password. */