logd: fix ignored return values in set{gid,uid}
authorPetr Štetiar <ynezz@true.cz>
Mon, 22 Mar 2021 17:22:14 +0000 (18:22 +0100)
committerPetr Štetiar <ynezz@true.cz>
Mon, 22 Mar 2021 17:22:14 +0000 (18:22 +0100)
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>
log/logd.c

index 7d531397db2c971d93ce0c58221fa27d33e2313c..5d6c458342490515d32560263ebfd07202927bfb 100644 (file)
@@ -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();