From 856fb91355bddbe7a15a9d11334c354d8ee7b6d3 Mon Sep 17 00:00:00 2001 From: Douglas Gilbert Date: Tue, 15 May 2018 20:44:45 +0000 Subject: 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 --- src/sg_sync.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'src/sg_sync.c') diff --git a/src/sg_sync.c b/src/sg_sync.c index 59cf8276..23a26d5b 100644 --- a/src/sg_sync.c +++ b/src/sg_sync.c @@ -35,7 +35,7 @@ * (e.g. disks). */ -static const char * version_str = "1.20 20180219"; +static const char * version_str = "1.21 20180514"; #define SYNCHRONIZE_CACHE16_CMD 0x91 #define SYNCHRONIZE_CACHE16_CMDLEN 16 @@ -152,7 +152,8 @@ int main(int argc, char * argv[]) bool do_16 = false; bool immed = false; bool sync_nv = false; - int sg_fd, res, c; + int res, c; + int sg_fd = -1; int group = 0; int ret = 0; int to_secs = DEF_PT_TIMEOUT; @@ -245,9 +246,11 @@ int main(int argc, char * argv[]) } sg_fd = sg_cmds_open_device(device_name, false /* rw */, 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 (do_16) @@ -264,11 +267,19 @@ int main(int argc, char * argv[]) pr2serr("Synchronize cache failed: %s\n", b); } - 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_sync failed: ", ret)) + pr2serr("Some error occurred, try again with '-v' " + "or '-vv' for more information\n"); } return (ret >= 0) ? ret : SG_LIB_CAT_OTHER; } -- cgit v1.2.3