[CRIU] [PATCH 2/4] util-fd: shift code to the left side
Andrey Vagin
avagin at openvz.org
Mon Apr 7 03:00:13 PDT 2014
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
pie/util-fd.c | 85 ++++++++++++++++++++++++++++++-----------------------------
1 file changed, 43 insertions(+), 42 deletions(-)
diff --git a/pie/util-fd.c b/pie/util-fd.c
index 09d8ece..12d1bf3 100644
--- a/pie/util-fd.c
+++ b/pie/util-fd.c
@@ -64,54 +64,55 @@ int send_fds(int sock, struct sockaddr_un *saddr, int len,
cmsg_data = scm_fdset_init(&fdset, saddr, len, with_flags);
for (i = 0; i < nr_fds; i += min_fd) {
+ int j;
+
min_fd = min(CR_SCM_MAX_FD, nr_fds - i);
scm_fdset_init_chunk(&fdset, min_fd);
builtin_memcpy(cmsg_data, &fds[i], sizeof(int) * min_fd);
- if (with_flags) {
- int j;
-
- for (j = 0; j < min_fd; j++) {
- int flags, fd = fds[i + j];
- struct fd_opts *p = fdset.opts + j;
- struct f_owner_ex owner_ex;
- u32 v[2];
-
- flags = __sys(fcntl)(fd, F_GETFD, 0);
- if (flags < 0) {
- pr_err("fcntl(%d, F_GETFD) -> %d\n", fd, flags);
- return -1;
- }
-
- p->flags = (char)flags;
-
- ret = __sys(fcntl)(fd, F_GETOWN_EX, (long)&owner_ex);
- if (ret) {
- pr_err("fcntl(%d, F_GETOWN_EX) -> %d\n", fd, ret);
- return -1;
- }
-
- /*
- * Simple case -- nothing is changed.
- */
- if (owner_ex.pid == 0) {
- p->fown.pid = 0;
- continue;
- }
-
- ret = __sys(fcntl)(fd, F_GETOWNER_UIDS, (long)&v);
- if (ret) {
- pr_err("fcntl(%d, F_GETOWNER_UIDS) -> %d\n", fd, ret);
- return -1;
- }
-
- p->fown.uid = v[0];
- p->fown.euid = v[1];
- p->fown.pid_type = owner_ex.type;
- p->fown.pid = owner_ex.pid;
+ if (!with_flags)
+ goto skip;
+
+ for (j = 0; j < min_fd; j++) {
+ int flags, fd = fds[i + j];
+ struct fd_opts *p = fdset.opts + j;
+ struct f_owner_ex owner_ex;
+ u32 v[2];
+
+ flags = __sys(fcntl)(fd, F_GETFD, 0);
+ if (flags < 0) {
+ pr_err("fcntl(%d, F_GETFD) -> %d\n", fd, flags);
+ return -1;
+ }
+
+ p->flags = (char)flags;
+
+ ret = __sys(fcntl)(fd, F_GETOWN_EX, (long)&owner_ex);
+ if (ret) {
+ pr_err("fcntl(%d, F_GETOWN_EX) -> %d\n", fd, ret);
+ return -1;
+ }
+
+ /*
+ * Simple case -- nothing is changed.
+ */
+ if (owner_ex.pid == 0) {
+ p->fown.pid = 0;
+ continue;
}
- }
+ ret = __sys(fcntl)(fd, F_GETOWNER_UIDS, (long) &v);
+ if (ret) {
+ pr_err("fcntl(%d, F_GETOWNER_UIDS) -> %d\n", fd, ret);
+ return -1;
+ }
+
+ p->fown.uid = v[0];
+ p->fown.euid = v[1];
+ p->fown.pid_type = owner_ex.type;
+ p->fown.pid = owner_ex.pid;
+ }
+skip:
ret = __sys(sendmsg)(sock, &fdset.hdr, 0);
if (ret <= 0)
return ret ? : -1;
--
1.8.5.3
More information about the CRIU
mailing list