From af2b44cb43ecdd7d2ad0dcaf930f2674701a5d15 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 14 Mar 2015 17:58:23 +0100 Subject: [PATCH] main: (order) check pidfile earlier for running NM We should check for conflicting process (pidfile) early on and error out. --- src/main.c | 4 ++-- src/nm-iface-helper.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.c b/src/main.c index 8deb62cccb..067a0cee3c 100644 --- a/src/main.c +++ b/src/main.c @@ -285,6 +285,8 @@ main (int argc, char *argv[]) nm_main_utils_ensure_root (); + nm_main_utils_ensure_not_running_pidfile (global_opt.pidfile); + if (!nm_logging_setup (global_opt.opt_log_level, global_opt.opt_log_domains, &bad_domains, @@ -332,8 +334,6 @@ main (int argc, char *argv[]) nm_main_utils_ensure_rundir (); - nm_main_utils_ensure_not_running_pidfile (global_opt.pidfile); - /* Read the config file and CLI overrides */ config = nm_config_setup (config_cli, &error); nm_config_cmd_line_options_free (config_cli); diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c index 33ba269236..226c6a8f14 100644 --- a/src/nm-iface-helper.c +++ b/src/nm-iface-helper.c @@ -378,6 +378,14 @@ main (int argc, char *argv[]) exit (1); } + ifindex = if_nametoindex (global_opt.ifname); + if (ifindex <= 0) { + fprintf (stderr, _("Failed to find interface index for %s (%s)\n"), global_opt.ifname, strerror (errno)); + exit (1); + } + pidfile = g_strdup_printf (NMIH_PID_FILE_FMT, ifindex); + nm_main_utils_ensure_not_running_pidfile (pidfile); + if (!nm_logging_setup (global_opt.opt_log_level, global_opt.opt_log_domains, &bad_domains, @@ -395,14 +403,6 @@ main (int argc, char *argv[]) nm_main_utils_ensure_rundir (); - ifindex = if_nametoindex (global_opt.ifname); - if (ifindex <= 0) { - fprintf (stderr, _("Failed to find interface index for %s (%s)\n"), global_opt.ifname, strerror (errno)); - exit (1); - } - pidfile = g_strdup_printf (NMIH_PID_FILE_FMT, ifindex); - nm_main_utils_ensure_not_running_pidfile (pidfile); - if (global_opt.become_daemon && !global_opt.debug) { if (daemon (0, 0) < 0) { int saved_errno;