From: Dominik Csapak <d.csapak@proxmox.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, sw@weilnetz.de, jasowang@redhat.com,
thuth@redhat.com, philmd@redhat.com
Subject: [Qemu-devel] [PATCH v2 2/3] tap: use qemu_launch_script instead of launch_script
Date: Thu, 4 Oct 2018 13:43:11 +0200 [thread overview]
Message-ID: <20181004114312.27346-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20181004114312.27346-1-d.csapak@proxmox.com>
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes since v1:
* new in v2
net/tap.c | 56 ++++++++++----------------------------------------------
1 file changed, 10 insertions(+), 46 deletions(-)
diff --git a/net/tap.c b/net/tap.c
index cc8525f154..15a0dd65b8 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -62,9 +62,6 @@ typedef struct TAPState {
Notifier exit;
} TAPState;
-static void launch_script(const char *setup_script, const char *ifname,
- int fd, Error **errp);
-
static void tap_send(void *opaque);
static void tap_writable(void *opaque);
@@ -300,7 +297,11 @@ static void tap_exit_notify(Notifier *notifier, void *data)
Error *err = NULL;
if (s->down_script[0]) {
- launch_script(s->down_script, s->down_script_arg, s->fd, &err);
+ char *args[3];
+ args[0] = (char *)(s->down_script);
+ args[1] = (char *)(s->down_script_arg);
+ args[2] = NULL;
+ qemu_launch_script(s->down_script, args, s->fd, &err);
if (err) {
error_report_err(err);
}
@@ -397,47 +398,6 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
return s;
}
-static void launch_script(const char *setup_script, const char *ifname,
- int fd, Error **errp)
-{
- int pid, status;
- char *args[3];
- char **parg;
-
- /* try to launch network script */
- pid = fork();
- if (pid < 0) {
- error_setg_errno(errp, errno, "could not launch network script %s",
- setup_script);
- return;
- }
- if (pid == 0) {
- int open_max = sysconf(_SC_OPEN_MAX), i;
-
- for (i = 3; i < open_max; i++) {
- if (i != fd) {
- close(i);
- }
- }
- parg = args;
- *parg++ = (char *)setup_script;
- *parg++ = (char *)ifname;
- *parg = NULL;
- execv(setup_script, args);
- _exit(1);
- } else {
- while (waitpid(pid, &status, 0) != pid) {
- /* loop */
- }
-
- if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
- return;
- }
- error_setg(errp, "network script %s failed with status %d",
- setup_script, status);
- }
-}
-
static int recv_fd(int c)
{
int fd;
@@ -626,7 +586,11 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr,
if (setup_script &&
setup_script[0] != '\0' &&
strcmp(setup_script, "no") != 0) {
- launch_script(setup_script, ifname, fd, &err);
+ char *args[3];
+ args[0] = (char *)setup_script;
+ args[1] = (char *)ifname;
+ args[2] = NULL;
+ qemu_launch_script(setup_script, args, fd, &err);
if (err) {
error_propagate(errp, err);
close(fd);
--
2.11.0
next prev parent reply other threads:[~2018-10-04 11:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-04 11:43 [Qemu-devel] [PATCH v2 0/3] add exit-script option to qemu Dominik Csapak
2018-10-04 11:43 ` [Qemu-devel] [PATCH v2 1/3] osdep: add qemu_launch_script for executing scripts Dominik Csapak
2018-10-04 11:43 ` Dominik Csapak [this message]
2018-10-04 11:43 ` [Qemu-devel] [PATCH v2 3/3] vl.c: call optional script when exiting Dominik Csapak
2018-10-08 3:28 ` [Qemu-devel] [PATCH v2 0/3] add exit-script option to qemu Jason Wang
2018-10-08 7:39 ` Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181004114312.27346-3-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=jasowang@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).