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

Submitted by Pavel Emelianov on Sept. 20, 2016, 1:26 p.m.

Details

Message ID 57E13911.5070307@virtuozzo.com
State Accepted
Series "Unify external resources in CLI"
Commit 95cecf9c2f3bd7b547cb05a0256b19eb76e18679
Headers show

Commit Message

Pavel Emelianov Sept. 20, 2016, 1:26 p.m.
Make it possible to distinguish 'no val' from 'empty val'.

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

Patch hide | download patch | download mbox

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) &&