]> git.armaanb.net Git - slock.git/commitdiff
final fixes and cleanups
authorAnselm R. Garbe <garbeam@gmail.com>
Sat, 24 Nov 2007 20:17:32 +0000 (21:17 +0100)
committerAnselm R. Garbe <garbeam@gmail.com>
Sat, 24 Nov 2007 20:17:32 +0000 (21:17 +0100)
README
config.mk
slock.c

diff --git a/README b/README
index fc24b27be00502b4f9151c8f80e4a1c0aa4216a1..594033708ed8752f8756b98cbf17ac05fac73960 100644 (file)
--- a/README
+++ b/README
@@ -21,4 +21,4 @@ necessary as root):
 
 Running slock
 -------------
-Simply invoke the 'slock' command.
+Simply invoke the 'slock' command. To get out of it, enter your password.
index 1a17285a9401d39a614644f904d058d06196ad0c..6dbd4c4c11058a391eefd154ccb82fe2522514d0 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -5,7 +5,6 @@ VERSION = 0.7
 
 # paths
 PREFIX = /usr/local
-MANPREFIX = ${PREFIX}/share/man
 
 X11INC = /usr/X11R6/include
 X11LIB = /usr/X11R6/lib
diff --git a/slock.c b/slock.c
index daa3cf76b2e759f732de923ffa71a77da054b7af..a7f79d9f2ba713caad01fc19d11a3c5fa8a285a4 100644 (file)
--- a/slock.c
+++ b/slock.c
@@ -7,6 +7,7 @@
 
 #include <ctype.h>
 #include <pwd.h>
+#include <stdarg.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 
+void
+eprint(const char *errstr, ...) {
+       va_list ap;
+
+       va_start(ap, errstr);
+       vfprintf(stderr, errstr, ap);
+       va_end(ap);
+       exit(EXIT_FAILURE);
+}
+
 const char *
 get_password() { /* only run as root */
        const char *rval;
        struct passwd *pw;
 
-       if(geteuid() != 0) {
-               fputs("slock: cannot retrieve password entry (make sure to suid slock)\n", stderr);
-               exit(EXIT_FAILURE);
-       }
+       if(geteuid() != 0)
+               eprint("slock: cannot retrieve password entry (make sure to suid slock)\n");
        pw = getpwuid(getuid());
        endpwent();
        rval =  pw->pw_passwd;
@@ -38,10 +47,8 @@ get_password() { /* only run as root */
        }
 #endif
        /* drop privileges */
-       if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) {
-               fputs("slock: cannot drop privileges\n",stdout);
-               exit(EXIT_FAILURE);
-       }
+       if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0)
+               eprint("slock: cannot drop privileges\n");
        return rval;
 }
 
@@ -62,15 +69,11 @@ main(int argc, char **argv) {
        XEvent ev;
        XSetWindowAttributes wa;
 
-       if((argc > 1) && !strncmp(argv[1], "-v", 3)) {
-               fputs("slock-"VERSION", © 2006-2007 Anselm R. Garbe\n", stdout);
-               exit(EXIT_SUCCESS);
-       }
+       if((argc > 1) && !strncmp(argv[1], "-v", 3))
+               eprint("slock-"VERSION", © 2006-2007 Anselm R. Garbe, Sander van Dijk\n");
        pws = get_password();
-       if(!(dpy = XOpenDisplay(0))) {
-               fputs("slock: cannot open display\n", stderr);
-               exit(EXIT_FAILURE);
-       }
+       if(!(dpy = XOpenDisplay(0)))
+               eprint("slock: cannot open display\n");
        screen = DefaultScreen(dpy);
        root = RootWindow(dpy, screen);