Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=fvbe.git;a=commitdiff;h=7e0bfb47e816b8be852754ae4632a752216eda9c

commit 7e0bfb47e816b8be852754ae4632a752216eda9c
Author: James Buren <[email protected]>
Date:   Wed Oct 23 01:15:05 2013 -0500

nmconfig: attempt to start/restart NetworkManager one time if we cannot verify 
that it is already running.

diff --git a/src/nmconfig.c b/src/nmconfig.c
index d5cf753..2d939bc 100644
--- a/src/nmconfig.c
+++ b/src/nmconfig.c
@@ -21,6 +21,36 @@ static struct nmdevice **nmdevices = 0;
static struct nmprofile **nmprofiles = 0;
static char *pname = 0;

+static bool nm_is_running(void)
+{
+  FILE *pipe = 0;
+  char line[LINE_MAX] = {0};
+  char *p = 0;
+
+  if((pipe = popen("LC_ALL=C nmcli -t -m tabular -f RUNNING -e yes nm 
2>&1","r")) == 0)
+  {
+    error(strerror(errno));
+    return false;
+  }
+
+  if(fgets(line,sizeof(line),pipe) == 0)
+  {
+    pclose(pipe);
+    return false;
+  }
+
+  if(pclose(pipe) == -1)
+  {
+    error(strerror(errno));
+    return false;
+  }
+
+  if((p = strchr(p,'\n')) != 0)
+    *p = 0;
+
+  return (strcmp(line,"running") == 0);
+}
+
static inline const char *nm_next_token(const char *p)
{
char c1 = 0;
@@ -313,6 +343,14 @@ static void nmprofile_free(struct nmprofile *p)
free(p);
}

+static bool nmconfig_start_service(void)
+{
+  if(nm_is_running())
+    return true;
+
+  return execute("systemctl restart NetworkManager.service",g->hostroot,0);
+}
+
static bool nmconfig_setup_devices(void)
{
FILE *pipe = 0;
@@ -469,6 +507,9 @@ static bool nmconfig_start(void)
size_t size = sizeof(entries) / sizeof(*entries);
char *entry = 0;

+  if(!nmconfig_start_service())
+    return false;
+
if(!nmconfig_setup_devices())
return false;
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to