aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2013-10-30 21:59:34 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2013-10-30 21:59:34 +0000
commit1f2bee2e23c650c9f24aa747c6005ea71efc3e62 (patch)
treed6f16978b376094dd34de25e0bfbc91852c75a43
parent1faf81fa5c7a0f623ca002e8f5bc65447fc8eda8 (diff)
downloadsg3_utils-1f2bee2e23c650c9f24aa747c6005ea71efc3e62.tar.gz
examples/sg_tst_excl: only accept char devices to stop sg write/read hurting block dev
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@526 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--ChangeLog2
-rw-r--r--examples/sg_tst_excl.cpp14
2 files changed, 14 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 36aa84de..24a2ff32 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,7 @@ Each utility has its own version number, date of last change and
some description at the top of its ".c" file. All utilities in the main
directory have their own "man" pages. There is also a sg3_utils man page.
-Changelog for sg3_utils-1.38 [20131029] [svn: r525]
+Changelog for sg3_utils-1.38 [20131030] [svn: r526]
- sg_inq: add --block=0|1 option to control opens
- sg_luns: guard against garbage response
- sg_lib_data: sync asc/ascq codes with T10 dated 20131008
diff --git a/examples/sg_tst_excl.cpp b/examples/sg_tst_excl.cpp
index ebcb5197..86c3266a 100644
--- a/examples/sg_tst_excl.cpp
+++ b/examples/sg_tst_excl.cpp
@@ -46,7 +46,7 @@
#include "sg_lib.h"
#include "sg_io_linux.h"
-static const char * version_str = "1.05 20131028";
+static const char * version_str = "1.06 20131030";
static const char * util_name = "sg_tst_excl";
/* This is a test program for checking O_EXCL on open() works. It uses
@@ -540,7 +540,19 @@ main(int argc, char * argv[])
return 1;
}
try {
+ struct stat a_stat;
+ if (stat(dev_name, &a_stat) < 0) {
+ perror("stat() on dev_name failed");
+ return 1;
+ }
+ if (! S_ISCHR(a_stat.st_mode)) {
+ fprintf(stderr, "%s should be a sg device which is a char "
+ "device. %s\n", dev_name, dev_name);
+ fprintf(stderr, "is not a char device and damage could be done "
+ "if it is a BLOCK\ndevice, exiting ...\n");
+ return 1;
+ }
if (! force) {
res = do_inquiry_prod_id(dev_name, block, wait_ms, ebusy_count,
b, sizeof(b));