diff options
author | Steven Barth <steven@midlink.org> | 2011-09-23 14:09:25 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2011-09-23 14:09:25 +0000 |
commit | 8e3fc8bfa55fe256ab9520db8df94dae57a1dc28 (patch) | |
tree | 11e0851e9a848bb350520e80e9f5bb45f27dbcdf | |
parent | 2c915b27e10c02795eea8b2fb9f327a62c5ef40d (diff) |
add a system_init function for system control
-rw-r--r-- | main.c | 6 | ||||
-rw-r--r-- | system-dummy.c | 5 | ||||
-rw-r--r-- | system-linux.c | 8 | ||||
-rw-r--r-- | system.h | 2 |
4 files changed, 18 insertions, 3 deletions
@@ -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(); diff --git a/system-dummy.c b/system-dummy.c index 5aa51c0..a5d352d 100644 --- a/system-dummy.c +++ b/system-dummy.c @@ -11,6 +11,11 @@ #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); diff --git a/system-linux.c b/system-linux.c index 1dbb651..d09fd63 100644 --- a/system-linux.c +++ b/system-linux.c @@ -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) @@ -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); |