From 92058d254ddfa37d5c7b4629ca738a502996203e Mon Sep 17 00:00:00 2001 From: Dave Chinner Date: Thu, 12 Jan 2017 14:12:41 -0600 Subject: [PATCH] libxcmd: don't check generic library commands The generic "help" and "quit" commands have different methods of skipping user provided command check functions that may prevent them from running. xfs_quota use CMD_ALL_FSTYPES and xfs_io uses CMD_FLAG_ONESHOT. Add a new CMD_FLAG_LIBRARY to indicate commands that should not be checked against application specific check functions so they are always present and can be run regardless of the context in which they are run. This gets rid of the CMD_ALL_FSTYPES flag, and enables us to remove the ONESHOT check in xfs_io so we use only app specific flags for determining if app commands should run or not. [ sandeen: remove CMD_ALL_FSTYPES definition ] Signed-Off-By: Dave Chinner Reviewed-by: Eric Sandeen Reviewed-by: Christoph Hellwig Signed-off-by: Eric Sandeen --- include/command.h | 1 + io/init.c | 3 --- libxcmd/command.c | 4 ++++ libxcmd/help.c | 2 +- libxcmd/quit.c | 2 +- quota/init.c | 4 ---- quota/init.h | 2 -- 7 files changed, 7 insertions(+), 11 deletions(-) diff --git a/include/command.h b/include/command.h index 637ee06e6..348002cbe 100644 --- a/include/command.h +++ b/include/command.h @@ -27,6 +27,7 @@ */ #define CMD_FLAG_ONESHOT (1<<31) #define CMD_FLAG_FOREIGN_OK (1<<30) /* command not restricted to XFS */ +#define CMD_FLAG_LIBRARY (1<<29) /* command provided by libxcmd */ typedef int (*cfunc_t)(int argc, char **argv); typedef void (*helpfunc_t)(void); diff --git a/io/init.c b/io/init.c index a382d9bae..28a7d6005 100644 --- a/io/init.c +++ b/io/init.c @@ -110,9 +110,6 @@ static int init_check_command( const cmdinfo_t *ct) { - if (ct->flags & CMD_FLAG_ONESHOT) - return 1; - if (!file && !(ct->flags & CMD_NOFILE_OK)) { fprintf(stderr, _("no files are open, try 'help open'\n")); return 0; diff --git a/libxcmd/command.c b/libxcmd/command.c index 03fb219e9..ce434479c 100644 --- a/libxcmd/command.c +++ b/libxcmd/command.c @@ -48,6 +48,10 @@ static int check_command( const cmdinfo_t *ci) { + /* always run internal library supplied commands */ + if (ci->flags & CMD_FLAG_LIBRARY) + return 1; + if (check_func) return check_func(ci); return 1; diff --git a/libxcmd/help.c b/libxcmd/help.c index bc31d6df1..f888377ca 100644 --- a/libxcmd/help.c +++ b/libxcmd/help.c @@ -89,7 +89,7 @@ help_init(void) help_cmd.cfunc = help_f; help_cmd.argmin = 0; help_cmd.argmax = 1; - help_cmd.flags = CMD_FLAG_ONESHOT | CMD_ALL_FSTYPES; + help_cmd.flags = CMD_FLAG_ONESHOT | CMD_FLAG_LIBRARY; help_cmd.args = _("[command]"); help_cmd.oneline = _("help for one or all commands"); diff --git a/libxcmd/quit.c b/libxcmd/quit.c index 19431015a..1e1ba986f 100644 --- a/libxcmd/quit.c +++ b/libxcmd/quit.c @@ -39,7 +39,7 @@ quit_init(void) quit_cmd.cfunc = quit_f; quit_cmd.argmin = -1; quit_cmd.argmax = -1; - quit_cmd.flags = CMD_FLAG_ONESHOT | CMD_ALL_FSTYPES; + quit_cmd.flags = CMD_FLAG_ONESHOT | CMD_FLAG_LIBRARY; quit_cmd.oneline = _("exit the program"); add_command(&quit_cmd); diff --git a/quota/init.c b/quota/init.c index 193f6421f..d45dc4c54 100644 --- a/quota/init.c +++ b/quota/init.c @@ -117,10 +117,6 @@ init_check_command( if (!fs_path) return 1; - /* Always run commands that are valid for all fs types. */ - if (ct->flags & CMD_ALL_FSTYPES) - return 1; - /* If it's an XFS filesystem, always run the command. */ if (!(fs_path->fs_flags & FS_FOREIGN)) return 1; diff --git a/quota/init.h b/quota/init.h index 4eb44c4d7..687985557 100644 --- a/quota/init.h +++ b/quota/init.h @@ -31,5 +31,3 @@ extern void report_init(void); extern void state_init(void); extern void init_cvtnum(unsigned int *, unsigned int *); - -#define CMD_ALL_FSTYPES (1<<0) /* command is always available */ -- 2.47.2