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




_______________________________________________
Qemu-devel mailing list
Qemu-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/qemu-devel

Reply via email to