From 80e1c3d17c00fb4f40e6742202c7a28fc7a22585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20M=C3=A4kisara?= Date: Mon, 16 Feb 2009 19:55:20 +0200 Subject: [PATCH] Check that the default tape device is a chardev When using the default tape device (no $TAPE env. var and no explicit tape given), check that it is indeed a character device; this will help with better error messages on systems using udev, where /dev/tape is a directory instead. --- mt.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mt.c b/mt.c index 41b85b8..cd2893f 100644 --- a/mt.c +++ b/mt.c @@ -319,8 +319,17 @@ main(int argc, char **argv) else break; - if (tape_name == NULL && (tape_name = getenv("TAPE")) == NULL) + if (tape_name == NULL && (tape_name = getenv("TAPE")) == NULL) { + struct stat stbuf; + tape_name = DEFTAPE; + if (!stat(tape_name, &stbuf) && + !S_ISCHR(stbuf.st_mode)) { + fprintf(stderr, "The default '%s' is not a character device.\n\n", tape_name); + usage(1); + exit(1); + } + } if (argn >= argc ) { usage(0);