static Lock **locks;
static int nscreens;
-static Bool running = True;
-static Bool failure = False;
static Bool rr;
static int rrevbase;
static int rrerrbase;
#endif
{
char buf[32], passwd[256], *encrypted;
- int num, screen;
+ int num, screen, running, failure;
unsigned int len, color;
KeySym ksym;
XEvent ev;
static int oldc = INIT;
len = 0;
- running = True;
+ running = 1;
+ failure = 0;
/* As "slock" stands for "Simple X display locker", the DPMS settings
* had been removed and you can set it with "xset" or some other
static void
cleanup(Display *dpy)
{
+ int s;
+
+ for (s = 0; s < nscreens; ++s)
+ unlockscreen(dpy, locks[s]);
+
free(locks);
XCloseDisplay(dpy);
}
XSetWindowAttributes wa;
Cursor invisible;
- if (!running || dpy == NULL || screen < 0 || !(lock = malloc(sizeof(Lock))))
+ if (dpy == NULL || screen < 0 || !(lock = malloc(sizeof(Lock))))
return NULL;
lock->screen = 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;
}
/* 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) {
cleanup(dpy);
return 1;
}
#endif
/* password ok, unlock everything and quit */
- for (s = 0; s < nscreens; s++)
- unlockscreen(dpy, locks[s]);
-
cleanup(dpy);
return 0;