Skip to content

Commit f86d91e

Browse files
fyin1jren1
authored andcommitted
dm: use getopt_long instead of getopt to parse dm cmdline
It will be easier if we want to add more command line options with long options. Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
1 parent 74e2bfc commit f86d91e

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

devicemodel/core/main.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <pthread.h>
4242
#include <sysexits.h>
4343
#include <stdbool.h>
44+
#include <getopt.h>
4445

4546
#include "types.h"
4647
#include "vmm.h"
@@ -546,6 +547,37 @@ sig_handler_term(int signo)
546547
mevent_notify();
547548
}
548549

550+
static struct option long_options[] = {
551+
{"no_x2apic_mode", no_argument, 0, 'a' },
552+
{"acpi", no_argument, 0, 'A' },
553+
{"bvmcons", no_argument, 0, 'b' },
554+
{"pincpu", required_argument, 0, 'p' },
555+
{"ncpus", required_argument, 0, 'c' },
556+
{"memflags_incore", no_argument, 0, 'C' },
557+
{"gdb_port", required_argument, 0, 'g' },
558+
{"lpc", required_argument, 0, 'l' },
559+
{"pci_slot", required_argument, 0, 's' },
560+
{"memflags_wired", no_argument, 0, 'S' },
561+
{"memsize", required_argument, 0, 'm' },
562+
{"ioapic", no_argument, 0, 'I' },
563+
{"vmexit_pause", no_argument, 0, 'p' },
564+
{"strictio", no_argument, 0, 'e' },
565+
{"rtc_localtime", no_argument, 0, 'u' },
566+
{"uuid", required_argument, 0, 'U' },
567+
{"strictmsr", no_argument, 0, 'w' },
568+
{"virtio_msix", no_argument, 0, 'W' },
569+
{"x2apic_mode", no_argument, 0, 'x' },
570+
{"mptgen", no_argument, 0, 'Y' },
571+
{"kernel", required_argument, 0, 'k' },
572+
{"ramdisk", required_argument, 0, 'r' },
573+
{"bootargs", required_argument, 0, 'B' },
574+
{"ptdev_msi", no_argument, 0, 'M' },
575+
{"version", no_argument, 0, 'v' },
576+
{"gvtargs", required_argument, 0, 'G' },
577+
{"help", no_argument, 0, 'h' },
578+
{0, 0, 0, 0 },
579+
};
580+
549581
int
550582
main(int argc, char *argv[])
551583
{
@@ -555,6 +587,7 @@ main(int argc, char *argv[])
555587
struct vmctx *ctx;
556588
size_t memsize;
557589
char *optstr;
590+
int option_idx = 0;
558591

559592
bvmcons = 0;
560593
progname = basename(argv[0]);
@@ -570,7 +603,8 @@ main(int argc, char *argv[])
570603
fprintf(stderr, "cannot register handler for SIGINT\n");
571604

572605
optstr = "abehuwxACHIMPSWYvk:r:B:p:g:c:s:m:l:U:G:";
573-
while ((c = getopt(argc, argv, optstr)) != -1) {
606+
while ((c = getopt_long(argc, argv, optstr, long_options,
607+
&option_idx)) != -1) {
574608
switch (c) {
575609
case 'a':
576610
x2apic_mode = 0;

0 commit comments

Comments
 (0)