[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [PATCH f16-branch] (take II) Restart NetworkManager to use anaconda's initial ifcfg config (#727951)



This looks better, thanks.  Ack.

On 08/08/11 07:41, Radek Vykydal wrote:
NM is started by systemd before anaconda writes out initial ifcfg files
which results in creating of automatic default connections (e.g.
"Wired connection 1"). The settings of auto connections are not persistent
so we are ok just restarting the NM.
---
  loader/loader.c         |    7 +++--
  pyanaconda/isys/iface.c |   48 +++++++++++++++++++++++++---------------------
  pyanaconda/isys/iface.h |    4 +-
  3 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/loader/loader.c b/loader/loader.c
index ec07b78..5b87ba8 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -2173,9 +2173,10 @@ int main(int argc, char ** argv) {
      }
  #endif

-    /* Start NetworkManager now so it's always available to talk to. */
-    if (iface_start_NetworkManager())
-        logMessage(INFO, "failed to start NetworkManager");
+    /* Restart NetworkManager now so that it uses our inital ifcfg config */
+    logMessage(INFO, "restarting NetworkManager");
+    if (iface_restart_NetworkManager())
+        logMessage(ERROR, "failed to restart NetworkManager");

      if (!FL_CMDLINE(flags))
          startNewt();
diff --git a/pyanaconda/isys/iface.c b/pyanaconda/isys/iface.c
index b5d539a..8ef4708 100644
--- a/pyanaconda/isys/iface.c
+++ b/pyanaconda/isys/iface.c
@@ -53,6 +53,7 @@

  #include "isys.h"
  #include "iface.h"
+#include "log.h"

  /* Internal-only function prototypes. */
  static struct nl_handle *_iface_get_handle(void);
@@ -501,37 +502,40 @@ int wait_for_nm(void) {
   * Start NetworkManager -- requires that you have already written out the
   * control files in /etc/sysconfig for the interface.
   */
-int iface_start_NetworkManager(void) {
-    pid_t pid;
+int iface_restart_NetworkManager(void) {
+    int child, status;

-    if (is_nm_running())
-        return 0;  /* already running */
-
-    /* Start NetworkManager */
-    pid = fork();
-    if (pid == 0) {
-        if (setpgrp() == -1) {
-            exit(1);
-        }
+    if (!(child = fork())) {

          if (_iface_redirect_io("/dev/null", STDIN_FILENO, O_RDONLY) ||
-            _iface_redirect_io(OUTPUT_TERMINAL, STDOUT_FILENO, O_WRONLY) ||
-            _iface_redirect_io(OUTPUT_TERMINAL, STDERR_FILENO, O_WRONLY)) {
-            exit(2);
+            _iface_redirect_io("/dev/tty3", STDOUT_FILENO, O_WRONLY) ||
+            _iface_redirect_io("/dev/tty3", STDERR_FILENO, O_WRONLY)) {
+            exit(253);
          }

-        if (execl(NETWORKMANAGER, NETWORKMANAGER,
-                  "--pid-file=/var/run/NetworkManager/NetworkManager.pid",
-                  NULL) == -1) {
-            exit(3);
-        }
-    } else if (pid == -1) {
+        execl("/bin/systemctl", "/bin/systemctl", "restart", "NetworkManager.service", NULL);
+        exit(254);
+    } else if (child<  0) {
+        logMessage(ERROR, "%s (%d): %m", __func__, __LINE__);
+        return 1;
+    }
+
+    if (waitpid(child,&status, 0) == -1) {
+        logMessage(ERROR, "%s (%d): %m", __func__, __LINE__);
+        return 1;
+    }
+
+    if (!WIFEXITED(status)) {
+        logMessage(ERROR, "%s (%d): %m", __func__, __LINE__);
+        return 1;
+    }
+
+    if (WEXITSTATUS(status)) {
+        logMessage(ERROR, "failed to restart NetworkManager with status %d", WEXITSTATUS(status));
          return 1;
      } else {
          return wait_for_nm();
      }
-
-    return 0;
  }

  /*
diff --git a/pyanaconda/isys/iface.h b/pyanaconda/isys/iface.h
index 2d0e4af..a386865 100644
--- a/pyanaconda/isys/iface.h
+++ b/pyanaconda/isys/iface.h
@@ -156,9 +156,9 @@ gboolean is_nm_connected(void);
  gboolean is_iface_activated(char * ifname);

  /*
- * Start NetworkManager
+ * Restart NetworkManager
   */
-int iface_start_NetworkManager(void);
+int iface_restart_NetworkManager(void);

  /*
   * Set Maximum Transfer Unit (MTU) on specified interface



--
David Cantrell <dcantrell redhat com>
Supervisor, Installer Engineering Team
Red Hat, Inc. | Westford, MA | EST5EDT


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]