reset/sanlk_reset.c | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
New commits:
commit 2d6fdc4685567214f0688223b53e2e05f110e9b6
Author: Nir Soffer <nsoffer(a)redhat.com>
Date: Tue Aug 19 11:21:52 2014 -0500
reset: Normalize exit codes
Previously some usage error were treated as failures, and some failures
caused the program to exit with strange exit codes (e.g. 255). This
patch normalizes the exit code to make sanlk-reset easier to consume by
other programs.
Exit codes:
0 program succeeded
1 program failed
2 program used incorrectly
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
diff --git a/reset/sanlk_reset.c b/reset/sanlk_reset.c
index 51e9a14..9b121e8 100644
--- a/reset/sanlk_reset.c
+++ b/reset/sanlk_reset.c
@@ -38,6 +38,7 @@ static struct sockaddr_un update_addr;
static socklen_t update_addrlen;
#include "sanlk_reset.h"
+#define EXIT_USAGE 2
#define MAX_LS 64
static char *prog_name;
@@ -430,7 +431,7 @@ static int update_local_daemon(char *cmd)
s = setup_resetd_socket();
if (s < 0) {
fprintf(stderr, "Failed to create socket %d\n", s);
- return s;
+ return EXIT_FAILURE;
}
for (i = 0; i < ls_count; i++) {
@@ -440,13 +441,13 @@ static int update_local_daemon(char *cmd)
rv = sendto(s, buf, UPDATE_SIZE, 0, (struct sockaddr *)&update_addr,
update_addrlen);
if (rv < 0) {
printf("Failed to update local sanlk-resetd: %s\n", strerror(errno));
- return rv;
+ return EXIT_FAILURE;
} else {
printf("Updated %s %s\n", cmd, ls_names[i]);
}
}
- return 0;
+ return EXIT_SUCCESS;
}
static void usage(void)
@@ -499,7 +500,7 @@ int main(int argc, char *argv[])
if (argc < 2) {
usage();
- exit(EXIT_FAILURE);
+ exit(EXIT_USAGE);
}
static struct option long_options[] = {
@@ -549,7 +550,7 @@ int main(int argc, char *argv[])
case '?':
default:
usage();
- exit(2);
+ exit(EXIT_USAGE);
}
}
@@ -575,7 +576,7 @@ int main(int argc, char *argv[])
if (!ls_count) {
fprintf(stderr, "lockspace_name is required\n");
- exit(2);
+ exit(EXIT_USAGE);
}
/*
@@ -592,12 +593,12 @@ int main(int argc, char *argv[])
if (strcmp(cmd, "reset")) {
fprintf(stderr, "unknown command\n");
- exit(2);
+ exit(EXIT_USAGE);
}
if ((ls_count > 1) && (target_host_id || target_generation)) {
fprintf(stderr, "-i and -g options are only allowed with a single
lockspace_name\n");
- exit(2);
+ exit(EXIT_USAGE);
}
for (i = 0; i < ls_count; i++) {
@@ -612,7 +613,7 @@ int main(int argc, char *argv[])
if (ls_hostids[i] < 1 || ls_hostids[i] > 2000) {
fprintf(stderr, "invalid host_id %d", ls_hostids[i]);
- exit(2);
+ exit(EXIT_USAGE);
}
}
commit dd664772005ded090404d17380a9bc984ac41cb8
Author: Nir Soffer <nsoffer(a)redhat.com>
Date: Tue Aug 19 11:19:56 2014 -0500
reset: Calling with too many lockspaces is a usage error
Previously we complained about ignoring lockspaces, but continue the
operation as usaual, so another program running the sanlk-reset tool
cannot detect the usage error.
Now this will fail with exit code 2 and this message:
too many lockspaces (max 64)
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
diff --git a/reset/sanlk_reset.c b/reset/sanlk_reset.c
index 7a15ff9..51e9a14 100644
--- a/reset/sanlk_reset.c
+++ b/reset/sanlk_reset.c
@@ -565,7 +565,8 @@ int main(int argc, char *argv[])
for (i = optind; i < argc; i++) {
if (ls_count == MAX_LS) {
- fprintf(stderr, "ignore lockspace_name %s\n", argv[i]);
+ fprintf(stderr, "too many lockspaces (max %d)\n", MAX_LS);
+ exit(2);
} else {
ls_names[ls_count] = argv[i];
ls_count++;
commit ba24c1d230932a947324ea916cd2b932f2948f69
Author: Nir Soffer <nsoffer(a)redhat.com>
Date: Tue Aug 19 01:56:28 2014 +0300
reset: Improve error message when command is missing
If some options were specified without any positional arguments, this
confusing error message was displayed:
$ sanlk-reset -i 42
lockspace_name is required
Now more correct message is displayed:
command is required
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
diff --git a/reset/sanlk_reset.c b/reset/sanlk_reset.c
index 7093095..7a15ff9 100644
--- a/reset/sanlk_reset.c
+++ b/reset/sanlk_reset.c
@@ -553,12 +553,18 @@ int main(int argc, char *argv[])
}
}
+ if (optind >= argc) {
+ fprintf(stderr, "command is required\n");
+ exit(2);
+ }
+
+ cmd = argv[optind];
+ optind++;
+
ls_count = 0;
for (i = optind; i < argc; i++) {
- if (i == optind) {
- cmd = argv[i];
- } else if (ls_count == MAX_LS) {
+ if (ls_count == MAX_LS) {
fprintf(stderr, "ignore lockspace_name %s\n", argv[i]);
} else {
ls_names[ls_count] = argv[i];
commit 0ded3083a28178c3e07680581c7047bc7eaf8aba
Author: Nir Soffer <nsoffer(a)redhat.com>
Date: Tue Aug 19 00:10:06 2014 +0300
reset: Add the clear command to the usage
The command was documented in the examples but not in the usage line.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
diff --git a/reset/sanlk_reset.c b/reset/sanlk_reset.c
index 56cada3..7093095 100644
--- a/reset/sanlk_reset.c
+++ b/reset/sanlk_reset.c
@@ -451,7 +451,7 @@ static int update_local_daemon(char *cmd)
static void usage(void)
{
- printf("%s [options] reg|end|reset lockspaces\n", prog_name);
+ printf("%s [options] reg|end|clear|reset lockspaces\n", prog_name);
printf(" --help | -h\n");
printf(" Show this help information.\n");
printf(" --version | -V\n");