[CRIU] [PATCH 5/8] parasite: Rework init() to handle errors and set status on return

Cyrill Gorcunov gorcunov at openvz.org
Tue Feb 21 15:22:15 EST 2012


Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 include/parasite.h |   23 +++++++++++++----------
 parasite.c         |   19 +++++++++++++------
 2 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/include/parasite.h b/include/parasite.h
index 30e593e..181cf7c 100644
--- a/include/parasite.h
+++ b/include/parasite.h
@@ -18,16 +18,19 @@
 #define PARASITE_MAX_SIZE	(64 << 10)
 
 /* we need own error code for diagnostics */
-#define PARASITE_ERR_FAIL	-1024
-#define PARASITE_ERR_OPEN	-1025
-#define PARASITE_ERR_MMAP	-1026
-#define PARASITE_ERR_MINCORE	-1027
-#define PARASITE_ERR_MUNMAP	-1028
-#define PARASITE_ERR_CLOSE	-1029
-#define PARASITE_ERR_WRITE	-1030
-#define PARASITE_ERR_MPROTECT	-1031
-#define PARASITE_ERR_SIGACTION  -1032
-#define PARASITE_ERR_GETITIMER  -1033
+#define PARASITE_ERR_FAIL		-1024
+#define PARASITE_ERR_OPEN		-1025
+#define PARASITE_ERR_MMAP		-1026
+#define PARASITE_ERR_MINCORE		-1027
+#define PARASITE_ERR_MUNMAP		-1028
+#define PARASITE_ERR_CLOSE		-1029
+#define PARASITE_ERR_WRITE		-1030
+#define PARASITE_ERR_MPROTECT		-1031
+#define PARASITE_ERR_SIGACTION		-1032
+#define PARASITE_ERR_GETITIMER		-1033
+#define PARASITE_ERR_SOCKET		-1034
+#define PARASITE_ERR_BIND		-1035
+#define PARASITE_ERR_SIGPROCMASK	-1036
 
 enum {
 	PARASITE_CMD_PINGME,
diff --git a/parasite.c b/parasite.c
index 50fcbf7..59e62ea 100644
--- a/parasite.c
+++ b/parasite.c
@@ -378,26 +378,33 @@ static int dump_misc(struct parasite_dump_misc *args)
 
 static int init(struct parasite_init_args *args)
 {
-	int ret;
+	parasite_status_t *st = &args->status;
 	k_rtsigset_t to_block;
+	int ret = -1;
 
 	tsock = sys_socket(PF_UNIX, SOCK_DGRAM, 0);
 	if (tsock < 0) {
-		return -1;
+		SET_PARASITE_STATUS(st, PARASITE_ERR_SOCKET, tsock);
+		goto err;
 	}
 
-	ret = sys_bind(tsock, (struct sockaddr *) &args->saddr, args->sun_len);
+	ret = sys_bind(tsock, (struct sockaddr *)&args->saddr, args->sun_len);
 	if (ret < 0) {
-		return -1;
+		SET_PARASITE_STATUS(st, PARASITE_ERR_BIND, ret);
+		goto err;
 	}
 
 	ksigfillset(&to_block);
 	ret = sys_sigprocmask(SIG_SETMASK, &to_block, &old_blocked);
-	if (ret < 0)
+	if (ret < 0) {
 		reset_blocked = ret;
-	else
+		SET_PARASITE_STATUS(st, PARASITE_ERR_SIGPROCMASK, ret);
+		goto err;
+	} else
 		reset_blocked = 1;
 
+	SET_PARASITE_STATUS_SUCCESS(st);
+err:
 	return ret;
 }
 
-- 
1.7.7.6



More information about the CRIU mailing list