From: Daniel Lezcano Date: Thu, 14 May 2009 19:28:27 +0000 (+0200) Subject: Replace netlink by abstract unix socket X-Git-Tag: lxc_0_6_3~96 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=31c53c2e1afc6c81ce4aad5ef4cb982cd2fea365;p=thirdparty%2Flxc.git Replace netlink by abstract unix socket Instead of messing with the netlink messages, let's use the abstract unix socket and assume we will have a single receiver and multiple sender. With this patch mcr-wait and mcr-monitor are mutually exclusive... for the moment. Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/af_unix.c b/src/lxc/af_unix.c index c24df8b7b..79f64ae3f 100644 --- a/src/lxc/af_unix.c +++ b/src/lxc/af_unix.c @@ -56,7 +56,7 @@ int lxc_af_unix_open(const char *path, int type, int flags) return -1; } - if (listen(fd, 100)) { + if (type == SOCK_STREAM && listen(fd, 100)) { close(fd); return -1; } diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h index 5908fb72b..f17a9060d 100644 --- a/src/lxc/lxc.h +++ b/src/lxc/lxc.h @@ -98,7 +98,7 @@ extern int lxc_monitor(const char *name, int output_fd); * The function will return an fd corresponding to the events * Returns a file descriptor on success, < 0 otherwise */ -extern int lxc_monitor_open(); +extern int lxc_monitor_open(void); /* * Read the state of the container if this one has changed diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c index a4ca5e40e..8e6bff8ab 100644 --- a/src/lxc/monitor.c +++ b/src/lxc/monitor.c @@ -31,12 +31,12 @@ #include #include #include +#include #include #include -#include -#include #include "error.h" +#include "af_unix.h" #include #include @@ -46,15 +46,6 @@ lxc_log_define(lxc_monitor, lxc); #define UNIX_PATH_MAX 108 #endif -#ifndef SOL_NETLINK -#define SOL_NETLINK 270 -#endif - -/* assuming this multicast group is not used by anyone else :/ - * otherwise a new genetlink family should be defined to own - * its multicast groups */ -#define MONITOR_MCGROUP RTNLGRP_MAX - int lxc_monitor(const char *name, int output_fd) { char path[MAXPATHLEN]; @@ -118,19 +109,14 @@ out: static void lxc_monitor_send(struct lxc_msg *msg) { int fd; - struct sockaddr_nl addr; - - fd = socket(PF_NETLINK, SOCK_RAW, 0); - if (fd < 0) { - SYSERROR("failed to create notification socket"); - return; - } + struct sockaddr_un addr = { .sun_family = AF_UNIX }; + char *offset = &addr.sun_path[1]; - memset(&addr, 0, sizeof(addr)); + strcpy(offset, "lxc-monitor"); - addr.nl_family = AF_NETLINK; - addr.nl_pid = 0; - addr.nl_groups = MONITOR_MCGROUP; + fd = socket(PF_UNIX, SOCK_DGRAM, 0); + if (fd < 0) + return; sendto(fd, msg, sizeof(*msg), 0, (const struct sockaddr *)&addr, sizeof(addr)); @@ -149,24 +135,17 @@ void lxc_monitor_send_state(const char *name, lxc_state_t state) int lxc_monitor_open(void) { + struct sockaddr_un addr = { .sun_family = AF_UNIX }; + char *offset = &addr.sun_path[1]; int fd; - struct sockaddr_nl addr; - fd = socket(PF_NETLINK, SOCK_RAW, 0); - if (fd < 0) { - SYSERROR("failed to create notification socket"); - return -LXC_ERROR_INTERNAL; - } + strcpy(offset, "lxc-monitor"); - memset(&addr, 0, sizeof(addr)); - - addr.nl_family = AF_NETLINK; - addr.nl_pid = 0; - addr.nl_groups = MONITOR_MCGROUP; + fd = socket(PF_UNIX, SOCK_DGRAM, 0); + if (fd < 0) + return -1; - if (bind(fd, (const struct sockaddr *)&addr, sizeof(addr))) { - SYSERROR("failed to bind to multicast group '%d'", - addr.nl_groups); + if (bind(fd, (struct sockaddr *)&addr, sizeof(addr))) { close(fd); return -1; } @@ -176,7 +155,7 @@ int lxc_monitor_open(void) int lxc_monitor_read(int fd, struct lxc_msg *msg) { - struct sockaddr_nl from; + struct sockaddr_un from; socklen_t len = sizeof(from); int ret;