btrfs-progs: fix argv0_buf handling
authorDavid Sterba <dsterba@suse.cz>
Mon, 8 Jun 2015 21:30:21 +0000 (23:30 +0200)
committerDavid Sterba <dsterba@suse.cz>
Tue, 9 Jun 2015 11:32:32 +0000 (13:32 +0200)
The variable argv0_buf was duplicated and the changes done in utils.c
were not propagated to help.c. So if an unknown commandline token was
found, the error message did not contain the known part:

 $ btrfs scrub test
 : unknown token 'test'

instead of

 $ btrfs scrub test
 btrfs scrub: uknown token 'test'

Signed-off-by: David Sterba <dsterba@suse.cz>
help.c
utils.c
utils.h

diff --git a/help.c b/help.c
index 56aaf9c..56aded3 100644 (file)
--- a/help.c
+++ b/help.c
@@ -22,8 +22,6 @@
 #include "commands.h"
 #include "utils.h"
 
-static char argv0_buf[ARGV0_BUF_SIZE];
-
 #define USAGE_SHORT            1U
 #define USAGE_LONG             2U
 #define USAGE_OPTIONS          4U
@@ -183,7 +181,7 @@ void usage_command_group(const struct cmd_group *grp, int full, int err)
 
 void help_unknown_token(const char *arg, const struct cmd_group *grp)
 {
-       fprintf(stderr, "%s: unknown token '%s'\n", argv0_buf, arg);
+       fprintf(stderr, "%s: unknown token '%s'\n", get_argv0_buf(), arg);
        usage_command_group(grp, 0, 1);
        exit(1);
 }
@@ -192,7 +190,7 @@ void help_ambiguous_token(const char *arg, const struct cmd_group *grp)
 {
        const struct cmd_struct *cmd = grp->commands;
 
-       fprintf(stderr, "%s: ambiguous token '%s'\n", argv0_buf, arg);
+       fprintf(stderr, "%s: ambiguous token '%s'\n", get_argv0_buf(), arg);
        fprintf(stderr, "\nDid you mean one of these ?\n");
 
        for (; cmd->token; cmd++) {
diff --git a/utils.c b/utils.c
index f34c27b..1783737 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -54,6 +54,11 @@ static int btrfs_scan_done = 0;
 
 static char argv0_buf[ARGV0_BUF_SIZE] = "btrfs";
 
+const char *get_argv0_buf(void)
+{
+       return argv0_buf;
+}
+
 void fixup_argv0(char **argv, const char *token)
 {
        int len = strlen(argv0_buf);
diff --git a/utils.h b/utils.h
index 12923de..e771482 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -235,4 +235,6 @@ static inline u64 div_factor(u64 num, int factor)
 int btrfs_tree_search2_ioctl_supported(int fd);
 int btrfs_check_nodesize(u32 nodesize, u32 sectorsize);
 
+const char *get_argv0_buf(void);
+
 #endif