aboutsummaryrefslogtreecommitdiff
path: root/src/sg_start.c
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2018-05-24 01:13:38 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2018-05-24 01:13:38 +0000
commit919290b79eb6649d6d05242180ddb3944ca9521b (patch)
treee2b2f839acafdc5493bb21e81e4361f37c8f4357 /src/sg_start.c
parent26e76bf6c671941fec1a8d2b3fb53fcd64993577 (diff)
downloadsg3_utils-919290b79eb6649d6d05242180ddb3944ca9521b.tar.gz
add SG_LIB_LOGIC_ERROR and SG_LIB_CONTRADICT; implement across many utilities and increase usage of sg_convert_errno()
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@774 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'src/sg_start.c')
-rw-r--r--src/sg_start.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/sg_start.c b/src/sg_start.c
index 28f22f20..b51efbbc 100644
--- a/src/sg_start.c
+++ b/src/sg_start.c
@@ -169,7 +169,7 @@ usage_old()
}
static int
-news_parse_cmd_line(struct opts_t * op, int argc, char * argv[])
+new_parse_cmd_line(struct opts_t * op, int argc, char * argv[])
{
int c, n, err;
@@ -446,7 +446,7 @@ old_parse_cmd_line(struct opts_t * op, int argc, char * argv[])
pr2serr("please, only one of 0, 1, --eject, "
"--load, --start or --stop\n");
usage_old();
- return SG_LIB_SYNTAX_ERROR;
+ return SG_LIB_CONTRADICT;
} else if (startstop_set) {
if (startstop)
op->do_start = true;
@@ -468,10 +468,10 @@ parse_cmd_line(struct opts_t * op, int argc, char * argv[])
op->opt_new = false;
res = old_parse_cmd_line(op, argc, argv);
if ((0 == res) && op->opt_new)
- res = news_parse_cmd_line(op, argc, argv);
+ res = new_parse_cmd_line(op, argc, argv);
} else {
op->opt_new = true;
- res = news_parse_cmd_line(op, argc, argv);
+ res = new_parse_cmd_line(op, argc, argv);
if ((0 == res) && (! op->opt_new))
res = old_parse_cmd_line(op, argc, argv);
}
@@ -493,7 +493,7 @@ main(int argc, char * argv[])
op->do_fl = -1; /* only when >= 0 set FL bit */
res = parse_cmd_line(op, argc, argv);
if (res)
- return SG_LIB_SYNTAX_ERROR;
+ return res;
if (op->do_help) {
if (op->opt_new)
usage();
@@ -508,11 +508,11 @@ main(int argc, char * argv[])
if (op->do_start && op->do_stop) {
pr2serr("Ambiguous to give both '--start' and '--stop'\n");
- return SG_LIB_SYNTAX_ERROR;
+ return SG_LIB_CONTRADICT;
}
if (op->do_load && op->do_eject) {
pr2serr("Ambiguous to give both '--load' and '--eject'\n");
- return SG_LIB_SYNTAX_ERROR;
+ return SG_LIB_CONTRADICT;
}
if (op->do_load)
op->do_start = true;
@@ -537,12 +537,12 @@ main(int argc, char * argv[])
if (! op->do_start) {
pr2serr("Giving '--fl=FL' with '--stop' (or '--eject') is "
"invalid\n");
- return SG_LIB_SYNTAX_ERROR;
+ return SG_LIB_CONTRADICT;
}
if (op->do_pc > 0) {
pr2serr("Giving '--fl=FL' with '--pc=PC' when PC is non-zero "
"is invalid\n");
- return SG_LIB_SYNTAX_ERROR;
+ return SG_LIB_CONTRADICT;
}
}
@@ -582,8 +582,10 @@ main(int argc, char * argv[])
fini:
if (sg_fd >= 0) {
res = sg_cmds_close_device(sg_fd);
- if (0 == ret)
- ret = sg_convert_errno(-res);
+ if (res < 0) {
+ if (0 == ret)
+ ret = sg_convert_errno(-res);
+ }
}
if (0 == op->verbose) {
if (! sg_if_can2stderr("sg_start failed: ", ret))