URL: https://github.com/SSSD/sssd/pull/403
Author: lslebodn
 Title: #403: Fix few sssctl debug-level related issues
Action: opened

PR body:
"""

"""

To pull the PR as Git branch:
git remote add ghsssd https://github.com/SSSD/sssd
git fetch ghsssd pull/403/head:pr403
git checkout pr403
From 56293aac91f7bbb678302733cbbfcc3d805f3823 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <[email protected]>
Date: Wed, 11 Oct 2017 14:21:45 +0200
Subject: [PATCH 1/3] TOOLS: Log redirection info for sss_debuglevel to stderr

---
 src/tools/wrappers/sss_debuglevel.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/tools/wrappers/sss_debuglevel.in b/src/tools/wrappers/sss_debuglevel.in
index 8df4918d6..4deeafff6 100644
--- a/src/tools/wrappers/sss_debuglevel.in
+++ b/src/tools/wrappers/sss_debuglevel.in
@@ -1,4 +1,4 @@
 #!/bin/sh
 sbindir=@sbindir@
-echo "Redirecting to $sbindir/sssctl debug-level"
+echo "Redirecting to $sbindir/sssctl debug-level" >&2
 $sbindir/sssctl debug-level $@

From e298789fb6d3bbfbf8cb3710833a350819ad6b5a Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <[email protected]>
Date: Wed, 11 Oct 2017 17:10:49 +0200
Subject: [PATCH 2/3] TOOLS: Print Better usage for sssctl debug-level

There is missing command name in help
sh# sssctl debug-level --help
Usage: DEBUG_LEVEL_TO_SET
  -c, --config=STRING     Specify a non-default config file

Help options:
  -?, --help              Show this help message
  --usage                 Display brief usage message
---
 src/tools/sssctl/sssctl_logs.c | 38 +++++++-------------------------------
 1 file changed, 7 insertions(+), 31 deletions(-)

diff --git a/src/tools/sssctl/sssctl_logs.c b/src/tools/sssctl/sssctl_logs.c
index 32e0a7ac5..02a60135b 100644
--- a/src/tools/sssctl/sssctl_logs.c
+++ b/src/tools/sssctl/sssctl_logs.c
@@ -315,37 +315,14 @@ errno_t sssctl_debug_level(struct sss_cmdline *cmdline,
             0, _("Specify a non-default config file"), NULL},
         POPT_TABLEEND
     };
-    poptContext pc = NULL;
-
-    debug_prg_name = cmdline->argv[0];
-
-    /* parse parameters */
-    pc = poptGetContext(cmdline->argv[0], cmdline->argc, cmdline->argv,
-                        long_options, POPT_CONTEXT_KEEP_FIRST);
-    poptSetOtherOptionHelp(pc, "DEBUG_LEVEL_TO_SET");
-    while ((ret = poptGetNextOpt(pc)) != -1) {
-        switch (ret) {
-        default:
-            fprintf(stderr, "\nInvalid option %s: %s\n\n",
-                    poptBadOption(pc, 0), poptStrerror(ret));
-            poptPrintUsage(pc, stderr, 0);
-            ret = EXIT_FAILURE;
-            goto fini;
-        }
-    }
-    DEBUG_CLI_INIT(pc_debug);
-
-    /* get debug level */
-    debug_as_string = poptGetArg(pc);
-    if (debug_as_string == NULL) {
-        BAD_POPT_PARAMS(pc, _("Specify debug level you want to set\n"),
-                        ret, fini);
-    }
 
-    /* No more arguments expected. If something follows it is an error. */
-    if (poptGetArg(pc)) {
-        BAD_POPT_PARAMS(pc, _("Only one argument expected\n"),
-                        ret, fini);
+    ret = sss_tool_popt_ex(cmdline, long_options, SSS_TOOL_OPT_OPTIONAL, NULL,
+                           NULL, "DEBUG_LEVEL_TO_SET",
+                           _("Specify debug level you want to set"),
+                           &debug_as_string, NULL);
+    if (ret != EOK) {
+        DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command arguments\n");
+        return ret;
     }
 
     /* get config file */
@@ -393,7 +370,6 @@ errno_t sssctl_debug_level(struct sss_cmdline *cmdline,
           "Is sssd running?");
 
 fini:
-    poptFreeContext(pc);
     talloc_free(ctx);
     return ret;
 }

From 69c6eefaf1982b528dddffa4209aef0a4ff7093e Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <[email protected]>
Date: Wed, 11 Oct 2017 17:20:05 +0200
Subject: [PATCH 3/3] TOOLS: Hide option --debug in sssctl

Related to old bug
https://pagure.io/SSSD/sssd/issue/1224
---
 src/tools/common/sss_tools.c   | 9 ++-------
 src/tools/sssctl/sssctl_logs.c | 2 --
 2 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/src/tools/common/sss_tools.c b/src/tools/common/sss_tools.c
index 0b676341f..0923cc0f5 100644
--- a/src/tools/common/sss_tools.c
+++ b/src/tools/common/sss_tools.c
@@ -32,11 +32,6 @@
 
 static void sss_tool_print_common_opts(int min_len)
 {
-    fprintf(stderr, _("Common options:\n"));
-    fprintf(stderr, "  %-*s\t %s\n", min_len, "--debug=INT",
-                    _("The debug level to run with"));
-    fprintf(stderr, "\n");
-    fprintf(stderr, _("Help options:\n"));
     fprintf(stderr, "  %-*s\t %s\n", min_len, "-?, --help",
                     _("Show this for a command"));
     fprintf(stderr, "  %-*s\t %s\n", min_len, "--usage",
@@ -46,7 +41,7 @@ static void sss_tool_print_common_opts(int min_len)
 static struct poptOption *sss_tool_common_opts_table(void)
 {
     static struct poptOption common_opts[] = {
-        {"debug", '\0', POPT_ARG_INT, NULL,
+        {"debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, NULL,
             0, NULL, NULL },
         POPT_TABLEEND
     };
@@ -380,7 +375,7 @@ errno_t sss_tool_popt_ex(struct sss_cmdline *cmdline,
         {NULL, '\0', POPT_ARG_INCLUDE_TABLE, nonnull_popt_table(options), \
          0, _("Command options:"), NULL },
         {NULL, '\0', POPT_ARG_INCLUDE_TABLE, sss_tool_common_opts_table(), \
-         0, _("Common options:"), NULL },
+         0, NULL, NULL },
         POPT_AUTOHELP
         POPT_TABLEEND
     };
diff --git a/src/tools/sssctl/sssctl_logs.c b/src/tools/sssctl/sssctl_logs.c
index 02a60135b..d6cce3756 100644
--- a/src/tools/sssctl/sssctl_logs.c
+++ b/src/tools/sssctl/sssctl_logs.c
@@ -309,8 +309,6 @@ errno_t sssctl_debug_level(struct sss_cmdline *cmdline,
     struct debuglevel_tool_ctx *ctx = NULL;
     struct poptOption long_options[] = {
         POPT_AUTOHELP
-        {"debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug,
-            0, _("The debug level to run with"), NULL },
         {"config", 'c', POPT_ARG_STRING, &pc_config_file,
             0, _("Specify a non-default config file"), NULL},
         POPT_TABLEEND
_______________________________________________
sssd-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to