Skip to content

Commit

Permalink
start: avoid unnecessary syscalls
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Sep 30, 2018
1 parent 9991e6d commit 40dcd16
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/lxc/start.c
Expand Up @@ -1038,6 +1038,8 @@ static int do_start(void *data)
uid_t new_uid;
gid_t new_gid;
struct lxc_list *iterator;
uid_t nsuid = 0;
gid_t nsgid = 0;
int devnull_fd = -1;
struct lxc_handler *handler = data;

Expand Down Expand Up @@ -1105,12 +1107,11 @@ static int do_start(void *data)
* privilege over our namespace.
*/
if (!lxc_list_empty(&handler->conf->id_map)) {
uid_t nsuid = (handler->conf->root_nsuid_map != NULL)
? 0
: handler->conf->init_uid;
gid_t nsgid = (handler->conf->root_nsgid_map != NULL)
? 0
: handler->conf->init_gid;
if (!handler->conf->root_nsuid_map)
nsuid = handler->conf->init_uid;

if (!handler->conf->root_nsgid_map)
nsgid = handler->conf->init_gid;

ret = lxc_switch_uid_gid(nsuid, nsgid);
if (ret < 0)
Expand Down Expand Up @@ -1358,6 +1359,13 @@ static int do_start(void *data)
goto out_warn_father;
}

/* Avoid unnecessary syscalls. */
if (new_uid == nsuid)
new_uid = LXC_INVALID_UID;

if (new_gid == nsgid)
new_gid = LXC_INVALID_GID;

ret = lxc_switch_uid_gid(new_uid, new_gid);
if (ret < 0)
goto out_warn_father;
Expand Down

0 comments on commit 40dcd16

Please sign in to comment.