From 6069edb0ea9c861d32016473a86d330f5ce60123 Mon Sep 17 00:00:00 2001 From: Andy Zhou Date: Fri, 9 Oct 2015 18:48:59 -0700 Subject: 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 Acked-by: Ansis Atteka --- lib/daemon-unix.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'lib/daemon-unix.c') 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; } -- cgit v1.2.1