diff options
Diffstat (limited to 'cli/src/cli.c')
-rw-r--r-- | cli/src/cli.c | 74 |
1 files changed, 15 insertions, 59 deletions
diff --git a/cli/src/cli.c b/cli/src/cli.c index 858c7091b8d..d362cd11a53 100644 --- a/cli/src/cli.c +++ b/cli/src/cli.c @@ -78,9 +78,6 @@ extern int connected; /* using argp for command line parsing */ -static char gf_doc[] = ""; - -static char argp_doc[] = ""; const char *argp_program_version = "" \ PACKAGE_NAME" "PACKAGE_VERSION" built on "__DATE__" "__TIME__ \ @@ -93,10 +90,7 @@ const char *argp_program_version = "" \ const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">"; -static struct argp_option gf_options[] = { - {0, 0, 0, 0, "Basic options:"}, - {0, } -}; + struct rpc_clnt *global_rpc; @@ -105,39 +99,6 @@ rpc_clnt_prog_t *cli_rpc_prog; extern struct rpc_clnt_program cli_prog; -static error_t -parse_opts (int key, char *arg, struct argp_state *argp_state) -{ - struct cli_state *state = NULL; - char **argv = NULL; - - state = argp_state->input; - - switch (key) { - case ARGP_KEY_ARG: - if (!state->argc) { - argv = calloc (state->argc + 2, - sizeof (*state->argv)); - } else { - argv = realloc (state->argv, (state->argc + 2) * - sizeof (*state->argv)); - } - if (!argv) - return -1; - - state->argv = argv; - - argv[state->argc] = strdup (arg); - if (!argv[state->argc]) - return -1; - state->argc++; - argv[state->argc] = NULL; - - break; - } - - return 0; -} @@ -394,29 +355,24 @@ parse_cmdline (int argc, char *argv[], struct cli_state *state) int i = 0; int j = 0; char *opt = NULL; - struct argp argp = { 0,}; - argp.options = gf_options; - argp.parser = parse_opts; - argp.args_doc = argp_doc; - argp.doc = gf_doc; + state->argc=argc-1; + state->argv=&argv[1]; - for (i = 0; i < argc; i++) { - opt = strtail (argv[i], "--"); + for (i = 0; i < state->argc; i++) { + opt = strtail (state->argv[i], "--"); if (opt) { ret = cli_opt_parse (opt, state); if (ret == -1) { - break; + cli_out ("unrecognized option --%s", opt); + return ret; } - for (j = i; j < argc - 1; j++) - argv[j] = argv[j + 1]; - argc--; + for (j = i; j < state->argc - 1; j++) + state->argv[j] = state->argv[j + 1]; + state->argc--; } } - ret = argp_parse (&argp, argc, argv, - ARGP_IN_ORDER, NULL, state); - return ret; } @@ -632,6 +588,11 @@ main (int argc, char *argv[]) int ret = -1; glusterfs_ctx_t *ctx = NULL; + if (geteuid ()) { + printf ("Only super user can run this command\n"); + return EPERM; + } + ret = glusterfs_globals_init (); if (ret) return ret; @@ -655,11 +616,6 @@ main (int argc, char *argv[]) if (ret) goto out; - if (geteuid ()) { - printf ("Only super user can run this command\n"); - return EPERM; - } - ret = logging_init (ctx); if (ret) goto out; |