commit 8296616c9491377f54b82f3fb4ddf4b34b387c4e
parent 230e1118843ba0d3acc70c7746a5a22026b25769
Author: sin <sin@2f30.org>
Date: Wed, 9 Jul 2014 14:45:36 +0100
Only check errno if getpw*() fails
Diffstat:
M | smdev.c | | | 24 | ++++++++++++++---------- |
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/smdev.c b/smdev.c
@@ -288,19 +288,23 @@ createdev(struct event *ev)
errno = 0;
pw = getpwnam(rule->user);
- if (errno)
- eprintf("getpwnam %s:", rule->user);
- else if (!pw)
- enprintf(1, "getpwnam %s: no such user\n",
- rule->user);
+ if (!pw) {
+ if (errno)
+ eprintf("getpwnam %s:", rule->user);
+ else
+ enprintf(1, "getpwnam %s: no such user\n",
+ rule->user);
+ }
errno = 0;
gr = getgrnam(rule->group);
- if (errno)
- eprintf("getgrnam %s:", rule->group);
- else if (!gr)
- enprintf(1, "getgrnam %s: no such group\n",
- rule->group);
+ if (!gr) {
+ if (errno)
+ eprintf("getgrnam %s:", rule->group);
+ else
+ enprintf(1, "getgrnam %s: no such group\n",
+ rule->group);
+ }
if (chown(rpath.path, pw->pw_uid, gr->gr_gid) < 0)
eprintf("chown %s:", rpath.path);