mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 17:51:53 +00:00
Flock: Polished the command-line options
This commit is contained in:
parent
861b37b2fe
commit
55bb0ae4b3
@ -139,8 +139,13 @@ static inline void
|
|||||||
usage(FILE *f)
|
usage(FILE *f)
|
||||||
{
|
{
|
||||||
fprintf(f,
|
fprintf(f,
|
||||||
"Usage: %s name\n\n"
|
"Usage: %s [options] name\n\n"
|
||||||
"Runs hypervisor with the given name.\n",
|
"Runs Flock hypervisor with the given name.\n"
|
||||||
|
"\n"
|
||||||
|
"Options:\n"
|
||||||
|
"\t-s <path>\topen control socket at this path\n"
|
||||||
|
"\t-l \tshortcut for -s ./<name>.ctl\n"
|
||||||
|
"\n",
|
||||||
flock_config.exec_name);
|
flock_config.exec_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,15 +181,17 @@ main(int argc, char **argv, char **argh UNUSED)
|
|||||||
/* Parse args */
|
/* Parse args */
|
||||||
flock_config.exec_name = argv[0] ?: "flock-sim";
|
flock_config.exec_name = argv[0] ?: "flock-sim";
|
||||||
int opt;
|
int opt;
|
||||||
|
bool csp_local = 0;
|
||||||
while ((opt = getopt(argc, argv, "ls:")) != -1)
|
while ((opt = getopt(argc, argv, "ls:")) != -1)
|
||||||
{
|
{
|
||||||
switch (opt)
|
switch (opt)
|
||||||
{
|
{
|
||||||
case 'l':
|
case 'l':
|
||||||
flock_config.control_socket_path = "flock-sim.ctl";
|
csp_local = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
|
csp_local = 0;
|
||||||
flock_config.control_socket_path = mb_strdup(&root_pool, optarg);
|
flock_config.control_socket_path = mb_strdup(&root_pool, optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -194,9 +201,6 @@ main(int argc, char **argv, char **argh UNUSED)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: have a default */
|
|
||||||
ASSERT_DIE(flock_config.control_socket_path);
|
|
||||||
|
|
||||||
/* Get hypervisor name */
|
/* Get hypervisor name */
|
||||||
if (optind != argc - 1)
|
if (optind != argc - 1)
|
||||||
{
|
{
|
||||||
@ -206,6 +210,16 @@ main(int argc, char **argv, char **argh UNUSED)
|
|||||||
|
|
||||||
flock_config.hypervisor_name = argv[optind];
|
flock_config.hypervisor_name = argv[optind];
|
||||||
|
|
||||||
|
/* Fix the control socket path if -l was given */
|
||||||
|
if (csp_local)
|
||||||
|
flock_config.control_socket_path = mb_sprintf(&root_pool, "./%s.ctl", flock_config.hypervisor_name);
|
||||||
|
else if (!flock_config.control_socket_path)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "No control socket path given, use -s or -l.");
|
||||||
|
usage(stderr);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
/* Mask signals for forking and other fragile stuff */
|
/* Mask signals for forking and other fragile stuff */
|
||||||
sigset_t oldmask;
|
sigset_t oldmask;
|
||||||
sigset_t newmask;
|
sigset_t newmask;
|
||||||
|
Loading…
Reference in New Issue
Block a user