diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2021-05-11 17:08:15 +0200 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2021-05-11 17:08:15 +0200 |
commit | 7503332a1eb811559d3a3eb97f53ba240ea631d5 (patch) | |
tree | 0dc67c60570fac1c17a417cbcff0b3f1f82a6bb4 /qrap.c | |
parent | f98e3589b407fcf4dc632f958f51b1245b0b0dcc (diff) | |
download | passt-7503332a1eb811559d3a3eb97f53ba240ea631d5.tar passt-7503332a1eb811559d3a3eb97f53ba240ea631d5.tar.gz passt-7503332a1eb811559d3a3eb97f53ba240ea631d5.tar.bz2 passt-7503332a1eb811559d3a3eb97f53ba240ea631d5.tar.lz passt-7503332a1eb811559d3a3eb97f53ba240ea631d5.tar.xz passt-7503332a1eb811559d3a3eb97f53ba240ea631d5.tar.zst passt-7503332a1eb811559d3a3eb97f53ba240ea631d5.zip |
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>
Diffstat (limited to 'qrap.c')
-rw-r--r-- | qrap.c | 36 |
1 files changed, 22 insertions, 14 deletions
@@ -64,11 +64,11 @@ void usage(const char *name) int main(int argc, char **argv) { 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 = { .sun_family = AF_UNIX, .sun_path = UNIX_SOCK_PATH, }; - int i, s, qemu_argc = 0; char fd_str[ARG_MAX]; long fd; @@ -93,9 +93,14 @@ int main(int argc, char **argv) for (qemu_argc = 1, i = 1; i < argc; i++) { char *p; - if (!strcmp(argv[i], "-net") || (!strcmp(argv[i], "-netdev"))) { - i++; - continue; + if (in_netdev) { + in_netdev = 0; + 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="))) @@ -104,17 +109,20 @@ int main(int argc, char **argv) qemu_argv[qemu_argc++] = argv[i]; } - if (*net_id) { - net_id_end = strpbrk(net_id, ", "); - if (net_id_end) - *net_id_end = 0; - } - qemu_argv[qemu_argc++] = "-netdev"; - snprintf(fd_str, ARG_MAX, "socket,fd=%u,id=%s", DEFAULT_FD, - *net_id ? net_id : "hostnet0"); - qemu_argv[qemu_argc++] = fd_str; - qemu_argv[qemu_argc] = NULL; + if (!has_socket) { + if (*net_id) { + net_id_end = strpbrk(net_id, ", "); + if (net_id_end) + *net_id_end = 0; + } + + qemu_argv[qemu_argc++] = "-netdev"; + snprintf(fd_str, ARG_MAX, "socket,fd=%u,id=%s", DEFAULT_FD, + *net_id ? net_id : "hostnet0"); + qemu_argv[qemu_argc++] = fd_str; + qemu_argv[qemu_argc] = NULL; + } valid_args: s = socket(AF_UNIX, SOCK_STREAM, 0); |