summary refs log tree commit diff
diff options
context:
space:
mode:
authorC. McEnroe <june@causal.agency>2020-10-23 11:37:10 -0400
committerC. McEnroe <june@causal.agency>2020-10-23 11:37:10 -0400
commit363ab9f834a955b4b664e99f176293c30d6ef75b (patch)
treebbdfed0eac97bc95b92bb54dcb0089b884c981c5
parentRemove default defines of RUNDIR, ETCDIR (diff)
downloadcatsit-363ab9f834a955b4b664e99f176293c30d6ef75b.tar.gz
catsit-363ab9f834a955b4b664e99f176293c30d6ef75b.zip
Only look up group if one is named
-rw-r--r--daemon.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/daemon.c b/daemon.c
index 686b7fd..490e13f 100644
--- a/daemon.c
+++ b/daemon.c
@@ -242,16 +242,17 @@ int main(int argc, char *argv[]) {
 	struct passwd *user = (userName ? getpwnam(userName) : getpwuid(getuid()));
 	if (errno) err(EX_OSFILE, "getpwnam");
 	if (!user) errx(EX_USAGE, "no such user %s", userName);
-
-	errno = 0;
-	struct group *group = (
-		groupName ? getgrnam(groupName) : getgrgid(user->pw_gid)
-	);
-	if (errno) err(EX_OSFILE, "getgrnam");
-	if (!group) errx(EX_USAGE, "no such group %s", groupName);
-
 	serviceUID = user->pw_uid;
-	serviceGID = group->gr_gid;
+
+	if (groupName) {
+		errno = 0;
+		struct group *group = getgrnam(groupName);
+		if (errno) err(EX_OSFILE, "getgrnam");
+		if (!group) errx(EX_USAGE, "no such group %s", groupName);
+		serviceGID = group->gr_gid;
+	} else {
+		serviceGID = user->pw_gid;
+	}
 
 	int len = asprintf(&serviceEnviron[USER], "USER=%s", user->pw_name);
 	if (len < 0) err(EX_OSERR, "asprintf");