Browse Source

logd: fix ignored return values in set{gid,uid}

Ubuntu 18.05 with gcc-7.5 yields following error:

 ubox/log/logd.c:263:3: error: ignoring return value of ‘setuid’, declared with attribute warn_unused_result [-Werror=unused-result]
   setuid(p->pw_uid);
   ^~~~~~~~~~~~~~~~~
 ubox/log/logd.c:264:3: error: ignoring return value of ‘setgid’, declared with attribute warn_unused_result [-Werror=unused-result]
   setgid(p->pw_gid);
   ^~~~~~~~~~~~~~~~~

Fixes: 9ef886819dd4 ("logd: self-degrade to 'logd' user after opening pipes")
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Petr Štetiar 3 years ago
parent
commit
41664054b8
1 changed files with 9 additions and 2 deletions
  1. 9 2
      log/logd.c

+ 9 - 2
log/logd.c

@@ -260,8 +260,15 @@ main(int argc, char **argv)
 	ubus_auto_connect(&conn);
 	p = getpwnam("logd");
 	if (p) {
-		setuid(p->pw_uid);
-		setgid(p->pw_gid);
+		if (setuid(p->pw_uid) < 0) {
+			fprintf(stderr, "setuid() failed: %s\n", strerror(errno));
+			exit(1);
+		}
+
+		if (setgid(p->pw_gid) < 0) {
+			fprintf(stderr, "setgid() failed: %s\n", strerror(errno));
+			exit(1);
+		}
 	}
 	uloop_run();
 	log_shutdown();