diff options
author | Andrew Tridgell <tridge@samba.org> | 2009-05-28 17:35:12 +1000 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2009-12-16 08:03:49 +0100 |
commit | 6eaaa52a1db78d382801a708e096f0ca1ae59249 (patch) | |
tree | ff5dc37b253dd067ea542f3af23d9c51d700a93b /ctdb | |
parent | b52a06ffc64e026cfcfb5f3395ea8b4f659b4390 (diff) | |
download | samba-6eaaa52a1db78d382801a708e096f0ca1ae59249.tar.gz samba-6eaaa52a1db78d382801a708e096f0ca1ae59249.tar.xz samba-6eaaa52a1db78d382801a708e096f0ca1ae59249.zip |
fixed tdbbackup to give tdb error messages (cherry picked from samba commit 08be1420ba52ef9bba90d0f811c7810841ee8568)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
(This used to be ctdb commit 3d44412593b8748a5158e15b83cd9eb548231194)
Diffstat (limited to 'ctdb')
-rw-r--r-- | ctdb/lib/tdb/tools/tdbbackup.c | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/ctdb/lib/tdb/tools/tdbbackup.c b/ctdb/lib/tdb/tools/tdbbackup.c index 6f3ca48314..024b078c83 100644 --- a/ctdb/lib/tdb/tools/tdbbackup.c +++ b/ctdb/lib/tdb/tools/tdbbackup.c @@ -53,6 +53,21 @@ static int failed; +static struct tdb_logging_context log_ctx; + +#ifdef PRINTF_ATTRIBUTE +static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); +#endif +static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + vfprintf(stdout, format, ap); + va_end(ap); + fflush(stdout); +} + static char *add_suffix(const char *name, const char *suffix) { char *ret; @@ -107,7 +122,8 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size) } /* open the old tdb */ - tdb = tdb_open(old_name, 0, 0, O_RDWR, 0); + tdb = tdb_open_ex(old_name, 0, 0, + O_RDWR, 0, &log_ctx, NULL); if (!tdb) { printf("Failed to open %s\n", old_name); free(tmp_name); @@ -116,10 +132,11 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size) /* create the new tdb */ unlink(tmp_name); - tdb_new = tdb_open(tmp_name, - hash_size ? hash_size : tdb_hash_size(tdb), - TDB_DEFAULT, O_RDWR|O_CREAT|O_EXCL, - st.st_mode & 0777); + tdb_new = tdb_open_ex(tmp_name, + hash_size ? hash_size : tdb_hash_size(tdb), + TDB_DEFAULT, + O_RDWR|O_CREAT|O_EXCL, st.st_mode & 0777, + &log_ctx, NULL); if (!tdb_new) { perror(tmp_name); free(tmp_name); @@ -154,7 +171,11 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size) /* close the new tdb and re-open read-only */ tdb_close(tdb_new); - tdb_new = tdb_open(tmp_name, 0, TDB_DEFAULT, O_RDONLY, 0); + tdb_new = tdb_open_ex(tmp_name, + 0, + TDB_DEFAULT, + O_RDONLY, 0, + &log_ctx, NULL); if (!tdb_new) { fprintf(stderr,"failed to reopen %s\n", tmp_name); unlink(tmp_name); @@ -198,7 +219,8 @@ static int verify_tdb(const char *fname, const char *bak_name) int count = -1; /* open the tdb */ - tdb = tdb_open(fname, 0, 0, O_RDONLY, 0); + tdb = tdb_open_ex(fname, 0, 0, + O_RDONLY, 0, &log_ctx, NULL); /* traverse the tdb, then close it */ if (tdb) { @@ -251,6 +273,8 @@ static void usage(void) int hashsize = 0; const char *suffix = ".bak"; + log_ctx.log_fn = tdb_log; + while ((c = getopt(argc, argv, "vhs:n:")) != -1) { switch (c) { case 'h': |