From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K6rhm-00015X-WF for qemu-devel@nongnu.org; Thu, 12 Jun 2008 14:39:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K6rhl-00014G-H9 for qemu-devel@nongnu.org; Thu, 12 Jun 2008 14:39:25 -0400 Received: from [199.232.76.173] (port=37833 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K6rhl-00014D-Bw for qemu-devel@nongnu.org; Thu, 12 Jun 2008 14:39:25 -0400 Received: from yx-out-1718.google.com ([74.125.44.158]:51761) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K6rhl-0004sh-6L for qemu-devel@nongnu.org; Thu, 12 Jun 2008 14:39:25 -0400 Received: by yx-out-1718.google.com with SMTP id 3so432098yxi.82 for ; Thu, 12 Jun 2008 11:39:24 -0700 (PDT) Message-ID: <48516D47.6080005@codemonkey.ws> Date: Thu, 12 Jun 2008 13:39:03 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] New scriptarg=... -net parameter allows passing of an argument References: <18513.23567.23400.891876@mariner.uk.xensource.com> In-Reply-To: <18513.23567.23400.891876@mariner.uk.xensource.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Ian Jackson wrote: > Previously, network scripts would have to do all of their work based > only on the script name and interface name. If the script's behaviour > is supposed to be different for different network interfaces this > might involve constructing a special script for each interface with > the associated need to delete it etc. > env args should get passed down to the script although I can see an argument for being able to specify this in -net. My only suggestion would be to use an env arg instead of "$2" as it will make it easier to extend in the future. Regards, Anthony Liguori > With this patch it is possible to specify > -net=...,scriptarg= > which gets passed as a $2 to the qemu-ifup script. > > Signed-off-by: Ian Jackson > > --- > vl.c | 27 +++++++++++++++++++-------- > 1 files changed, 19 insertions(+), 8 deletions(-) > > diff --git a/vl.c b/vl.c > index 229b536..28f6fe0 100644 > --- a/vl.c > +++ b/vl.c > @@ -3963,6 +3963,7 @@ typedef struct TAPState { > VLANClientState *vc; > int fd; > char down_script[1024]; > + char script_arg[1024]; > } TAPState; > > static void tap_receive(void *opaque, const uint8_t *buf, int size) > @@ -4198,10 +4199,11 @@ static int tap_open(char *ifname, int ifname_size) > } > #endif > > -static int launch_script(const char *setup_script, const char *ifname, int fd) > +static int launch_script(const char *setup_script, const char *ifname, > + const char *script_arg, int fd) > { > int pid, status; > - char *args[3]; > + char *args[4]; > char **parg; > > /* try to launch network script */ > @@ -4219,6 +4221,8 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) > parg = args; > *parg++ = (char *)setup_script; > *parg++ = (char *)ifname; > + if (script_arg && script_arg[0]) > + *parg++ = (char *)script_arg; > *parg++ = NULL; > execv(setup_script, args); > _exit(1); > @@ -4235,7 +4239,8 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) > } > > static int net_tap_init(VLANState *vlan, const char *ifname1, > - const char *setup_script, const char *down_script) > + const char *setup_script, const char *down_script, > + const char *script_arg) > { > TAPState *s; > int fd; > @@ -4252,7 +4257,7 @@ static int net_tap_init(VLANState *vlan, const char *ifname1, > if (!setup_script || !strcmp(setup_script, "no")) > setup_script = ""; > if (setup_script[0] != '\0') { > - if (launch_script(setup_script, ifname, fd)) > + if (launch_script(setup_script, ifname, script_arg, fd)) > return -1; > } > s = net_tap_fd_init(vlan, fd); > @@ -4262,6 +4267,8 @@ static int net_tap_init(VLANState *vlan, const char *ifname1, > "tap: ifname=%s setup_script=%s", ifname, setup_script); > if (down_script && strcmp(down_script, "no")) > snprintf(s->down_script, sizeof(s->down_script), "%s", down_script); > + if (script_arg && script_arg[0]) > + snprintf(s->script_arg, sizeof(s->script_arg), "%s", script_arg); > return 0; > } > > @@ -4854,7 +4861,7 @@ static int net_client_init(const char *str) > #else > if (!strcmp(device, "tap")) { > char ifname[64]; > - char setup_script[1024], down_script[1024]; > + char setup_script[1024], down_script[1024], script_arg[1024]; > int fd; > vlan->nb_host_devs++; > if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { > @@ -4873,7 +4880,10 @@ static int net_client_init(const char *str) > if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) { > pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT); > } > - ret = net_tap_init(vlan, ifname, setup_script, down_script); > + if (get_param_value(script_arg, sizeof(script_arg), "scriptarg", p) == 0) { > + pstrcpy(script_arg, sizeof(script_arg), ""); > + } > + ret = net_tap_init(vlan, ifname, setup_script, down_script, script_arg); > } > } else > #endif > @@ -7191,11 +7201,12 @@ static void help(int exitcode) > "-net tap[,vlan=n],ifname=name\n" > " connect the host TAP network interface to VLAN 'n'\n" > #else > - "-net tap[,vlan=n][,fd=h][,ifname=name][,script=file][,downscript=dfile]\n" > + "-net tap[,vlan=n][,fd=h][,ifname=name][,script=file][,downscript=dfile][,scriptarg=extraargument]\n" > " connect the host TAP network interface to VLAN 'n' and use the\n" > " network scripts 'file' (default=%s)\n" > " and 'dfile' (default=%s);\n" > " use '[down]script=no' to disable script execution;\n" > + " use 'scriptarg=...' to pass an additional (nonempty) argument;\n" > " use 'fd=h' to connect to an already opened TAP interface\n" > #endif > "-net socket[,vlan=n][,fd=h][,listen=[host]:port][,connect=host:port]\n" > @@ -8638,7 +8649,7 @@ int main(int argc, char **argv) > > if (sscanf(vc->info_str, "tap: ifname=%63s ", ifname) == 1 && > s->down_script[0]) > - launch_script(s->down_script, ifname, s->fd); > + launch_script(s->down_script, ifname, s->script_arg, s->fd); > } > } > } >