Re: [libvirt] [PATCH 01/11] bhyve: stop using private gnulib _getopt_internal_r func

2019-10-03 Thread Ján Tomko

On Thu, Oct 03, 2019 at 02:53:08PM +0100, Daniel P. Berrangé wrote:

The _getopt_internal_r func is not intended for public use, it is an
internal function shared between the gnulib getopt and argp modules.

Signed-off-by: Daniel P. Berrangé 
---
src/bhyve/bhyve_parse_command.c | 88 +
1 file changed, 46 insertions(+), 42 deletions(-)

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 7d460e9824..0bfe17c08c 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -23,7 +23,6 @@

#include 
#include 
-#include 

#include "bhyve_capabilities.h"
#include "bhyve_command.h"
@@ -633,6 +632,14 @@ bhyveParseBhyvePCIArg(virDomainDefPtr def,
return -1;
}

+#define CONSUME_ARG(var) \
+if ((opti + 1) == argc) { \
+virReportError(VIR_ERR_INVALID_ARG, "Missing argument for '%s'", \
+   argv[opti]); \


src/bhyve/bhyve_parse_command.c:637:virReportError(VIR_ERR_INVALID_ARG, 
"Missing argument for '%s'", \
maint.mk: found unmarked diagnostic(s)


+goto error; \
+} \
+var = argv[++opti]
+
/*
 * Parse the /usr/sbin/bhyve command line.
 */
@@ -815,12 +825,7 @@ bhyveParseBhyveLoadCommandLine(virDomainDefPtr def,
def->os.bootloaderArgs = virStringListJoin((const char**) [1], " 
");
}

-if (argc != parser->optind) {
-virReportError(VIR_ERR_OPERATION_FAILED, "%s",
-   _("Failed to parse arguments for bhyveload command"));
-goto error;
-}
-
+fprintf(stderr, "Ok %s  %s %d\n", def->name, argv[argc], argc);


Debugging leftovers


if (def->name == NULL) {
if (VIR_STRDUP(def->name, argv[argc]) < 0)
goto error;


Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 01/11] bhyve: stop using private gnulib _getopt_internal_r func

2019-10-03 Thread Daniel P . Berrangé
The _getopt_internal_r func is not intended for public use, it is an
internal function shared between the gnulib getopt and argp modules.

Signed-off-by: Daniel P. Berrangé 
---
 src/bhyve/bhyve_parse_command.c | 88 +
 1 file changed, 46 insertions(+), 42 deletions(-)

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index 7d460e9824..0bfe17c08c 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -23,7 +23,6 @@
 
 #include 
 #include 
-#include 
 
 #include "bhyve_capabilities.h"
 #include "bhyve_command.h"
@@ -633,6 +632,14 @@ bhyveParseBhyvePCIArg(virDomainDefPtr def,
 return -1;
 }
 
+#define CONSUME_ARG(var) \
+if ((opti + 1) == argc) { \
+virReportError(VIR_ERR_INVALID_ARG, "Missing argument for '%s'", \
+   argv[opti]); \
+goto error; \
+} \
+var = argv[++opti]
+
 /*
  * Parse the /usr/sbin/bhyve command line.
  */
@@ -642,28 +649,24 @@ bhyveParseBhyveCommandLine(virDomainDefPtr def,
unsigned caps,
int argc, char **argv)
 {
-int c;
-const char optstr[] = "abehuwxACHIPSWYp:g:c:s:m:l:U:";
 int vcpus = 1;
 size_t memory = 0;
 unsigned nahcidisks = 0;
 unsigned nvirtiodisks = 0;
-struct _getopt_data *parser;
-
-if (!argv)
-goto error;
+size_t opti;
+const char *arg;
 
-if (VIR_ALLOC(parser) < 0)
-goto error;
+for (opti = 1; opti < argc; opti++) {
+if (argv[opti][0] != '-')
+break;
 
-while ((c = _getopt_internal_r(argc, argv, optstr,
-NULL, NULL, 0, parser, 0)) != -1) {
-switch (c) {
+switch (argv[opti][1]) {
 case 'A':
 def->features[VIR_DOMAIN_FEATURE_ACPI] = VIR_TRISTATE_SWITCH_ON;
 break;
 case 'c':
-if (virStrToLong_i(parser->optarg, NULL, 10, ) < 0) {
+CONSUME_ARG(arg);
+if (virStrToLong_i(arg, NULL, 10, ) < 0) {
 virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("Failed to parse number of vCPUs"));
 goto error;
@@ -674,20 +677,23 @@ bhyveParseBhyveCommandLine(virDomainDefPtr def,
 goto error;
 break;
 case 'l':
-if (bhyveParseBhyveLPCArg(def, caps, parser->optarg))
+CONSUME_ARG(arg);
+if (bhyveParseBhyveLPCArg(def, caps, arg))
 goto error;
 break;
 case 's':
+CONSUME_ARG(arg);
 if (bhyveParseBhyvePCIArg(def,
   xmlopt,
   caps,
   ,
   ,
-  parser->optarg))
+  arg))
 goto error;
 break;
 case 'm':
-if (bhyveParseMemsize(parser->optarg, )) {
+CONSUME_ARG(arg);
+if (bhyveParseMemsize(arg, )) {
 virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("Failed to parse memory"));
 goto error;
@@ -709,19 +715,23 @@ bhyveParseBhyveCommandLine(virDomainDefPtr def,
 def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
 break;
 case 'U':
-if (virUUIDParse(parser->optarg, def->uuid) < 0) {
+CONSUME_ARG(arg);
+if (virUUIDParse(arg, def->uuid) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("Cannot parse UUID '%s'"), parser->optarg);
+   _("Cannot parse UUID '%s'"), arg);
 goto error;
 }
 break;
 case 'S':
 def->mem.locked = true;
 break;
+case 'p':
+case 'g':
+CONSUME_ARG(arg);
 }
 }
 
-if (argc != parser->optind) {
+if (argc != opti) {
 virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("Failed to parse arguments for bhyve command"));
 goto error;
@@ -738,11 +748,9 @@ bhyveParseBhyveCommandLine(virDomainDefPtr def,
 goto error;
 }
 
-VIR_FREE(parser);
 return 0;
 
  error:
-VIR_FREE(parser);
 return -1;
 }
 
@@ -753,42 +761,38 @@ static int
 bhyveParseBhyveLoadCommandLine(virDomainDefPtr def,
int argc, char **argv)
 {
-int c;
 /* bhyveload called with default arguments when only -m and -d are given.
  * Store this in a bit field and check if only those two options are given
  * later */
 unsigned arguments = 0;
 size_t memory = 0;
-struct _getopt_data *parser;
 size_t i = 0;
 int ret = -1;
+size_t opti;
+const char *arg;
 
-const char optstr[] = "CSc:d:e:h:l:m:";
-
-if (!argv)
-