From 41664054b8b1bc19d842421c49d1b4d612ff8297 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20=C5=A0tetiar?= Date: Mon, 22 Mar 2021 18:22:14 +0100 Subject: [PATCH] logd: fix ignored return values in set{gid,uid} MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- log/logd.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/log/logd.c b/log/logd.c index 7d53139..5d6c458 100644 --- a/log/logd.c +++ b/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(); -- 2.30.2