From 9a479f81f6e5494d5f9ffe1b5e351d7ff03e4df5 Mon Sep 17 00:00:00 2001 From: Rafal Wojtczuk Date: Mon, 21 Jun 2010 18:02:05 +0200 Subject: [PATCH] penctl: 3rd arg is seq --- appvm/qubes_penctl.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/appvm/qubes_penctl.c b/appvm/qubes_penctl.c index ab373f0..fc890f0 100644 --- a/appvm/qubes_penctl.c +++ b/appvm/qubes_penctl.c @@ -24,7 +24,7 @@ #include #include #include -int check_name(unsigned char *s) +void check_name(unsigned char *s) { int c; for (; *s; s++) { @@ -35,9 +35,16 @@ int check_name(unsigned char *s) continue; if (c == '_' || c == '-') continue; - return 0; + fprintf(stderr, "invalid string %s\n", s); + exit(1); } - return 1; +} + +void usage(char *argv0) +{ + fprintf(stderr, "usage: %s new\n" + "%s send vmname [seq]\n", argv0, argv0); + exit(1); } int main(int argc, char **argv) @@ -50,18 +57,21 @@ int main(int argc, char **argv) perror("xs_domain_open"); exit(1); } - if (argc < 2) { - fprintf(stderr, "usage: %s new\n" - "%s send vmname\n", argv[0], argv[0]); - exit(1); - } - if (argc > 2) { - if (!check_name((unsigned char*)argv[2])) { - fprintf(stderr, "invalid vmname %s\n", argv[2]); - exit(1); - } + switch (argc) { + case 2: + break; + case 3: + check_name((unsigned char *) argv[2]); snprintf(buf, sizeof(buf), "send %s", argv[2]); + break; + case 4: + check_name((unsigned char *) argv[2]); + check_name((unsigned char *) argv[3]); + snprintf(buf, sizeof(buf), "send %s %s", argv[2], argv[3]); + default: + usage(argv[0]); } + if (!xs_write(xs, 0, "device/qpen", buf, strlen(buf))) { perror("xs_write"); exit(1);