]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
utils: rework lxc_setgroups()
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 5 Feb 2021 11:07:44 +0000 (12:07 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 5 Feb 2021 11:12:29 +0000 (12:12 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/utils.c
src/lxc/utils.h

index afe4e641e66e721505fc0e90fda0ef5a3f1cdc13..600a6845871aba375bb847414e1f34f05a461026 100644 (file)
@@ -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;
 }
 
index e918fb77f3374d27368b73d7bf35d79d2a2f4046..7217d69137199be87ad0f12e149583a38b8205aa 100644 (file)
@@ -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. */