Mercurial > hg > Applications > virsh-wrapper
changeset 28:554085aec682
fix exec command.
author | taiki <taiki@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 18 Aug 2014 16:45:32 -1000 |
parents | b731ce75cd35 |
children | cfa197bad124 |
files | ie-virsh.c |
diffstat | 1 files changed, 13 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/ie-virsh.c Thu Aug 14 11:23:34 2014 -1000 +++ b/ie-virsh.c Mon Aug 18 16:45:32 2014 -1000 @@ -32,7 +32,7 @@ const char guests_sym[] = "guests"; const char delimiter[] = "_"; -static char bad_name[] = "Bad vmname. Try students/e11/e115711/01 or teachers/kono/02\n"; +static char bad_name[] = "Bad vmname. Try 01 or 02 ... 04"; enum { NAME_LENGTH = 50, @@ -135,7 +135,7 @@ { const char *regex = "[ek]([0-9]{6})"; - regex_t *pattern = (regex_t *)malloc(sizeof(regex_t*)); + regex_t *pattern = NEW(regex_t); int ret = 1; if (regcomp(pattern, regex, REG_EXTENDED|REG_NEWLINE) != 0) { @@ -254,12 +254,13 @@ fprintf(stderr, bad_name); exit(0); } - - change_delimiter(vm_name); + char *vm_path = (char *)malloc(sizeof(char) * VM_NAME_LENGTH); + strncpy(vm_path, vm_name, VM_NAME_LENGTH); + change_delimiter(vm_path); char exec[1024]; // strncpy(exec, "/usr/local/bin/newvm.py -c /etc/libvirt/qemu/fedora16.xml -n ",900); strncpy(exec, "/usr/local/bin/newvm.py -c /etc/libvirt/qemu/fedora19.xml -n ",900); - strncat(exec, vm_name,1000); + strncat(exec, vm_path,1000); fprintf(stdout, "excuting %s\n",exec ); system(exec); } @@ -277,7 +278,8 @@ name_xml[0] = 0; if (argc>=3) { if ( strncmp(argv[1], "define", 6) == 0 ) { - strncpy(name_xml,argv[2],900); + change_delimiter(vm_name); + strncpy(name_xml, vm_name,900); strncat(name_xml,".xml",1000); } else if (check_vmlist_name(vmlist, argv[2])==0) { fprintf(stderr, bad_name); @@ -297,19 +299,19 @@ if (argv[1]==0 || strncmp(argv[1], "list", 4) == 0 ) { print_vmlist(vmlist); } else if (strncmp(argv[1], start_command, 5) == 0) { - if (execl(command, command, start_command, argv[2], NULL) < 0) { + if (execl(command, command, start_command, vm_name, NULL) < 0) { perror("Execl:"); } } else if ( strncmp(argv[1], stop_command, 4) == 0 ) { - if (execl(command, command, stop_command, argv[2], NULL) < 0) { + if (execl(command, command, stop_command, vm_name, NULL) < 0) { perror("Execl:"); } } else if ( strncmp(argv[1], dumpxml_command, 7) == 0 ) { - if (execl(command, command, dumpxml_command, argv[2], NULL) < 0) { + if (execl(command, command, dumpxml_command, vm_name, NULL) < 0) { perror("Execl:"); } } else if ( strncmp(argv[1], console_command, 8) == 0 ) { - if (execl(command, command, console_command, argv[2], NULL) < 0) { + if (execl(command, command, console_command, vm_name, NULL) < 0) { perror("Execl:"); } } else if (strncmp(argv[1], define_command, 6) == 0 ) { @@ -319,7 +321,7 @@ } } else if ( strncmp(argv[1], undefine_command, 8) == 0 ) { chdir("/usr/local/etc/libvirt/qemu"); - if (execl(command, command, undefine_command, argv[2], NULL) < 0) { + if (execl(command, command, undefine_command, vm_name, NULL) < 0) { perror("Execl:"); } } else {