utils: rework lxc_setgroups()

parent 8917c382
...@@ -1454,14 +1454,20 @@ bool lxc_drop_groups(void) ...@@ -1454,14 +1454,20 @@ bool lxc_drop_groups(void)
return ret == 0; 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) { int ret;
SYSERROR("Failed to setgroups()");
return false; 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; return true;
} }
......
...@@ -156,7 +156,7 @@ __hidden extern bool task_blocks_signal(pid_t pid, int signal); ...@@ -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. * 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_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); __hidden extern bool lxc_drop_groups(void);
/* Find an unused loop device and associate it with source. */ /* Find an unused loop device and associate it with source. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment