add a system_init function for system control
authorSteven Barth <steven@midlink.org>
Fri, 23 Sep 2011 14:09:25 +0000 (14:09 +0000)
committerSteven Barth <steven@midlink.org>
Fri, 23 Sep 2011 14:09:25 +0000 (14:09 +0000)
main.c
system-dummy.c
system-linux.c
system.h

diff --git a/main.c b/main.c
index 7602f23b0aaa89ff96d0b736726c3c63ff9d7dd6..e008f64166143e187ce5cd395ceba9e16267f758 100644 (file)
--- a/main.c
+++ b/main.c
@@ -7,6 +7,7 @@
 #include "netifd.h"
 #include "ubus.h"
 #include "config.h"
+#include "system.h"
 #include "interface.h"
 
 const char *main_path = ".";
@@ -63,6 +64,11 @@ int main(int argc, char **argv)
                return 1;
        }
 
+       if (system_init()) {
+               fprintf(stderr, "Failed to initialize system control\n");
+               return 1;
+       }
+
        config_init_interfaces(NULL);
 
        uloop_run();
index 5aa51c035510e73f41f3b6a1eac18a36f7390563..a5d352d7c2454098e1f123f6bc4d0e0e6b5a591d 100644 (file)
 #include "device.h"
 #include "system.h"
 
+int system_init(void)
+{
+       return 0;
+}
+
 int system_bridge_addbr(struct device *bridge)
 {
        DPRINTF("brctl addbr %s\n", bridge->ifname);
index 1dbb651f747f47d805fce4a5e9150f52bb79921a..d09fd635a8485ae955ae8e028b2ff4028c290aab 100644 (file)
@@ -19,7 +19,7 @@
 static int sock_ioctl = -1;
 static struct nl_sock *sock_rtnl = NULL;
 
-static void __init system_init(void)
+int system_init(void)
 {
        sock_ioctl = socket(AF_LOCAL, SOCK_DGRAM, 0);
        fcntl(sock_ioctl, F_SETFD, fcntl(sock_ioctl, F_GETFD) | FD_CLOEXEC);
@@ -30,12 +30,14 @@ static void __init system_init(void)
                        sock_rtnl = NULL;
                }
        }
+
+       return -(sock_ioctl < 0 || !sock_rtnl);
 }
 
 static int system_rtnl_call(struct nl_msg *msg)
 {
-       return -!!(!sock_rtnl || nl_send_auto_complete(sock_rtnl, msg)
-                                       || nl_wait_for_ack(sock_rtnl));
+       return -(nl_send_auto_complete(sock_rtnl, msg)
+                       || nl_wait_for_ack(sock_rtnl));
 }
 
 int system_bridge_addbr(struct device *bridge)
index 86584674fe47493c6a05e515ae989f9b31c51e4f..c9b28c8bed6a02f113c76fe2ce1ee4a9c56135ef 100644 (file)
--- a/system.h
+++ b/system.h
@@ -5,6 +5,8 @@
 #include "device.h"
 #include "interface-ip.h"
 
+int system_init(void);
+
 int system_bridge_addbr(struct device *bridge);
 int system_bridge_delbr(struct device *bridge);
 int system_bridge_addif(struct device *bridge, struct device *dev);