From 217dfe7c6b68f5e203dec3435fa3bf65db6cc493 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Mon, 18 Sep 2017 12:44:33 +0800 Subject: [PATCH] drop_privs: ignore if uid or gid is zero 0 is the natural default for the info struct. If you are not 0 (root) then you can't change to root, it will fail without having done anything. What the user probably wanted is just leave it as the uid/gid it was started as. If you are 0 (root) you are already at 0 and the change has no meaning. Net effect is get rid of two warning logs if you left it at 0 in the info struct and start as non-root. --- lib/lws-plat-unix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lws-plat-unix.c b/lib/lws-plat-unix.c index 28e5bbe4..50b84ffc 100644 --- a/lib/lws-plat-unix.c +++ b/lib/lws-plat-unix.c @@ -315,11 +315,11 @@ lws_plat_drop_app_privileges(struct lws_context_creation_info *info) int n; #endif - if (info->gid != -1) + if (info->gid && info->gid != -1) if (setgid(info->gid)) lwsl_warn("setgid: %s\n", strerror(LWS_ERRNO)); - if (info->uid != -1) { + if (info->uid && info->uid != -1) { struct passwd *p = getpwuid(info->uid); if (p) {