22parse_int_optstring(
char const *optstring,
int *out)
27 long num = strtol(optstring, &endp, 10);
30 if (errno || *endp !=
'\0' || num < INT_MIN || num > INT_MAX)
39verbosity_mask_from_string(
char const *str,
unsigned *mask)
41 if (strcmp(
"quiet", str) == 0)
46 if (strcmp(
"warn", str) == 0)
51 if (strcmp(
"info", str) == 0)
53 *mask = Dbg::Warn | Dbg::Info;
56 if (strcmp(
"debug", str) == 0)
58 *mask = Dbg::Warn | Dbg::Info | Dbg::Debug;
61 if (strcmp(
"trace", str) == 0)
63 *mask = Dbg::Warn | Dbg::Info | Dbg::Debug | Dbg::Trace;
100set_verbosity(
char const *str)
103 if (verbosity_mask_from_string(str, &mask) == 0)
105 Dbg::set_verbosity(mask);
109 static char const *
const components[] =
110 {
"core",
"virtio",
"port",
"request",
"queue",
"packet" };
112 static_assert(std::extent<
decltype(components)>::value == Dbg::Max_component,
113 "Component names must match 'enum Component'.");
115 for (
unsigned i = 0; i < Dbg::Max_component; ++i)
117 auto len = strlen(components[i]);
118 if (strncmp(components[i], str, len) == 0 && str[len] ==
'='
119 && verbosity_mask_from_string(str + len + 1, &mask) == 0)
121 Dbg::set_verbosity(i, mask);
128Options::parse_cmd_line(
int argc,
char **argv,
129 std::shared_ptr<Ds_vector> trusted_dataspaces)
133 struct option options[] =
135 {
"size", 1, 0,
's' },
136 {
"ports", 1, 0,
'p' },
138 {
"no-random-mac", 0, 0,
'M' },
139 {
"debug", 1, 0,
'D' },
140 {
"verbose", 0, 0,
'v' },
141 {
"quiet", 0, 0,
'q' },
142 {
"register-ds", 1, 0,
'd' },
146 unsigned long verbosity = Dbg::Warn;
148 Dbg info(Dbg::Core, Dbg::Info);
150 Dbg::set_verbosity(Dbg::Core, Dbg::Info);
151 info.printf(
"Arguments:\n");
152 for (
int i = 0; i < argc; ++i)
153 info.printf(
"\t%s\n", argv[i]);
155 Dbg::set_verbosity(verbosity);
156 while ( (opt = getopt_long(argc, argv,
"s:p:mMqvD:d:", options, &index)) != -1)
163 if (!parse_int_optstring(optarg, &_virtq_max_num)
164 || _virtq_max_num < 1 || _virtq_max_num > 32768
165 || (_virtq_max_num & (_virtq_max_num - 1)))
167 Err().printf(
"Max number of virtqueue buffers must be power of 2"
168 " between 1 and 32768. Invalid value %i or argument "
170 _virtq_max_num, optarg);
173 info.printf(
"Max number of buffers in virtqueue: %i\n",
177 if (parse_int_optstring(optarg, &_max_ports))
178 info.printf(
"Max number of ports: %u\n", _max_ports);
181 Err().printf(
"Invalid number of ports argument: %s\n", optarg);
186 verbosity = Dbg::Quiet;
187 Dbg::set_verbosity(verbosity);
190 verbosity = (verbosity << 1) | 1;
191 Dbg::set_verbosity(verbosity);
194 set_verbosity(optarg);
197 info.printf(
"Option -m ignored to compatibility.\n");
204 L4::Cap<L4Re::Dataspace> ds =
206 "Find a dataspace capability.\n");
207 trusted_dataspaces->push_back(ds);
211 Err().printf(
"Unknown command line option '%c' (%d)\n", opt, opt);
218static Options options;
221Options::get_options()
225Options::parse_options(
int argc,
char **argv,
226 std::shared_ptr<Ds_vector> trusted_dataspaces)
228 if (options.parse_cmd_line(argc, argv, trusted_dataspaces) < 0)
static Env const * env() noexcept
Returns the initial environment for the current task.
@ L4_ENOENT
No such entity.
T chkcap(T &&cap, char const *extra="", l4_ret_t err=-L4_ENOMEM)
Check for valid capability or raise C++ exception.