[CRIU] [PATCH 4/6] ext: Lookup by key return NULL or ENOENT

Pavel Emelyanov xemul at virtuozzo.com
Tue Sep 20 06:26:41 PDT 2016


Make it possible to distinguish 'no val' from 'empty val'.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/external.c | 5 ++++-
 criu/mount.c    | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/criu/external.c b/criu/external.c
index f3459df..c7ff072 100644
--- a/criu/external.c
+++ b/criu/external.c
@@ -1,3 +1,4 @@
+#include "err.h"
 #include "list.h"
 #include "cr_options.h"
 #include "xmalloc.h"
@@ -36,8 +37,10 @@ char *external_lookup_by_key(char *key)
 			continue;
 		if (ext->id[len] == ':')
 			return ext->id + len + 1;
+		else if (ext->id[len] == '\0')
+			return NULL;
 	}
-	return NULL;
+	return ERR_PTR(-ENOENT);
 }
 
 int external_for_each_type(char *type, int (*cb)(struct external *, void *), void *arg)
diff --git a/criu/mount.c b/criu/mount.c
index 6e98f1e..5a4ecd9 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -494,7 +494,7 @@ static int try_resolve_ext_mount(struct mount_info *info)
 		char *val;
 
 		val = external_lookup_by_key(devstr);
-		if (val) {
+		if (!IS_ERR_OR_NULL(val)) {
 			char *source;
 			int len;
 
@@ -2256,7 +2256,7 @@ static char *resolve_source(struct mount_info *mi)
 		char *val;
 
 		val = external_lookup_by_key(mi->source);
-		if (val)
+		if (!IS_ERR_OR_NULL(val))
 			return val;
 
 		if (!stat(mi->source, &st) && S_ISBLK(st.st_mode) &&
-- 
2.5.0



More information about the CRIU mailing list