aboutsummaryrefslogtreecommitdiff
path: root/slock.c
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 /slock.c
parente378f735d857f7da124177e3540912d920be5022 (diff)
downloadslock-39fb855aa100c5a5a8b7f3b6cc1fbb2135fe7dde.tar.gz
slock-39fb855aa100c5a5a8b7f3b6cc1fbb2135fe7dde.tar.xz
Move screen unlocking inside cleanup()
Diffstat (limited to 'slock.c')
-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)
static void
cleanup(Display *dpy)
{
+ int s;
+
+ for (s = 0; s < nscreens; ++s)
+ unlockscreen(dpy, locks[s]);
+
free(locks);
XCloseDisplay(dpy);
}
@@ -305,8 +310,6 @@ lockscreen(Display *dpy, int screen)
fprintf(stderr, "slock: unable to grab mouse pointer for screen %d\n", screen);
if (kbgrab != GrabSuccess)
fprintf(stderr, "slock: unable to grab keyboard for screen %d\n", screen);
- running = 0;
- unlockscreen(dpy, lock);
return NULL;
}
@@ -359,19 +362,21 @@ main(int argc, char **argv) {
/* get number of screens in display "dpy" and blank them */
nscreens = ScreenCount(dpy);
- if (!(locks = malloc(sizeof(Lock *) * nscreens))) {
+ if (!(locks = calloc(nscreens, sizeof(Lock *)))) {
XCloseDisplay(dpy);
die("slock: out of memory\n");
}
for (nlocks = 0, s = 0; s < nscreens; s++) {
if ((locks[s] = lockscreen(dpy, s)) != NULL)
nlocks++;
+ else
+ break;
}
XSync(dpy, 0);
- /* did we actually manage to lock anything? */
- if (nlocks == 0) {
- /* nothing to protect */
+ /* did we manage to lock everything? */
+ if (nlocks != nscreens) {
+ running = 0;
cleanup(dpy);
return 1;
}
@@ -400,9 +405,6 @@ main(int argc, char **argv) {
#endif
/* password ok, unlock everything and quit */
- for (s = 0; s < nscreens; s++)
- unlockscreen(dpy, locks[s]);
-
cleanup(dpy);
return 0;