mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
bhyve: stop using private gnulib _getopt_internal_r func
The _getopt_internal_r func is not intended for public use, it is an internal function shared between the gnulib getopt and argp modules. Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
371cff5789
commit
6894ba88b8
@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <libutil.h>
|
#include <libutil.h>
|
||||||
#include <getopt_int.h>
|
|
||||||
|
|
||||||
#include "bhyve_capabilities.h"
|
#include "bhyve_capabilities.h"
|
||||||
#include "bhyve_command.h"
|
#include "bhyve_command.h"
|
||||||
@ -633,6 +632,14 @@ bhyveParseBhyvePCIArg(virDomainDefPtr def,
|
|||||||
return -1;
|
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.
|
* Parse the /usr/sbin/bhyve command line.
|
||||||
*/
|
*/
|
||||||
@ -642,28 +649,24 @@ bhyveParseBhyveCommandLine(virDomainDefPtr def,
|
|||||||
unsigned caps,
|
unsigned caps,
|
||||||
int argc, char **argv)
|
int argc, char **argv)
|
||||||
{
|
{
|
||||||
int c;
|
|
||||||
const char optstr[] = "abehuwxACHIPSWYp:g:c:s:m:l:U:";
|
|
||||||
int vcpus = 1;
|
int vcpus = 1;
|
||||||
size_t memory = 0;
|
size_t memory = 0;
|
||||||
unsigned nahcidisks = 0;
|
unsigned nahcidisks = 0;
|
||||||
unsigned nvirtiodisks = 0;
|
unsigned nvirtiodisks = 0;
|
||||||
struct _getopt_data *parser;
|
size_t opti;
|
||||||
|
const char *arg;
|
||||||
|
|
||||||
if (!argv)
|
for (opti = 1; opti < argc; opti++) {
|
||||||
goto error;
|
if (argv[opti][0] != '-')
|
||||||
|
break;
|
||||||
|
|
||||||
if (VIR_ALLOC(parser) < 0)
|
switch (argv[opti][1]) {
|
||||||
goto error;
|
|
||||||
|
|
||||||
while ((c = _getopt_internal_r(argc, argv, optstr,
|
|
||||||
NULL, NULL, 0, parser, 0)) != -1) {
|
|
||||||
switch (c) {
|
|
||||||
case 'A':
|
case 'A':
|
||||||
def->features[VIR_DOMAIN_FEATURE_ACPI] = VIR_TRISTATE_SWITCH_ON;
|
def->features[VIR_DOMAIN_FEATURE_ACPI] = VIR_TRISTATE_SWITCH_ON;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
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",
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||||
_("Failed to parse number of vCPUs"));
|
_("Failed to parse number of vCPUs"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -674,20 +677,23 @@ bhyveParseBhyveCommandLine(virDomainDefPtr def,
|
|||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
if (bhyveParseBhyveLPCArg(def, caps, parser->optarg))
|
CONSUME_ARG(arg);
|
||||||
|
if (bhyveParseBhyveLPCArg(def, caps, arg))
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
|
CONSUME_ARG(arg);
|
||||||
if (bhyveParseBhyvePCIArg(def,
|
if (bhyveParseBhyvePCIArg(def,
|
||||||
xmlopt,
|
xmlopt,
|
||||||
caps,
|
caps,
|
||||||
&nahcidisks,
|
&nahcidisks,
|
||||||
&nvirtiodisks,
|
&nvirtiodisks,
|
||||||
parser->optarg))
|
arg))
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
if (bhyveParseMemsize(parser->optarg, &memory)) {
|
CONSUME_ARG(arg);
|
||||||
|
if (bhyveParseMemsize(arg, &memory)) {
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||||
_("Failed to parse memory"));
|
_("Failed to parse memory"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -709,19 +715,23 @@ bhyveParseBhyveCommandLine(virDomainDefPtr def,
|
|||||||
def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
|
def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
|
||||||
break;
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
if (virUUIDParse(parser->optarg, def->uuid) < 0) {
|
CONSUME_ARG(arg);
|
||||||
|
if (virUUIDParse(arg, def->uuid) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Cannot parse UUID '%s'"), parser->optarg);
|
_("Cannot parse UUID '%s'"), arg);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
def->mem.locked = true;
|
def->mem.locked = true;
|
||||||
break;
|
break;
|
||||||
|
case 'p':
|
||||||
|
case 'g':
|
||||||
|
CONSUME_ARG(arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != parser->optind) {
|
if (argc != opti) {
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||||
_("Failed to parse arguments for bhyve command"));
|
_("Failed to parse arguments for bhyve command"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -738,11 +748,9 @@ bhyveParseBhyveCommandLine(virDomainDefPtr def,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(parser);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
VIR_FREE(parser);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -753,42 +761,38 @@ static int
|
|||||||
bhyveParseBhyveLoadCommandLine(virDomainDefPtr def,
|
bhyveParseBhyveLoadCommandLine(virDomainDefPtr def,
|
||||||
int argc, char **argv)
|
int argc, char **argv)
|
||||||
{
|
{
|
||||||
int c;
|
|
||||||
/* bhyveload called with default arguments when only -m and -d are given.
|
/* 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
|
* Store this in a bit field and check if only those two options are given
|
||||||
* later */
|
* later */
|
||||||
unsigned arguments = 0;
|
unsigned arguments = 0;
|
||||||
size_t memory = 0;
|
size_t memory = 0;
|
||||||
struct _getopt_data *parser;
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
size_t opti;
|
||||||
|
const char *arg;
|
||||||
|
|
||||||
const char optstr[] = "CSc:d:e:h:l:m:";
|
for (opti = 1; opti < argc; opti++) {
|
||||||
|
if (argv[opti][0] != '-')
|
||||||
|
break;
|
||||||
|
|
||||||
if (!argv)
|
switch (argv[opti][1]) {
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (VIR_ALLOC(parser) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
while ((c = _getopt_internal_r(argc, argv, optstr,
|
|
||||||
NULL, NULL, 0, parser, 0)) != -1) {
|
|
||||||
switch (c) {
|
|
||||||
case 'd':
|
case 'd':
|
||||||
|
CONSUME_ARG(arg);
|
||||||
arguments |= 1;
|
arguments |= 1;
|
||||||
/* Iterate over the disks of the domain trying to match up the
|
/* Iterate over the disks of the domain trying to match up the
|
||||||
* source */
|
* source */
|
||||||
for (i = 0; i < def->ndisks; i++) {
|
for (i = 0; i < def->ndisks; i++) {
|
||||||
if (STREQ(virDomainDiskGetSource(def->disks[i]),
|
if (STREQ(virDomainDiskGetSource(def->disks[i]),
|
||||||
parser->optarg)) {
|
arg)) {
|
||||||
def->disks[i]->info.bootIndex = i;
|
def->disks[i]->info.bootIndex = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
|
CONSUME_ARG(arg);
|
||||||
arguments |= 2;
|
arguments |= 2;
|
||||||
if (bhyveParseMemsize(parser->optarg, &memory)) {
|
if (bhyveParseMemsize(arg, &memory)) {
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||||
_("Failed to parse memory"));
|
_("Failed to parse memory"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -806,6 +810,12 @@ bhyveParseBhyveLoadCommandLine(virDomainDefPtr def,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argc != opti) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||||
|
_("Failed to parse arguments for bhyve command"));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (arguments != 3) {
|
if (arguments != 3) {
|
||||||
/* Set os.bootloader since virDomainDefFormatInternal will only format
|
/* Set os.bootloader since virDomainDefFormatInternal will only format
|
||||||
* the bootloader arguments if os->bootloader is set. */
|
* the bootloader arguments if os->bootloader is set. */
|
||||||
@ -815,12 +825,6 @@ bhyveParseBhyveLoadCommandLine(virDomainDefPtr def,
|
|||||||
def->os.bootloaderArgs = virStringListJoin((const char**) &argv[1], " ");
|
def->os.bootloaderArgs = virStringListJoin((const char**) &argv[1], " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != parser->optind) {
|
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
|
||||||
_("Failed to parse arguments for bhyveload command"));
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (def->name == NULL) {
|
if (def->name == NULL) {
|
||||||
if (VIR_STRDUP(def->name, argv[argc]) < 0)
|
if (VIR_STRDUP(def->name, argv[argc]) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -834,7 +838,6 @@ bhyveParseBhyveLoadCommandLine(virDomainDefPtr def,
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
error:
|
error:
|
||||||
VIR_FREE(parser);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user