aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Rameau <quinq@fifth.space>2016-09-01 13:47:05 +0200
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-09-02 10:50:32 +0200
commit39fb855aa100c5a5a8b7f3b6cc1fbb2135fe7dde (patch)
treef11ce8e866a351346c2c11487e7cffc62c3421b7
parente378f735d857f7da124177e3540912d920be5022 (diff)
Move screen unlocking inside cleanup()
-rw-r--r--slock.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/slock.c b/slock.c
index 97c7489..0682279 100644
--- a/slock.c
+++ b/slock.c
@@ -234,6 +234,11 @@ unlockscreen(Display *dpy, Lock *lock)
234static void 234static void
235cleanup(Display *dpy) 235cleanup(Display *dpy)
236{ 236{
237 int s;
238
239 for (s = 0; s < nscreens; ++s)
240 unlockscreen(dpy, locks[s]);
241
237 free(locks); 242 free(locks);
238 XCloseDisplay(dpy); 243 XCloseDisplay(dpy);
239} 244}
@@ -305,8 +310,6 @@ lockscreen(Display *dpy, int screen)
305 fprintf(stderr, "slock: unable to grab mouse pointer for screen %d\n", screen); 310 fprintf(stderr, "slock: unable to grab mouse pointer for screen %d\n", screen);
306 if (kbgrab != GrabSuccess) 311 if (kbgrab != GrabSuccess)
307 fprintf(stderr, "slock: unable to grab keyboard for screen %d\n", screen); 312 fprintf(stderr, "slock: unable to grab keyboard for screen %d\n", screen);
308 running = 0;
309 unlockscreen(dpy, lock);
310 return NULL; 313 return NULL;
311} 314}
312 315
@@ -359,19 +362,21 @@ main(int argc, char **argv) {
359 362
360 /* get number of screens in display "dpy" and blank them */ 363 /* get number of screens in display "dpy" and blank them */
361 nscreens = ScreenCount(dpy); 364 nscreens = ScreenCount(dpy);
362 if (!(locks = malloc(sizeof(Lock *) * nscreens))) { 365 if (!(locks = calloc(nscreens, sizeof(Lock *)))) {
363 XCloseDisplay(dpy); 366 XCloseDisplay(dpy);
364 die("slock: out of memory\n"); 367 die("slock: out of memory\n");
365 } 368 }
366 for (nlocks = 0, s = 0; s < nscreens; s++) { 369 for (nlocks = 0, s = 0; s < nscreens; s++) {
367 if ((locks[s] = lockscreen(dpy, s)) != NULL) 370 if ((locks[s] = lockscreen(dpy, s)) != NULL)
368 nlocks++; 371 nlocks++;
372 else
373 break;
369 } 374 }
370 XSync(dpy, 0); 375 XSync(dpy, 0);
371 376
372 /* did we actually manage to lock anything? */ 377 /* did we manage to lock everything? */
373 if (nlocks == 0) { 378 if (nlocks != nscreens) {
374 /* nothing to protect */ 379 running = 0;
375 cleanup(dpy); 380 cleanup(dpy);
376 return 1; 381 return 1;
377 } 382 }
@@ -400,9 +405,6 @@ main(int argc, char **argv) {
400#endif 405#endif
401 406
402 /* password ok, unlock everything and quit */ 407 /* password ok, unlock everything and quit */
403 for (s = 0; s < nscreens; s++)
404 unlockscreen(dpy, locks[s]);
405
406 cleanup(dpy); 408 cleanup(dpy);
407 409
408 return 0; 410 return 0;