]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Replace netlink by abstract unix socket
authorDaniel Lezcano <daniel.lezcano@free.fr>
Thu, 14 May 2009 19:28:27 +0000 (21:28 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 14 May 2009 19:28:27 +0000 (21:28 +0200)
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 <dlezcano@fr.ibm.com>
src/lxc/af_unix.c
src/lxc/lxc.h
src/lxc/monitor.c

index c24df8b7bcc2b339f85f9d675c868681cf09f633..79f64ae3fbcec73f106179c7def99c0fa5f5d154 100644 (file)
@@ -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;
        }
index 5908fb72b24105e3f53eb8dae8b2318c7bce0b6c..f17a9060def228facbac36b8fde47b56d11ab26b 100644 (file)
@@ -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
index a4ca5e40e631bcdda12d5082fbb86485b73802e8..8e6bff8ab9e2025b04a8d8453d3c8ce1f5b250a9 100644 (file)
 #include <sys/param.h>
 #include <sys/inotify.h>
 #include <sys/socket.h>
+#include <sys/un.h>
 #include <netinet/in.h>
 #include <net/if.h>
-#include <linux/netlink.h>
-#include <linux/rtnetlink.h>
 
 #include "error.h"
+#include "af_unix.h"
 #include <lxc/lxc.h>
 #include <lxc/log.h>
 
@@ -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;