--- qemu-start/trunk/qemu-start.c 2007/11/09 14:07:44 313 +++ qemu-start/trunk/qemu-start.c 2008/04/09 19:00:11 314 @@ -33,6 +33,9 @@ #include #include +/* Autogenerated by gengetopt */ +#include "cmdline.h" + /* This define is present in recent glibc, it is not available on sarge */ #ifndef HOST_NAME_MAX #define HOST_NAME_MAX 64 @@ -189,7 +192,7 @@ } if (asprintf(&xauthfile,"%s/.Xauthority",userdata->pw_dir) < 1) { - perror("Constructing xauthority filename failed"); + perror("Constructing xauthority filename failed"); exit(1); } @@ -216,7 +219,7 @@ exit(1); } if (! WIFEXITED(status) || WEXITSTATUS(status)) { - fprintf(stderr,"Child returned error"); + fprintf(stderr,"Child returned error\n"); exit(1); } } @@ -230,38 +233,45 @@ struct ifreq ifr; struct passwd *userdata; char *newargs[argc + 2]; - int i,fd,vlan,tapnr; - char *ptr; + int fd,vlan,tapnr; + unsigned int i; + unsigned new_arg_count = 5; + struct gengetopt_args_info args_info; char *display; + char *system; + char *topleft; - /* Check parameters */ - if (argc < 4) { - fprintf(stderr, "Usage: qemu-start TAPDEVNR VLAN SYSTEM ...\n"); - fprintf(stderr, " A device tapTAPDEVNR must have been configured.\n"); - fprintf(stderr, " VLAN is the Virtual LAN number (just use 0 if unsure).\n"); - fprintf(stderr, " SYSTEM is the system to emulate. Use \"\" for the current architecture\n"); - fprintf(stderr, " (uses /usr/bin/qemm); else a binary /usr/bin/qemu-system-SYSTEM is used.\n"); - exit(1); - } + /* Ugly fix because gengetopt 2.18 does not have the `usage' option */ + gengetopt_args_info_usage = "qemu-start [OPTIONS] -- [OPTIONS for QEMU]"; - /* First parameter: TAPDEVNR */ - tapnr = strtol(argv[1],&ptr,0); - if (*ptr) { - fprintf(stderr, "Invalid value `%s' for TAPDEVNR parameter (use a number!)\n",argv[1]); + if (cmdline_parser(argc, argv, &args_info)) exit(1); - } - /* Second parameter: VLAN */ - vlan = strtol(argv[2],&ptr,0); - if (*ptr) { - fprintf(stderr, "Invalid value `%s' for VLAN parameter (use a number!)\n", argv[2]); - exit(1); + /* parameter: TAPDEVNR */ + tapnr = args_info.tapnr_arg; + + /* parameter: VLAN */ + vlan = args_info.vlan_arg; + + /* parameter: System type */ + if (args_info.system_given) { + if (index(args_info.system_arg,'/')) { + fprintf(stderr, "Invalid value `%s' for system (may not contain a slash character)\n", args_info.system_arg); + exit(1); + } + asprintf(&system, "%s", args_info.system_arg); } - /* Third parameter: System type */ - if (index(argv[3],'/')) { - fprintf(stderr, "Invalid value `%s' for system (may not contain a slash character)\n", argv[3]); - exit(1); + /* parameters: Window location */ + if (args_info.window_left_given || args_info.window_top_given) { + if (!(args_info.window_left_given && args_info.window_top_given)) { + fprintf(stderr,("If either window-left (x) or window-top (y) are given, then both must be given\n")); + exit(1); + } + if (asprintf(&topleft, "%d,%d",args_info.window_left_arg,args_info.window_top_arg) < 0) { + perror("Preparing top-left environment value string failed"); + exit(1); + } } /* Export the xauth data */ @@ -322,11 +332,17 @@ perror("Setting environment failed"); exit(1); } + if (args_info.window_left_given || args_info.window_top_given) { + if (setenv("SDL_VIDEO_WINDOW_POS", topleft, 1)) { + perror("Setting top-left environment value failed"); + exit(1); + } + } /* Create the right qemu invocation */ - if (!strlen(argv[3])) + if (!args_info.system_given) newargs[0] = QEMU; - else if (asprintf(&newargs[0],"%s-system-%s",QEMU,argv[3]) < 0) { + else if (asprintf(&newargs[0],"%s-system-%s",QEMU,args_info.system_arg) < 0) { perror("Preparing qemu executable filename failed"); exit(1); } @@ -335,16 +351,31 @@ perror("Preparing nic argument failed"); exit(1); } + if (args_info.macaddr_given) { + if (asprintf(&newargs[2], "%s,mac=%s", newargs[2], args_info.macaddr_arg) < 0) { + perror("Adding macaddress to nic argument failed"); + } + } + if (args_info.nic_model_given) { + if (asprintf(&newargs[2], "%s,model=%s", newargs[2], args_info.nic_model_arg) < 0) { + perror("Adding nic model to nic argument failed"); + } + } newargs[3] = "-net"; if (asprintf(&newargs[4],"tap,fd=%d,vlan=%d",fd,vlan) < 0) { perror("Preparing tap argument failed"); exit(1); } - for (i = 4; i <= argc; i++) - newargs[i+1] = argv[i]; + for (i = 0; i < args_info.inputs_num; i++) { + newargs[i+5] = args_info.inputs[i]; + new_arg_count++; + } + newargs[new_arg_count] = NULL; + + for (i = 0; newargs[i]; i++) + fprintf(stderr, "%d: %s\n", i, newargs[i]); execvp(newargs[0], newargs); perror("Execution of qemu failed"); exit(1); } -