From: Christian Brauner Date: Fri, 5 Feb 2021 11:07:44 +0000 (+0100) Subject: utils: rework lxc_setgroups() X-Git-Tag: lxc-5.0.0~299^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a7f1dc6605804183024432e80d89c5b94ce3048;p=thirdparty%2Flxc.git utils: rework lxc_setgroups() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/utils.c b/src/lxc/utils.c index afe4e641e..600a68458 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -1454,14 +1454,20 @@ bool lxc_drop_groups(void) return ret == 0; } -bool lxc_setgroups(int size, gid_t list[]) +bool lxc_setgroups(gid_t list[], size_t size) { - if (setgroups(size, list) < 0) { - SYSERROR("Failed to setgroups()"); - return false; + int ret; + + ret = setgroups(size, list); + if (ret) + return log_error_errno(false, errno, "Failed to set supplimentary groups"); + + if (size > 0 && lxc_log_trace()) { + for (size_t i = 0; i < size; i++) + TRACE("Setting supplimentary group %d", list[i]); } - NOTICE("Dropped additional groups"); + NOTICE("Set supplimentary groups"); return true; } diff --git a/src/lxc/utils.h b/src/lxc/utils.h index e918fb77f..7217d6913 100644 --- a/src/lxc/utils.h +++ b/src/lxc/utils.h @@ -156,7 +156,7 @@ __hidden extern bool task_blocks_signal(pid_t pid, int signal); * If LXC_INVALID_{G,U}ID is passed then the set{g,u}id() will not be called. */ __hidden extern bool lxc_switch_uid_gid(uid_t uid, gid_t gid); -__hidden extern bool lxc_setgroups(int size, gid_t list[]); +__hidden extern bool lxc_setgroups(gid_t list[], size_t size); __hidden extern bool lxc_drop_groups(void); /* Find an unused loop device and associate it with source. */