Commit 7279c0e7 authored by Pavel Emelyanov's avatar Pavel Emelyanov

scm: Compile out opts management

In pure-compel library messing with opts is not required,
only criu and criu's pie will need it, so make it possible
to compile out common/scm-code's opts management.
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent bc102ea1
...@@ -24,4 +24,6 @@ ...@@ -24,4 +24,6 @@
#include "common/bug.h" #include "common/bug.h"
#define SCM_FDSET_HAS_OPTS
#include "common/scm-code.c" #include "common/scm-code.c"
...@@ -6,6 +6,14 @@ ...@@ -6,6 +6,14 @@
#error "The __memcpy macro is required" #error "The __memcpy macro is required"
#endif #endif
#ifdef SCM_FDSET_HAS_OPTS
#define OPTS_LEN(_flags, _nr) (_flags ? sizeof(struct fd_opts) * (_nr) : 1)
#define OPTS_BUF(_fdset) ((_fdset)->opts)
#else
#define OPTS_LEN(_flags, _nr) (1)
#define OPTS_BUF(_fdset) (&(_fdset)->dummy)
#endif
static void scm_fdset_init_chunk(struct scm_fdset *fdset, int nr_fds, bool with_flags) static void scm_fdset_init_chunk(struct scm_fdset *fdset, int nr_fds, bool with_flags)
{ {
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
...@@ -15,7 +23,7 @@ static void scm_fdset_init_chunk(struct scm_fdset *fdset, int nr_fds, bool with_ ...@@ -15,7 +23,7 @@ static void scm_fdset_init_chunk(struct scm_fdset *fdset, int nr_fds, bool with_
cmsg = CMSG_FIRSTHDR(&fdset->hdr); cmsg = CMSG_FIRSTHDR(&fdset->hdr);
cmsg->cmsg_len = fdset->hdr.msg_controllen; cmsg->cmsg_len = fdset->hdr.msg_controllen;
fdset->iov.iov_len = with_flags ? (sizeof(struct fd_opts) * nr_fds) : 1; fdset->iov.iov_len = OPTS_LEN(with_flags, nr_fds);
} }
static int *scm_fdset_init(struct scm_fdset *fdset, struct sockaddr_un *saddr, static int *scm_fdset_init(struct scm_fdset *fdset, struct sockaddr_un *saddr,
...@@ -25,7 +33,7 @@ static int *scm_fdset_init(struct scm_fdset *fdset, struct sockaddr_un *saddr, ...@@ -25,7 +33,7 @@ static int *scm_fdset_init(struct scm_fdset *fdset, struct sockaddr_un *saddr,
BUILD_BUG_ON(sizeof(fdset->msg_buf) < (CMSG_SPACE(sizeof(int) * CR_SCM_MAX_FD))); BUILD_BUG_ON(sizeof(fdset->msg_buf) < (CMSG_SPACE(sizeof(int) * CR_SCM_MAX_FD)));
fdset->iov.iov_base = fdset->opts; fdset->iov.iov_base = OPTS_BUF(fdset);
fdset->hdr.msg_iov = &fdset->iov; fdset->hdr.msg_iov = &fdset->iov;
fdset->hdr.msg_iovlen = 1; fdset->hdr.msg_iovlen = 1;
...@@ -56,6 +64,7 @@ int send_fds(int sock, struct sockaddr_un *saddr, int len, ...@@ -56,6 +64,7 @@ int send_fds(int sock, struct sockaddr_un *saddr, int len,
scm_fdset_init_chunk(&fdset, min_fd, with_flags); scm_fdset_init_chunk(&fdset, min_fd, with_flags);
__memcpy(cmsg_data, &fds[i], sizeof(int) * min_fd); __memcpy(cmsg_data, &fds[i], sizeof(int) * min_fd);
#ifdef SCM_FDSET_HAS_OPTS
if (with_flags) { if (with_flags) {
int j; int j;
...@@ -99,6 +108,7 @@ int send_fds(int sock, struct sockaddr_un *saddr, int len, ...@@ -99,6 +108,7 @@ int send_fds(int sock, struct sockaddr_un *saddr, int len,
p->fown.pid = owner_ex.pid; p->fown.pid = owner_ex.pid;
} }
} }
#endif
ret = __sys(sendmsg)(sock, &fdset.hdr, 0); ret = __sys(sendmsg)(sock, &fdset.hdr, 0);
if (ret <= 0) if (ret <= 0)
...@@ -146,8 +156,10 @@ int recv_fds(int sock, int *fds, int nr_fds, struct fd_opts *opts) ...@@ -146,8 +156,10 @@ int recv_fds(int sock, int *fds, int nr_fds, struct fd_opts *opts)
if (unlikely(min_fd <= 0)) if (unlikely(min_fd <= 0))
return -1; return -1;
__memcpy(&fds[i], cmsg_data, sizeof(int) * min_fd); __memcpy(&fds[i], cmsg_data, sizeof(int) * min_fd);
#ifdef SCM_FDSET_HAS_OPTS
if (opts) if (opts)
__memcpy(opts + i, fdset.opts, sizeof(struct fd_opts) * min_fd); __memcpy(opts + i, fdset.opts, sizeof(struct fd_opts) * min_fd);
#endif
} }
return 0; return 0;
......
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