diff options
author | Simo Sorce <idra@samba.org> | 2008-12-22 17:30:41 -0500 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2008-12-22 18:52:37 -0500 |
commit | 9e1e585aa2740bd55bd60d965bd6c271ee9caa2e (patch) | |
tree | 02d225bc01207e2838e056a175d91f14576698dd /tdb/tools | |
parent | 6582952ae76c03c53227499028652b47692448e4 (diff) | |
download | sssd-9e1e585aa2740bd55bd60d965bd6c271ee9caa2e.tar.gz sssd-9e1e585aa2740bd55bd60d965bd6c271ee9caa2e.tar.bz2 sssd-9e1e585aa2740bd55bd60d965bd6c271ee9caa2e.zip |
Rebase tdb code with all changes in samba master
Diffstat (limited to 'tdb/tools')
-rw-r--r-- | tdb/tools/tdbbackup.c | 25 | ||||
-rw-r--r-- | tdb/tools/tdbtool.c | 29 |
2 files changed, 47 insertions, 7 deletions
diff --git a/tdb/tools/tdbbackup.c b/tdb/tools/tdbbackup.c index 6f3ca483..83c0e163 100644 --- a/tdb/tools/tdbbackup.c +++ b/tdb/tools/tdbbackup.c @@ -126,9 +126,17 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size) return 1; } - /* lock the old tdb */ - if (tdb_lockall(tdb) != 0) { - fprintf(stderr,"Failed to lock %s\n", old_name); + if (tdb_transaction_start(tdb) != 0) { + printf("Failed to start transaction on old tdb\n"); + tdb_close(tdb); + tdb_close(tdb_new); + unlink(tmp_name); + free(tmp_name); + return 1; + } + + if (tdb_transaction_start(tdb_new) != 0) { + printf("Failed to start transaction on new tdb\n"); tdb_close(tdb); tdb_close(tdb_new); unlink(tmp_name); @@ -152,6 +160,14 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size) /* close the old tdb */ tdb_close(tdb); + if (tdb_transaction_commit(tdb_new) != 0) { + fprintf(stderr, "Failed to commit new tdb\n"); + tdb_close(tdb_new); + unlink(tmp_name); + free(tmp_name); + return 1; + } + /* 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); @@ -173,9 +189,6 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size) return 1; } - /* make sure the new tdb has reached stable storage */ - fsync(tdb_fd(tdb_new)); - /* close the new tdb and rename it to .bak */ tdb_close(tdb_new); if (rename(tmp_name, new_name) != 0) { diff --git a/tdb/tools/tdbtool.c b/tdb/tools/tdbtool.c index d104ccd7..2a11cdae 100644 --- a/tdb/tools/tdbtool.c +++ b/tdb/tools/tdbtool.c @@ -57,6 +57,7 @@ enum commands { CMD_FIRST, CMD_NEXT, CMD_SYSTEM, + CMD_CHECK, CMD_QUIT, CMD_HELP }; @@ -87,6 +88,7 @@ COMMAND_TABLE cmd_table[] = { {"1", CMD_FIRST}, {"next", CMD_NEXT}, {"n", CMD_NEXT}, + {"check", CMD_CHECK}, {"quit", CMD_QUIT}, {"q", CMD_QUIT}, {"!", CMD_SYSTEM}, @@ -179,7 +181,8 @@ static void help(void) " delete key : delete a record by key\n" " list : print the database hash table and freelist\n" " free : print the database freelist\n" -" ! command : execute system command\n" +" check : check the integrity of an opened database\n" +" ! command : execute system command\n" " 1 | first : print the first record\n" " n | next : print the next record\n" " q | quit : terminate\n" @@ -452,6 +455,27 @@ static void next_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey) print_rec(the_tdb, *pkey, dbuf, NULL); } +static int test_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +{ + return 0; +} + +static void check_db(TDB_CONTEXT *the_tdb) +{ + int tdbcount=-1; + if (the_tdb) { + tdbcount = tdb_traverse(the_tdb, test_fn, NULL); + } else { + printf("Error: No database opened!\n"); + } + + if (tdbcount<0) { + printf("Integrity check for the opened database failed.\n"); + } else { + printf("Database integrity is OK and has %d records.\n", tdbcount); + } +} + static int do_command(void) { COMMAND_TABLE *ctp = cmd_table; @@ -552,6 +576,9 @@ static int do_command(void) if (bIterate) next_record(tdb, &iterate_kbuf); return 0; + case CMD_CHECK: + check_db(tdb); + return 0; case CMD_HELP: help(); return 0; |