slock with DPMS and other tweaks
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use argv0 instead of passing "slock:" to die every time

FRIGN b02c4d45 a6dc051e

+16 -12
+16 -12
slock.c
··· 46 46 static Bool rr; 47 47 static int rrevbase; 48 48 static int rrerrbase; 49 + static char *argv0; 49 50 50 51 static void 51 52 die(const char *errstr, ...) ··· 53 54 va_list ap; 54 55 55 56 va_start(ap, errstr); 57 + fprintf(stderr, "%s: ", argv0); 56 58 vfprintf(stderr, errstr, ap); 57 59 va_end(ap); 58 60 exit(1); ··· 88 90 errno = 0; 89 91 if (!(pw = getpwuid(getuid()))) { 90 92 if (errno) 91 - die("slock: getpwuid: %s\n", strerror(errno)); 93 + die("getpwuid: %s\n", strerror(errno)); 92 94 else 93 - die("slock: cannot retrieve password entry\n"); 95 + die("cannot retrieve password entry\n"); 94 96 } 95 97 rval = pw->pw_passwd; 96 98 ··· 98 100 if (rval[0] == 'x' && rval[1] == '\0') { 99 101 struct spwd *sp; 100 102 if (!(sp = getspnam(getenv("USER")))) 101 - die("slock: cannot retrieve shadow entry (make sure to suid or sgid slock)\n"); 103 + die("cannot retrieve shadow entry (make sure to suid or sgid slock)\n"); 102 104 rval = sp->sp_pwdp; 103 105 } 104 106 #endif ··· 106 108 /* drop privileges */ 107 109 if (geteuid() == 0 && 108 110 ((getegid() != pw->pw_gid && setgid(pw->pw_gid) < 0) || setuid(pw->pw_uid) < 0)) 109 - die("slock: cannot drop privileges\n"); 111 + die("cannot drop privileges\n"); 110 112 return rval; 111 113 } 112 114 #endif ··· 254 256 usleep(1000); 255 257 } 256 258 if (!len) { 257 - fprintf(stderr, "slock: unable to grab mouse pointer for screen %d\n", screen); 259 + fprintf(stderr, "unable to grab mouse pointer for screen %d\n", screen); 258 260 } else { 259 261 for (len = 1000; len; len--) { 260 262 if (XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess) { ··· 264 266 } 265 267 usleep(1000); 266 268 } 267 - fprintf(stderr, "slock: unable to grab keyboard for screen %d\n", screen); 269 + fprintf(stderr, "unable to grab keyboard for screen %d\n", screen); 268 270 } 269 271 /* grabbing one of the inputs failed */ 270 272 running = 0; ··· 281 283 Display *dpy; 282 284 int screen; 283 285 286 + argv0 = argv[0], argc--, argv++; 287 + 284 288 #ifdef __linux__ 285 289 dontkillme(); 286 290 #endif 287 291 288 292 if (!getpwuid(getuid())) 289 - die("slock: no passwd entry for you\n"); 293 + die("no passwd entry for you\n"); 290 294 291 295 #ifndef HAVE_BSD_AUTH 292 296 pws = getpw(); 293 297 #endif 294 298 295 299 if (!(dpy = XOpenDisplay(0))) 296 - die("slock: cannot open display\n"); 300 + die("cannot open display\n"); 297 301 rr = XRRQueryExtension(dpy, &rrevbase, &rrerrbase); 298 302 /* Get the number of screens in display "dpy" and blank them all. */ 299 303 nscreens = ScreenCount(dpy); 300 304 if (!(locks = malloc(sizeof(Lock*) * nscreens))) 301 - die("slock: malloc: %s\n", strerror(errno)); 305 + die("Out of memory.\n"); 302 306 int nlocks = 0; 303 307 for (screen = 0; screen < nscreens; screen++) { 304 308 if ((locks[screen] = lockscreen(dpy, screen)) != NULL) ··· 313 317 return 1; 314 318 } 315 319 316 - if (argc >= 2 && fork() == 0) { 320 + if (argc >= 1 && fork() == 0) { 317 321 if (dpy) 318 322 close(ConnectionNumber(dpy)); 319 - execvp(argv[1], argv+1); 320 - die("slock: execvp %s failed: %s\n", argv[1], strerror(errno)); 323 + execvp(argv[0], argv); 324 + die("execvp %s failed: %s\n", argv[0], strerror(errno)); 321 325 } 322 326 323 327 /* Everything is now blank. Now wait for the correct password. */