"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/cli/src/cli-cmd-misc.c" (16 Sep 2020, 3245 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "cli-cmd-misc.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2    Copyright (c) 2010-2012 Red Hat, Inc. <http://www.redhat.com>
    3    This file is part of GlusterFS.
    4 
    5    This file is licensed to you under your choice of the GNU Lesser
    6    General Public License, version 3 or any later version (LGPLv3 or
    7    later), or the GNU General Public License, version 2 (GPLv2), in all
    8    cases as published by the Free Software Foundation.
    9 */
   10 #include <stdio.h>
   11 #include <string.h>
   12 #include <stdlib.h>
   13 #include <stdint.h>
   14 #include <pthread.h>
   15 
   16 #include "cli.h"
   17 #include "cli-cmd.h"
   18 #include "cli-mem-types.h"
   19 #include "protocol-common.h"
   20 
   21 extern struct rpc_clnt *global_rpc;
   22 
   23 extern rpc_clnt_prog_t *cli_rpc_prog;
   24 
   25 extern struct cli_cmd volume_cmds[];
   26 extern struct cli_cmd bitrot_cmds[];
   27 extern struct cli_cmd quota_cmds[];
   28 extern struct cli_cmd cli_probe_cmds[];
   29 extern struct cli_cmd cli_log_cmds[];
   30 extern struct cli_cmd cli_system_cmds[];
   31 extern struct cli_cmd cli_bd_cmds[];
   32 extern struct cli_cmd snapshot_cmds[];
   33 extern struct cli_cmd global_cmds[];
   34 struct cli_cmd cli_misc_cmds[];
   35 
   36 int
   37 cli_cmd_quit_cbk(struct cli_state *state, struct cli_cmd_word *word,
   38                  const char **words, int wordcount)
   39 {
   40     exit(0);
   41 }
   42 
   43 static gf_boolean_t
   44 cli_is_help_command(const char *pattern)
   45 {
   46     /* FixFixFix
   47      * This is not the best way to determine whether
   48      * this is a help command
   49      */
   50     if (strstr(pattern, "help"))
   51         return _gf_true;
   52 
   53     return _gf_false;
   54 }
   55 
   56 int
   57 cli_cmd_display_help(struct cli_state *state, struct cli_cmd_word *in_word,
   58                      const char **words, int wordcount)
   59 {
   60     static struct cli_cmd *cmd[] = {
   61         cli_misc_cmds, cli_probe_cmds, volume_cmds, bitrot_cmds,
   62         quota_cmds,    snapshot_cmds,  global_cmds, NULL};
   63     struct cli_cmd *cmd_ind = NULL;
   64     int i = 0;
   65     gf_boolean_t list_all = _gf_false;
   66 
   67     /* cli_system_cmds commands for internal usage
   68       they are not exposed
   69     */
   70 
   71     /* If "help all" */
   72     if (wordcount == 2)
   73         list_all = _gf_true;
   74 
   75     for (i = 0; cmd[i] != NULL; i++) {
   76         for (cmd_ind = cmd[i]; cmd_ind->pattern; cmd_ind++) {
   77             if ((_gf_false == cmd_ind->disable) &&
   78                 cli_is_help_command(cmd_ind->pattern)) {
   79                 if (list_all && (cmd_ind->cbk)) {
   80                     cmd_ind->cbk(state, in_word, words, wordcount);
   81                 } else {
   82                     cli_out(" %-25s- %s", cmd_ind->pattern, cmd_ind->desc);
   83                 }
   84             }
   85         }
   86     }
   87 
   88     cli_out("\n");
   89     return 0;
   90 }
   91 
   92 struct cli_cmd cli_help_cmds[] = {
   93     {"help [all]", cli_cmd_display_help, "display help for command classes"},
   94 
   95     {NULL, NULL, NULL}};
   96 
   97 struct cli_cmd cli_misc_cmds[] = {{"quit", cli_cmd_quit_cbk, "quit"},
   98                                   {"exit", cli_cmd_quit_cbk, "exit"},
   99 
  100                                   {NULL, NULL, NULL}};
  101 
  102 int
  103 cli_cmd_misc_register(struct cli_state *state)
  104 {
  105     int ret = 0;
  106     struct cli_cmd *cmd = NULL;
  107 
  108     for (cmd = cli_misc_cmds; cmd->pattern; cmd++) {
  109         ret = cli_cmd_register(&state->tree, cmd);
  110         if (ret)
  111             goto out;
  112     }
  113 
  114     for (cmd = cli_help_cmds; cmd->pattern; cmd++) {
  115         ret = cli_cmd_register(&state->tree, cmd);
  116         if (ret)
  117             goto out;
  118     }
  119 out:
  120     return ret;
  121 }