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.
This commit is contained in:
Kai Mäkisara
2009-02-16 19:55:20 +02:00
committed by Iustin Pop
parent f734645c0f
commit 80e1c3d17c

11
mt.c
View File

@@ -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);