Skip to content

Commit 0ca7e63

Browse files
committed
examples/nitro: Add more required arguments
Add more arguments for customizing the nitro enclaves example. These arguments include - Enclave rootfs. - Number of vCPUs for enclave. - Amount of RAM (in MiB) allocated to enclave. Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
1 parent 99980a0 commit 0ca7e63

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

examples/nitro.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@
3333
static void print_help(char *const name)
3434
{
3535
fprintf(stderr,
36-
"Usage: %s EIF_FILE [COMMAND_ARGS...]\n"
36+
"Usage: %s ENCLAVE_IMAGE NEWROOT NUM_VCPUS RAM_MIB\n"
3737
"OPTIONS: \n"
3838
" -h --help Show help\n"
3939
"\n"
4040
"ENCLAVE_IMAGE: The enclave image to run\n",
41+
"NEWROOT: The root directory of the enclave\n",
42+
"NUM_VCPUS: The amount of vCPUs for running the enclave\n",
43+
"RAM_MIB: The amount of RAM (MiB) allocated for enclave\n",
4144
name
4245
);
4346
}
@@ -50,6 +53,9 @@ static const struct option long_options[] = {
5053
struct cmdline {
5154
bool show_help;
5255
const char *eif_path;
56+
const char *new_root;
57+
unsigned int num_vcpus;
58+
unsigned int ram_mib;
5359
};
5460

5561
bool parse_cmdline(int argc, char *const argv[], struct cmdline *cmdline)
@@ -78,11 +84,22 @@ bool parse_cmdline(int argc, char *const argv[], struct cmdline *cmdline)
7884
}
7985
}
8086

81-
if (optind < argc) {
87+
if (optind < argc - 3) {
8288
cmdline->eif_path = argv[optind];
89+
cmdline->new_root = argv[optind + 1];
90+
cmdline->num_vcpus = strtoul(argv[optind + 2], NULL, 10);
91+
cmdline->ram_mib = strtoul(argv[optind + 3], NULL, 10);
8392
return true;
84-
} else
85-
fprintf(stderr, "Missing EIF_FILE argument");
93+
}
94+
95+
if (optind >= argc - 3)
96+
fprintf(stderr, "Missing RAM_MIB argument\n");
97+
if (optind >= argc - 2)
98+
fprintf(stderr, "Missing NUM_VCPUS argument\n");
99+
if (optind >= argc - 1)
100+
fprintf(stderr, "Missing NEWROOT argument\n");
101+
if (optind == argc)
102+
fprintf(stderr, "Missing ENCLAVE_IMAGE argument\n");
86103

87104
return false;
88105
}

0 commit comments

Comments
 (0)