diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2018-05-15 20:44:45 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2018-05-15 20:44:45 +0000 |
commit | 856fb91355bddbe7a15a9d11334c354d8ee7b6d3 (patch) | |
tree | 9446f14be2d17b1f0449a466e0762a9a3361ca7b /src/sg_stream_ctl.c | |
parent | 71e56cc16387a76971a04fda4ff9306ec704daf9 (diff) | |
download | sg3_utils-856fb91355bddbe7a15a9d11334c354d8ee7b6d3.tar.gz |
cleanup of error messages around sg_cmds_open_device(); add flock error msg for ddpt
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@772 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'src/sg_stream_ctl.c')
-rw-r--r-- | src/sg_stream_ctl.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/sg_stream_ctl.c b/src/sg_stream_ctl.c index f2372ed7..794bf254 100644 --- a/src/sg_stream_ctl.c +++ b/src/sg_stream_ctl.c @@ -33,7 +33,7 @@ * to the given SCSI device. Based on sbc4r15.pdf . */ -static const char * version_str = "1.03 20180427"; +static const char * version_str = "1.04 20180513"; #define STREAM_CONTROL_SA 0x14 #define GET_STREAM_STATUS_SA 0x16 @@ -242,7 +242,8 @@ main(int argc, char * argv[]) bool ctl_given = false; bool maxlen_given = false; bool read_only = false; - int c, k, sg_fd, res, resid; + int c, k, res, resid; + int sg_fd = -1; int maxlen = 0; int ret = 0; int verbose = 0; @@ -253,8 +254,8 @@ main(int argc, char * argv[]) uint32_t param_dl; const char * device_name = NULL; const char * cmd_name = NULL; - uint8_t * arr; - uint8_t * free_arr; + uint8_t * arr = NULL; + uint8_t * free_arr = NULL; while (1) { int option_index = 0; @@ -367,9 +368,11 @@ main(int argc, char * argv[]) sg_fd = sg_cmds_open_device(device_name, read_only, verbose); if (sg_fd < 0) { - pr2serr("open error: %s: %s\n", device_name, - safe_strerror(-sg_fd)); - return SG_LIB_FILE_ERROR; + if (verbose) + pr2serr("open error: %s: %s\n", device_name, + safe_strerror(-sg_fd)); + ret = sg_convert_errno(-sg_fd); + goto fini; } if (maxlen > (int)pg_sz) @@ -464,11 +467,18 @@ main(int argc, char * argv[]) fini: if (free_arr) free(free_arr); - res = sg_cmds_close_device(sg_fd); - if (res < 0) { - pr2serr("close error: %s\n", safe_strerror(-res)); - if (0 == ret) - return SG_LIB_FILE_ERROR; + if (sg_fd >= 0) { + res = sg_cmds_close_device(sg_fd); + if (res < 0) { + pr2serr("close error: %s\n", safe_strerror(-res)); + if (0 == ret) + ret = sg_convert_errno(-res); + } + } + if (0 == verbose) { + if (! sg_if_can2stderr("sg_stream_ctl failed: ", ret)) + pr2serr("Some error occurred, try again with '-v' " + "or '-vv' for more information\n"); } return (ret >= 0) ? ret : SG_LIB_CAT_OTHER; } |