From 360d0492db4eacc0b257566bf50c609c2c31d545 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 18 Jul 2013 08:33:24 -0700 Subject: [PATCH] Tweak mdb_stat(1) Don't obtain reader txn before displaying reader table. Exit after reader table if no other DB query options were given. --- libraries/liblmdb/mdb.c | 5 ++++- libraries/liblmdb/mdb_stat.c | 16 ++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index f86ec356b6..e15b5bdb8e 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -7926,7 +7926,7 @@ int mdb_reader_list(MDB_env *env, MDB_msg_func *func, void *ctx) if (!env || !func) return -1; if (!env->me_txns) { - return func("No reader locks\n", ctx); + return func("(no reader locks)\n", ctx); } rdrs = env->me_numreaders; mr = env->me_txns->mti_readers; @@ -7949,6 +7949,9 @@ int mdb_reader_list(MDB_env *env, MDB_msg_func *func, void *ctx) return rc; } } + if (first) { + func("(no active readers)\n", ctx); + } return 0; } /** @} */ diff --git a/libraries/liblmdb/mdb_stat.c b/libraries/liblmdb/mdb_stat.c index 5a0946683d..8331bb9cde 100644 --- a/libraries/liblmdb/mdb_stat.c +++ b/libraries/liblmdb/mdb_stat.c @@ -31,7 +31,7 @@ static void prstat(MDB_stat *ms) static void usage(char *prog) { - fprintf(stderr, "usage: %s dbpath [-e] [-f[f[f]]] [-n] [-a|-s subdb] [-r]\n", prog); + fprintf(stderr, "usage: %s dbpath [-n] [-e] [-r] | [-f[f[f]]] [-a|-s subdb]\n", prog); exit(EXIT_FAILURE); } @@ -56,6 +56,7 @@ int main(int argc, char *argv[]) * -s: print stat of only the named subDB * -e: print env info * -f: print freelist info + * -r: print reader info * -n: use NOSUBDIR flag on env_open * (default) print stat of only the main DB */ @@ -103,11 +104,6 @@ int main(int argc, char *argv[]) printf("mdb_env_open failed, error %d %s\n", rc, mdb_strerror(rc)); goto env_close; } - rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn); - if (rc) { - printf("mdb_txn_begin failed, error %d %s\n", rc, mdb_strerror(rc)); - goto env_close; - } if (envinfo) { rc = mdb_env_stat(env, &mst); @@ -126,6 +122,14 @@ int main(int argc, char *argv[]) if (rdrinfo) { printf("Reader Table Status\n"); rc = mdb_reader_list(env, (MDB_msg_func *)fputs, stdout); + if (!(subname || alldbs || freinfo)) + goto env_close; + } + + rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn); + if (rc) { + printf("mdb_txn_begin failed, error %d %s\n", rc, mdb_strerror(rc)); + goto env_close; } if (freinfo) { -- 2.39.5