From bc2ea72a79d0149f4c138c833c49866b52f27652 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. (cherry picked from commit af2b44cb43ecdd7d2ad0dcaf930f2674701a5d15) --- 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 1c18306b9e..e6b48c13ca 100644 --- a/src/main.c +++ b/src/main.c @@ -279,6 +279,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, @@ -326,8 +328,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_new (&error); if (config == NULL) { diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c index 1d842358c4..7d90bff812 100644 --- a/src/nm-iface-helper.c +++ b/src/nm-iface-helper.c @@ -381,6 +381,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, @@ -398,14 +406,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;