Skip to contentSkip to conversation

dmsetup: change the return value when no devices are found

PATCH New Lidong Zhong 1 participant 1 message Dec 23, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmsetup: change the return value when no devices are found

Calling 'dmsetup ls --target=multipath' results in this:

root: dmsetup ls --target=multipath
No devices found
root: echo $?
0

Note, 'No devices found' is printed on _stdout_, making it impossible to differentiate if this is an error (as in: dmsetup did not find any devices matching the above criteria) or if this is legit (as in: dmsetup found a device named 'No devices found').

This is absolutely wrong and makes it impossible to use dmsetup in a script.

---
 tools/dmsetup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/dmsetup.c +2 -1
index 1efffb6..2be3e6c 100644
@@ -1835,7 +1835,8 @@ static int _process_all(const struct command *cmd, const char *subcommand, int a
 
 	if (!names->dev) {
 		if (!silent)
-			printf("No devices found\n");
+			fprintf(stderr, "No devices found\n");
+		r = 0;
 		goto out;
 	}
 
Signature · 1 line
2.1.2