Commit 31c53c2e by Daniel Lezcano Committed by Daniel Lezcano

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: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 8b92dc3a
...@@ -56,7 +56,7 @@ int lxc_af_unix_open(const char *path, int type, int flags) ...@@ -56,7 +56,7 @@ int lxc_af_unix_open(const char *path, int type, int flags)
return -1; return -1;
} }
if (listen(fd, 100)) { if (type == SOCK_STREAM && listen(fd, 100)) {
close(fd); close(fd);
return -1; return -1;
} }
......
...@@ -98,7 +98,7 @@ extern int lxc_monitor(const char *name, int output_fd); ...@@ -98,7 +98,7 @@ extern int lxc_monitor(const char *name, int output_fd);
* The function will return an fd corresponding to the events * The function will return an fd corresponding to the events
* Returns a file descriptor on success, < 0 otherwise * 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 * Read the state of the container if this one has changed
......
...@@ -31,12 +31,12 @@ ...@@ -31,12 +31,12 @@
#include <sys/param.h> #include <sys/param.h>
#include <sys/inotify.h> #include <sys/inotify.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <net/if.h> #include <net/if.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include "error.h" #include "error.h"
#include "af_unix.h"
#include <lxc/lxc.h> #include <lxc/lxc.h>
#include <lxc/log.h> #include <lxc/log.h>
...@@ -46,15 +46,6 @@ lxc_log_define(lxc_monitor, lxc); ...@@ -46,15 +46,6 @@ lxc_log_define(lxc_monitor, lxc);
#define UNIX_PATH_MAX 108 #define UNIX_PATH_MAX 108
#endif #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) int lxc_monitor(const char *name, int output_fd)
{ {
char path[MAXPATHLEN]; char path[MAXPATHLEN];
...@@ -118,19 +109,14 @@ out: ...@@ -118,19 +109,14 @@ out:
static void lxc_monitor_send(struct lxc_msg *msg) static void lxc_monitor_send(struct lxc_msg *msg)
{ {
int fd; int fd;
struct sockaddr_nl addr; struct sockaddr_un addr = { .sun_family = AF_UNIX };
char *offset = &addr.sun_path[1];
fd = socket(PF_NETLINK, SOCK_RAW, 0);
if (fd < 0) {
SYSERROR("failed to create notification socket");
return;
}
memset(&addr, 0, sizeof(addr)); strcpy(offset, "lxc-monitor");
addr.nl_family = AF_NETLINK; fd = socket(PF_UNIX, SOCK_DGRAM, 0);
addr.nl_pid = 0; if (fd < 0)
addr.nl_groups = MONITOR_MCGROUP; return;
sendto(fd, msg, sizeof(*msg), 0, sendto(fd, msg, sizeof(*msg), 0,
(const struct sockaddr *)&addr, sizeof(addr)); (const struct sockaddr *)&addr, sizeof(addr));
...@@ -149,24 +135,17 @@ void lxc_monitor_send_state(const char *name, lxc_state_t state) ...@@ -149,24 +135,17 @@ void lxc_monitor_send_state(const char *name, lxc_state_t state)
int lxc_monitor_open(void) int lxc_monitor_open(void)
{ {
struct sockaddr_un addr = { .sun_family = AF_UNIX };
char *offset = &addr.sun_path[1];
int fd; int fd;
struct sockaddr_nl addr;
fd = socket(PF_NETLINK, SOCK_RAW, 0); strcpy(offset, "lxc-monitor");
if (fd < 0) {
SYSERROR("failed to create notification socket");
return -LXC_ERROR_INTERNAL;
}
memset(&addr, 0, sizeof(addr)); fd = socket(PF_UNIX, SOCK_DGRAM, 0);
if (fd < 0)
addr.nl_family = AF_NETLINK; return -1;
addr.nl_pid = 0;
addr.nl_groups = MONITOR_MCGROUP;
if (bind(fd, (const struct sockaddr *)&addr, sizeof(addr))) { if (bind(fd, (struct sockaddr *)&addr, sizeof(addr))) {
SYSERROR("failed to bind to multicast group '%d'",
addr.nl_groups);
close(fd); close(fd);
return -1; return -1;
} }
...@@ -176,7 +155,7 @@ int lxc_monitor_open(void) ...@@ -176,7 +155,7 @@ int lxc_monitor_open(void)
int lxc_monitor_read(int fd, struct lxc_msg *msg) int lxc_monitor_read(int fd, struct lxc_msg *msg)
{ {
struct sockaddr_nl from; struct sockaddr_un from;
socklen_t len = sizeof(from); socklen_t len = sizeof(from);
int ret; int ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment