qrap: Adapt -net/-netdev command-line mangling to existing arguments
If a socket netdev parameter is already passed, don't touch the command line. If it's not, add it, taking the id= reference from a netdev= parameter, if any. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
f98e3589b4
commit
7503332a1e
1 changed files with 22 additions and 14 deletions
16
qrap.c
16
qrap.c
|
@ -64,11 +64,11 @@ void usage(const char *name)
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *qemu_argv[ARG_MAX], net_id[ARG_MAX] = { 0 }, *net_id_end;
|
char *qemu_argv[ARG_MAX], net_id[ARG_MAX] = { 0 }, *net_id_end;
|
||||||
|
int i, s, qemu_argc = 0, in_netdev = 0, has_socket = 0;
|
||||||
struct sockaddr_un addr = {
|
struct sockaddr_un addr = {
|
||||||
.sun_family = AF_UNIX,
|
.sun_family = AF_UNIX,
|
||||||
.sun_path = UNIX_SOCK_PATH,
|
.sun_path = UNIX_SOCK_PATH,
|
||||||
};
|
};
|
||||||
int i, s, qemu_argc = 0;
|
|
||||||
char fd_str[ARG_MAX];
|
char fd_str[ARG_MAX];
|
||||||
long fd;
|
long fd;
|
||||||
|
|
||||||
|
@ -93,9 +93,14 @@ int main(int argc, char **argv)
|
||||||
for (qemu_argc = 1, i = 1; i < argc; i++) {
|
for (qemu_argc = 1, i = 1; i < argc; i++) {
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if (!strcmp(argv[i], "-net") || (!strcmp(argv[i], "-netdev"))) {
|
if (in_netdev) {
|
||||||
i++;
|
in_netdev = 0;
|
||||||
continue;
|
if (strstr(argv[i], ",socket") ||
|
||||||
|
strstr(argv[i], "socket,"))
|
||||||
|
has_socket = 1;
|
||||||
|
} else if (!strcmp(argv[i], "-net") ||
|
||||||
|
!strcmp(argv[i], "-netdev")) {
|
||||||
|
in_netdev = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!*net_id && (p = strstr(argv[i], ",netdev=")))
|
if (!*net_id && (p = strstr(argv[i], ",netdev=")))
|
||||||
|
@ -104,6 +109,8 @@ int main(int argc, char **argv)
|
||||||
qemu_argv[qemu_argc++] = argv[i];
|
qemu_argv[qemu_argc++] = argv[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!has_socket) {
|
||||||
if (*net_id) {
|
if (*net_id) {
|
||||||
net_id_end = strpbrk(net_id, ", ");
|
net_id_end = strpbrk(net_id, ", ");
|
||||||
if (net_id_end)
|
if (net_id_end)
|
||||||
|
@ -115,6 +122,7 @@ int main(int argc, char **argv)
|
||||||
*net_id ? net_id : "hostnet0");
|
*net_id ? net_id : "hostnet0");
|
||||||
qemu_argv[qemu_argc++] = fd_str;
|
qemu_argv[qemu_argc++] = fd_str;
|
||||||
qemu_argv[qemu_argc] = NULL;
|
qemu_argv[qemu_argc] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
valid_args:
|
valid_args:
|
||||||
s = socket(AF_UNIX, SOCK_STREAM, 0);
|
s = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
|
|
Loading…
Reference in a new issue