aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2013-10-26 19:35:46 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2013-10-26 19:35:46 +0000
commite0ec59f174d88e123217e4abaf5b7defbe826f08 (patch)
tree650e587156e39040f33bc481561da853f081e92e /examples
parent202ebc2c8f989533012042de47db0b5c9e786b6e (diff)
downloadsg3_utils-e0ec59f174d88e123217e4abaf5b7defbe826f08.tar.gz
examples/sg_tst_excl[23] cleanup
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@524 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'examples')
-rw-r--r--examples/sg_tst_excl2.cpp34
-rw-r--r--examples/sg_tst_excl3.cpp36
2 files changed, 35 insertions, 35 deletions
diff --git a/examples/sg_tst_excl2.cpp b/examples/sg_tst_excl2.cpp
index fd480e7b..6cefb628 100644
--- a/examples/sg_tst_excl2.cpp
+++ b/examples/sg_tst_excl2.cpp
@@ -46,7 +46,7 @@
#include "sg_lib.h"
#include "sg_pt.h"
-static const char * version_str = "1.04 20130829";
+static const char * version_str = "1.05 20131026";
static const char * util_name = "sg_tst_excl2";
/* This is a test program for checking O_EXCL on open() works. It uses
@@ -135,7 +135,7 @@ usage(void)
}
static int
-pt_err(int res, int sg_fd, struct sg_pt_base * ptp)
+pt_err(int res)
{
if (res < 0)
fprintf(stderr, " pass through os error: %s\n",
@@ -146,15 +146,11 @@ pt_err(int res, int sg_fd, struct sg_pt_base * ptp)
fprintf(stderr, " pass through timeout\n");
else
fprintf(stderr, " do_scsi_pt error=%d\n", res);
- if (ptp)
- destruct_scsi_pt_obj(ptp);
- scsi_pt_close_device(sg_fd);
return -1;
}
static int
-pt_cat_no_good(int cat, int sg_fd, struct sg_pt_base * ptp,
- const unsigned char * sbp)
+pt_cat_no_good(int cat, struct sg_pt_base * ptp, const unsigned char * sbp)
{
int slen;
char b[256];
@@ -182,9 +178,6 @@ pt_cat_no_good(int cat, int sg_fd, struct sg_pt_base * ptp,
fprintf(stderr, " unknown pt result category (%d)\n", cat);
break;
}
- if (ptp)
- destruct_scsi_pt_obj(ptp);
- scsi_pt_close_device(sg_fd);
return -1;
}
@@ -251,12 +244,14 @@ do_rd_inc_wr_twice(const char * dev_name, unsigned int lba, int block,
res = do_scsi_pt(ptp, sg_fd, 20 /* secs timeout */, 1);
if (res) {
fprintf(stderr, "READ_16 do_scsi_pt() error\n");
- pt_err(res, sg_fd, ptp);
+ res = pt_err(res);
+ goto err;
}
cat = get_scsi_pt_result_category(ptp);
if (SCSI_PT_RESULT_GOOD != cat) {
fprintf(stderr, "READ_16 do_scsi_pt() category problem\n");
- return pt_cat_no_good(cat, sg_fd, ptp, sense_buffer);
+ res = pt_cat_no_good(cat, ptp, sense_buffer);
+ goto err;
}
u = (lb[0] << 24) + (lb[1] << 16) + (lb[2] << 8) + lb[3];
@@ -284,15 +279,17 @@ do_rd_inc_wr_twice(const char * dev_name, unsigned int lba, int block,
res = do_scsi_pt(ptp, sg_fd, 20 /* secs timeout */, 1);
if (res) {
fprintf(stderr, "WRITE_16 do_scsi_pt() error\n");
- pt_err(res, sg_fd, ptp);
+ res = pt_err(res);
+ goto err;
}
cat = get_scsi_pt_result_category(ptp);
if (SCSI_PT_RESULT_GOOD != cat) {
fprintf(stderr, "WRITE_16 do_scsi_pt() category problem\n");
- return pt_cat_no_good(cat, sg_fd, ptp, sense_buffer);
+ res = pt_cat_no_good(cat, ptp, sense_buffer);
+ goto err;
}
}
-
+err:
if (ptp)
destruct_scsi_pt_obj(ptp);
scsi_pt_close_device(sg_fd);
@@ -348,12 +345,14 @@ do_inquiry_prod_id(const char * dev_name, int block, int excl, int wait_ms,
res = do_scsi_pt(ptp, sg_fd, 20 /* secs timeout */, 1);
if (res) {
fprintf(stderr, "INQUIRY do_scsi_pt() error\n");
- pt_err(res, sg_fd, ptp);
+ res = pt_err(res);
+ goto err;
}
cat = get_scsi_pt_result_category(ptp);
if (SCSI_PT_RESULT_GOOD != cat) {
fprintf(stderr, "INQUIRY do_scsi_pt() category problem\n");
- return pt_cat_no_good(cat, sg_fd, ptp, sense_buffer);
+ res = pt_cat_no_good(cat, ptp, sense_buffer);
+ goto err;
}
/* Good, so fetch Product ID from response, copy to 'b' */
@@ -366,6 +365,7 @@ do_inquiry_prod_id(const char * dev_name, int block, int excl, int wait_ms,
b[b_mlen - 1] = '\0';
}
}
+err:
if (ptp)
destruct_scsi_pt_obj(ptp);
close(sg_fd);
diff --git a/examples/sg_tst_excl3.cpp b/examples/sg_tst_excl3.cpp
index b5db01d6..9ca59c99 100644
--- a/examples/sg_tst_excl3.cpp
+++ b/examples/sg_tst_excl3.cpp
@@ -46,7 +46,7 @@
#include "sg_lib.h"
#include "sg_pt.h"
-static const char * version_str = "1.01 20131021";
+static const char * version_str = "1.02 20131026";
static const char * util_name = "sg_tst_excl3";
/* This is a test program for checking O_EXCL on open() works. It uses
@@ -138,7 +138,7 @@ usage(void)
}
static int
-pt_err(int res, int sg_fd, struct sg_pt_base * ptp)
+pt_err(int res)
{
if (res < 0)
fprintf(stderr, " pass through os error: %s\n",
@@ -149,15 +149,11 @@ pt_err(int res, int sg_fd, struct sg_pt_base * ptp)
fprintf(stderr, " pass through timeout\n");
else
fprintf(stderr, " do_scsi_pt error=%d\n", res);
- if (ptp)
- destruct_scsi_pt_obj(ptp);
- scsi_pt_close_device(sg_fd);
return -1;
}
static int
-pt_cat_no_good(int cat, int sg_fd, struct sg_pt_base * ptp,
- const unsigned char * sbp)
+pt_cat_no_good(int cat, struct sg_pt_base * ptp, const unsigned char * sbp)
{
int slen;
char b[256];
@@ -185,9 +181,6 @@ pt_cat_no_good(int cat, int sg_fd, struct sg_pt_base * ptp,
fprintf(stderr, " unknown pt result category (%d)\n", cat);
break;
}
- if (ptp)
- destruct_scsi_pt_obj(ptp);
- scsi_pt_close_device(sg_fd);
return -1;
}
@@ -254,12 +247,14 @@ do_rd_inc_wr_twice(const char * dev_name, int read_only, unsigned int lba,
res = do_scsi_pt(ptp, sg_fd, 20 /* secs timeout */, 1);
if (res) {
fprintf(stderr, "READ_16 do_scsi_pt() error\n");
- pt_err(res, sg_fd, ptp);
+ res = pt_err(res);
+ goto err;
}
cat = get_scsi_pt_result_category(ptp);
if (SCSI_PT_RESULT_GOOD != cat) {
fprintf(stderr, "READ_16 do_scsi_pt() category problem\n");
- return pt_cat_no_good(cat, sg_fd, ptp, sense_buffer);
+ res = pt_cat_no_good(cat, ptp, sense_buffer);
+ goto err;
}
u = (lb[0] << 24) + (lb[1] << 16) + (lb[2] << 8) + lb[3];
@@ -290,15 +285,17 @@ do_rd_inc_wr_twice(const char * dev_name, int read_only, unsigned int lba,
res = do_scsi_pt(ptp, sg_fd, 20 /* secs timeout */, 1);
if (res) {
fprintf(stderr, "WRITE_16 do_scsi_pt() error\n");
- pt_err(res, sg_fd, ptp);
+ res = pt_err(res);
+ goto err;
}
cat = get_scsi_pt_result_category(ptp);
if (SCSI_PT_RESULT_GOOD != cat) {
fprintf(stderr, "WRITE_16 do_scsi_pt() category problem\n");
- return pt_cat_no_good(cat, sg_fd, ptp, sense_buffer);
+ res = pt_cat_no_good(cat, ptp, sense_buffer);
+ goto err;
}
}
-
+err:
if (ptp)
destruct_scsi_pt_obj(ptp);
scsi_pt_close_device(sg_fd);
@@ -354,12 +351,14 @@ do_inquiry_prod_id(const char * dev_name, int block, int excl, int wait_ms,
res = do_scsi_pt(ptp, sg_fd, 20 /* secs timeout */, 1);
if (res) {
fprintf(stderr, "INQUIRY do_scsi_pt() error\n");
- pt_err(res, sg_fd, ptp);
+ res = pt_err(res);
+ goto err;
}
cat = get_scsi_pt_result_category(ptp);
if (SCSI_PT_RESULT_GOOD != cat) {
fprintf(stderr, "INQUIRY do_scsi_pt() category problem\n");
- return pt_cat_no_good(cat, sg_fd, ptp, sense_buffer);
+ res = pt_cat_no_good(cat, ptp, sense_buffer);
+ goto err;
}
/* Good, so fetch Product ID from response, copy to 'b' */
@@ -372,10 +371,11 @@ do_inquiry_prod_id(const char * dev_name, int block, int excl, int wait_ms,
b[b_mlen - 1] = '\0';
}
}
+err:
if (ptp)
destruct_scsi_pt_obj(ptp);
close(sg_fd);
- return 0;
+ return res;
}
static void