Mercurial > hg > Applications > virsh-wrapper
changeset 30:2888c7ec9013
can't define vm name is not number.
author | taiki <taiki@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 02 Sep 2014 08:10:27 -1000 |
parents | cfa197bad124 |
children | ea7578513baa |
files | ie-virsh.c |
diffstat | 1 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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]); }