qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: swz <swzhengst@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] question about -n (TUN/TAP script option)
Date: Mon, 14 Nov 2005 19:41:01 +0800	[thread overview]
Message-ID: <1131968461.4940.12.camel@localhost.localdomain> (raw)
In-Reply-To: <200511131740.09439.dfeustel@verizon.net>

When I run qemu as root, it work ok. Now I want to no use root, and I
have find that only the script(default is /etc/qemu-ifup) want root. So
I write another script qemu-ifup-wrapper, source code(use c):

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

const char* script = "/etc/qemu-ifup";
const char* cmdname = "qemu-ifup-wrapper";

int main(int ac, char* av[])
{
    const char** new_av = NULL;
    
    if (setuid(0) == -1) {
        const char* reason = strerror(errno);
        fprintf(stderr, "%s: cannot setuid root (%s)\n", cmdname,
reason);
        exit(1);
    }
    
    new_av = malloc(sizeof(char*) * (ac + 1));
    memcpy(new_av, av, sizeof(char*) * ac);
    new_av[ac] = NULL;
    new_av[0]  = script;
    
    execv(script, new_av);

    const char* reason = strerror(errno);
    fprintf(stderr, "%s: cannot execute '%s' (%s)\n", cmdname, script,
reason);
    exit(1);
}

and ls -al qemu-ifup-wrapper is:

-rwsr-sr-x  1 root root 8505 2005-11-14 19:04 qemu-ifup-wrapper

The problem is when I use qemu -n qemu-ifup-wrapper to start qemu, the
script unwork. but when I use sudo qemu -n qemu-ifup-wrapper, the script
work ok. I don't know why.

And in commandline, I run /etc/qemu-ifup, sudo /etc/qemu-ifup
and ./qemu-ifup-wrapper, sudo ./qemu-ifup-wrapper, the result of them is
same:

0.0.0.0: ERROR while getting interface flags: No such device
0.0.0.0: ERROR while getting interface flags: No such device
Incorrect number of arguments for command
Usage: brctl addif <bridge> <device>    add interface to bridge

Thank you!
Regard
Zheng SW

      reply	other threads:[~2005-11-14 11:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-13 22:40 [Qemu-devel] Internet Access for Browser in Qemu Dave Feustel
2005-11-14 11:41 ` swz [this message]

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=1131968461.4940.12.camel@localhost.localdomain \
    --to=swzhengst@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /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).