diff options
Diffstat (limited to 'src/sg_timestamp.c')
-rw-r--r-- | src/sg_timestamp.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/sg_timestamp.c b/src/sg_timestamp.c index 976bca56..2049052c 100644 --- a/src/sg_timestamp.c +++ b/src/sg_timestamp.c @@ -316,7 +316,8 @@ main(int argc, char * argv[]) bool no_timestamp = false; bool readonly = false; bool secs_given = false; - int sg_fd, res, c; + int res, c; + int sg_fd = 1; int elapsed = 0; int do_origin = 0; int do_help = 0; @@ -427,9 +428,11 @@ main(int argc, char * argv[]) sg_fd = sg_cmds_open_device(device_name, readonly, 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; } memset(d_buff, 0, 12); @@ -495,11 +498,19 @@ main(int argc, char * argv[]) } } - 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; +fini: + 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_timestamp failed: ", ret)) + pr2serr("Some error occurred, try again with '-v' " + "or '-vv' for more information\n"); } return (ret >= 0) ? ret : SG_LIB_CAT_OTHER; } |