diff --git a/nvttest/nvttest.c b/nvttest/nvttest.c index 9619f08..845e594 100644 --- a/nvttest/nvttest.c +++ b/nvttest/nvttest.c @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -20,6 +21,7 @@ static const char help_text[] = "Usage: nvttest OPTIONS...\n" "OPTIONS:\n" + " -D name : Specify device name (/dev/name, default /dev/ttyNVT0)\n" " -d : Enable debug\n" " -n loops : Test loops per thread\n" " -q : Quiet\n" @@ -28,7 +30,7 @@ static const char help_text[] = ; /**INDENT-ON**/ -static const char *dev = "/dev/ttyNVT0"; +static char dev[64] = "/dev/ttyNVT0"; typedef struct { int nthread; @@ -126,18 +128,22 @@ int main(int argc, char **argv) topts_t topts = { }, *popts; pthread_t *ptids; int debug, quiet; + struct stat st; debug = quiet = 0; nthr = 1; topts.nloop = 1; - while ((opt = getopt(argc, argv, "dn:qrt:")) != -1) + while ((opt = getopt(argc, argv, "D:dn:qrt:")) != -1) { switch (opt) { default: /* '?' */ _usage(1); break; + case 'D': + snprintf(dev, sizeof(dev), "/dev/%s", optarg); + break; case 'd': debug += 1; break; @@ -156,6 +162,12 @@ int main(int argc, char **argv) } } + if (stat(dev, &st) || !S_ISCHR(st.st_mode)) + { + fprintf(stderr, "Invalid device file: '%s'\n", dev); + exit(EXIT_FAILURE); + } + nvt_log_level(quiet, debug); nvt_log_dest(NVT_LOG_STDOUT);