From a3d61e0485c70ec5215c34b6caf40e2e6c6c5338 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 24 May 2004 16:27:23 +0000 Subject: r848: convert lib/tdb into the same layout as lib/ldb metze (This used to be commit bacab322ce89979f0ad0811cd15b73d81eceb69d) --- source4/lib/tdb/tools/Makefile | 29 ++ source4/lib/tdb/tools/tdbbackup.c | 149 ++++++++++ source4/lib/tdb/tools/tdbdump.c | 89 ++++++ source4/lib/tdb/tools/tdbtest.c | 263 ++++++++++++++++++ source4/lib/tdb/tools/tdbtool.c | 547 +++++++++++++++++++++++++++++++++++++ source4/lib/tdb/tools/tdbtorture.c | 227 +++++++++++++++ 6 files changed, 1304 insertions(+) create mode 100644 source4/lib/tdb/tools/Makefile create mode 100644 source4/lib/tdb/tools/tdbbackup.c create mode 100644 source4/lib/tdb/tools/tdbdump.c create mode 100644 source4/lib/tdb/tools/tdbtest.c create mode 100644 source4/lib/tdb/tools/tdbtool.c create mode 100644 source4/lib/tdb/tools/tdbtorture.c (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/Makefile b/source4/lib/tdb/tools/Makefile new file mode 100644 index 0000000000..59fbb079bd --- /dev/null +++ b/source4/lib/tdb/tools/Makefile @@ -0,0 +1,29 @@ +# +# Makefile for tdb directory +# + +CFLAGS = -DSTANDALONE -DTDB_DEBUG -g -DHAVE_MMAP=1 +CC = gcc + +PROGS = tdbtest tdbtool tdbtorture +TDB_OBJ = tdb.o spinlock.o + +default: $(PROGS) + +tdbtest: tdbtest.o $(TDB_OBJ) + $(CC) $(CFLAGS) -o tdbtest tdbtest.o $(TDB_OBJ) -lgdbm + +tdbtool: tdbtool.o $(TDB_OBJ) + $(CC) $(CFLAGS) -o tdbtool tdbtool.o $(TDB_OBJ) + +tdbtorture: tdbtorture.o $(TDB_OBJ) + $(CC) $(CFLAGS) -o tdbtorture tdbtorture.o $(TDB_OBJ) + +tdbdump: tdbdump.o $(TDB_OBJ) + $(CC) $(CFLAGS) -o tdbdump tdbdump.o $(TDB_OBJ) + +tdbbackup: tdbbackup.o $(TDB_OBJ) + $(CC) $(CFLAGS) -o tdbbackup tdbbackup.o $(TDB_OBJ) + +clean: + rm -f $(PROGS) *.o *~ *% core test.db test.tdb test.gdbm diff --git a/source4/lib/tdb/tools/tdbbackup.c b/source4/lib/tdb/tools/tdbbackup.c new file mode 100644 index 0000000000..1a0e1c1588 --- /dev/null +++ b/source4/lib/tdb/tools/tdbbackup.c @@ -0,0 +1,149 @@ +/* + Unix SMB/CIFS implementation. + low level tdb backup and restore utility + Copyright (C) Andrew Tridgell 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* + + This program is meant for backup/restore of tdb databases. Typical usage would be: + tdbbackup *.tdb + when Samba shuts down cleanly, which will make a backup of all the local databases + to *.bak files. Then on Samba startup you would use: + tdbbackup -v *.tdb + and this will check the databases for corruption and if corruption is detected then + the backup will be restored. + + You may also like to do a backup on a regular basis while Samba is + running, perhaps using cron. + + The reason this program is needed is to cope with power failures + while Samba is running. A power failure could lead to database + corruption and Samba will then not start correctly. + + Note that many of the databases in Samba are transient and thus + don't need to be backed up, so you can optimise the above a little + by only running the backup on the critical databases. + + */ + +#ifdef STANDALONE +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#else + +#include "includes.h" + +#endif + +#include "tdb.h" +#include "tdbback.h" + +/* + see if one file is newer than another +*/ +static int file_newer(const char *fname1, const char *fname2) +{ + struct stat st1, st2; + if (stat(fname1, &st1) != 0) { + return 0; + } + if (stat(fname2, &st2) != 0) { + return 1; + } + return (st1.st_mtime > st2.st_mtime); +} + +static void usage(void) +{ + printf("Usage: tdbbackup [options] \n\n"); + printf(" -h this help message\n"); + printf(" -s suffix set the backup suffix\n"); + printf(" -v verify mode (restore if corrupt)\n"); +} + + + int main(int argc, char *argv[]) +{ + int i; + int ret = 0; + int c; + int verify = 0; + const char *suffix = ".bak"; + extern int optind; + extern char *optarg; + + while ((c = getopt(argc, argv, "vhs:")) != -1) { + switch (c) { + case 'h': + usage(); + exit(0); + case 'v': + verify = 1; + break; + case 's': + suffix = optarg; + break; + } + } + + argc -= optind; + argv += optind; + + if (argc < 1) { + usage(); + exit(1); + } + + for (i=0; i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "tdb.h" + +static void print_data(TDB_DATA d) +{ + unsigned char *p = d.dptr; + int len = d.dsize; + while (len--) { + if (isprint(*p) && !strchr("\"\\", *p)) { + fputc(*p, stdout); + } else { + printf("\\%02X", *p); + } + p++; + } +} + +static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +{ + printf("{\n"); + printf("key = \""); + print_data(key); + printf("\"\n"); + printf("data = \""); + print_data(dbuf); + printf("\"\n"); + printf("}\n"); + return 0; +} + +static int dump_tdb(const char *fname) +{ + TDB_CONTEXT *tdb; + + tdb = tdb_open(fname, 0, 0, O_RDONLY, 0); + if (!tdb) { + printf("Failed to open %s\n", fname); + return 1; + } + + tdb_traverse(tdb, traverse_fn, NULL); + return 0; +} + + int main(int argc, char *argv[]) +{ + char *fname; + + if (argc < 2) { + printf("Usage: tdbdump \n"); + exit(1); + } + + fname = argv[1]; + + return dump_tdb(fname); +} diff --git a/source4/lib/tdb/tools/tdbtest.c b/source4/lib/tdb/tools/tdbtest.c new file mode 100644 index 0000000000..89295a3291 --- /dev/null +++ b/source4/lib/tdb/tools/tdbtest.c @@ -0,0 +1,263 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "tdb.h" +#include + +/* a test program for tdb - the trivial database */ + + + +#define DELETE_PROB 7 +#define STORE_PROB 5 + +static TDB_CONTEXT *db; +static GDBM_FILE gdbm; + +struct timeval tp1,tp2; + +static void start_timer(void) +{ + gettimeofday(&tp1,NULL); +} + +static double end_timer(void) +{ + gettimeofday(&tp2,NULL); + return((tp2.tv_sec - tp1.tv_sec) + + (tp2.tv_usec - tp1.tv_usec)*1.0e-6); +} + +static void fatal(char *why) +{ + perror(why); + exit(1); +} + +static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + vfprintf(stdout, format, ap); + va_end(ap); + fflush(stdout); +} + +static void compare_db(void) +{ + TDB_DATA d, key, nextkey; + datum gd, gkey, gnextkey; + + key = tdb_firstkey(db); + while (key.dptr) { + d = tdb_fetch(db, key); + gkey.dptr = key.dptr; + gkey.dsize = key.dsize; + + gd = gdbm_fetch(gdbm, gkey); + + if (!gd.dptr) fatal("key not in gdbm"); + if (gd.dsize != d.dsize) fatal("data sizes differ"); + if (memcmp(gd.dptr, d.dptr, d.dsize)) { + fatal("data differs"); + } + + nextkey = tdb_nextkey(db, key); + free(key.dptr); + free(d.dptr); + free(gd.dptr); + key = nextkey; + } + + gkey = gdbm_firstkey(gdbm); + while (gkey.dptr) { + gd = gdbm_fetch(gdbm, gkey); + key.dptr = gkey.dptr; + key.dsize = gkey.dsize; + + d = tdb_fetch(db, key); + + if (!d.dptr) fatal("key not in db"); + if (d.dsize != gd.dsize) fatal("data sizes differ"); + if (memcmp(d.dptr, gd.dptr, gd.dsize)) { + fatal("data differs"); + } + + gnextkey = gdbm_nextkey(gdbm, gkey); + free(gkey.dptr); + free(gd.dptr); + free(d.dptr); + gkey = gnextkey; + } +} + +static char *randbuf(int len) +{ + char *buf; + int i; + buf = (char *)malloc(len+1); + + for (i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "tdb.h" + +/* a tdb tool for manipulating a tdb database */ + +#define FSTRING_LEN 256 +typedef char fstring[FSTRING_LEN]; + +typedef struct connections_key { + pid_t pid; + int cnum; + fstring name; +} connections_key; + +typedef struct connections_data { + int magic; + pid_t pid; + int cnum; + uid_t uid; + gid_t gid; + char name[24]; + char addr[24]; + char machine[128]; + time_t start; +} connections_data; + +static TDB_CONTEXT *tdb; + +static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); + +static void print_asc(unsigned char *buf,int len) +{ + int i; + + /* We're probably printing ASCII strings so don't try to display + the trailing NULL character. */ + + if (buf[len - 1] == 0) + len--; + + for (i=0;i8) printf(" "); + while (n--) printf(" "); + + n = i%16; + if (n > 8) n = 8; + print_asc(&buf[i-(i%16)],n); printf(" "); + n = (i%16) - n; + if (n>0) print_asc(&buf[i-n],n); + printf("\n"); + } +} + +static void help(void) +{ + printf("\n" +"tdbtool: \n" +" create dbname : create a database\n" +" open dbname : open an existing database\n" +" erase : erase the database\n" +" dump : dump the database as strings\n" +" insert key data : insert a record\n" +" move key file : move a record to a destination tdb\n" +" store key data : store a record (replace)\n" +" show key : show a record by key\n" +" delete key : delete a record by key\n" +" list : print the database hash table and freelist\n" +" free : print the database freelist\n" +" 1 | first : print the first record\n" +" n | next : print the next record\n" +" q | quit : terminate\n" +" \\n : repeat 'next' command\n" +"\n"); +} + +static void terror(char *why) +{ + printf("%s\n", why); +} + +static char *get_token(int startover) +{ + static char tmp[1024]; + static char *cont = NULL; + char *insert, *start; + char *k = strtok(NULL, " "); + + if (!k) + return NULL; + + if (startover) + start = tmp; + else + start = cont; + + strcpy(start, k); + insert = start + strlen(start) - 1; + while (*insert == '\\') { + *insert++ = ' '; + k = strtok(NULL, " "); + if (!k) + break; + strcpy(insert, k); + insert = start + strlen(start) - 1; + } + + /* Get ready for next call */ + cont = start + strlen(start) + 1; + return start; +} + +static void create_tdb(void) +{ + char *tok = get_token(1); + if (!tok) { + help(); + return; + } + if (tdb) tdb_close(tdb); + tdb = tdb_open(tok, 0, TDB_CLEAR_IF_FIRST, + O_RDWR | O_CREAT | O_TRUNC, 0600); + if (!tdb) { + printf("Could not create %s: %s\n", tok, strerror(errno)); + } +} + +static void open_tdb(void) +{ + char *tok = get_token(1); + if (!tok) { + help(); + return; + } + if (tdb) tdb_close(tdb); + tdb = tdb_open(tok, 0, 0, O_RDWR, 0600); + if (!tdb) { + printf("Could not open %s: %s\n", tok, strerror(errno)); + } +} + +static void insert_tdb(void) +{ + char *k = get_token(1); + char *d = get_token(0); + TDB_DATA key, dbuf; + + if (!k || !d) { + help(); + return; + } + + key.dptr = k; + key.dsize = strlen(k)+1; + dbuf.dptr = d; + dbuf.dsize = strlen(d)+1; + + if (tdb_store(tdb, key, dbuf, TDB_INSERT) == -1) { + terror("insert failed"); + } +} + +static void store_tdb(void) +{ + char *k = get_token(1); + char *d = get_token(0); + TDB_DATA key, dbuf; + + if (!k || !d) { + help(); + return; + } + + key.dptr = k; + key.dsize = strlen(k)+1; + dbuf.dptr = d; + dbuf.dsize = strlen(d)+1; + + printf("Storing key:\n"); + print_rec(tdb, key, dbuf, NULL); + + if (tdb_store(tdb, key, dbuf, TDB_REPLACE) == -1) { + terror("store failed"); + } +} + +static void show_tdb(void) +{ + char *k = get_token(1); + TDB_DATA key, dbuf; + + if (!k) { + help(); + return; + } + + key.dptr = k; + key.dsize = strlen(k)+1; + + dbuf = tdb_fetch(tdb, key); + if (!dbuf.dptr) { + /* maybe it is non-NULL terminated key? */ + key.dsize = strlen(k); + dbuf = tdb_fetch(tdb, key); + + if ( !dbuf.dptr ) { + terror("fetch failed"); + return; + } + } + + /* printf("%s : %*.*s\n", k, (int)dbuf.dsize, (int)dbuf.dsize, dbuf.dptr); */ + print_rec(tdb, key, dbuf, NULL); + + free( dbuf.dptr ); + + return; +} + +static void delete_tdb(void) +{ + char *k = get_token(1); + TDB_DATA key; + + if (!k) { + help(); + return; + } + + key.dptr = k; + key.dsize = strlen(k)+1; + + if (tdb_delete(tdb, key) != 0) { + terror("delete failed"); + } +} + +static void move_rec(void) +{ + char *k = get_token(1); + char *file = get_token(0); + TDB_DATA key, dbuf; + TDB_CONTEXT *dst_tdb; + + if (!k) { + help(); + return; + } + + if ( !file ) { + terror("need destination tdb name"); + return; + } + + key.dptr = k; + key.dsize = strlen(k)+1; + + dbuf = tdb_fetch(tdb, key); + if (!dbuf.dptr) { + /* maybe it is non-NULL terminated key? */ + key.dsize = strlen(k); + dbuf = tdb_fetch(tdb, key); + + if ( !dbuf.dptr ) { + terror("fetch failed"); + return; + } + } + + print_rec(tdb, key, dbuf, NULL); + + dst_tdb = tdb_open(file, 0, 0, O_RDWR, 0600); + if ( !dst_tdb ) { + terror("unable to open destination tdb"); + return; + } + + if ( tdb_store( dst_tdb, key, dbuf, TDB_REPLACE ) == -1 ) { + terror("failed to move record"); + } + else + printf("record moved\n"); + + tdb_close( dst_tdb ); + + return; +} + +#if 0 +static int print_conn_key(TDB_DATA key) +{ + printf( "pid =%5d ", ((connections_key*)key.dptr)->pid); + printf( "cnum =%10d ", ((connections_key*)key.dptr)->cnum); + printf( "name =[%s]\n", ((connections_key*)key.dptr)->name); + return 0; +} + +static int print_conn_data(TDB_DATA dbuf) +{ + printf( "pid =%5d ", ((connections_data*)dbuf.dptr)->pid); + printf( "cnum =%10d ", ((connections_data*)dbuf.dptr)->cnum); + printf( "name =[%s]\n", ((connections_data*)dbuf.dptr)->name); + + printf( "uid =%5d ", ((connections_data*)dbuf.dptr)->uid); + printf( "addr =[%s]\n", ((connections_data*)dbuf.dptr)->addr); + printf( "gid =%5d ", ((connections_data*)dbuf.dptr)->gid); + printf( "machine=[%s]\n", ((connections_data*)dbuf.dptr)->machine); + printf( "start = %s\n", ctime(&((connections_data*)dbuf.dptr)->start)); + return 0; +} +#endif + +static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +{ +#if 0 + print_conn_key(key); + print_conn_data(dbuf); + return 0; +#else + printf("\nkey %d bytes\n", key.dsize); + print_asc(key.dptr, key.dsize); + printf("\ndata %d bytes\n", dbuf.dsize); + print_data(dbuf.dptr, dbuf.dsize); + return 0; +#endif +} + +static int print_key(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +{ + print_asc(key.dptr, key.dsize); + printf("\n"); + return 0; +} + +static int total_bytes; + +static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +{ + total_bytes += dbuf.dsize; + return 0; +} + +static void info_tdb(void) +{ + int count; + total_bytes = 0; + if ((count = tdb_traverse(tdb, traverse_fn, NULL) == -1)) + printf("Error = %s\n", tdb_errorstr(tdb)); + else + printf("%d records totalling %d bytes\n", count, total_bytes); +} + +static char *tdb_getline(char *prompt) +{ + static char line[1024]; + char *p; + fputs(prompt, stdout); + line[0] = 0; + p = fgets(line, sizeof(line)-1, stdin); + if (p) p = strchr(p, '\n'); + if (p) *p = 0; + return p?line:NULL; +} + +static int do_delete_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, + void *state) +{ + return tdb_delete(the_tdb, key); +} + +static void first_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey) +{ + TDB_DATA dbuf; + *pkey = tdb_firstkey(the_tdb); + + dbuf = tdb_fetch(the_tdb, *pkey); + if (!dbuf.dptr) terror("fetch failed"); + else { + /* printf("%s : %*.*s\n", k, (int)dbuf.dsize, (int)dbuf.dsize, dbuf.dptr); */ + print_rec(the_tdb, *pkey, dbuf, NULL); + } +} + +static void next_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey) +{ + TDB_DATA dbuf; + *pkey = tdb_nextkey(the_tdb, *pkey); + + dbuf = tdb_fetch(the_tdb, *pkey); + if (!dbuf.dptr) + terror("fetch failed"); + else + /* printf("%s : %*.*s\n", k, (int)dbuf.dsize, (int)dbuf.dsize, dbuf.dptr); */ + print_rec(the_tdb, *pkey, dbuf, NULL); +} + +int main(int argc, char *argv[]) +{ + int bIterate = 0; + char *line; + char *tok; + TDB_DATA iterate_kbuf; + + if (argv[1]) { + static char tmp[1024]; + sprintf(tmp, "open %s", argv[1]); + tok=strtok(tmp," "); + open_tdb(); + } + + while ((line = tdb_getline("tdb> "))) { + + /* Shell command */ + + if (line[0] == '!') { + system(line + 1); + continue; + } + + if ((tok = strtok(line," "))==NULL) { + if (bIterate) + next_record(tdb, &iterate_kbuf); + continue; + } + if (strcmp(tok,"create") == 0) { + bIterate = 0; + create_tdb(); + continue; + } else if (strcmp(tok,"open") == 0) { + open_tdb(); + continue; + } else if ((strcmp(tok, "q") == 0) || + (strcmp(tok, "quit") == 0)) { + break; + } + + /* all the rest require a open database */ + if (!tdb) { + bIterate = 0; + terror("database not open"); + help(); + continue; + } + + if (strcmp(tok,"insert") == 0) { + bIterate = 0; + insert_tdb(); + } else if (strcmp(tok,"store") == 0) { + bIterate = 0; + store_tdb(); + } else if (strcmp(tok,"show") == 0) { + bIterate = 0; + show_tdb(); + } else if (strcmp(tok,"erase") == 0) { + bIterate = 0; + tdb_traverse(tdb, do_delete_fn, NULL); + } else if (strcmp(tok,"delete") == 0) { + bIterate = 0; + delete_tdb(); + } else if (strcmp(tok,"dump") == 0) { + bIterate = 0; + tdb_traverse(tdb, print_rec, NULL); + } else if (strcmp(tok,"move") == 0) { + bIterate = 0; + move_rec(); + } else if (strcmp(tok,"list") == 0) { + tdb_dump_all(tdb); + } else if (strcmp(tok, "free") == 0) { + tdb_printfreelist(tdb); + } else if (strcmp(tok,"info") == 0) { + info_tdb(); + } else if ( (strcmp(tok, "1") == 0) || + (strcmp(tok, "first") == 0)) { + bIterate = 1; + first_record(tdb, &iterate_kbuf); + } else if ((strcmp(tok, "n") == 0) || + (strcmp(tok, "next") == 0)) { + next_record(tdb, &iterate_kbuf); + } else if ((strcmp(tok, "keys") == 0)) { + bIterate = 0; + tdb_traverse(tdb, print_key, NULL); + } else { + help(); + } + } + + if (tdb) tdb_close(tdb); + + return 0; +} diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c new file mode 100644 index 0000000000..3f704e537e --- /dev/null +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -0,0 +1,227 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "tdb.h" + +/* this tests tdb by doing lots of ops from several simultaneous + writers - that stresses the locking code. Build with TDB_DEBUG=1 + for best effect */ + + + +#define REOPEN_PROB 30 +#define DELETE_PROB 8 +#define STORE_PROB 4 +#define APPEND_PROB 6 +#define LOCKSTORE_PROB 0 +#define TRAVERSE_PROB 20 +#define CULL_PROB 100 +#define KEYLEN 3 +#define DATALEN 100 +#define LOCKLEN 20 + +static TDB_CONTEXT *db; + +static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + vfprintf(stdout, format, ap); + va_end(ap); + fflush(stdout); +#if 0 + { + char *ptr; + asprintf(&ptr,"xterm -e gdb /proc/%d/exe %d", getpid(), getpid()); + system(ptr); + free(ptr); + } +#endif +} + +static void fatal(char *why) +{ + perror(why); + exit(1); +} + +static char *randbuf(int len) +{ + char *buf; + int i; + buf = (char *)malloc(len+1); + + for (i=0;i Date: Mon, 24 May 2004 16:39:19 +0000 Subject: r849: move tdb/tools/Makefile to tdb/Makefile.tdb like in ldb also fix the makefile to let it compile the tools fine metze (This used to be commit e3191b54ea583913a9fd21eeb4e57d82e996c847) --- source4/lib/tdb/tools/Makefile | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 source4/lib/tdb/tools/Makefile (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/Makefile b/source4/lib/tdb/tools/Makefile deleted file mode 100644 index 59fbb079bd..0000000000 --- a/source4/lib/tdb/tools/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -# -# Makefile for tdb directory -# - -CFLAGS = -DSTANDALONE -DTDB_DEBUG -g -DHAVE_MMAP=1 -CC = gcc - -PROGS = tdbtest tdbtool tdbtorture -TDB_OBJ = tdb.o spinlock.o - -default: $(PROGS) - -tdbtest: tdbtest.o $(TDB_OBJ) - $(CC) $(CFLAGS) -o tdbtest tdbtest.o $(TDB_OBJ) -lgdbm - -tdbtool: tdbtool.o $(TDB_OBJ) - $(CC) $(CFLAGS) -o tdbtool tdbtool.o $(TDB_OBJ) - -tdbtorture: tdbtorture.o $(TDB_OBJ) - $(CC) $(CFLAGS) -o tdbtorture tdbtorture.o $(TDB_OBJ) - -tdbdump: tdbdump.o $(TDB_OBJ) - $(CC) $(CFLAGS) -o tdbdump tdbdump.o $(TDB_OBJ) - -tdbbackup: tdbbackup.o $(TDB_OBJ) - $(CC) $(CFLAGS) -o tdbbackup tdbbackup.o $(TDB_OBJ) - -clean: - rm -f $(PROGS) *.o *~ *% core test.db test.tdb test.gdbm -- cgit From 45e93c19ef95978f908f5b14962770510634cd3b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 29 May 2004 08:11:46 +0000 Subject: r943: change samba4 to use 'uint8_t' instead of 'unsigned char' metze (This used to be commit b5378803fdcb3b3afe7c2932a38828e83470f61a) --- source4/lib/tdb/tools/tdbdump.c | 2 +- source4/lib/tdb/tools/tdbtool.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbdump.c b/source4/lib/tdb/tools/tdbdump.c index 9c1dc2761b..1a7128c473 100644 --- a/source4/lib/tdb/tools/tdbdump.c +++ b/source4/lib/tdb/tools/tdbdump.c @@ -35,7 +35,7 @@ static void print_data(TDB_DATA d) { - unsigned char *p = d.dptr; + uint8_t *p = d.dptr; int len = d.dsize; while (len--) { if (isprint(*p) && !strchr("\"\\", *p)) { diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index 92009dcef4..65bbedf709 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -63,7 +63,7 @@ static TDB_CONTEXT *tdb; static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); -static void print_asc(unsigned char *buf,int len) +static void print_asc(uint8_t *buf,int len) { int i; @@ -77,7 +77,7 @@ static void print_asc(unsigned char *buf,int len) printf("%c",isprint(buf[i])?buf[i]:'.'); } -static void print_data(unsigned char *buf,int len) +static void print_data(uint8_t *buf,int len) { int i=0; if (len<=0) return; -- cgit From 4309727424a0a27bbf5372789bc8644b96a28ba9 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 3 Jun 2004 15:59:26 +0000 Subject: r990: fix tdb standalone build metze (This used to be commit 4c1c9f59ccea8b6cd7edf3bad8acb9cd8c772670) --- source4/lib/tdb/tools/tdbtool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index 65bbedf709..92009dcef4 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -63,7 +63,7 @@ static TDB_CONTEXT *tdb; static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); -static void print_asc(uint8_t *buf,int len) +static void print_asc(unsigned char *buf,int len) { int i; @@ -77,7 +77,7 @@ static void print_asc(uint8_t *buf,int len) printf("%c",isprint(buf[i])?buf[i]:'.'); } -static void print_data(uint8_t *buf,int len) +static void print_data(unsigned char *buf,int len) { int i=0; if (len<=0) return; -- cgit From 826a515ec063cf7b986ddfcfd47f2f7f09a12be5 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 27 Aug 2004 15:52:54 +0000 Subject: r2088: add tdbtorture tdbdump and tdbtest to the build NOTE: tdbbackup and tdbtool seems to be broken... NOTE: I also added SMB_EXT_LIB(GDBM,...) because that is needed by tdbtest metze (This used to be commit e66630662d4203ccecbb20962e83dbf50a2c056f) --- source4/lib/tdb/tools/tdbdump.c | 9 ++++++++- source4/lib/tdb/tools/tdbtest.c | 35 +++++++++++++++++++++++------------ source4/lib/tdb/tools/tdbtorture.c | 16 ++++++++++++---- 3 files changed, 43 insertions(+), 17 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbdump.c b/source4/lib/tdb/tools/tdbdump.c index 1a7128c473..0e179f8c3e 100644 --- a/source4/lib/tdb/tools/tdbdump.c +++ b/source4/lib/tdb/tools/tdbdump.c @@ -18,6 +18,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef STANDALONE #include #include #include @@ -33,9 +34,15 @@ #include #include "tdb.h" +#else + +#include "includes.h" + +#endif + static void print_data(TDB_DATA d) { - uint8_t *p = d.dptr; + unsigned char *p = d.dptr; int len = d.dsize; while (len--) { if (isprint(*p) && !strchr("\"\\", *p)) { diff --git a/source4/lib/tdb/tools/tdbtest.c b/source4/lib/tdb/tools/tdbtest.c index 89295a3291..9a210f8a61 100644 --- a/source4/lib/tdb/tools/tdbtest.c +++ b/source4/lib/tdb/tools/tdbtest.c @@ -1,3 +1,6 @@ +/* a test program for tdb - the trivial database */ + +#ifdef STANDALONE #include #include #include @@ -10,10 +13,13 @@ #include #include #include "tdb.h" -#include +#else -/* a test program for tdb - the trivial database */ +#include "includes.h" +#endif + +#include #define DELETE_PROB 7 @@ -24,24 +30,27 @@ static GDBM_FILE gdbm; struct timeval tp1,tp2; -static void start_timer(void) +static void _start_timer(void) { gettimeofday(&tp1,NULL); } -static double end_timer(void) +static double _end_timer(void) { gettimeofday(&tp2,NULL); return((tp2.tv_sec - tp1.tv_sec) + (tp2.tv_usec - tp1.tv_usec)*1.0e-6); } -static void fatal(char *why) +static void fatal(const char *why) { perror(why); exit(1); } +#ifdef PRINTF_ATTRIBUTE +static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); +#endif static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...) { va_list ap; @@ -192,14 +201,15 @@ static void merge_test(void) { int i; char keys[5][2]; + char tdata[] = "test"; TDB_DATA key, data; for (i = 0; i < 5; i++) { - sprintf(keys[i], "%d", i); + snprintf(keys[i],2, "%d", i); key.dptr = keys[i]; key.dsize = 2; - data.dptr = "test"; + data.dptr = tdata; data.dsize = 4; if (tdb_store(db, key, data, TDB_REPLACE) != 0) { @@ -223,12 +233,13 @@ int main(int argc, char *argv[]) { int i, seed=0; int loops = 10000; + char test_gdbm[] = "test.gdbm"; unlink("test.gdbm"); db = tdb_open("test.tdb", 0, TDB_CLEAR_IF_FIRST, O_RDWR | O_CREAT | O_TRUNC, 0600); - gdbm = gdbm_open("test.gdbm", 512, GDBM_WRITER|GDBM_NEWDB|GDBM_FAST, + gdbm = gdbm_open(test_gdbm, 512, GDBM_WRITER|GDBM_NEWDB|GDBM_FAST, 0600, NULL); if (!db || !gdbm) { @@ -239,17 +250,17 @@ int main(int argc, char *argv[]) #if 1 srand(seed); - start_timer(); + _start_timer(); for (i=0;i #include #include @@ -13,11 +18,11 @@ #include #include "tdb.h" -/* this tests tdb by doing lots of ops from several simultaneous - writers - that stresses the locking code. Build with TDB_DEBUG=1 - for best effect */ +#else +#include "includes.h" +#endif #define REOPEN_PROB 30 #define DELETE_PROB 8 @@ -32,6 +37,9 @@ static TDB_CONTEXT *db; +#ifdef PRINTF_ATTRIBUTE +static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); +#endif static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...) { va_list ap; @@ -50,7 +58,7 @@ static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...) #endif } -static void fatal(char *why) +static void fatal(const char *why) { perror(why); exit(1); -- cgit From 2812998ae99ed96f5b9a7edff471eecf7359edac Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 27 Aug 2004 18:00:55 +0000 Subject: r2092: fix the build(don't catch main() by make proto) metze (This used to be commit ecdb0b442659e80ca91d5ec5b505224c68a97c5a) --- source4/lib/tdb/tools/tdbtest.c | 2 +- source4/lib/tdb/tools/tdbtorture.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtest.c b/source4/lib/tdb/tools/tdbtest.c index 9a210f8a61..6c20a5dc77 100644 --- a/source4/lib/tdb/tools/tdbtest.c +++ b/source4/lib/tdb/tools/tdbtest.c @@ -229,7 +229,7 @@ static void merge_test(void) tdb_delete(db, key); } -int main(int argc, char *argv[]) + int main(int argc, const char *argv[]) { int i, seed=0; int loops = 10000; diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index d7c0812800..005a2713af 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -185,7 +185,7 @@ static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, #define NLOOPS 200000 #endif -int main(int argc, char *argv[]) + int main(int argc, const char *argv[]) { int i, seed=0; int loops = NLOOPS; -- cgit From 48ce437be2e3da6d67844dfed3d574986c55a67e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Nov 2004 05:22:44 +0000 Subject: r3421: got rid of some unused code (This used to be commit 0333f417a86a54a328ca9bd908076f9fe8405dc7) --- source4/lib/tdb/tools/tdbtool.c | 30 ------------------------------ 1 file changed, 30 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index 92009dcef4..50486122bc 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -343,43 +343,13 @@ static void move_rec(void) return; } -#if 0 -static int print_conn_key(TDB_DATA key) -{ - printf( "pid =%5d ", ((connections_key*)key.dptr)->pid); - printf( "cnum =%10d ", ((connections_key*)key.dptr)->cnum); - printf( "name =[%s]\n", ((connections_key*)key.dptr)->name); - return 0; -} - -static int print_conn_data(TDB_DATA dbuf) -{ - printf( "pid =%5d ", ((connections_data*)dbuf.dptr)->pid); - printf( "cnum =%10d ", ((connections_data*)dbuf.dptr)->cnum); - printf( "name =[%s]\n", ((connections_data*)dbuf.dptr)->name); - - printf( "uid =%5d ", ((connections_data*)dbuf.dptr)->uid); - printf( "addr =[%s]\n", ((connections_data*)dbuf.dptr)->addr); - printf( "gid =%5d ", ((connections_data*)dbuf.dptr)->gid); - printf( "machine=[%s]\n", ((connections_data*)dbuf.dptr)->machine); - printf( "start = %s\n", ctime(&((connections_data*)dbuf.dptr)->start)); - return 0; -} -#endif - static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { -#if 0 - print_conn_key(key); - print_conn_data(dbuf); - return 0; -#else printf("\nkey %d bytes\n", key.dsize); print_asc(key.dptr, key.dsize); printf("\ndata %d bytes\n", dbuf.dsize); print_data(dbuf.dptr, dbuf.dsize); return 0; -#endif } static int print_key(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) -- cgit From f20f1f994ac375ab96cc8a38075b99aa20041b3f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Nov 2004 23:37:12 +0000 Subject: r3445: made the gtk tooks use minimal includes. This approximately halves the total include lines in compiling C files in Samba (the .gch file is now 5M instead of 12M) This also gets rid of the silly gtk compile warning for non-gtk code (This used to be commit 8ebd20cf551c8c1fad98ec723d91873fa202b85a) --- source4/lib/tdb/tools/tdbtorture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 005a2713af..95eb71281c 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -217,7 +217,7 @@ static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, if (getpid() == pids[0]) { for (i=0;i Date: Tue, 2 Nov 2004 00:24:21 +0000 Subject: r3447: more include/system/XXX.h include files (This used to be commit 264ce9181089922547e8f6f67116f2d7277a5105) --- source4/lib/tdb/tools/tdbtorture.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 95eb71281c..6471aec3ad 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -21,6 +21,7 @@ #else #include "includes.h" +#include "system/time.h" #endif -- cgit From 26c6b4c70bd85d8030a96651f2a255a4d48fcda1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 Nov 2004 01:42:45 +0000 Subject: r3449: more include file reduction the ldb part isn't ideal, I will have to think of a better solution (This used to be commit 6b1f86aea8427a8e957b1aeb0ec2f507297f07cb) --- source4/lib/tdb/tools/tdbdump.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbdump.c b/source4/lib/tdb/tools/tdbdump.c index 0e179f8c3e..822f65e594 100644 --- a/source4/lib/tdb/tools/tdbdump.c +++ b/source4/lib/tdb/tools/tdbdump.c @@ -37,6 +37,7 @@ #else #include "includes.h" +#include "system/iconv.h" #endif -- cgit From 2df2d1b67f9bf2907f452688b2c54b73052cfb49 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 Nov 2004 04:51:57 +0000 Subject: r3461: another place where "open" was used as a structure element (This used to be commit 1087ea830e7aead86d54a1836512e88554afc919) --- source4/lib/tdb/tools/tdbtorture.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 6471aec3ad..e90a967138 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -22,6 +22,7 @@ #include "includes.h" #include "system/time.h" +#include "system/wait.h" #endif -- cgit From c199c2af1fa686962bb313222a0a0a29625ec450 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 25 Nov 2004 19:27:17 +0000 Subject: r3968: fix compiler warnings metze (This used to be commit 6440476f7f2fd5776ec4a21240e7482603000d19) --- source4/lib/tdb/tools/tdbdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbdump.c b/source4/lib/tdb/tools/tdbdump.c index 822f65e594..dbb647cbbf 100644 --- a/source4/lib/tdb/tools/tdbdump.c +++ b/source4/lib/tdb/tools/tdbdump.c @@ -43,7 +43,7 @@ static void print_data(TDB_DATA d) { - unsigned char *p = d.dptr; + unsigned char *p = (unsigned char *)d.dptr; int len = d.dsize; while (len--) { if (isprint(*p) && !strchr("\"\\", *p)) { -- cgit From f9e507980e6a3340ae135e81d3106a836116d6b0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 1 Jan 2005 05:06:22 +0000 Subject: r4466: rather than defining "STANDALONE" for building tdb, ldb and talloc outside the tree, instead defined _SAMBA_BUILD_ inside the Samba build. This makes it easier to pull code out of Samba for external use. (This used to be commit 09e98c8745cca7ccb1ad7134c0c09b8e4c0f4f06) --- source4/lib/tdb/tools/tdbbackup.c | 2 +- source4/lib/tdb/tools/tdbdump.c | 2 +- source4/lib/tdb/tools/tdbtest.c | 2 +- source4/lib/tdb/tools/tdbtorture.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbbackup.c b/source4/lib/tdb/tools/tdbbackup.c index 1a0e1c1588..4cb6a8cfdd 100644 --- a/source4/lib/tdb/tools/tdbbackup.c +++ b/source4/lib/tdb/tools/tdbbackup.c @@ -41,7 +41,7 @@ */ -#ifdef STANDALONE +#ifndef _SAMBA_BUILD_ #if HAVE_CONFIG_H #include #endif diff --git a/source4/lib/tdb/tools/tdbdump.c b/source4/lib/tdb/tools/tdbdump.c index dbb647cbbf..dd018af6f5 100644 --- a/source4/lib/tdb/tools/tdbdump.c +++ b/source4/lib/tdb/tools/tdbdump.c @@ -18,7 +18,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifdef STANDALONE +#ifndef _SAMBA_BUILD_ #include #include #include diff --git a/source4/lib/tdb/tools/tdbtest.c b/source4/lib/tdb/tools/tdbtest.c index 6c20a5dc77..f4854b5931 100644 --- a/source4/lib/tdb/tools/tdbtest.c +++ b/source4/lib/tdb/tools/tdbtest.c @@ -1,6 +1,6 @@ /* a test program for tdb - the trivial database */ -#ifdef STANDALONE +#ifndef _SAMBA_BUILD_ #include #include #include diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index e90a967138..890e25af50 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -2,7 +2,7 @@ writers - that stresses the locking code. Build with TDB_DEBUG=1 for best effect */ -#ifdef STANDALONE +#ifndef _SAMBA_BUILD_ #include #include #include -- cgit From 70067ef957d5ea10358ecec0ff7902e873a97521 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 1 Jan 2005 05:08:41 +0000 Subject: r4467: - tdb standalone build doesn't need -DSTANDALONE any more - fixed standalone build (This used to be commit ade0b71e4194f99d807d26276592bc041d46df7b) --- source4/lib/tdb/tools/tdbtorture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 890e25af50..bb2313369b 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -219,7 +219,7 @@ static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, if (getpid() == pids[0]) { for (i=0;i Date: Thu, 10 Feb 2005 03:48:43 +0000 Subject: r5296: - only include the tdb headers where they are needed - removed the u32 hack in events.c as I think this was only needed as tdb.h defines u32. Metze, can you check that this hack is indeed no longer needed on your suse system? (This used to be commit 6f79432fe656164d4770dbce114a30dda5e7bf9a) --- source4/lib/tdb/tools/tdbdump.c | 1 + source4/lib/tdb/tools/tdbtest.c | 1 + source4/lib/tdb/tools/tdbtorture.c | 1 + 3 files changed, 3 insertions(+) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbdump.c b/source4/lib/tdb/tools/tdbdump.c index dd018af6f5..8aa573ca9b 100644 --- a/source4/lib/tdb/tools/tdbdump.c +++ b/source4/lib/tdb/tools/tdbdump.c @@ -37,6 +37,7 @@ #else #include "includes.h" +#include "lib/tdb/include/tdb.h" #include "system/iconv.h" #endif diff --git a/source4/lib/tdb/tools/tdbtest.c b/source4/lib/tdb/tools/tdbtest.c index f4854b5931..0a2185d6b8 100644 --- a/source4/lib/tdb/tools/tdbtest.c +++ b/source4/lib/tdb/tools/tdbtest.c @@ -16,6 +16,7 @@ #else #include "includes.h" +#include "lib/tdb/include/tdb.h" #endif diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index bb2313369b..63b3b0d381 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -21,6 +21,7 @@ #else #include "includes.h" +#include "lib/tdb/include/tdb.h" #include "system/time.h" #include "system/wait.h" -- cgit From e82aad1ce39a6b7a2e51b9e2cb494d74ec70e158 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Feb 2005 05:09:35 +0000 Subject: r5298: - got rid of pstring.h from includes.h. This at least makes it a bit less likely that anyone will use pstring for new code - got rid of winbind_client.h from includes.h. This one triggered a huge change, as winbind_client.h was including system/filesys.h and defining the old uint32 and uint16 types, as well as its own pstring and fstring. (This used to be commit 9db6c79e902ec538108d6b7d3324039aabe1704f) --- source4/lib/tdb/tools/tdbdump.c | 1 + source4/lib/tdb/tools/tdbtorture.c | 1 + 2 files changed, 2 insertions(+) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbdump.c b/source4/lib/tdb/tools/tdbdump.c index 8aa573ca9b..774093dbc0 100644 --- a/source4/lib/tdb/tools/tdbdump.c +++ b/source4/lib/tdb/tools/tdbdump.c @@ -39,6 +39,7 @@ #include "includes.h" #include "lib/tdb/include/tdb.h" #include "system/iconv.h" +#include "system/filesys.h" #endif diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 63b3b0d381..7e8e77952c 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -24,6 +24,7 @@ #include "lib/tdb/include/tdb.h" #include "system/time.h" #include "system/wait.h" +#include "system/filesys.h" #endif -- cgit From 8674eaa5cc9b1ddeb65f05527a5b539f15e4afcb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Feb 2005 05:22:53 +0000 Subject: r5300: more uint32 and system/filesys.h build fixes when developer mode is enabled (This used to be commit 93931b1a741a3722c311ada80c4c9d3d670f91b2) --- source4/lib/tdb/tools/tdbtest.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtest.c b/source4/lib/tdb/tools/tdbtest.c index 0a2185d6b8..e55d08f840 100644 --- a/source4/lib/tdb/tools/tdbtest.c +++ b/source4/lib/tdb/tools/tdbtest.c @@ -16,6 +16,7 @@ #else #include "includes.h" +#include "system/filesys.h" #include "lib/tdb/include/tdb.h" #endif -- cgit From c8ca613e935b44488435a269957a68b48d2af90f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 11 Feb 2005 10:15:56 +0000 Subject: r5330: Remove #include from includes.h. Add #include "system/time.h" back (it was removed in some of these places because the definitions were provided by on tridge's platform.) Andrew Bartlett (This used to be commit 34b1da730304bed7fee5bae7cbde7fbccecb6af5) --- source4/lib/tdb/tools/tdbtest.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtest.c b/source4/lib/tdb/tools/tdbtest.c index e55d08f840..4f7f7faafc 100644 --- a/source4/lib/tdb/tools/tdbtest.c +++ b/source4/lib/tdb/tools/tdbtest.c @@ -17,6 +17,7 @@ #include "includes.h" #include "system/filesys.h" +#include "system/time.h" #include "lib/tdb/include/tdb.h" #endif -- cgit From 606beece8ed995f457b012a8010aa0e8ed1f5b07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 14 Jul 2005 04:27:55 +0000 Subject: r8448: - added a test target for tdb - reduced the torture size so it doesn't kill the build farm hosts (This used to be commit 7a88a9f06cbe5c125edad0da7908b94bcedfe4fc) --- source4/lib/tdb/tools/tdbtorture.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 7e8e77952c..687d304b70 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -182,11 +182,11 @@ static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, } #ifndef NPROC -#define NPROC 6 +#define NPROC 2 #endif #ifndef NLOOPS -#define NLOOPS 200000 +#define NLOOPS 5000 #endif int main(int argc, const char *argv[]) @@ -197,6 +197,8 @@ static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, pids[0] = getpid(); + unlink("torture.tdb"); + for (i=0;i Date: Fri, 16 Sep 2005 03:52:42 +0000 Subject: r10253: a fairly large tdb cleanup and re-organise. Nearly all of this change just involves splitting up the core tdb.c code into separate files on logical boundaries, but there are some minor functional changes as well: - move the 'struct tdb_context' into tdb_private.h, hiding it from users. This was done to allow the structure to change without breaking code that uses tdb. - added accessor functions tdb_fd(), tdb_name(), and tdb_log_fn() to access the elements of struct tdb_context that were used by external code but are no longer visible - simplied tdb_append() to use tdb_fetch()/tdb_store(), which is just as good due to the way tdb locks work - changed some of the types (such as tdb_off to tdb_off_t) to make syntax highlighting work better - removed the old optional spinlock code. It was a bad idea. - fixed a bug in tdb_reopen_all() that caused tdbtorture to sometimes fail or report nasty looking errors. This is the only real bug fixed in this commit. Jeremy/Jerry, you might like to pickup this change for Samba3, as that could definately affect smbd in Samba3. The aim of all of these changes is to make the tdb transactions/journaling code I am working on easier to write. I started to write it on top of the existing tdb.c code and it got very messy. Splitting up the code makes it much easier to follow. There are more cleanups we could do in tdb, such as using uint32_t instead of u32 (suggested by metze). I'll leave those for another day. (This used to be commit 4673cdd0d261614e707b72a7a348bb0e7dbb2482) --- source4/lib/tdb/tools/tdbdump.c | 4 ++-- source4/lib/tdb/tools/tdbtest.c | 8 ++++---- source4/lib/tdb/tools/tdbtool.c | 32 ++++++++++++++++---------------- source4/lib/tdb/tools/tdbtorture.c | 16 ++++++++-------- 4 files changed, 30 insertions(+), 30 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbdump.c b/source4/lib/tdb/tools/tdbdump.c index 774093dbc0..9122551a0a 100644 --- a/source4/lib/tdb/tools/tdbdump.c +++ b/source4/lib/tdb/tools/tdbdump.c @@ -57,7 +57,7 @@ static void print_data(TDB_DATA d) } } -static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +static int traverse_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { printf("{\n"); printf("key = \""); @@ -72,7 +72,7 @@ static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *stat static int dump_tdb(const char *fname) { - TDB_CONTEXT *tdb; + struct tdb_context *tdb; tdb = tdb_open(fname, 0, 0, O_RDONLY, 0); if (!tdb) { diff --git a/source4/lib/tdb/tools/tdbtest.c b/source4/lib/tdb/tools/tdbtest.c index 4f7f7faafc..edf12ecfdd 100644 --- a/source4/lib/tdb/tools/tdbtest.c +++ b/source4/lib/tdb/tools/tdbtest.c @@ -28,7 +28,7 @@ #define DELETE_PROB 7 #define STORE_PROB 5 -static TDB_CONTEXT *db; +static struct tdb_context *db; static GDBM_FILE gdbm; struct timeval tp1,tp2; @@ -52,9 +52,9 @@ static void fatal(const char *why) } #ifdef PRINTF_ATTRIBUTE -static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); +static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); #endif -static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...) +static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) { va_list ap; @@ -191,7 +191,7 @@ static void addrec_gdbm(void) free(d); } -static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +static int traverse_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { #if 0 printf("[%s] [%s]\n", key.dptr, dbuf.dptr); diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index 50486122bc..5a8c871699 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -59,9 +59,9 @@ typedef struct connections_data { time_t start; } connections_data; -static TDB_CONTEXT *tdb; +static struct tdb_context *tdb; -static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); +static int print_rec(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); static void print_asc(unsigned char *buf,int len) { @@ -207,9 +207,9 @@ static void insert_tdb(void) return; } - key.dptr = k; + key.dptr = (unsigned char *)k; key.dsize = strlen(k)+1; - dbuf.dptr = d; + dbuf.dptr = (unsigned char *)d; dbuf.dsize = strlen(d)+1; if (tdb_store(tdb, key, dbuf, TDB_INSERT) == -1) { @@ -228,9 +228,9 @@ static void store_tdb(void) return; } - key.dptr = k; + key.dptr = (unsigned char *)k; key.dsize = strlen(k)+1; - dbuf.dptr = d; + dbuf.dptr = (unsigned char *)d; dbuf.dsize = strlen(d)+1; printf("Storing key:\n"); @@ -251,7 +251,7 @@ static void show_tdb(void) return; } - key.dptr = k; + key.dptr = (unsigned char *)k; key.dsize = strlen(k)+1; dbuf = tdb_fetch(tdb, key); @@ -284,7 +284,7 @@ static void delete_tdb(void) return; } - key.dptr = k; + key.dptr = (unsigned char *)k; key.dsize = strlen(k)+1; if (tdb_delete(tdb, key) != 0) { @@ -297,7 +297,7 @@ static void move_rec(void) char *k = get_token(1); char *file = get_token(0); TDB_DATA key, dbuf; - TDB_CONTEXT *dst_tdb; + struct tdb_context *dst_tdb; if (!k) { help(); @@ -309,7 +309,7 @@ static void move_rec(void) return; } - key.dptr = k; + key.dptr = (unsigned char *)k; key.dsize = strlen(k)+1; dbuf = tdb_fetch(tdb, key); @@ -343,7 +343,7 @@ static void move_rec(void) return; } -static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +static int print_rec(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { printf("\nkey %d bytes\n", key.dsize); print_asc(key.dptr, key.dsize); @@ -352,7 +352,7 @@ static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *st return 0; } -static int print_key(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +static int print_key(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { print_asc(key.dptr, key.dsize); printf("\n"); @@ -361,7 +361,7 @@ static int print_key(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *st static int total_bytes; -static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +static int traverse_fn(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { total_bytes += dbuf.dsize; return 0; @@ -389,13 +389,13 @@ static char *tdb_getline(char *prompt) return p?line:NULL; } -static int do_delete_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, +static int do_delete_fn(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { return tdb_delete(the_tdb, key); } -static void first_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey) +static void first_record(struct tdb_context *the_tdb, TDB_DATA *pkey) { TDB_DATA dbuf; *pkey = tdb_firstkey(the_tdb); @@ -408,7 +408,7 @@ static void first_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey) } } -static void next_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey) +static void next_record(struct tdb_context *the_tdb, TDB_DATA *pkey) { TDB_DATA dbuf; *pkey = tdb_nextkey(the_tdb, *pkey); diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 687d304b70..0cf82fa5a5 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -39,12 +39,12 @@ #define DATALEN 100 #define LOCKLEN 20 -static TDB_CONTEXT *db; +static struct tdb_context *db; #ifdef PRINTF_ATTRIBUTE -static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); +static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); #endif -static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...) +static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) { va_list ap; @@ -81,7 +81,7 @@ static char *randbuf(int len) return buf; } -static int cull_traverse(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, +static int cull_traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { if (random() % CULL_PROB == 0) { @@ -104,13 +104,13 @@ static void addrec_db(void) d = randbuf(dlen); s = randbuf(slen); - key.dptr = k; + key.dptr = (unsigned char *)k; key.dsize = klen+1; - data.dptr = d; + data.dptr = (unsigned char *)d; data.dsize = dlen+1; - lockkey.dptr = s; + lockkey.dptr = (unsigned char *)s; lockkey.dsize = slen+1; #if REOPEN_PROB @@ -174,7 +174,7 @@ next: free(s); } -static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, +static int traverse_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { tdb_delete(tdb, key); -- cgit From 069e498da2a03bd253a2fcf2b7ff13f266ab63b4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 19 Sep 2005 22:01:57 +0000 Subject: r10330: Add SConscript to more subsystems. Some of the tdb tools build now. Start on custom Samba scons tools (for handling proto generation, pidl, etc) (This used to be commit 4bffe4435944fffa3f9680b5a2fe63f2bdd98003) --- source4/lib/tdb/tools/tdbbackup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbbackup.c b/source4/lib/tdb/tools/tdbbackup.c index 4cb6a8cfdd..872ca99f0d 100644 --- a/source4/lib/tdb/tools/tdbbackup.c +++ b/source4/lib/tdb/tools/tdbbackup.c @@ -63,11 +63,11 @@ #else #include "includes.h" +#include "system/filesys.h" #endif #include "tdb.h" -#include "tdbback.h" /* see if one file is newer than another -- cgit From ede8415d61b6791114c65de1c283a4e8c11f1585 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 Sep 2005 03:56:41 +0000 Subject: r10405: added transactions into tdb, and hook them into ldb. See my samba-technical posting for more details on the transactions design. This also adds a number of command line arguments to tdbtorture, making it more flexible, and fixes some lock deadlock conditions in the tdbtorture code. (This used to be commit 06bd8abba942ec9f1e23f5c5d546cbb71ca3a701) --- source4/lib/tdb/tools/tdbtool.c | 26 ++++++-- source4/lib/tdb/tools/tdbtorture.c | 129 +++++++++++++++++++++++++++---------- 2 files changed, 114 insertions(+), 41 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index 5a8c871699..0941a73118 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "tdb.h" /* a tdb tool for manipulating a tdb database */ @@ -77,6 +78,19 @@ static void print_asc(unsigned char *buf,int len) printf("%c",isprint(buf[i])?buf[i]:'.'); } +#ifdef PRINTF_ATTRIBUTE +static void tdb_log(struct tdb_context *t, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); +#endif +static void tdb_log(struct tdb_context *t, int level, const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + vfprintf(stdout, format, ap); + va_end(ap); + fflush(stdout); +} + static void print_data(unsigned char *buf,int len) { int i=0; @@ -131,7 +145,7 @@ static void help(void) "\n"); } -static void terror(char *why) +static void terror(const char *why) { printf("%s\n", why); } @@ -175,8 +189,8 @@ static void create_tdb(void) return; } if (tdb) tdb_close(tdb); - tdb = tdb_open(tok, 0, TDB_CLEAR_IF_FIRST, - O_RDWR | O_CREAT | O_TRUNC, 0600); + tdb = tdb_open_ex(tok, 0, TDB_CLEAR_IF_FIRST, + O_RDWR | O_CREAT | O_TRUNC, 0600, tdb_log, NULL); if (!tdb) { printf("Could not create %s: %s\n", tok, strerror(errno)); } @@ -190,7 +204,7 @@ static void open_tdb(void) return; } if (tdb) tdb_close(tdb); - tdb = tdb_open(tok, 0, 0, O_RDWR, 0600); + tdb = tdb_open_ex(tok, 0, 0, O_RDWR, 0600, tdb_log, NULL); if (!tdb) { printf("Could not open %s: %s\n", tok, strerror(errno)); } @@ -326,7 +340,7 @@ static void move_rec(void) print_rec(tdb, key, dbuf, NULL); - dst_tdb = tdb_open(file, 0, 0, O_RDWR, 0600); + dst_tdb = tdb_open_ex(file, 0, 0, O_RDWR, 0600, tdb_log, NULL); if ( !dst_tdb ) { terror("unable to open destination tdb"); return; @@ -377,7 +391,7 @@ static void info_tdb(void) printf("%d records totalling %d bytes\n", count, total_bytes); } -static char *tdb_getline(char *prompt) +static char *tdb_getline(const char *prompt) { static char line[1024]; char *p; diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 0cf82fa5a5..b0a2e7484f 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -1,6 +1,8 @@ /* this tests tdb by doing lots of ops from several simultaneous - writers - that stresses the locking code. Build with TDB_DEBUG=1 - for best effect */ + writers - that stresses the locking code. +*/ + +#define _GNU_SOURCE #ifndef _SAMBA_BUILD_ #include @@ -28,11 +30,14 @@ #endif +#include + #define REOPEN_PROB 30 #define DELETE_PROB 8 #define STORE_PROB 4 #define APPEND_PROB 6 -#define LOCKSTORE_PROB 0 +#define TRANSACTION_PROB 10 +#define LOCKSTORE_PROB 5 #define TRAVERSE_PROB 20 #define CULL_PROB 100 #define KEYLEN 3 @@ -40,6 +45,7 @@ #define LOCKLEN 20 static struct tdb_context *db; +static int in_transaction; #ifdef PRINTF_ATTRIBUTE static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); @@ -84,25 +90,25 @@ static char *randbuf(int len) static int cull_traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { +#if CULL_PROB if (random() % CULL_PROB == 0) { tdb_delete(tdb, key); } +#endif return 0; } static void addrec_db(void) { - int klen, dlen, slen; - char *k, *d, *s; - TDB_DATA key, data, lockkey; + int klen, dlen; + char *k, *d; + TDB_DATA key, data; klen = 1 + (rand() % KEYLEN); dlen = 1 + (rand() % DATALEN); - slen = 1 + (rand() % LOCKLEN); k = randbuf(klen); d = randbuf(dlen); - s = randbuf(slen); key.dptr = (unsigned char *)k; key.dsize = klen+1; @@ -110,11 +116,32 @@ static void addrec_db(void) data.dptr = (unsigned char *)d; data.dsize = dlen+1; - lockkey.dptr = (unsigned char *)s; - lockkey.dsize = slen+1; +#if TRANSACTION_PROB + if (in_transaction == 0 && random() % TRANSACTION_PROB == 0) { + if (tdb_transaction_start(db) != 0) { + fatal("tdb_transaction_start failed"); + } + in_transaction++; + goto next; + } + if (in_transaction && random() % TRANSACTION_PROB == 0) { + if (tdb_transaction_commit(db) != 0) { + fatal("tdb_transaction_commit failed"); + } + in_transaction--; + goto next; + } + if (in_transaction && random() % TRANSACTION_PROB == 0) { + if (tdb_transaction_cancel(db) != 0) { + fatal("tdb_transaction_cancel failed"); + } + in_transaction--; + goto next; + } +#endif #if REOPEN_PROB - if (random() % REOPEN_PROB == 0) { + if (in_transaction == 0 && random() % REOPEN_PROB == 0) { tdb_reopen_all(); goto next; } @@ -147,13 +174,13 @@ static void addrec_db(void) #if LOCKSTORE_PROB if (random() % LOCKSTORE_PROB == 0) { - tdb_chainlock(db, lockkey); + tdb_chainlock(db, key); data = tdb_fetch(db, key); if (tdb_store(db, key, data, TDB_REPLACE) != 0) { fatal("tdb_store failed"); } if (data.dptr) free(data.dptr); - tdb_chainunlock(db, lockkey); + tdb_chainunlock(db, key); goto next; } #endif @@ -171,7 +198,6 @@ static void addrec_db(void) next: free(k); free(d); - free(s); } static int traverse_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, @@ -181,38 +207,71 @@ static int traverse_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, return 0; } -#ifndef NPROC -#define NPROC 2 -#endif - -#ifndef NLOOPS -#define NLOOPS 5000 -#endif - - int main(int argc, const char *argv[]) +static void usage(void) { - int i, seed=0; - int loops = NLOOPS; - pid_t pids[NPROC]; + printf("Usage: tdbtorture [-n NUM_PROCS] [-l NUM_LOOPS] [-s SEED] [-H HASH_SIZE]\n"); + exit(0); +} - pids[0] = getpid(); + int main(int argc, char * const *argv) +{ + int i, seed = -1; + int num_procs = 2; + int num_loops = 5000; + int hash_size = 2; + int c; + extern char *optarg; + pid_t *pids; + + while ((c = getopt(argc, argv, "n:l:s:H:h")) != -1) { + switch (c) { + case 'n': + num_procs = strtol(optarg, NULL, 0); + break; + case 'l': + num_loops = strtol(optarg, NULL, 0); + break; + case 'H': + hash_size = strtol(optarg, NULL, 0); + break; + case 's': + seed = strtol(optarg, NULL, 0); + break; + default: + usage(); + } + } unlink("torture.tdb"); - for (i=0;i Date: Thu, 22 Sep 2005 13:12:46 +0000 Subject: r10421: following on discussions with simo, I have worked out a way of allowing searches to proceed while another process is in a transaction, then only upgrading the transaction lock to a write lock on commit. The solution is: - split tdb_traverse() into two calls, called tdb_traverse() and tdb_traverse_read(). The _read() version only gets read locks, and will fail any write operations made in the callback from the traverse. - the normal tdb_traverse() call allows for read or write operations in the callback, but gets the transaction lock, preventing transastions from starting inside the traverse In addition we enforce the following rule that you may not start a transaction within a traverse callback, although you can start a traverse within a transaction With these rules in place I believe all the deadlock possibilities are removed, and we can now allow for searches to happen in parallel with transactions (This used to be commit 7dd31288a701d772e45b1960ac4ce4cc1be782ed) --- source4/lib/tdb/tools/tdbtorture.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index b0a2e7484f..c0076a92d4 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -39,6 +39,7 @@ #define TRANSACTION_PROB 10 #define LOCKSTORE_PROB 5 #define TRAVERSE_PROB 20 +#define TRAVERSE_READ_PROB 20 #define CULL_PROB 100 #define KEYLEN 3 #define DATALEN 100 @@ -192,6 +193,13 @@ static void addrec_db(void) } #endif +#if TRAVERSE_READ_PROB + if (random() % TRAVERSE_READ_PROB == 0) { + tdb_traverse_read(db, NULL, NULL); + goto next; + } +#endif + data = tdb_fetch(db, key); if (data.dptr) free(data.dptr); @@ -273,7 +281,7 @@ static void usage(void) addrec_db(); } - tdb_traverse(db, NULL, NULL); + tdb_traverse_read(db, NULL, NULL); tdb_traverse(db, traverse_fn, NULL); tdb_traverse(db, traverse_fn, NULL); -- cgit From 036b27c8e4f8bdd61049c5f3b78573937badbdd6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 24 Sep 2005 02:31:43 +0000 Subject: r10459: fixed some portability problems (This used to be commit 03942dd54b31e7a4cf9c6270b26ccf68a3234b40) --- source4/lib/tdb/tools/tdbtorture.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index c0076a92d4..591fdab2f7 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -30,7 +30,10 @@ #endif +#ifdef HAVE_GETOPT_H #include +#endif + #define REOPEN_PROB 30 #define DELETE_PROB 8 -- cgit From fbc2dbbb41e1ed5fe1ca778c24fef81f480a2322 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 24 Sep 2005 03:29:50 +0000 Subject: r10463: consider it an error if tdbtorture produces any log messages (This used to be commit d9ee0e8b59ee52ed1e41865cffe97e32b504e7e7) --- source4/lib/tdb/tools/tdbtorture.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 591fdab2f7..3fc395ba98 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -50,6 +50,7 @@ static struct tdb_context *db; static int in_transaction; +static int log_count; #ifdef PRINTF_ATTRIBUTE static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); @@ -58,6 +59,8 @@ static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) { va_list ap; + log_count++; + va_start(ap, format); vfprintf(stdout, format, ap); va_end(ap); @@ -304,7 +307,13 @@ static void usage(void) exit(1); } } - printf("OK\n"); + if (log_count == 0) { + printf("OK\n"); + } + } + + if (log_count != 0) { + exit(1); } return 0; -- cgit From 3bcfc68e0d158b272e0ef87bf585f79a570136ba Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 24 Sep 2005 06:49:28 +0000 Subject: r10468: - terminate tdbtorture quickly when an error is detected - more workarounds for aix not handling malloc of size 0 (This used to be commit c2b1739c6389503854f55fa8407c55071781eff4) --- source4/lib/tdb/tools/tdbtorture.c | 64 ++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 23 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 3fc395ba98..eded561106 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -50,7 +50,7 @@ static struct tdb_context *db; static int in_transaction; -static int log_count; +static int error_count; #ifdef PRINTF_ATTRIBUTE static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); @@ -59,7 +59,7 @@ static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) { va_list ap; - log_count++; + error_count++; va_start(ap, format); vfprintf(stdout, format, ap); @@ -78,7 +78,7 @@ static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) static void fatal(const char *why) { perror(why); - exit(1); + error_count++; } static char *randbuf(int len) @@ -283,37 +283,55 @@ static void usage(void) srand(seed + i); srandom(seed + i); - for (i=0;i Date: Sat, 24 Sep 2005 07:07:22 +0000 Subject: r10470: solaris8 has a problem with tdbtorture with 3 processes. To see if this is just a solaris issue this patch changes the default to 3, and I'll see how many build farm boxes break (This used to be commit c85836bafc9c042deac2a02ef6fddbfeaa5f47f1) --- source4/lib/tdb/tools/tdbtorture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index eded561106..96f8c16dfb 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -230,7 +230,7 @@ static void usage(void) int main(int argc, char * const *argv) { int i, seed = -1; - int num_procs = 2; + int num_procs = 3; int num_loops = 5000; int hash_size = 2; int c; -- cgit From 60a455dd449acdad9bdb21fbe68a15e2b584a5d2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 24 Sep 2005 07:30:20 +0000 Subject: r10471: stratos doesn't have getpagesize(), so guess 8k on systems that don't have it. Overestimating is harmless. (This used to be commit ab953c8c72060c496876b6f39d388ad2f7e3c7e0) --- source4/lib/tdb/tools/tdbtorture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 96f8c16dfb..c6298167fd 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -319,7 +319,7 @@ static void usage(void) if (pids[j] == pid) break; } if (j == num_procs) { - printf("unknown child %d exited!?\n", pid); + printf("unknown child %d exited!?\n", (int)pid); exit(1); } if (WEXITSTATUS(status) != 0) { -- cgit From 2a9b65cd17b271ff88fca6bda0bddc6230c2b319 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 24 Sep 2005 13:10:19 +0000 Subject: r10475: make sure we report failures in tdbtorture (ie. get the exit status right) (This used to be commit a795fc0aa141c08af6e37af07c88164bad3db35b) --- source4/lib/tdb/tools/tdbtorture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index c6298167fd..840397b73b 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -334,5 +334,5 @@ static void usage(void) printf("OK\n"); } - return 0; + return error_count; } -- cgit From fce0dcf2450f68fdc201152bdd063569bdcf1770 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 17 Apr 2006 11:42:59 +0000 Subject: r15100: Port the bugfix for #3569 to Samba4 (This used to be commit 5f1d52f232051324082b840f29dd7719a9328bd5) --- source4/lib/tdb/tools/tdbtorture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 840397b73b..ac09898696 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -149,7 +149,7 @@ static void addrec_db(void) #if REOPEN_PROB if (in_transaction == 0 && random() % REOPEN_PROB == 0) { - tdb_reopen_all(); + tdb_reopen_all(0); goto next; } #endif -- cgit From 172a83d72491f90f6191be1040ef8b2e1789bd2e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 13 May 2006 19:14:12 +0000 Subject: r15573: Fix build of systems that have iconv headers in non-standard locations Split of system/locale.h header from system/iconv.h Previously, iconv wasn't being used on these systems (This used to be commit aa6d66fda69779d1c2948a1aca85dbd5208f1cba) --- source4/lib/tdb/tools/tdbdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbdump.c b/source4/lib/tdb/tools/tdbdump.c index 9122551a0a..74ba64fdd9 100644 --- a/source4/lib/tdb/tools/tdbdump.c +++ b/source4/lib/tdb/tools/tdbdump.c @@ -38,7 +38,7 @@ #include "includes.h" #include "lib/tdb/include/tdb.h" -#include "system/iconv.h" +#include "system/locale.h" #include "system/filesys.h" #endif -- cgit From d3fee429aee87e9c05a4a606fbf0b60b16dac782 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 3 Jul 2006 06:40:56 +0000 Subject: r16774: This patch modifies the tdb API to allow the logging function to be used as part of ldb. This allows tdb failures to be passed all the way up to Samba's DEBUG system, which allowed easier debugging. Unfortunately I had to extend the tdb API, as the logging function didn't have a context pointer. I've worked over the 'debug levels' in TDB. Most of them were 0, which didn't seem right, as some were trace-like messages. We didn't see any of these previously, except when accessing TDB directly. Andrew Bartlett (This used to be commit 58898092c1ce043f6d698db5065f372b79109e22) --- source4/lib/tdb/tools/tdbtool.c | 10 +++++----- source4/lib/tdb/tools/tdbtorture.c | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index 0941a73118..5aa47bd9f5 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -79,9 +79,9 @@ static void print_asc(unsigned char *buf,int len) } #ifdef PRINTF_ATTRIBUTE -static void tdb_log(struct tdb_context *t, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); +static void tdb_log(struct tdb_context *t, enum tdb_debug_level level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); #endif -static void tdb_log(struct tdb_context *t, int level, const char *format, ...) +static void tdb_log(struct tdb_context *t, enum tdb_debug_level level, const char *format, ...) { va_list ap; @@ -190,7 +190,7 @@ static void create_tdb(void) } if (tdb) tdb_close(tdb); tdb = tdb_open_ex(tok, 0, TDB_CLEAR_IF_FIRST, - O_RDWR | O_CREAT | O_TRUNC, 0600, tdb_log, NULL); + O_RDWR | O_CREAT | O_TRUNC, 0600, tdb_log, NULL, NULL); if (!tdb) { printf("Could not create %s: %s\n", tok, strerror(errno)); } @@ -204,7 +204,7 @@ static void open_tdb(void) return; } if (tdb) tdb_close(tdb); - tdb = tdb_open_ex(tok, 0, 0, O_RDWR, 0600, tdb_log, NULL); + tdb = tdb_open_ex(tok, 0, 0, O_RDWR, 0600, tdb_log, NULL, NULL); if (!tdb) { printf("Could not open %s: %s\n", tok, strerror(errno)); } @@ -340,7 +340,7 @@ static void move_rec(void) print_rec(tdb, key, dbuf, NULL); - dst_tdb = tdb_open_ex(file, 0, 0, O_RDWR, 0600, tdb_log, NULL); + dst_tdb = tdb_open_ex(file, 0, 0, O_RDWR, 0600, tdb_log, NULL, NULL); if ( !dst_tdb ) { terror("unable to open destination tdb"); return; diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index ac09898696..559a84d99b 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -53,9 +53,9 @@ static int in_transaction; static int error_count; #ifdef PRINTF_ATTRIBUTE -static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); +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, int level, const char *format, ...) +static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) { va_list ap; @@ -266,7 +266,7 @@ static void usage(void) } db = tdb_open_ex("torture.tdb", hash_size, TDB_CLEAR_IF_FIRST, - O_RDWR | O_CREAT, 0600, tdb_log, NULL); + O_RDWR | O_CREAT, 0600, tdb_log, NULL, NULL); if (!db) { fatal("db open failed"); } -- cgit From 35fda6c5f344e71b1ed0bd195a62161e31401149 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 10 Jul 2006 12:51:36 +0000 Subject: r16916: Implement metze's proposed changes to the tdb logging API. This clearly links the log function with its private pointer, and makes the argument list for tdb_open_ex a bit shorter. Andrew Bartlett (This used to be commit 5d5503e8d8a10ead3ef21a5ffda52cadb9a07727) --- source4/lib/tdb/tools/tdbtool.c | 5 ++++- source4/lib/tdb/tools/tdbtorture.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index 5aa47bd9f5..7f7dce8c3c 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -183,6 +183,9 @@ static char *get_token(int startover) static void create_tdb(void) { + struct tdb_logging_context log_ctx; + log_ctx.log_fn = tdb_log; + char *tok = get_token(1); if (!tok) { help(); @@ -190,7 +193,7 @@ static void create_tdb(void) } if (tdb) tdb_close(tdb); tdb = tdb_open_ex(tok, 0, TDB_CLEAR_IF_FIRST, - O_RDWR | O_CREAT | O_TRUNC, 0600, tdb_log, NULL, NULL); + O_RDWR | O_CREAT | O_TRUNC, 0600, log_ctx, NULL); if (!tdb) { printf("Could not create %s: %s\n", tok, strerror(errno)); } diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 559a84d99b..d88211c4a7 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -237,6 +237,9 @@ static void usage(void) extern char *optarg; pid_t *pids; + struct tdb_logging_context log_ctx; + log_ctx.log_fn = tdb_log; + while ((c = getopt(argc, argv, "n:l:s:H:h")) != -1) { switch (c) { case 'n': @@ -266,7 +269,7 @@ static void usage(void) } db = tdb_open_ex("torture.tdb", hash_size, TDB_CLEAR_IF_FIRST, - O_RDWR | O_CREAT, 0600, tdb_log, NULL, NULL); + O_RDWR | O_CREAT, 0600, &log_ctx, NULL); if (!db) { fatal("db open failed"); } -- cgit From fabc6ae74ded03faac1ed23d79a61e205cd78daa Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 10 Jul 2006 13:35:58 +0000 Subject: r16917: Fix compile errors found by the testing of tdb on the build farm. Andrew Bartlett (This used to be commit a6e0846d9b5f1adc2ff137247a5c3f32746e43b5) --- source4/lib/tdb/tools/tdbtool.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index 7f7dce8c3c..f8105ad941 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -193,7 +193,7 @@ static void create_tdb(void) } if (tdb) tdb_close(tdb); tdb = tdb_open_ex(tok, 0, TDB_CLEAR_IF_FIRST, - O_RDWR | O_CREAT | O_TRUNC, 0600, log_ctx, NULL); + O_RDWR | O_CREAT | O_TRUNC, 0600, &log_ctx, NULL); if (!tdb) { printf("Could not create %s: %s\n", tok, strerror(errno)); } @@ -201,13 +201,16 @@ static void create_tdb(void) static void open_tdb(void) { + struct tdb_logging_context log_ctx; + log_ctx.log_fn = tdb_log; + char *tok = get_token(1); if (!tok) { help(); return; } if (tdb) tdb_close(tdb); - tdb = tdb_open_ex(tok, 0, 0, O_RDWR, 0600, tdb_log, NULL, NULL); + tdb = tdb_open_ex(tok, 0, 0, O_RDWR, 0600, &log_ctx, NULL); if (!tdb) { printf("Could not open %s: %s\n", tok, strerror(errno)); } @@ -316,6 +319,9 @@ static void move_rec(void) TDB_DATA key, dbuf; struct tdb_context *dst_tdb; + struct tdb_logging_context log_ctx; + log_ctx.log_fn = tdb_log; + if (!k) { help(); return; @@ -343,7 +349,7 @@ static void move_rec(void) print_rec(tdb, key, dbuf, NULL); - dst_tdb = tdb_open_ex(file, 0, 0, O_RDWR, 0600, tdb_log, NULL, NULL); + dst_tdb = tdb_open_ex(file, 0, 0, O_RDWR, 0600, &log_ctx, NULL); if ( !dst_tdb ) { terror("unable to open destination tdb"); return; -- cgit From 43f6d7d18906b98cac5fc26e78d2d9ee454fa23c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 11 Jul 2006 07:15:21 +0000 Subject: r16938: Fix breakage of TDB on VOS (declaration after statement) Andrew Bartlett (This used to be commit d0ed7cd241e0e7889406f62fd620d8fe39d4498c) --- source4/lib/tdb/tools/tdbtool.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index f8105ad941..903cbe7769 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -183,10 +183,11 @@ static char *get_token(int startover) static void create_tdb(void) { + char *tok = get_token(1); + struct tdb_logging_context log_ctx; log_ctx.log_fn = tdb_log; - char *tok = get_token(1); if (!tok) { help(); return; -- cgit From 36cb569e9be142f0b4a4e584a365b35e8bfa454d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 23 Aug 2006 02:51:40 +0000 Subject: r17737: fixed a 'declaration in code' error (This used to be commit aca417c6b164b54334cc46e126dd362ddab509d3) --- source4/lib/tdb/tools/tdbtool.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index 903cbe7769..de0ecdd7ca 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -203,9 +203,10 @@ static void create_tdb(void) static void open_tdb(void) { struct tdb_logging_context log_ctx; + char *tok = get_token(1); + log_ctx.log_fn = tdb_log; - char *tok = get_token(1); if (!tok) { help(); return; -- cgit From 39b2377f902f771dca8329b8b9ed1743ae0247a7 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 24 Aug 2006 09:47:51 +0000 Subject: r17781: fix compiler warning metze (This used to be commit bbe641f23676961972ac337304ece1116b0219b6) --- source4/lib/tdb/tools/tdbtorture.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index d88211c4a7..9b0a60348c 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -2,9 +2,8 @@ writers - that stresses the locking code. */ -#define _GNU_SOURCE - #ifndef _SAMBA_BUILD_ +#define _GNU_SOURCE #include #include #include @@ -46,7 +45,6 @@ #define CULL_PROB 100 #define KEYLEN 3 #define DATALEN 100 -#define LOCKLEN 20 static struct tdb_context *db; static int in_transaction; -- cgit From a983b06d37c3b87a02444d9a9862777b88629344 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 6 Sep 2006 04:44:32 +0000 Subject: r18129: moved the system includes into libreplace - this gives much more isolation of our portability environment from the main code, and also simplifies the includes system (no separate #ifdef _SAMBA_BUILD for tdb. ldb etc now) (This used to be commit 77d1a468e06290aba789e2f3affc769fc5159a21) --- source4/lib/tdb/tools/tdbbackup.c | 28 ++-------------------------- source4/lib/tdb/tools/tdbdump.c | 22 +--------------------- source4/lib/tdb/tools/tdbtest.c | 19 +------------------ source4/lib/tdb/tools/tdbtorture.c | 23 +---------------------- 4 files changed, 5 insertions(+), 87 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbbackup.c b/source4/lib/tdb/tools/tdbbackup.c index 872ca99f0d..45beb5e292 100644 --- a/source4/lib/tdb/tools/tdbbackup.c +++ b/source4/lib/tdb/tools/tdbbackup.c @@ -41,33 +41,9 @@ */ -#ifndef _SAMBA_BUILD_ -#if HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#else - -#include "includes.h" -#include "system/filesys.h" - -#endif - +#include "replace.h" #include "tdb.h" +#include "system/filesys.h" /* see if one file is newer than another diff --git a/source4/lib/tdb/tools/tdbdump.c b/source4/lib/tdb/tools/tdbdump.c index 74ba64fdd9..9111b739ab 100644 --- a/source4/lib/tdb/tools/tdbdump.c +++ b/source4/lib/tdb/tools/tdbdump.c @@ -18,31 +18,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef _SAMBA_BUILD_ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "replace.h" #include "tdb.h" - -#else - -#include "includes.h" -#include "lib/tdb/include/tdb.h" #include "system/locale.h" #include "system/filesys.h" -#endif - static void print_data(TDB_DATA d) { unsigned char *p = (unsigned char *)d.dptr; diff --git a/source4/lib/tdb/tools/tdbtest.c b/source4/lib/tdb/tools/tdbtest.c index edf12ecfdd..c7a09789fe 100644 --- a/source4/lib/tdb/tools/tdbtest.c +++ b/source4/lib/tdb/tools/tdbtest.c @@ -1,26 +1,9 @@ /* a test program for tdb - the trivial database */ -#ifndef _SAMBA_BUILD_ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "replace.h" #include "tdb.h" -#else - -#include "includes.h" #include "system/filesys.h" #include "system/time.h" -#include "lib/tdb/include/tdb.h" - -#endif #include diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 9b0a60348c..14a2b48cdc 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -2,33 +2,12 @@ writers - that stresses the locking code. */ -#ifndef _SAMBA_BUILD_ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "replace.h" #include "tdb.h" - -#else - -#include "includes.h" -#include "lib/tdb/include/tdb.h" #include "system/time.h" #include "system/wait.h" #include "system/filesys.h" -#endif - #ifdef HAVE_GETOPT_H #include #endif -- cgit From 9da0c020571d901569e552224bfedd8bedbf43ba Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 30 Nov 2006 03:25:07 +0000 Subject: r19960: Add code to check for loops in the free list. Should help us validate tdb's against corruption. Jeremy. (This used to be commit bd0710fa09799cb496b1f9f365c57c3b542445f3) --- source4/lib/tdb/tools/tdbtest.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtest.c b/source4/lib/tdb/tools/tdbtest.c index c7a09789fe..1564a42bc4 100644 --- a/source4/lib/tdb/tools/tdbtest.c +++ b/source4/lib/tdb/tools/tdbtest.c @@ -219,6 +219,7 @@ static void merge_test(void) { int i, seed=0; int loops = 10000; + int num_entries; char test_gdbm[] = "test.gdbm"; unlink("test.gdbm"); @@ -232,8 +233,6 @@ static void merge_test(void) fatal("db open failed"); } - tdb_logging_function(db, tdb_log); - #if 1 srand(seed); _start_timer(); @@ -248,6 +247,12 @@ static void merge_test(void) for (i=0;i Date: Tue, 3 Apr 2007 07:04:37 +0000 Subject: r22052: merge tdbtool from samba3 and build it metze (This used to be commit f471e752161e392ef7324df30517af1818a27d1d) --- source4/lib/tdb/tools/tdbtool.c | 646 ++++++++++++++++++++++++---------------- 1 file changed, 395 insertions(+), 251 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index de0ecdd7ca..4998ff7323 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -21,26 +21,80 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "replace.h" +#include "system/locale.h" +#include "system/time.h" +#include "system/filesys.h" #include "tdb.h" +#include "pstring.h" + +static int do_command(void); +const char *cmdname; +char *arg1, *arg2; +size_t arg1len, arg2len; +int do_connections; +int bIterate = 0; +char *line; +TDB_DATA iterate_kbuf; +char cmdline[1024]; + +enum commands { + CMD_CREATE_TDB, + CMD_OPEN_TDB, + CMD_ERASE, + CMD_DUMP, + CMD_CDUMP, + CMD_INSERT, + CMD_MOVE, + CMD_STORE, + CMD_SHOW, + CMD_KEYS, + CMD_HEXKEYS, + CMD_DELETE, + CMD_LIST_HASH_FREE, + CMD_LIST_FREE, + CMD_INFO, + CMD_FIRST, + CMD_NEXT, + CMD_SYSTEM, + CMD_QUIT, + CMD_HELP +}; + +typedef struct { + const char *name; + enum commands cmd; +} COMMAND_TABLE; + +COMMAND_TABLE cmd_table[] = { + {"create", CMD_CREATE_TDB}, + {"open", CMD_OPEN_TDB}, + {"erase", CMD_ERASE}, + {"dump", CMD_DUMP}, + {"cdump", CMD_CDUMP}, + {"insert", CMD_INSERT}, + {"move", CMD_MOVE}, + {"store", CMD_STORE}, + {"show", CMD_SHOW}, + {"keys", CMD_KEYS}, + {"hexkeys", CMD_HEXKEYS}, + {"delete", CMD_DELETE}, + {"list", CMD_LIST_HASH_FREE}, + {"free", CMD_LIST_FREE}, + {"info", CMD_INFO}, + {"first", CMD_FIRST}, + {"1", CMD_FIRST}, + {"next", CMD_NEXT}, + {"n", CMD_NEXT}, + {"quit", CMD_QUIT}, + {"q", CMD_QUIT}, + {"!", CMD_SYSTEM}, + {NULL, CMD_HELP} +}; /* a tdb tool for manipulating a tdb database */ -#define FSTRING_LEN 256 -typedef char fstring[FSTRING_LEN]; +/* these are taken from smb.h - make sure they are in sync */ typedef struct connections_key { pid_t pid; @@ -56,15 +110,20 @@ typedef struct connections_data { gid_t gid; char name[24]; char addr[24]; - char machine[128]; + char machine[FSTRING_LEN]; time_t start; + unsigned bcast_msg_flags; } connections_data; -static struct tdb_context *tdb; +static TDB_CONTEXT *tdb; -static int print_rec(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); +static int print_crec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); +static int print_arec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); +static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); +static int print_key(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); +static int print_hexkey(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); -static void print_asc(unsigned char *buf,int len) +static void print_asc(const char *buf,int len) { int i; @@ -78,20 +137,7 @@ static void print_asc(unsigned char *buf,int len) printf("%c",isprint(buf[i])?buf[i]:'.'); } -#ifdef PRINTF_ATTRIBUTE -static void tdb_log(struct tdb_context *t, enum tdb_debug_level level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); -#endif -static void tdb_log(struct tdb_context *t, 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 void print_data(unsigned char *buf,int len) +static void print_data(const char *buf,int len) { int i=0; if (len<=0) return; @@ -131,6 +177,10 @@ static void help(void) " open dbname : open an existing database\n" " erase : erase the database\n" " dump : dump the database as strings\n" +" cdump : dump the database as connection records\n" +" keys : dump the database keys as strings\n" +" hexkeys : dump the database keys as hex values\n" +" info : print summary info about the database\n" " insert key data : insert a record\n" " move key file : move a record to a destination tdb\n" " store key data : store a record (replace)\n" @@ -138,6 +188,7 @@ 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" " 1 | first : print the first record\n" " n | next : print the next record\n" " q | quit : terminate\n" @@ -150,110 +201,62 @@ static void terror(const char *why) printf("%s\n", why); } -static char *get_token(int startover) -{ - static char tmp[1024]; - static char *cont = NULL; - char *insert, *start; - char *k = strtok(NULL, " "); - - if (!k) - return NULL; - - if (startover) - start = tmp; - else - start = cont; - - strcpy(start, k); - insert = start + strlen(start) - 1; - while (*insert == '\\') { - *insert++ = ' '; - k = strtok(NULL, " "); - if (!k) - break; - strcpy(insert, k); - insert = start + strlen(start) - 1; - } - - /* Get ready for next call */ - cont = start + strlen(start) + 1; - return start; -} - -static void create_tdb(void) +static void create_tdb(const char *tdbname) { - char *tok = get_token(1); - - struct tdb_logging_context log_ctx; - log_ctx.log_fn = tdb_log; - - if (!tok) { - help(); - return; - } if (tdb) tdb_close(tdb); - tdb = tdb_open_ex(tok, 0, TDB_CLEAR_IF_FIRST, - O_RDWR | O_CREAT | O_TRUNC, 0600, &log_ctx, NULL); + tdb = tdb_open(tdbname, 0, TDB_CLEAR_IF_FIRST, + O_RDWR | O_CREAT | O_TRUNC, 0600); if (!tdb) { - printf("Could not create %s: %s\n", tok, strerror(errno)); + printf("Could not create %s: %s\n", tdbname, strerror(errno)); } } -static void open_tdb(void) +static void open_tdb(const char *tdbname) { - struct tdb_logging_context log_ctx; - char *tok = get_token(1); - - log_ctx.log_fn = tdb_log; - - if (!tok) { - help(); - return; - } if (tdb) tdb_close(tdb); - tdb = tdb_open_ex(tok, 0, 0, O_RDWR, 0600, &log_ctx, NULL); + tdb = tdb_open(tdbname, 0, 0, O_RDWR, 0600); if (!tdb) { - printf("Could not open %s: %s\n", tok, strerror(errno)); + printf("Could not open %s: %s\n", tdbname, strerror(errno)); } } -static void insert_tdb(void) +static void insert_tdb(char *keyname, size_t keylen, char* data, size_t datalen) { - char *k = get_token(1); - char *d = get_token(0); TDB_DATA key, dbuf; - if (!k || !d) { - help(); + if ((keyname == NULL) || (keylen == 0)) { + terror("need key"); return; } - key.dptr = (unsigned char *)k; - key.dsize = strlen(k)+1; - dbuf.dptr = (unsigned char *)d; - dbuf.dsize = strlen(d)+1; + key.dptr = (unsigned char *)keyname; + key.dsize = keylen; + dbuf.dptr = (unsigned char *)data; + dbuf.dsize = datalen; if (tdb_store(tdb, key, dbuf, TDB_INSERT) == -1) { terror("insert failed"); } } -static void store_tdb(void) +static void store_tdb(char *keyname, size_t keylen, char* data, size_t datalen) { - char *k = get_token(1); - char *d = get_token(0); TDB_DATA key, dbuf; - if (!k || !d) { - help(); + if ((keyname == NULL) || (keylen == 0)) { + terror("need key"); return; } - key.dptr = (unsigned char *)k; - key.dsize = strlen(k)+1; - dbuf.dptr = (unsigned char *)d; - dbuf.dsize = strlen(d)+1; + if ((data == NULL) || (datalen == 0)) { + terror("need data"); + return; + } + + key.dptr = (unsigned char *)keyname; + key.dsize = keylen; + dbuf.dptr = (unsigned char *)data; + dbuf.dsize = datalen; printf("Storing key:\n"); print_rec(tdb, key, dbuf, NULL); @@ -263,32 +266,24 @@ static void store_tdb(void) } } -static void show_tdb(void) +static void show_tdb(char *keyname, size_t keylen) { - char *k = get_token(1); TDB_DATA key, dbuf; - if (!k) { - help(); + if ((keyname == NULL) || (keylen == 0)) { + terror("need key"); return; } - key.dptr = (unsigned char *)k; - key.dsize = strlen(k)+1; + key.dptr = (unsigned char *)keyname; + key.dsize = keylen; dbuf = tdb_fetch(tdb, key); if (!dbuf.dptr) { - /* maybe it is non-NULL terminated key? */ - key.dsize = strlen(k); - dbuf = tdb_fetch(tdb, key); - - if ( !dbuf.dptr ) { - terror("fetch failed"); - return; - } + terror("fetch failed"); + return; } - /* printf("%s : %*.*s\n", k, (int)dbuf.dsize, (int)dbuf.dsize, dbuf.dptr); */ print_rec(tdb, key, dbuf, NULL); free( dbuf.dptr ); @@ -296,62 +291,50 @@ static void show_tdb(void) return; } -static void delete_tdb(void) +static void delete_tdb(char *keyname, size_t keylen) { - char *k = get_token(1); TDB_DATA key; - if (!k) { - help(); + if ((keyname == NULL) || (keylen == 0)) { + terror("need key"); return; } - key.dptr = (unsigned char *)k; - key.dsize = strlen(k)+1; + key.dptr = (unsigned char *)keyname; + key.dsize = keylen; if (tdb_delete(tdb, key) != 0) { terror("delete failed"); } } -static void move_rec(void) +static void move_rec(char *keyname, size_t keylen, char* tdbname) { - char *k = get_token(1); - char *file = get_token(0); TDB_DATA key, dbuf; - struct tdb_context *dst_tdb; - - struct tdb_logging_context log_ctx; - log_ctx.log_fn = tdb_log; + TDB_CONTEXT *dst_tdb; - if (!k) { - help(); + if ((keyname == NULL) || (keylen == 0)) { + terror("need key"); return; } - - if ( !file ) { + + if ( !tdbname ) { terror("need destination tdb name"); return; } - key.dptr = (unsigned char *)k; - key.dsize = strlen(k)+1; + key.dptr = (unsigned char *)keyname; + key.dsize = keylen; dbuf = tdb_fetch(tdb, key); if (!dbuf.dptr) { - /* maybe it is non-NULL terminated key? */ - key.dsize = strlen(k); - dbuf = tdb_fetch(tdb, key); - - if ( !dbuf.dptr ) { - terror("fetch failed"); - return; - } + terror("fetch failed"); + return; } print_rec(tdb, key, dbuf, NULL); - dst_tdb = tdb_open_ex(file, 0, 0, O_RDWR, 0600, &log_ctx, NULL); + dst_tdb = tdb_open(tdbname, 0, 0, O_RDWR, 0600); if ( !dst_tdb ) { terror("unable to open destination tdb"); return; @@ -368,25 +351,76 @@ static void move_rec(void) return; } -static int print_rec(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +static int print_conn_key(TDB_DATA key) +{ + printf( "\nkey %d bytes\n", (int)key.dsize); + printf( "pid =%5d ", ((connections_key*)key.dptr)->pid); + printf( "cnum =%10d ", ((connections_key*)key.dptr)->cnum); + printf( "name =[%s]\n", ((connections_key*)key.dptr)->name); + return 0; +} + +static int print_conn_data(TDB_DATA dbuf) { - printf("\nkey %d bytes\n", key.dsize); - print_asc(key.dptr, key.dsize); - printf("\ndata %d bytes\n", dbuf.dsize); - print_data(dbuf.dptr, dbuf.dsize); + printf( "\ndata %d bytes\n", (int)dbuf.dsize); + printf( "pid =%5d ", ((connections_data*)dbuf.dptr)->pid); + printf( "cnum =%10d ", ((connections_data*)dbuf.dptr)->cnum); + printf( "name =[%s]\n", ((connections_data*)dbuf.dptr)->name); + + printf( "uid =%5d ", ((connections_data*)dbuf.dptr)->uid); + printf( "addr =[%s]\n", ((connections_data*)dbuf.dptr)->addr); + printf( "gid =%5d ", ((connections_data*)dbuf.dptr)->gid); + printf( "machine=[%s]\n", ((connections_data*)dbuf.dptr)->machine); + printf( "start = %s\n", ctime(&((connections_data*)dbuf.dptr)->start)); + printf( "magic = 0x%x ", ((connections_data*)dbuf.dptr)->magic); + printf( "flags = 0x%x\n", ((connections_data*)dbuf.dptr)->bcast_msg_flags); return 0; } -static int print_key(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { - print_asc(key.dptr, key.dsize); + if (do_connections && (dbuf.dsize == sizeof(connections_data))) + print_crec(the_tdb, key, dbuf, state); + else + print_arec(the_tdb, key, dbuf, state); + return 0; +} + +static int print_crec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +{ + print_conn_key(key); + print_conn_data(dbuf); + return 0; +} + +static int print_arec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +{ + printf("\nkey %d bytes\n", (int)key.dsize); + print_asc((const char *)key.dptr, key.dsize); + printf("\ndata %d bytes\n", (int)dbuf.dsize); + print_data((const char *)dbuf.dptr, dbuf.dsize); + return 0; +} + +static int print_key(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +{ + printf("key %d bytes: ", (int)key.dsize); + print_asc((const char *)key.dptr, key.dsize); + printf("\n"); + return 0; +} + +static int print_hexkey(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +{ + printf("key %d bytes\n", (int)key.dsize); + print_data((const char *)key.dptr, key.dsize); printf("\n"); return 0; } static int total_bytes; -static int traverse_fn(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { total_bytes += dbuf.dsize; return 0; @@ -396,7 +430,7 @@ static void info_tdb(void) { int count; total_bytes = 0; - if ((count = tdb_traverse(tdb, traverse_fn, NULL) == -1)) + if ((count = tdb_traverse(tdb, traverse_fn, NULL)) == -1) printf("Error = %s\n", tdb_errorstr(tdb)); else printf("%d records totalling %d bytes\n", count, total_bytes); @@ -404,23 +438,23 @@ static void info_tdb(void) static char *tdb_getline(const char *prompt) { - static char line[1024]; + static char thisline[1024]; char *p; fputs(prompt, stdout); - line[0] = 0; - p = fgets(line, sizeof(line)-1, stdin); + thisline[0] = 0; + p = fgets(thisline, sizeof(thisline)-1, stdin); if (p) p = strchr(p, '\n'); if (p) *p = 0; - return p?line:NULL; + return p?thisline:NULL; } -static int do_delete_fn(struct tdb_context *the_tdb, TDB_DATA key, TDB_DATA dbuf, +static int do_delete_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { return tdb_delete(the_tdb, key); } -static void first_record(struct tdb_context *the_tdb, TDB_DATA *pkey) +static void first_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey) { TDB_DATA dbuf; *pkey = tdb_firstkey(the_tdb); @@ -428,12 +462,11 @@ static void first_record(struct tdb_context *the_tdb, TDB_DATA *pkey) dbuf = tdb_fetch(the_tdb, *pkey); if (!dbuf.dptr) terror("fetch failed"); else { - /* printf("%s : %*.*s\n", k, (int)dbuf.dsize, (int)dbuf.dsize, dbuf.dptr); */ print_rec(the_tdb, *pkey, dbuf, NULL); } } -static void next_record(struct tdb_context *the_tdb, TDB_DATA *pkey) +static void next_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey) { TDB_DATA dbuf; *pkey = tdb_nextkey(the_tdb, *pkey); @@ -442,98 +475,209 @@ static void next_record(struct tdb_context *the_tdb, TDB_DATA *pkey) if (!dbuf.dptr) terror("fetch failed"); else - /* printf("%s : %*.*s\n", k, (int)dbuf.dsize, (int)dbuf.dsize, dbuf.dptr); */ print_rec(the_tdb, *pkey, dbuf, NULL); } +static int do_command(void) +{ + COMMAND_TABLE *ctp = cmd_table; + enum commands mycmd = CMD_HELP; + int cmd_len; + + do_connections = 0; + + if (cmdname && strlen(cmdname) == 0) { + mycmd = CMD_NEXT; + } else { + while (ctp->name) { + cmd_len = strlen(ctp->name); + if (strncmp(ctp->name,cmdname,cmd_len) == 0) { + mycmd = ctp->cmd; + break; + } + ctp++; + } + } + + switch (mycmd) { + case CMD_CREATE_TDB: + bIterate = 0; + create_tdb(arg1); + return 0; + case CMD_OPEN_TDB: + bIterate = 0; + open_tdb(arg1); + return 0; + case CMD_SYSTEM: + /* Shell command */ + system(arg1); + return 0; + case CMD_QUIT: + return 1; + default: + /* all the rest require a open database */ + if (!tdb) { + bIterate = 0; + terror("database not open"); + help(); + return 0; + } + switch (mycmd) { + case CMD_ERASE: + bIterate = 0; + tdb_traverse(tdb, do_delete_fn, NULL); + return 0; + case CMD_DUMP: + bIterate = 0; + tdb_traverse(tdb, print_rec, NULL); + return 0; + case CMD_CDUMP: + do_connections = 1; + bIterate = 0; + tdb_traverse(tdb, print_rec, NULL); + return 0; + case CMD_INSERT: + bIterate = 0; + insert_tdb(arg1, arg1len,arg2,arg2len); + return 0; + case CMD_MOVE: + bIterate = 0; + move_rec(arg1,arg1len,arg2); + return 0; + case CMD_STORE: + bIterate = 0; + store_tdb(arg1,arg1len,arg2,arg2len); + return 0; + case CMD_SHOW: + bIterate = 0; + show_tdb(arg1, arg1len); + return 0; + case CMD_KEYS: + tdb_traverse(tdb, print_key, NULL); + return 0; + case CMD_HEXKEYS: + tdb_traverse(tdb, print_hexkey, NULL); + return 0; + case CMD_DELETE: + bIterate = 0; + delete_tdb(arg1,arg1len); + return 0; + case CMD_LIST_HASH_FREE: + tdb_dump_all(tdb); + return 0; + case CMD_LIST_FREE: + tdb_printfreelist(tdb); + return 0; + case CMD_INFO: + info_tdb(); + return 0; + case CMD_FIRST: + bIterate = 1; + first_record(tdb, &iterate_kbuf); + return 0; + case CMD_NEXT: + if (bIterate) + next_record(tdb, &iterate_kbuf); + return 0; + case CMD_HELP: + help(); + return 0; + case CMD_CREATE_TDB: + case CMD_OPEN_TDB: + case CMD_SYSTEM: + case CMD_QUIT: + /* + * unhandled commands. cases included here to avoid compiler + * warnings. + */ + return 0; + } + } + + return 0; +} + +static char *convert_string(char *instring, size_t *sizep) +{ + size_t length = 0; + char *outp, *inp; + char temp[3]; + + + outp = inp = instring; + + while (*inp) { + if (*inp == '\\') { + inp++; + if (*inp && strchr("0123456789abcdefABCDEF",(int)*inp)) { + temp[0] = *inp++; + temp[1] = '\0'; + if (*inp && strchr("0123456789abcdefABCDEF",(int)*inp)) { + temp[1] = *inp++; + temp[2] = '\0'; + } + *outp++ = (char)strtol((const char *)temp,NULL,16); + } else { + *outp++ = *inp++; + } + } else { + *outp++ = *inp++; + } + length++; + } + *sizep = length; + return instring; +} + int main(int argc, char *argv[]) { - int bIterate = 0; - char *line; - char *tok; - TDB_DATA iterate_kbuf; + cmdname = ""; + arg1 = NULL; + arg1len = 0; + arg2 = NULL; + arg2len = 0; if (argv[1]) { - static char tmp[1024]; - sprintf(tmp, "open %s", argv[1]); - tok=strtok(tmp," "); - open_tdb(); + cmdname = "open"; + arg1 = argv[1]; + do_command(); + cmdname = ""; + arg1 = NULL; } - while ((line = tdb_getline("tdb> "))) { - - /* Shell command */ - - if (line[0] == '!') { - system(line + 1); - continue; - } - - if ((tok = strtok(line," "))==NULL) { - if (bIterate) - next_record(tdb, &iterate_kbuf); - continue; - } - if (strcmp(tok,"create") == 0) { - bIterate = 0; - create_tdb(); - continue; - } else if (strcmp(tok,"open") == 0) { - open_tdb(); - continue; - } else if ((strcmp(tok, "q") == 0) || - (strcmp(tok, "quit") == 0)) { - break; - } - - /* all the rest require a open database */ - if (!tdb) { - bIterate = 0; - terror("database not open"); - help(); - continue; - } - - if (strcmp(tok,"insert") == 0) { - bIterate = 0; - insert_tdb(); - } else if (strcmp(tok,"store") == 0) { - bIterate = 0; - store_tdb(); - } else if (strcmp(tok,"show") == 0) { - bIterate = 0; - show_tdb(); - } else if (strcmp(tok,"erase") == 0) { - bIterate = 0; - tdb_traverse(tdb, do_delete_fn, NULL); - } else if (strcmp(tok,"delete") == 0) { - bIterate = 0; - delete_tdb(); - } else if (strcmp(tok,"dump") == 0) { - bIterate = 0; - tdb_traverse(tdb, print_rec, NULL); - } else if (strcmp(tok,"move") == 0) { - bIterate = 0; - move_rec(); - } else if (strcmp(tok,"list") == 0) { - tdb_dump_all(tdb); - } else if (strcmp(tok, "free") == 0) { - tdb_printfreelist(tdb); - } else if (strcmp(tok,"info") == 0) { - info_tdb(); - } else if ( (strcmp(tok, "1") == 0) || - (strcmp(tok, "first") == 0)) { - bIterate = 1; - first_record(tdb, &iterate_kbuf); - } else if ((strcmp(tok, "n") == 0) || - (strcmp(tok, "next") == 0)) { - next_record(tdb, &iterate_kbuf); - } else if ((strcmp(tok, "keys") == 0)) { - bIterate = 0; - tdb_traverse(tdb, print_key, NULL); - } else { - help(); - } + switch (argc) { + case 1: + case 2: + /* Interactive mode */ + while ((cmdname = tdb_getline("tdb> "))) { + arg2 = arg1 = NULL; + if ((arg1 = strchr((const char *)cmdname,' ')) != NULL) { + arg1++; + arg2 = arg1; + while (*arg2) { + if (*arg2 == ' ') { + *arg2++ = '\0'; + break; + } + if ((*arg2++ == '\\') && (*arg2 == ' ')) { + arg2++; + } + } + } + if (arg1) arg1 = convert_string(arg1,&arg1len); + if (arg2) arg2 = convert_string(arg2,&arg2len); + if (do_command()) break; + } + break; + case 5: + arg2 = convert_string(argv[4],&arg2len); + case 4: + arg1 = convert_string(argv[3],&arg1len); + case 3: + cmdname = argv[2]; + default: + do_command(); + break; } if (tdb) tdb_close(tdb); -- cgit From 464c48a62e9ddea7c463fa9a34abfc53c9a6617f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 3 Apr 2007 09:08:18 +0000 Subject: r22053: remove samba3 specific stuff from tdbtool should I merge this to SAMBA_3_0? as it's also totally broken there, as the connection_struct definition is completely different metze (This used to be commit 5677b01d1dc63276a36daac400d5b0d935034ce6) --- source4/lib/tdb/tools/tdbtool.c | 77 ----------------------------------------- 1 file changed, 77 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index 4998ff7323..cf801d5dc5 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -26,13 +26,11 @@ #include "system/time.h" #include "system/filesys.h" #include "tdb.h" -#include "pstring.h" static int do_command(void); const char *cmdname; char *arg1, *arg2; size_t arg1len, arg2len; -int do_connections; int bIterate = 0; char *line; TDB_DATA iterate_kbuf; @@ -43,7 +41,6 @@ enum commands { CMD_OPEN_TDB, CMD_ERASE, CMD_DUMP, - CMD_CDUMP, CMD_INSERT, CMD_MOVE, CMD_STORE, @@ -71,7 +68,6 @@ COMMAND_TABLE cmd_table[] = { {"open", CMD_OPEN_TDB}, {"erase", CMD_ERASE}, {"dump", CMD_DUMP}, - {"cdump", CMD_CDUMP}, {"insert", CMD_INSERT}, {"move", CMD_MOVE}, {"store", CMD_STORE}, @@ -94,31 +90,8 @@ COMMAND_TABLE cmd_table[] = { /* a tdb tool for manipulating a tdb database */ -/* these are taken from smb.h - make sure they are in sync */ - -typedef struct connections_key { - pid_t pid; - int cnum; - fstring name; -} connections_key; - -typedef struct connections_data { - int magic; - pid_t pid; - int cnum; - uid_t uid; - gid_t gid; - char name[24]; - char addr[24]; - char machine[FSTRING_LEN]; - time_t start; - unsigned bcast_msg_flags; -} connections_data; - static TDB_CONTEXT *tdb; -static int print_crec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); -static int print_arec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); static int print_key(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); static int print_hexkey(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); @@ -177,7 +150,6 @@ static void help(void) " open dbname : open an existing database\n" " erase : erase the database\n" " dump : dump the database as strings\n" -" cdump : dump the database as connection records\n" " keys : dump the database keys as strings\n" " hexkeys : dump the database keys as hex values\n" " info : print summary info about the database\n" @@ -351,49 +323,7 @@ static void move_rec(char *keyname, size_t keylen, char* tdbname) return; } -static int print_conn_key(TDB_DATA key) -{ - printf( "\nkey %d bytes\n", (int)key.dsize); - printf( "pid =%5d ", ((connections_key*)key.dptr)->pid); - printf( "cnum =%10d ", ((connections_key*)key.dptr)->cnum); - printf( "name =[%s]\n", ((connections_key*)key.dptr)->name); - return 0; -} - -static int print_conn_data(TDB_DATA dbuf) -{ - printf( "\ndata %d bytes\n", (int)dbuf.dsize); - printf( "pid =%5d ", ((connections_data*)dbuf.dptr)->pid); - printf( "cnum =%10d ", ((connections_data*)dbuf.dptr)->cnum); - printf( "name =[%s]\n", ((connections_data*)dbuf.dptr)->name); - - printf( "uid =%5d ", ((connections_data*)dbuf.dptr)->uid); - printf( "addr =[%s]\n", ((connections_data*)dbuf.dptr)->addr); - printf( "gid =%5d ", ((connections_data*)dbuf.dptr)->gid); - printf( "machine=[%s]\n", ((connections_data*)dbuf.dptr)->machine); - printf( "start = %s\n", ctime(&((connections_data*)dbuf.dptr)->start)); - printf( "magic = 0x%x ", ((connections_data*)dbuf.dptr)->magic); - printf( "flags = 0x%x\n", ((connections_data*)dbuf.dptr)->bcast_msg_flags); - return 0; -} - static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) -{ - if (do_connections && (dbuf.dsize == sizeof(connections_data))) - print_crec(the_tdb, key, dbuf, state); - else - print_arec(the_tdb, key, dbuf, state); - return 0; -} - -static int print_crec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) -{ - print_conn_key(key); - print_conn_data(dbuf); - return 0; -} - -static int print_arec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { printf("\nkey %d bytes\n", (int)key.dsize); print_asc((const char *)key.dptr, key.dsize); @@ -484,8 +414,6 @@ static int do_command(void) enum commands mycmd = CMD_HELP; int cmd_len; - do_connections = 0; - if (cmdname && strlen(cmdname) == 0) { mycmd = CMD_NEXT; } else { @@ -531,11 +459,6 @@ static int do_command(void) bIterate = 0; tdb_traverse(tdb, print_rec, NULL); return 0; - case CMD_CDUMP: - do_connections = 1; - bIterate = 0; - tdb_traverse(tdb, print_rec, NULL); - return 0; case CMD_INSERT: bIterate = 0; insert_tdb(arg1, arg1len,arg2,arg2len); -- cgit From 81fb404a6f61205ed141fd9f0681e704e2a33ad6 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 17 Apr 2007 17:24:02 +0000 Subject: r22319: sync lib/tdb/ with samba3 metze (This used to be commit 8f24f6b38e967075589529a08c68a1a56f9f0499) --- source4/lib/tdb/tools/tdbbackup.c | 186 +++++++++++++++++++++++++++++++++++++- source4/lib/tdb/tools/tdbdump.c | 57 ++++++++++-- 2 files changed, 228 insertions(+), 15 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbbackup.c b/source4/lib/tdb/tools/tdbbackup.c index 45beb5e292..2e728d46aa 100644 --- a/source4/lib/tdb/tools/tdbbackup.c +++ b/source4/lib/tdb/tools/tdbbackup.c @@ -42,8 +42,181 @@ */ #include "replace.h" -#include "tdb.h" +#include "system/locale.h" +#include "system/time.h" #include "system/filesys.h" +#include "tdb.h" + +#ifdef HAVE_GETOPT_H +#include +#endif + +static int failed; + +static char *add_suffix(const char *name, const char *suffix) +{ + char *ret; + int len = strlen(name) + strlen(suffix) + 1; + ret = (char *)malloc(len); + if (!ret) { + fprintf(stderr,"Out of memory!\n"); + exit(1); + } + snprintf(ret, len, "%s%s", name, suffix); + return ret; +} + +static int copy_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +{ + TDB_CONTEXT *tdb_new = (TDB_CONTEXT *)state; + + if (tdb_store(tdb_new, key, dbuf, TDB_INSERT) != 0) { + fprintf(stderr,"Failed to insert into %s\n", tdb_name(tdb)); + failed = 1; + return 1; + } + return 0; +} + + +static int test_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +{ + return 0; +} + +/* + carefully backup a tdb, validating the contents and + only doing the backup if its OK + this function is also used for restore +*/ +static int backup_tdb(const char *old_name, const char *new_name, int hash_size) +{ + TDB_CONTEXT *tdb; + TDB_CONTEXT *tdb_new; + char *tmp_name; + struct stat st; + int count1, count2; + + tmp_name = add_suffix(new_name, ".tmp"); + + /* stat the old tdb to find its permissions */ + if (stat(old_name, &st) != 0) { + perror(old_name); + free(tmp_name); + return 1; + } + + /* open the old tdb */ + tdb = tdb_open(old_name, 0, 0, O_RDWR, 0); + if (!tdb) { + printf("Failed to open %s\n", old_name); + free(tmp_name); + return 1; + } + + /* 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); + if (!tdb_new) { + perror(tmp_name); + free(tmp_name); + return 1; + } + + /* lock the old tdb */ + if (tdb_lockall(tdb) != 0) { + fprintf(stderr,"Failed to lock %s\n", old_name); + tdb_close(tdb); + tdb_close(tdb_new); + unlink(tmp_name); + free(tmp_name); + return 1; + } + + failed = 0; + + /* traverse and copy */ + count1 = tdb_traverse(tdb, copy_fn, (void *)tdb_new); + if (count1 < 0 || failed) { + fprintf(stderr,"failed to copy %s\n", old_name); + tdb_close(tdb); + tdb_close(tdb_new); + unlink(tmp_name); + free(tmp_name); + return 1; + } + + /* close the old tdb */ + tdb_close(tdb); + + /* 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); + if (!tdb_new) { + fprintf(stderr,"failed to reopen %s\n", tmp_name); + unlink(tmp_name); + perror(tmp_name); + free(tmp_name); + return 1; + } + + /* traverse the new tdb to confirm */ + count2 = tdb_traverse(tdb_new, test_fn, 0); + if (count2 != count1) { + fprintf(stderr,"failed to copy %s\n", old_name); + tdb_close(tdb_new); + unlink(tmp_name); + free(tmp_name); + 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); + unlink(new_name); + if (rename(tmp_name, new_name) != 0) { + perror(new_name); + free(tmp_name); + return 1; + } + + free(tmp_name); + + return 0; +} + +/* + verify a tdb and if it is corrupt then restore from *.bak +*/ +static int verify_tdb(const char *fname, const char *bak_name) +{ + TDB_CONTEXT *tdb; + int count = -1; + + /* open the tdb */ + tdb = tdb_open(fname, 0, 0, O_RDONLY, 0); + + /* traverse the tdb, then close it */ + if (tdb) { + count = tdb_traverse(tdb, test_fn, NULL); + tdb_close(tdb); + } + + /* count is < 0 means an error */ + if (count < 0) { + printf("restoring %s\n", fname); + return backup_tdb(bak_name, fname, 0); + } + + printf("%s : %d records\n", fname, count); + + return 0; +} /* see if one file is newer than another @@ -66,6 +239,7 @@ static void usage(void) printf(" -h this help message\n"); printf(" -s suffix set the backup suffix\n"); printf(" -v verify mode (restore if corrupt)\n"); + printf(" -n hashsize set the new hash size for the backup\n"); } @@ -75,11 +249,10 @@ static void usage(void) int ret = 0; int c; int verify = 0; + int hashsize = 0; const char *suffix = ".bak"; - extern int optind; - extern char *optarg; - while ((c = getopt(argc, argv, "vhs:")) != -1) { + while ((c = getopt(argc, argv, "vhs:n:")) != -1) { switch (c) { case 'h': usage(); @@ -90,6 +263,9 @@ static void usage(void) case 's': suffix = optarg; break; + case 'n': + hashsize = atoi(optarg); + break; } } @@ -113,7 +289,7 @@ static void usage(void) } } else { if (file_newer(fname, bak_name) && - backup_tdb(fname, bak_name) != 0) { + backup_tdb(fname, bak_name, hashsize) != 0) { ret = 1; } } diff --git a/source4/lib/tdb/tools/tdbdump.c b/source4/lib/tdb/tools/tdbdump.c index 9111b739ab..4ceef2d60c 100644 --- a/source4/lib/tdb/tools/tdbdump.c +++ b/source4/lib/tdb/tools/tdbdump.c @@ -19,9 +19,10 @@ */ #include "replace.h" -#include "tdb.h" #include "system/locale.h" +#include "system/time.h" #include "system/filesys.h" +#include "tdb.h" static void print_data(TDB_DATA d) { @@ -37,22 +38,23 @@ static void print_data(TDB_DATA d) } } -static int traverse_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) +static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) { printf("{\n"); - printf("key = \""); + printf("key(%d) = \"", (int)key.dsize); print_data(key); printf("\"\n"); - printf("data = \""); + printf("data(%d) = \"", (int)dbuf.dsize); print_data(dbuf); printf("\"\n"); printf("}\n"); return 0; } -static int dump_tdb(const char *fname) +static int dump_tdb(const char *fname, const char *keyname) { - struct tdb_context *tdb; + TDB_CONTEXT *tdb; + TDB_DATA key, value; tdb = tdb_open(fname, 0, 0, O_RDONLY, 0); if (!tdb) { @@ -60,20 +62,55 @@ static int dump_tdb(const char *fname) return 1; } - tdb_traverse(tdb, traverse_fn, NULL); + if (!keyname) { + tdb_traverse(tdb, traverse_fn, NULL); + } else { + key.dptr = discard_const_p(uint8_t,keyname); + key.dsize = strlen( keyname); + value = tdb_fetch(tdb, key); + if (!value.dptr) { + return 1; + } else { + print_data(value); + free(value.dptr); + } + } + return 0; } +static void usage( void) +{ + printf( "Usage: tdbdump [options] \n\n"); + printf( " -h this help message\n"); + printf( " -k keyname dumps value of keyname\n"); +} + int main(int argc, char *argv[]) { - char *fname; + char *fname, *keyname=NULL; + int c; if (argc < 2) { printf("Usage: tdbdump \n"); exit(1); } - fname = argv[1]; + while ((c = getopt( argc, argv, "hk:")) != -1) { + switch (c) { + case 'h': + usage(); + exit( 0); + case 'k': + keyname = optarg; + break; + default: + usage(); + exit( 1); + } + } + + fname = argv[optind]; - return dump_tdb(fname); + return dump_tdb(fname, keyname); } -- cgit From 046870c023c950377c97c58e79ec730351a3fa97 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 21 Apr 2007 07:25:40 +0000 Subject: r22422: merged tdb changes from ctdb (This used to be commit a0ff739bcab32065d9d3957eb1d93f7791f84f04) --- source4/lib/tdb/tools/tdbtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtest.c b/source4/lib/tdb/tools/tdbtest.c index 1564a42bc4..416bc50a5b 100644 --- a/source4/lib/tdb/tools/tdbtest.c +++ b/source4/lib/tdb/tools/tdbtest.c @@ -214,7 +214,7 @@ static void merge_test(void) key.dptr = keys[3]; tdb_delete(db, key); } - + int main(int argc, const char *argv[]) { int i, seed=0; -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/lib/tdb/tools/tdbbackup.c | 5 ++--- source4/lib/tdb/tools/tdbdump.c | 5 ++--- source4/lib/tdb/tools/tdbtool.c | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbbackup.c b/source4/lib/tdb/tools/tdbbackup.c index 2e728d46aa..2a75c44b1d 100644 --- a/source4/lib/tdb/tools/tdbbackup.c +++ b/source4/lib/tdb/tools/tdbbackup.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ /* diff --git a/source4/lib/tdb/tools/tdbdump.c b/source4/lib/tdb/tools/tdbdump.c index 4ceef2d60c..a654c0fb31 100644 --- a/source4/lib/tdb/tools/tdbdump.c +++ b/source4/lib/tdb/tools/tdbdump.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "replace.h" diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index cf801d5dc5..580dd9d02a 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -8,7 +8,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -17,8 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "replace.h" -- cgit From 5c98bbe2f0a3ee60f5e9bdeb0588eebc7acc8ba2 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 12 Jul 2007 13:41:34 +0000 Subject: r23853: Fix a very misleading error message in tdbbackup. Michael (This used to be commit 1685057927e0ae37ed6be780ee0fb4b3bbefc00f) --- source4/lib/tdb/tools/tdbbackup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbbackup.c b/source4/lib/tdb/tools/tdbbackup.c index 2a75c44b1d..b9fbc41447 100644 --- a/source4/lib/tdb/tools/tdbbackup.c +++ b/source4/lib/tdb/tools/tdbbackup.c @@ -70,7 +70,7 @@ static int copy_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) TDB_CONTEXT *tdb_new = (TDB_CONTEXT *)state; if (tdb_store(tdb_new, key, dbuf, TDB_INSERT) != 0) { - fprintf(stderr,"Failed to insert into %s\n", tdb_name(tdb)); + fprintf(stderr,"Failed to insert into %s\n", tdb_name(tdb_new)); failed = 1; return 1; } -- cgit From a45166bae0947614ff1cbfce928879eafe284f3f Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 17 Jul 2007 10:30:13 +0000 Subject: r23925: Use NULL instead of 0 for a void * argument. (This used to be commit bf7774360bbcf557e3cbc4ef0c45f750b4ba89c3) --- source4/lib/tdb/tools/tdbbackup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbbackup.c b/source4/lib/tdb/tools/tdbbackup.c index b9fbc41447..a161085798 100644 --- a/source4/lib/tdb/tools/tdbbackup.c +++ b/source4/lib/tdb/tools/tdbbackup.c @@ -163,7 +163,7 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size) } /* traverse the new tdb to confirm */ - count2 = tdb_traverse(tdb_new, test_fn, 0); + count2 = tdb_traverse(tdb_new, test_fn, NULL); if (count2 != count1) { fprintf(stderr,"failed to copy %s\n", old_name); tdb_close(tdb_new); -- cgit From 5fa17c14a5f58312b63445636a904cbf79d10f21 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 18 Jul 2007 08:29:00 +0000 Subject: r23950: unlink before rename is superfluous. Michael (This used to be commit dc0104be9acfcd97f95388029a421204723b641a) --- source4/lib/tdb/tools/tdbbackup.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbbackup.c b/source4/lib/tdb/tools/tdbbackup.c index a161085798..dedfb9e665 100644 --- a/source4/lib/tdb/tools/tdbbackup.c +++ b/source4/lib/tdb/tools/tdbbackup.c @@ -177,7 +177,6 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size) /* close the new tdb and rename it to .bak */ tdb_close(tdb_new); - unlink(new_name); if (rename(tmp_name, new_name) != 0) { perror(new_name); free(tmp_name); -- cgit From 959915a8cbea0c598ef1f29ce666329a521ef2f6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 15:35:18 +0000 Subject: r25001: Fix more C++ and other warnings, fix some of the indentation with ts=4 lines that I accidently added earlier. (This used to be commit 0bcb21ed740fcec0f48ad36bbc2deee2948e8fc7) --- source4/lib/tdb/tools/tdbtorture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index 14a2b48cdc..ca71c736ad 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -238,7 +238,7 @@ static void usage(void) unlink("torture.tdb"); - pids = calloc(sizeof(pid_t), num_procs); + pids = (pid_t *)calloc(sizeof(pid_t), num_procs); pids[0] = getpid(); for (i=0;i Date: Wed, 7 Nov 2007 06:59:02 +0100 Subject: r25892: Keep the tdb code in sync between 3.2.x and 4.0. Add in the alarm fix to allow locks to exit on alarm signal. Sync up the changes in tools. Jeremy. (This used to be commit cb6c663fa8818f49cc36f196bb5f4dea47edd69e) --- source4/lib/tdb/tools/tdbbackup.c | 1 + source4/lib/tdb/tools/tdbdump.c | 1 + source4/lib/tdb/tools/tdbtool.c | 55 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 55 insertions(+), 2 deletions(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbbackup.c b/source4/lib/tdb/tools/tdbbackup.c index dedfb9e665..6f3ca48314 100644 --- a/source4/lib/tdb/tools/tdbbackup.c +++ b/source4/lib/tdb/tools/tdbbackup.c @@ -44,6 +44,7 @@ #include "system/locale.h" #include "system/time.h" #include "system/filesys.h" +#include "system/wait.h" #include "tdb.h" #ifdef HAVE_GETOPT_H diff --git a/source4/lib/tdb/tools/tdbdump.c b/source4/lib/tdb/tools/tdbdump.c index a654c0fb31..8d930383b0 100644 --- a/source4/lib/tdb/tools/tdbdump.c +++ b/source4/lib/tdb/tools/tdbdump.c @@ -21,6 +21,7 @@ #include "system/locale.h" #include "system/time.h" #include "system/filesys.h" +#include "system/wait.h" #include "tdb.h" static void print_data(TDB_DATA d) diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index 580dd9d02a..79435a3571 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -24,6 +24,7 @@ #include "system/locale.h" #include "system/time.h" #include "system/filesys.h" +#include "system/wait.h" #include "tdb.h" static int do_command(void); @@ -34,6 +35,7 @@ int bIterate = 0; char *line; TDB_DATA iterate_kbuf; char cmdline[1024]; +static int disable_mmap; enum commands { CMD_CREATE_TDB, @@ -50,6 +52,8 @@ enum commands { CMD_LIST_HASH_FREE, CMD_LIST_FREE, CMD_INFO, + CMD_MMAP, + CMD_SPEED, CMD_FIRST, CMD_NEXT, CMD_SYSTEM, @@ -77,6 +81,8 @@ COMMAND_TABLE cmd_table[] = { {"list", CMD_LIST_HASH_FREE}, {"free", CMD_LIST_FREE}, {"info", CMD_INFO}, + {"speed", CMD_SPEED}, + {"mmap", CMD_MMAP}, {"first", CMD_FIRST}, {"1", CMD_FIRST}, {"next", CMD_NEXT}, @@ -87,6 +93,20 @@ COMMAND_TABLE cmd_table[] = { {NULL, CMD_HELP} }; +struct timeval tp1,tp2; + +static void _start_timer(void) +{ + gettimeofday(&tp1,NULL); +} + +static double _end_timer(void) +{ + gettimeofday(&tp2,NULL); + return((tp2.tv_sec - tp1.tv_sec) + + (tp2.tv_usec - tp1.tv_usec)*1.0e-6); +} + /* a tdb tool for manipulating a tdb database */ static TDB_CONTEXT *tdb; @@ -175,7 +195,7 @@ static void terror(const char *why) static void create_tdb(const char *tdbname) { if (tdb) tdb_close(tdb); - tdb = tdb_open(tdbname, 0, TDB_CLEAR_IF_FIRST, + tdb = tdb_open(tdbname, 0, TDB_CLEAR_IF_FIRST | (disable_mmap?TDB_NOMMAP:0), O_RDWR | O_CREAT | O_TRUNC, 0600); if (!tdb) { printf("Could not create %s: %s\n", tdbname, strerror(errno)); @@ -185,7 +205,7 @@ static void create_tdb(const char *tdbname) static void open_tdb(const char *tdbname) { if (tdb) tdb_close(tdb); - tdb = tdb_open(tdbname, 0, 0, O_RDWR, 0600); + tdb = tdb_open(tdbname, 0, disable_mmap?TDB_NOMMAP:0, O_RDWR, 0600); if (!tdb) { printf("Could not open %s: %s\n", tdbname, strerror(errno)); } @@ -365,6 +385,31 @@ static void info_tdb(void) printf("%d records totalling %d bytes\n", count, total_bytes); } +static void speed_tdb(const char *tlimit) +{ + unsigned timelimit = tlimit?atoi(tlimit):0; + double t; + int ops=0; + if (timelimit == 0) timelimit = 10; + printf("Testing traverse speed for %u seconds\n", timelimit); + _start_timer(); + while ((t=_end_timer()) < timelimit) { + tdb_traverse(tdb, traverse_fn, NULL); + printf("%10.3f ops/sec\r", (++ops)/t); + } + printf("\n"); +} + +static void toggle_mmap(void) +{ + disable_mmap = !disable_mmap; + if (disable_mmap) { + printf("mmap is disabled\n"); + } else { + printf("mmap is enabled\n"); + } +} + static char *tdb_getline(const char *prompt) { static char thisline[1024]; @@ -493,6 +538,12 @@ static int do_command(void) case CMD_INFO: info_tdb(); return 0; + case CMD_SPEED: + speed_tdb(arg1); + return 0; + case CMD_MMAP: + toggle_mmap(); + return 0; case CMD_FIRST: bIterate = 1; first_record(tdb, &iterate_kbuf); -- cgit From 523445cdaa118fd9cb61d63d1a71a0762b98cdcf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 7 Nov 2007 07:13:44 +0100 Subject: r25893: Fix ldb, tdb builds (and one warning). Jeremy. (This used to be commit 52b26645b04a9c5fb70e7b869b60c9157f821d50) --- source4/lib/tdb/tools/tdbtorture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtorture.c b/source4/lib/tdb/tools/tdbtorture.c index ca71c736ad..9265cf07aa 100644 --- a/source4/lib/tdb/tools/tdbtorture.c +++ b/source4/lib/tdb/tools/tdbtorture.c @@ -3,10 +3,10 @@ */ #include "replace.h" -#include "tdb.h" #include "system/time.h" #include "system/wait.h" #include "system/filesys.h" +#include "tdb.h" #ifdef HAVE_GETOPT_H #include -- cgit From 61a015a786c52008f4471e62750ad93507bce518 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 18 Jan 2008 15:45:22 +1100 Subject: merged changes from v3-2-test (This used to be commit 7077df3e2e3f171532f6a5ac87d45201736c9c11) --- source4/lib/tdb/tools/tdbtool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index 79435a3571..d104ccd7c4 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -135,7 +135,7 @@ static void print_data(const char *buf,int len) if (len<=0) return; printf("[%03X] ",i); for (i=0;i Date: Tue, 8 Jul 2008 15:33:36 +0200 Subject: tdbtool: fix off-by-one error in argument length. (bug #2344) This prevented all commands operating on keys (all non-traverse commands) in tdbtool to fail with a "fetch failed" or "delete failed" message. It seems that it fixes bug #2344 ... Apparently this bug was introduced with 94e53472666ed in 2005. Either nobody is using tdbtool or else tdb_find() has become more strict about the key legth in the meantime. :-) Michael (This used to be commit fafb8ad2b81b9a46cf8259bedc1dca5023b06115) --- source4/lib/tdb/tools/tdbtool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index d104ccd7c4..500e441c6a 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -598,7 +598,7 @@ static char *convert_string(char *instring, size_t *sizep) } length++; } - *sizep = length; + *sizep = length + 1; return instring; } -- cgit From 1db2c047276fd9ba491c2ae45b81b50c6721b6b2 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 9 Jul 2008 12:48:05 +0200 Subject: Revert "tdbtool: fix off-by-one error in argument length. (bug #2344)" This reverts commit fafb8ad2b81b9a46cf8259bedc1dca5023b06115. This fix is not valid: 1. convert_string() is not only used for key strings but also for data. 2. Some databases use string_tdb_data() i.e. non-null-terminated strings as keynames and others (like the one I was using), use string_term_tdb_data(), i.e. zero-terminated key strings. After discussion with Metze, the easiest (and proper way) to handle this is to specify key names as "keyname\0" for databases which use string_term_tdb_data(). Sorry for the noise... Michael (This used to be commit 17c012c4645f4e9542537c15f80d9b4e74304d11) --- source4/lib/tdb/tools/tdbtool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/tdb/tools') diff --git a/source4/lib/tdb/tools/tdbtool.c b/source4/lib/tdb/tools/tdbtool.c index 500e441c6a..d104ccd7c4 100644 --- a/source4/lib/tdb/tools/tdbtool.c +++ b/source4/lib/tdb/tools/tdbtool.c @@ -598,7 +598,7 @@ static char *convert_string(char *instring, size_t *sizep) } length++; } - *sizep = length + 1; + *sizep = length; return instring; } -- cgit