[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v2 04/12] vshCommandOpt: Allow caller avoiding assert()



Signed-off-by: Michal Privoznik <mprivozn redhat com>
---
 tools/vsh.c | 7 ++++---
 tools/vsh.h | 3 ++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 3a9941017..26f1f9e03 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -816,8 +816,8 @@ vshCommandFree(vshCmd *cmd)
  * to the option if found, 0 with *OPT set to NULL if the name is
  * valid and the option is not required, -1 with *OPT set to NULL if
  * the option is required but not present, and assert if NAME is not
- * valid (which indicates a programming error).  No error messages are
- * issued if a value is returned.
+ * valid (which indicates a programming error) unless cmd->skipChecks
+ * is set. No error messages are issued if a value is returned.
  */
 static int
 vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt,
@@ -830,7 +830,8 @@ vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt,
     /* See if option is valid and/or required.  */
     *opt = NULL;
     while (valid) {
-        assert(valid->name);
+        if (!cmd->skipChecks)
+            assert(valid->name);
         if (STREQ(name, valid->name))
             break;
         valid++;
diff --git a/tools/vsh.h b/tools/vsh.h
index 8f7df9ff8..112b1b57d 100644
--- a/tools/vsh.h
+++ b/tools/vsh.h
@@ -188,7 +188,8 @@ struct _vshCmdDef {
 struct _vshCmd {
     const vshCmdDef *def;       /* command definition */
     vshCmdOpt *opts;            /* list of command arguments */
-    vshCmd *next;      /* next command */
+    vshCmd *next;               /* next command */
+    bool skipChecks;            /* skip validity checks when retrieving opts */
 };
 
 /*
-- 
2.13.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]