# HG changeset patch # User taiki # Date 1409681427 36000 # Node ID 2888c7ec90135ed317c08c4b7b8fc77e69a52d38 # Parent cfa197bad124690b3a04346667819d42f82c940b can't define vm name is not number. diff -r cfa197bad124 -r 2888c7ec9013 ie-virsh.c --- a/ie-virsh.c Tue Aug 26 06:51:06 2014 -1000 +++ b/ie-virsh.c Tue Sep 02 08:10:27 2014 -1000 @@ -220,7 +220,7 @@ int account_type = check_user_name(name); if (account_type < 0) { - fprintf(stderr, "Parmission denied. :%s", name); + fprintf(stderr, "Parmission denied. :%s\n", name); } @@ -243,6 +243,21 @@ char *vm_name = (char *)malloc(sizeof(char) * VM_NAME_LENGTH); vm_name[0] = '\0'; if (strncmp(argv[1], "list", 4) != 0) { + const char *regex = "0[1-4]"; + regex_t *num_pattern = NEW(regex_t); + + if (regcomp(num_pattern, regex, REG_EXTENDED|REG_NEWLINE) != 0) { + exit(0); + } + + int ret = regexec(num_pattern, argv[2], (size_t) 0, NULL, 0); + regfree(num_pattern); + + if (ret){ + fprintf(stderr, "This name is not number: %s\n", argv[2]); + exit(0); + } + make_vm_name(vm_name, account_type, name, argv[2]); }