2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-05 00:35:33 +00:00

lib: simplify daemon_become_new_user__()

A global variable 'switch_user' was used to make sure
we switch process's current user only once. This logic is now
simplified by testing for uid directly; if switch process has
taken place, the current uid will be not be zero.

Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Ansis Atteka <aatteka@nicira.com>
This commit is contained in:
Andy Zhou
2015-10-09 18:48:59 -07:00
parent c4e34c6114
commit 6069edb0ea
2 changed files with 7 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,7 +84,6 @@ static bool monitor;
/* --user: Only root can use this option. Switch to new uid:gid after
* initially running as root. */
static bool switch_user = false;
static bool non_root_user = false;
static uid_t uid;
static gid_t gid;
static char *user = NULL;
@@ -445,11 +444,6 @@ daemonize_start(bool access_datapath)
switch_user = false;
}
/* If --user is specified, make sure user switch has completed by now. */
if (non_root_user) {
ovs_assert(geteuid() && getuid());
}
if (detach) {
pid_t pid;
@@ -875,9 +869,7 @@ daemon_become_new_user(bool access_datapath)
assert_single_threaded();
if (switch_user) {
daemon_become_new_user__(access_datapath);
/* Make sure daemonize_start() will not switch
* user again. */
/* daemonize_start() should not switch user again. */
switch_user = false;
}
}
@@ -1041,5 +1033,5 @@ daemon_set_new_user(const char *user_spec)
}
}
switch_user = non_root_user = true;
switch_user = true;
}