diff options
author | Andy Zhou <azhou@nicira.com> | 2015-10-09 18:48:59 -0700 |
---|---|---|
committer | Andy Zhou <azhou@nicira.com> | 2015-11-11 18:05:44 -0800 |
commit | 6069edb0ea9c861d32016473a86d330f5ce60123 (patch) | |
tree | eda86c3a357897ad234e0ffd8bc7104046e14c26 /lib/daemon-unix.c | |
parent | c4e34c6114bcf4cf9248fe910ae8f202b6293f40 (diff) | |
download | openvswitch-6069edb0ea9c861d32016473a86d330f5ce60123.tar.gz |
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>
Diffstat (limited to 'lib/daemon-unix.c')
-rw-r--r-- | lib/daemon-unix.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/lib/daemon-unix.c b/lib/daemon-unix.c index 868e2c9f5..012574555 100644 --- a/lib/daemon-unix.c +++ b/lib/daemon-unix.c @@ -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; } |