From nobody Sun Dec 14 21:49:40 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1570110822; cv=none; d=zoho.com; s=zohoarc; b=B3Cq5ctj9qQ6+GkTY7pdbamICJXMu2Wq3M0+NML1+aCyktiC98EWXST1GTukhk5uwDp8EKxqyrETOwhenC6UHsK30j379Ffcv1hg+xmh2dIyK15ONXXoW8ux0NS4VoVDGZ8++yBaokh4u6UbH4Qn1pcv1OrYQTokaxnFecLH/90= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570110822; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=5o7rR83nVRoo+ybzNPLYH/6oK6m9f4iLGmuYPRmYMPQ=; b=JNe7wJb9Vluq5OhFmJwJimw3Nm1kjhWaL5zqWdnubRLI6c93TTe0Ez2uRAdCy9FWE7TNrtvFhRP8AIyt+57jyCNgNuJplDnACWDQpfOacYE4hj6bWP5y57aJYN8UpIRp3rQReFU8/kPFga+Ykf4IgHOQZ18f9TFH2WXQXyyG6I4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570110822036213.64178976361984; Thu, 3 Oct 2019 06:53:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2836410DCCA7; Thu, 3 Oct 2019 13:53:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F31EE1001B2C; Thu, 3 Oct 2019 13:53:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id AFF5F4EE70; Thu, 3 Oct 2019 13:53:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x93DrONp019849 for ; Thu, 3 Oct 2019 09:53:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6687F608C2; Thu, 3 Oct 2019 13:53:24 +0000 (UTC) Received: from dhcp-17-55.lcy.redhat.com (unknown [10.42.17.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8317608A5; Thu, 3 Oct 2019 13:53:23 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 3 Oct 2019 14:53:08 +0100 Message-Id: <20191003135318.19149-2-berrange@redhat.com> In-Reply-To: <20191003135318.19149-1-berrange@redhat.com> References: <20191003135318.19149-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/11] bhyve: stop using private gnulib _getopt_internal_r func X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Thu, 03 Oct 2019 13:53:40 +0000 (UTC) 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=C3=A9 Reviewed-by: J=C3=A1n Tomko --- 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_comman= d.c index 7d460e9824..0bfe17c08c 100644 --- a/src/bhyve/bhyve_parse_command.c +++ b/src/bhyve/bhyve_parse_command.c @@ -23,7 +23,6 @@ =20 #include #include -#include =20 #include "bhyve_capabilities.h" #include "bhyve_command.h" @@ -633,6 +632,14 @@ bhyveParseBhyvePCIArg(virDomainDefPtr def, return -1; } =20 +#define CONSUME_ARG(var) \ + if ((opti + 1) =3D=3D argc) { \ + virReportError(VIR_ERR_INVALID_ARG, "Missing argument for '%s'", \ + argv[opti]); \ + goto error; \ + } \ + var =3D 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[] =3D "abehuwxACHIPSWYp:g:c:s:m:l:U:"; int vcpus =3D 1; size_t memory =3D 0; unsigned nahcidisks =3D 0; unsigned nvirtiodisks =3D 0; - struct _getopt_data *parser; - - if (!argv) - goto error; + size_t opti; + const char *arg; =20 - if (VIR_ALLOC(parser) < 0) - goto error; + for (opti =3D 1; opti < argc; opti++) { + if (argv[opti][0] !=3D '-') + break; =20 - while ((c =3D _getopt_internal_r(argc, argv, optstr, - NULL, NULL, 0, parser, 0)) !=3D -1) { - switch (c) { + switch (argv[opti][1]) { case 'A': def->features[VIR_DOMAIN_FEATURE_ACPI] =3D VIR_TRISTATE_SWITCH= _ON; break; case 'c': - if (virStrToLong_i(parser->optarg, NULL, 10, &vcpus) < 0) { + CONSUME_ARG(arg); + if (virStrToLong_i(arg, NULL, 10, &vcpus) < 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, &nahcidisks, &nvirtiodisks, - parser->optarg)) + arg)) goto error; break; case 'm': - if (bhyveParseMemsize(parser->optarg, &memory)) { + CONSUME_ARG(arg); + if (bhyveParseMemsize(arg, &memory)) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("Failed to parse memory")); goto error; @@ -709,19 +715,23 @@ bhyveParseBhyveCommandLine(virDomainDefPtr def, def->clock.offset =3D 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 =3D true; break; + case 'p': + case 'g': + CONSUME_ARG(arg); } } =20 - if (argc !=3D parser->optind) { + if (argc !=3D 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; } =20 - VIR_FREE(parser); return 0; =20 error: - VIR_FREE(parser); return -1; } =20 @@ -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 giv= en. * Store this in a bit field and check if only those two options are g= iven * later */ unsigned arguments =3D 0; size_t memory =3D 0; - struct _getopt_data *parser; size_t i =3D 0; int ret =3D -1; + size_t opti; + const char *arg; =20 - const char optstr[] =3D "CSc:d:e:h:l:m:"; - - if (!argv) - goto error; - - if (VIR_ALLOC(parser) < 0) - goto error; + for (opti =3D 1; opti < argc; opti++) { + if (argv[opti][0] !=3D '-') + break; =20 - while ((c =3D _getopt_internal_r(argc, argv, optstr, - NULL, NULL, 0, parser, 0)) !=3D -1) { - switch (c) { + switch (argv[opti][1]) { case 'd': + CONSUME_ARG(arg); arguments |=3D 1; /* Iterate over the disks of the domain trying to match up the * source */ for (i =3D 0; i < def->ndisks; i++) { if (STREQ(virDomainDiskGetSource(def->disks[i]), - parser->optarg)) { + arg)) { def->disks[i]->info.bootIndex =3D i; break; } } break; case 'm': + CONSUME_ARG(arg); arguments |=3D 2; - if (bhyveParseMemsize(parser->optarg, &memory)) { + if (bhyveParseMemsize(arg, &memory)) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("Failed to parse memory")); goto error; @@ -806,6 +810,12 @@ bhyveParseBhyveLoadCommandLine(virDomainDefPtr def, } } =20 + if (argc !=3D opti) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("Failed to parse arguments for bhyve command")); + goto error; + } + if (arguments !=3D 3) { /* Set os.bootloader since virDomainDefFormatInternal will only fo= rmat * the bootloader arguments if os->bootloader is set. */ @@ -815,12 +825,7 @@ bhyveParseBhyveLoadCommandLine(virDomainDefPtr def, def->os.bootloaderArgs =3D virStringListJoin((const char**) &argv[= 1], " "); } =20 - if (argc !=3D 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); if (def->name =3D=3D NULL) { if (VIR_STRDUP(def->name, argv[argc]) < 0) goto error; @@ -834,7 +839,6 @@ bhyveParseBhyveLoadCommandLine(virDomainDefPtr def, =20 ret =3D 0; error: - VIR_FREE(parser); return ret; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list