]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
Use different error code when command not found
authorKeith Busch <keith.busch@intel.com>
Mon, 1 Aug 2016 21:25:38 +0000 (15:25 -0600)
committerKeith Busch <keith.busch@intel.com>
Mon, 1 Aug 2016 21:25:38 +0000 (15:25 -0600)
A failed system call returns -1 with errno set, so lets differentiate
a failed system call from not finding a command at all. This suppresses
large help messages on any generic system call failure.

Signed-off-by: Keith Busch <keith.busch@intel.com>
nvme.c
plugin.c

diff --git a/nvme.c b/nvme.c
index 3e1b3d60e663ea6360fdd73e5c7e3d374b8f07c3..a33bc0d6cadfd12bbeeb1ef720682fb981cd0a67 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -2624,7 +2624,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
 
        ret = handle_plugin(argc - 1, &argv[1], nvme.extensions);
-       if (ret == -1)
+       if (ret == -ENOTTY)
                general_help(&builtin);
 
        return ret;
index dd971bf041a49886448677f5b7453fd9e0c5d2dd..ba771f9082f1388c2511256cf9b5d71c1274ec9c 100644 (file)
--- a/plugin.c
+++ b/plugin.c
@@ -143,7 +143,7 @@ int handle_plugin(int argc, char **argv, struct plugin *plugin)
        /* Check extensions only if this is running the built-in plugin */
        if (plugin->name) { 
                printf("ERROR: Invalid sub-command '%s' for plugin %s\n", str, plugin->name);
-               return -1;
+               return -ENOTTY;
         }
 
        extension = plugin->next;
@@ -162,5 +162,5 @@ int handle_plugin(int argc, char **argv, struct plugin *plugin)
                extension = extension->next;
        }
        printf("ERROR: Invalid sub-command '%s'\n", str);
-       return -1;
+       return -ENOTTY;
 }