[CRIU] [PATCH 1/3] scm: Return sensible error codes in recv_fds()
Kirill Tkhai
ktkhai at virtuozzo.com
Wed Jan 25 01:46:19 PST 2017
Replace "-1" return with errno codes.
ENOMSG and EBADFD were choosen to do not cross with
standard recvmsg() errors (described in its man page).
This patch is need as preparation to making recv_msg()
be able to be non-block, and return EAGAIN and EWOULDBLOCK
in case of no data.
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
compel/plugins/std/fds.c | 1 +
compel/src/lib/infect.c | 1 +
criu/pie/util-fd.c | 2 ++
include/common/scm-code.c | 4 ++--
4 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/compel/plugins/std/fds.c b/compel/plugins/std/fds.c
index 8cfe6d288..a61bbfd2c 100644
--- a/compel/plugins/std/fds.c
+++ b/compel/plugins/std/fds.c
@@ -15,6 +15,7 @@
#include "common/bug.h"
#define __sys(foo) sys_##foo
+#define __sys_err(ret) ret
#define __memcpy std_memcpy
#include "common/scm-code.c"
diff --git a/compel/src/lib/infect.c b/compel/src/lib/infect.c
index 599c37274..b8997a40d 100644
--- a/compel/src/lib/infect.c
+++ b/compel/src/lib/infect.c
@@ -30,6 +30,7 @@
#include "infect-util.h"
#define __sys(foo) foo
+#define __sys_err(ret) (-errno)
#define __memcpy memcpy
#include "common/scm.h"
diff --git a/criu/pie/util-fd.c b/criu/pie/util-fd.c
index 84b8c5e0c..a64d0821b 100644
--- a/criu/pie/util-fd.c
+++ b/criu/pie/util-fd.c
@@ -13,8 +13,10 @@
#ifdef CR_NOGLIBC
# include <compel/plugins/std/syscall.h>
# define __sys(foo) sys_##foo
+# define __sys_err(ret) ret
#else
# define __sys(foo) foo
+# define __sys_err(ret) (-errno)
#endif
#define __memcpy builtin_memcpy
diff --git a/include/common/scm-code.c b/include/common/scm-code.c
index 504c97212..4015405d2 100644
--- a/include/common/scm-code.c
+++ b/include/common/scm-code.c
@@ -90,7 +90,7 @@ int recv_fds(int sock, int *fds, int nr_fds, void *data, unsigned ch_size)
ret = __sys(recvmsg)(sock, &fdset.hdr, 0);
if (ret <= 0)
- return ret ? : -1;
+ return ret ? __sys_err(ret) : -ENOMSG;
cmsg = CMSG_FIRSTHDR(&fdset.hdr);
if (!cmsg || cmsg->cmsg_type != SCM_RIGHTS)
@@ -111,7 +111,7 @@ int recv_fds(int sock, int *fds, int nr_fds, void *data, unsigned ch_size)
BUG_ON(min_fd > CR_SCM_MAX_FD);
if (unlikely(min_fd <= 0))
- return -1;
+ return -EBADFD;
__memcpy(&fds[i], cmsg_data, sizeof(int) * min_fd);
if (data)
More information about the CRIU
mailing list