[lxc-devel] [lxd/master] unixfd: split into header.{c,h}
brauner on Github
lxc-bot at linuxcontainers.org
Sun Oct 20 17:02:23 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191020/5dbcb46e/attachment.bin>
-------------- next part --------------
From aa531ed5d09dd01cecd9d4f14818072d4b1d8d11 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 20 Oct 2019 17:56:00 +0200
Subject: [PATCH] unixfd: split into header.{c,h}
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
shared/netutils/network_linux.go | 7 ++++---
shared/netutils/unixfd.c | 14 +++++++-------
shared/netutils/unixfd.h | 17 +++++++++++++++++
3 files changed, 28 insertions(+), 10 deletions(-)
create mode 100644 shared/netutils/unixfd.h
diff --git a/shared/netutils/network_linux.go b/shared/netutils/network_linux.go
index e593dc87cc..6f633ee0a8 100644
--- a/shared/netutils/network_linux.go
+++ b/shared/netutils/network_linux.go
@@ -19,10 +19,11 @@ import (
)
/*
-#include "../../shared/netutils/netns_getifaddrs.c"
-#include "../../shared/netutils/unixfd.c"
+#cgo CFLAGS: -std=gnu11 -Wvla
+
+#include "unixfd.h"
+#include "netns_getifaddrs.c"
*/
-// #cgo CFLAGS: -std=gnu11 -Wvla
import "C"
func NetnsGetifaddrs(initPID int32) (map[string]api.InstanceStateNetwork, error) {
diff --git a/shared/netutils/unixfd.c b/shared/netutils/unixfd.c
index 103c808f7f..c27bdd456c 100644
--- a/shared/netutils/unixfd.c
+++ b/shared/netutils/unixfd.c
@@ -1,6 +1,6 @@
-// +build none
-
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
@@ -17,6 +17,7 @@
#include <sys/types.h>
#include <sys/un.h>
+#include "unixfd.h"
#include "../../lxd/include/memory_utils.h"
int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds,
@@ -56,9 +57,8 @@ int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds,
return sendmsg(fd, &msg, MSG_NOSIGNAL);
}
-static ssize_t lxc_abstract_unix_recv_fds_iov(int fd, int *recvfds,
- int num_recvfds,
- struct iovec *iov, size_t iovlen)
+ssize_t lxc_abstract_unix_recv_fds_iov(int fd, int *recvfds, int num_recvfds,
+ struct iovec *iov, size_t iovlen)
{
__do_free char *cmsgbuf = NULL;
ssize_t ret;
@@ -107,7 +107,7 @@ static ssize_t lxc_abstract_unix_recv_fds_iov(int fd, int *recvfds,
return ret;
}
-static ssize_t lxc_abstract_unix_recv_fds(int fd, int *recvfds, int num_recvfds,
+ssize_t lxc_abstract_unix_recv_fds(int fd, int *recvfds, int num_recvfds,
void *data, size_t size)
{
char buf[1] = {0};
diff --git a/shared/netutils/unixfd.h b/shared/netutils/unixfd.h
new file mode 100644
index 0000000000..6ae46b7414
--- /dev/null
+++ b/shared/netutils/unixfd.h
@@ -0,0 +1,17 @@
+#ifndef LXD_UNIXFD_H
+#define LXD_UNIXFD_H
+
+#include <sys/socket.h>
+#include <sys/types.h>
+
+extern int lxc_abstract_unix_send_fds(int fd, int *sendfds, int num_sendfds,
+ void *data, size_t size);
+
+extern ssize_t lxc_abstract_unix_recv_fds_iov(int fd, int *recvfds,
+ int num_recvfds,
+ struct iovec *iov, size_t iovlen);
+
+extern ssize_t lxc_abstract_unix_recv_fds(int fd, int *recvfds, int num_recvfds,
+ void *data, size_t size);
+
+#endif // LXD_UNIXFD_H
More information about the lxc-devel
mailing list