summaryrefslogtreecommitdiff
path: root/src/utilities/util_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utilities/util_main.c')
-rw-r--r--src/utilities/util_main.c117
1 files changed, 62 insertions, 55 deletions
diff --git a/src/utilities/util_main.c b/src/utilities/util_main.c
index 7157f0d90fe..68e3b0f1bc5 100644
--- a/src/utilities/util_main.c
+++ b/src/utilities/util_main.c
@@ -20,7 +20,43 @@ static const char *command; /* Command name */
#define REC_LOGOFF "log=(enabled=false)"
#define REC_RECOVER "log=(recover=on)"
-static int usage(void);
+static void
+usage(void)
+{
+ fprintf(stderr,
+ "WiredTiger Data Engine (version %d.%d)\n",
+ WIREDTIGER_VERSION_MAJOR, WIREDTIGER_VERSION_MINOR);
+ fprintf(stderr,
+ "global options:\n"
+ "\t" "-C\t" "wiredtiger_open configuration\n"
+ "\t" "-h\t" "database directory\n"
+ "\t" "-L\t" "turn logging off for debug-mode\n"
+ "\t" "-R\t" "run recovery if configured\n"
+ "\t" "-V\t" "display library version and exit\n"
+ "\t" "-v\t" "verbose\n");
+ fprintf(stderr,
+ "commands:\n"
+ "\t" "alter\t alter an object\n"
+ "\t" "backup\t database backup\n"
+ "\t" "compact\t compact an object\n"
+ "\t" "copyright copyright information\n"
+ "\t" "create\t create an object\n"
+ "\t" "drop\t drop an object\n"
+ "\t" "dump\t dump an object\n"
+ "\t" "list\t list database objects\n"
+ "\t" "load\t load an object\n"
+ "\t" "loadtext load an object from a text file\n"
+ "\t" "printlog display the database log\n"
+ "\t" "read\t read values from an object\n"
+ "\t" "rebalance rebalance an object\n"
+ "\t" "rename\t rename an object\n"
+ "\t" "salvage\t salvage a file\n"
+ "\t" "stat\t display statistics for an object\n"
+ "\t" "truncate truncate an object, removing all content\n"
+ "\t" "upgrade\t upgrade an object\n"
+ "\t" "verify\t verify an object\n"
+ "\t" "write\t write values to an object\n");
+}
int
main(int argc, char *argv[])
@@ -73,8 +109,9 @@ main(int argc, char *argv[])
cmd_config = __wt_optarg;
break;
case 'E': /* secret key */
+ free(secretkey); /* lint: set more than once */
if ((secretkey = strdup(__wt_optarg)) == NULL) {
- ret = util_err(NULL, errno, NULL);
+ (void)util_err(NULL, errno, NULL);
goto err;
}
memset(__wt_optarg, 0, strlen(__wt_optarg));
@@ -92,24 +129,27 @@ main(int argc, char *argv[])
break;
case 'V': /* version */
printf("%s\n", wiredtiger_version(NULL, NULL, NULL));
- return (EXIT_SUCCESS);
+ goto done;
case 'v': /* verbose */
verbose = true;
break;
case '?':
default:
- return (usage());
+ usage();
+ goto err;
}
if (logoff && recover) {
fprintf(stderr, "Only one of -L and -R is allowed.\n");
- return (EXIT_FAILURE);
+ goto err;
}
argc -= __wt_optind;
argv += __wt_optind;
/* The next argument is the command name. */
- if (argc < 1)
- return (usage());
+ if (argc < 1) {
+ usage();
+ goto err;
+ }
command = argv[0];
/* Reset getopt. */
@@ -130,7 +170,7 @@ main(int argc, char *argv[])
func = util_compact;
else if (strcmp(command, "copyright") == 0) {
util_copyright();
- return (EXIT_SUCCESS);
+ goto done;
} else if (strcmp(command, "create") == 0) {
func = util_create;
config = "create";
@@ -194,8 +234,10 @@ main(int argc, char *argv[])
default:
break;
}
- if (func == NULL)
- return (usage());
+ if (func == NULL) {
+ usage();
+ goto err;
+ }
/* Build the configuration string. */
len = 10; /* some slop */
@@ -212,7 +254,7 @@ main(int argc, char *argv[])
}
len += strlen(rec_config);
if ((p = malloc(len)) == NULL) {
- ret = util_err(NULL, errno, NULL);
+ (void)util_err(NULL, errno, NULL);
goto err;
}
(void)snprintf(p, len, "%s,%s,%s%s%s%s",
@@ -223,19 +265,24 @@ main(int argc, char *argv[])
/* Open the database and a session. */
if ((ret = wiredtiger_open(home,
verbose ? verbose_handler : NULL, config, &conn)) != 0) {
- ret = util_err(NULL, ret, NULL);
+ (void)util_err(NULL, ret, NULL);
goto err;
}
if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) {
- ret = util_err(NULL, ret, NULL);
+ (void)util_err(NULL, ret, NULL);
goto err;
}
/* Call the function. */
ret = func(session, argc, argv);
+ if (0) {
+err: ret = 1;
+ }
+done:
+
/* Close the database. */
-err: if (conn != NULL && (tret = conn->close(conn, NULL)) != 0 && ret == 0)
+ if (conn != NULL && (tret = conn->close(conn, NULL)) != 0 && ret == 0)
ret = tret;
free(p);
@@ -244,46 +291,6 @@ err: if (conn != NULL && (tret = conn->close(conn, NULL)) != 0 && ret == 0)
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
-static int
-usage(void)
-{
- fprintf(stderr,
- "WiredTiger Data Engine (version %d.%d)\n",
- WIREDTIGER_VERSION_MAJOR, WIREDTIGER_VERSION_MINOR);
- fprintf(stderr,
- "global options:\n"
- "\t" "-C\t" "wiredtiger_open configuration\n"
- "\t" "-h\t" "database directory\n"
- "\t" "-L\t" "turn logging off for debug-mode\n"
- "\t" "-R\t" "run recovery if configured\n"
- "\t" "-V\t" "display library version and exit\n"
- "\t" "-v\t" "verbose\n");
- fprintf(stderr,
- "commands:\n"
- "\t" "alter\t alter an object\n"
- "\t" "backup\t database backup\n"
- "\t" "compact\t compact an object\n"
- "\t" "copyright copyright information\n"
- "\t" "create\t create an object\n"
- "\t" "drop\t drop an object\n"
- "\t" "dump\t dump an object\n"
- "\t" "list\t list database objects\n"
- "\t" "load\t load an object\n"
- "\t" "loadtext load an object from a text file\n"
- "\t" "printlog display the database log\n"
- "\t" "read\t read values from an object\n"
- "\t" "rebalance rebalance an object\n"
- "\t" "rename\t rename an object\n"
- "\t" "salvage\t salvage a file\n"
- "\t" "stat\t display statistics for an object\n"
- "\t" "truncate truncate an object, removing all content\n"
- "\t" "upgrade\t upgrade an object\n"
- "\t" "verify\t verify an object\n"
- "\t" "write\t write values to an object\n");
-
- return (EXIT_FAILURE);
-}
-
/*
* util_uri --
* Build a name.
@@ -314,7 +321,7 @@ util_uri(WT_SESSION *session, const char *s, const char *type)
* the default type for the operation.
*/
if (strchr(s, ':') != NULL)
- strcpy(name, s);
+ snprintf(name, len, "%s", s);
else
snprintf(name, len, "%s:%s", type, s);
return (name);