diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-01-16 12:38:36 +0100 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-01-18 16:47:41 +0100 |
commit | 55e827af0fb94f6c2b9e76a7bfe7e98cf697dc7b (patch) | |
tree | 1a5385cc6d25f9cccbb9ae1afa9d15f34410bb54 | |
parent | e867c38123175d6f050e051ee6b00f4737a9712a (diff) |
code style fix
-rw-r--r-- | slock.c | 27 |
1 files changed, 9 insertions, 18 deletions
@@ -94,20 +94,18 @@ getpw(void) | |||
94 | struct passwd *pw; | 94 | struct passwd *pw; |
95 | 95 | ||
96 | errno = 0; | 96 | errno = 0; |
97 | pw = getpwuid(getuid()); | 97 | if (!(pw = getpwuid(getuid()))) { |
98 | if (!pw) { | ||
99 | if (errno) | 98 | if (errno) |
100 | die("slock: getpwuid: %s\n", strerror(errno)); | 99 | die("slock: getpwuid: %s\n", strerror(errno)); |
101 | else | 100 | else |
102 | die("slock: cannot retrieve password entry\n"); | 101 | die("slock: cannot retrieve password entry\n"); |
103 | } | 102 | } |
104 | rval = pw->pw_passwd; | 103 | rval = pw->pw_passwd; |
105 | 104 | ||
106 | #if HAVE_SHADOW_H | 105 | #if HAVE_SHADOW_H |
107 | if (rval[0] == 'x' && rval[1] == '\0') { | 106 | if (rval[0] == 'x' && rval[1] == '\0') { |
108 | struct spwd *sp; | 107 | struct spwd *sp; |
109 | sp = getspnam(getenv("USER")); | 108 | if (!(sp = getspnam(getenv("USER")))) |
110 | if (!sp) | ||
111 | die("slock: cannot retrieve shadow entry (make sure to suid or sgid slock)\n"); | 109 | die("slock: cannot retrieve shadow entry (make sure to suid or sgid slock)\n"); |
112 | rval = sp->sp_pwdp; | 110 | rval = sp->sp_pwdp; |
113 | } | 111 | } |
@@ -180,7 +178,7 @@ readpw(Display *dpy, const char *pws) | |||
180 | --len; | 178 | --len; |
181 | break; | 179 | break; |
182 | default: | 180 | default: |
183 | if (num && !iscntrl((int) buf[0]) && (len + num < sizeof(passwd))) { | 181 | if (num && !iscntrl((int)buf[0]) && (len + num < sizeof(passwd))) { |
184 | memcpy(passwd + len, buf, num); | 182 | memcpy(passwd + len, buf, num); |
185 | len += num; | 183 | len += num; |
186 | } | 184 | } |
@@ -232,15 +230,10 @@ lockscreen(Display *dpy, int screen) | |||
232 | XSetWindowAttributes wa; | 230 | XSetWindowAttributes wa; |
233 | Cursor invisible; | 231 | Cursor invisible; |
234 | 232 | ||
235 | if (dpy == NULL || screen < 0) | 233 | if (dpy == NULL || screen < 0 || !(lock = malloc(sizeof(Lock)))) |
236 | return NULL; | ||
237 | |||
238 | lock = malloc(sizeof(Lock)); | ||
239 | if (lock == NULL) | ||
240 | return NULL; | 234 | return NULL; |
241 | 235 | ||
242 | lock->screen = screen; | 236 | lock->screen = screen; |
243 | |||
244 | lock->root = RootWindow(dpy, lock->screen); | 237 | lock->root = RootWindow(dpy, lock->screen); |
245 | 238 | ||
246 | for (i = 0; i < NUMCOLS; i++) { | 239 | for (i = 0; i < NUMCOLS; i++) { |
@@ -266,7 +259,7 @@ lockscreen(Display *dpy, int screen) | |||
266 | break; | 259 | break; |
267 | usleep(1000); | 260 | usleep(1000); |
268 | } | 261 | } |
269 | if (running && (len > 0)) { | 262 | if (running && len) { |
270 | for (len = 1000; len; len--) { | 263 | for (len = 1000; len; len--) { |
271 | if (XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess) | 264 | if (XGrabKeyboard(dpy, lock->root, True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess) |
272 | break; | 265 | break; |
@@ -278,8 +271,7 @@ lockscreen(Display *dpy, int screen) | |||
278 | if (!running) { | 271 | if (!running) { |
279 | unlockscreen(dpy, lock); | 272 | unlockscreen(dpy, lock); |
280 | lock = NULL; | 273 | lock = NULL; |
281 | } | 274 | } else { |
282 | else { | ||
283 | XSelectInput(dpy, lock->root, SubstructureNotifyMask); | 275 | XSelectInput(dpy, lock->root, SubstructureNotifyMask); |
284 | } | 276 | } |
285 | 277 | ||
@@ -323,12 +315,11 @@ main(int argc, char **argv) { | |||
323 | rr = XRRQueryExtension(dpy, &rrevbase, &rrerrbase); | 315 | rr = XRRQueryExtension(dpy, &rrevbase, &rrerrbase); |
324 | /* Get the number of screens in display "dpy" and blank them all. */ | 316 | /* Get the number of screens in display "dpy" and blank them all. */ |
325 | nscreens = ScreenCount(dpy); | 317 | nscreens = ScreenCount(dpy); |
326 | locks = malloc(sizeof(Lock *) * nscreens); | 318 | if (!(locks = malloc(sizeof(Lock*) * nscreens))) |
327 | if (locks == NULL) | ||
328 | die("slock: malloc: %s\n", strerror(errno)); | 319 | die("slock: malloc: %s\n", strerror(errno)); |
329 | int nlocks = 0; | 320 | int nlocks = 0; |
330 | for (screen = 0; screen < nscreens; screen++) { | 321 | for (screen = 0; screen < nscreens; screen++) { |
331 | if ( (locks[screen] = lockscreen(dpy, screen)) != NULL) | 322 | if ((locks[screen] = lockscreen(dpy, screen)) != NULL) |
332 | nlocks++; | 323 | nlocks++; |
333 | } | 324 | } |
334 | XSync(dpy, False); | 325 | XSync(dpy, False); |