From 65faa5ed7ebba7136999f52514c71d8670402627 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 30 May 2013 15:56:30 -0700 Subject: [PATCH] tweak mdb_copy, trap signals --- libraries/liblmdb/mdb_copy.1 | 5 ----- libraries/liblmdb/mdb_copy.c | 23 ++++++++++++++++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/libraries/liblmdb/mdb_copy.1 b/libraries/liblmdb/mdb_copy.1 index 11a0042..7837de5 100644 --- a/libraries/liblmdb/mdb_copy.1 +++ b/libraries/liblmdb/mdb_copy.1 @@ -18,11 +18,6 @@ is specified it must be the path of an empty directory for storing the backup. Otherwise, the backup will be written to stdout. -Note: currently, if the copy is interrupted a stale lock -will be left in the LMDB environment. This may be fixed -in a future release, but until then you must not -interrupt the copy process. - .SH DIAGNOSTICS Exit status is zero if no errors occur. Errors result in a non-zero exit status and diff --git a/libraries/liblmdb/mdb_copy.c b/libraries/liblmdb/mdb_copy.c index a2ac4cc..ca92009 100644 --- a/libraries/liblmdb/mdb_copy.c +++ b/libraries/liblmdb/mdb_copy.c @@ -11,10 +11,22 @@ * top-level directory of the distribution or, alternatively, at * . */ +#ifdef _WIN32 +#include +#define MDB_STDOUT GetStdHandle(STD_OUTPUT_HANDLE) +#else +#define MDB_STDOUT 1 +#endif #include #include +#include #include "lmdb.h" +static void +sighandle(int sig) +{ +} + int main(int argc,char * argv[]) { int rc; @@ -26,6 +38,15 @@ int main(int argc,char * argv[]) exit(EXIT_FAILURE); } +#ifdef SIGPIPE + signal(SIGPIPE, sighandle); +#endif +#ifdef SIGHUP + signal(SIGHUP, sighandle); +#endif + signal(SIGINT, sighandle); + signal(SIGTERM, sighandle); + rc = mdb_env_create(&env); rc = mdb_env_open(env, envname, MDB_RDONLY, 0); @@ -33,7 +54,7 @@ int main(int argc,char * argv[]) printf("mdb_env_open failed, error %d %s\n", rc, mdb_strerror(rc)); } else { if (argc == 2) - rc = mdb_env_copyfd(env, 1); + rc = mdb_env_copyfd(env, MDB_STDOUT); else rc = mdb_env_copy(env, argv[2]); if (rc)