mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-09 05:20:19 +01:00
main: (order) move root user check after help/version option
With this change, `NetworkManager --help` and `NetworkManager --version`
work for non-root user.
(cherry picked from commit 95786a4e4e)
Conflicts:
src/main-utils.c
src/main-utils.h
This commit is contained in:
parent
3aad126ec1
commit
4a42792322
4 changed files with 16 additions and 5 deletions
|
|
@ -36,6 +36,7 @@
|
|||
#include "gsystem-local-alloc.h"
|
||||
#include "main-utils.h"
|
||||
#include "nm-posix-signals.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-logging.h"
|
||||
|
||||
static sigset_t signal_set;
|
||||
|
|
@ -216,6 +217,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,
|
||||
|
|
@ -248,11 +258,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;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include <glib.h>
|
||||
|
||||
void nm_main_utils_ensure_root (void);
|
||||
|
||||
gboolean nm_main_utils_setup_signals (GMainLoop *main_loop, gboolean *quit_early_ptr);
|
||||
|
||||
void nm_main_utils_ensure_rundir (void);
|
||||
|
|
|
|||
|
|
@ -277,6 +277,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,
|
||||
|
|
|
|||
|
|
@ -370,6 +370,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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue