From 95786a4e4e307dfd2c961280e65d16d5138050d6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 13 Mar 2015 20:57:18 +0100 Subject: [PATCH] main: (order) move root user check after help/version option With this change, `NetworkManager --help` and `NetworkManager --version` work for non-root user. --- src/main-utils.c | 15 ++++++++++----- src/main-utils.h | 2 ++ src/main.c | 2 ++ src/nm-iface-helper.c | 2 ++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main-utils.c b/src/main-utils.c index 564254dc91..1d899587ec 100644 --- a/src/main-utils.c +++ b/src/main-utils.c @@ -36,6 +36,7 @@ #include "gsystem-local-alloc.h" #include "main-utils.h" +#include "NetworkManagerUtils.h" #include "nm-logging.h" static gboolean @@ -172,6 +173,15 @@ nm_main_utils_ensure_not_running_pidfile (const char *pidfile) } } +void +nm_main_utils_ensure_root () +{ + if (getuid () != 0) { + fprintf (stderr, _("You must be root to run %s!\n"), str_if_set (g_get_prgname (), "")); + exit (1); + } +} + gboolean nm_main_utils_early_setup (const char *progname, int *argc, @@ -205,11 +215,6 @@ nm_main_utils_early_setup (const char *progname, setlocale (LC_ALL, ""); textdomain (GETTEXT_PACKAGE); - if (getuid () != 0) { - fprintf (stderr, _("You must be root to run %s!\n"), progname); - exit (1); - } - for (i = 0; options[i].long_name; i++) { if (!strcmp (options[i].long_name, "log-level")) { opt_fmt_log_level = options[i].description; diff --git a/src/main-utils.h b/src/main-utils.h index e928e20b69..7adfa94940 100644 --- a/src/main-utils.h +++ b/src/main-utils.h @@ -23,6 +23,8 @@ #include +void nm_main_utils_ensure_root (void); + void nm_main_utils_setup_signals (GMainLoop *main_loop); void nm_main_utils_ensure_rundir (void); diff --git a/src/main.c b/src/main.c index f34302d23b..8deb62cccb 100644 --- a/src/main.c +++ b/src/main.c @@ -283,6 +283,8 @@ main (int argc, char *argv[]) exit (0); } + nm_main_utils_ensure_root (); + if (!nm_logging_setup (global_opt.opt_log_level, global_opt.opt_log_domains, &bad_domains, diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c index 803ee54291..d26e05665c 100644 --- a/src/nm-iface-helper.c +++ b/src/nm-iface-helper.c @@ -367,6 +367,8 @@ main (int argc, char *argv[]) exit (0); } + nm_main_utils_ensure_root (); + if (!global_opt.ifname || !global_opt.uuid) { fprintf (stderr, _("An interface name and UUID are required\n")); exit (1);