Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
9132d16a
Commit
9132d16a
authored
Oct 19, 2009
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tdb: use logging and tdb_check in tdbtool
parent
1122f6d4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
17 deletions
+25
-17
ccan/tdb/tools/tdbtool.c
ccan/tdb/tools/tdbtool.c
+25
-17
No files found.
ccan/tdb/tools/tdbtool.c
View file @
9132d16a
...
...
@@ -30,6 +30,7 @@
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdarg.h>
static
int
do_command
(
void
);
const
char
*
cmdname
;
...
...
@@ -119,6 +120,15 @@ static double _end_timer(void)
(
tp2
.
tv_usec
-
tp1
.
tv_usec
)
*
1.0e-6
);
}
static
void
tdb_log
(
struct
tdb_context
*
tdb
,
enum
tdb_debug_level
level
,
const
char
*
format
,
...)
{
va_list
ap
;
va_start
(
ap
,
format
);
vfprintf
(
stderr
,
format
,
ap
);
va_end
(
ap
);
}
/* a tdb tool for manipulating a tdb database */
static
TDB_CONTEXT
*
tdb
;
...
...
@@ -211,9 +221,12 @@ static void terror(const char *why)
static
void
create_tdb
(
const
char
*
tdbname
)
{
struct
tdb_logging_context
log_ctx
;
log_ctx
.
log_fn
=
tdb_log
;
if
(
tdb
)
tdb_close
(
tdb
);
tdb
=
tdb_open
(
tdbname
,
0
,
TDB_CLEAR_IF_FIRST
|
(
disable_mmap
?
TDB_NOMMAP
:
0
),
O_RDWR
|
O_CREAT
|
O_TRUNC
,
0600
);
tdb
=
tdb_open
_ex
(
tdbname
,
0
,
TDB_CLEAR_IF_FIRST
|
(
disable_mmap
?
TDB_NOMMAP
:
0
),
O_RDWR
|
O_CREAT
|
O_TRUNC
,
0600
,
&
log_ctx
,
NULL
);
if
(
!
tdb
)
{
printf
(
"Could not create %s: %s
\n
"
,
tdbname
,
strerror
(
errno
));
}
...
...
@@ -221,8 +234,12 @@ static void create_tdb(const char *tdbname)
static
void
open_tdb
(
const
char
*
tdbname
)
{
struct
tdb_logging_context
log_ctx
;
log_ctx
.
log_fn
=
tdb_log
;
if
(
tdb
)
tdb_close
(
tdb
);
tdb
=
tdb_open
(
tdbname
,
0
,
disable_mmap
?
TDB_NOMMAP
:
0
,
O_RDWR
,
0600
);
tdb
=
tdb_open_ex
(
tdbname
,
0
,
disable_mmap
?
TDB_NOMMAP
:
0
,
O_RDWR
,
0600
,
&
log_ctx
,
NULL
);
if
(
!
tdb
)
{
printf
(
"Could not open %s: %s
\n
"
,
tdbname
,
strerror
(
errno
));
}
...
...
@@ -522,24 +539,15 @@ static void next_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey)
print_rec
(
the_tdb
,
*
pkey
,
dbuf
,
NULL
);
}
static
int
test_fn
(
TDB_CONTEXT
*
the_tdb
,
TDB_DATA
key
,
TDB_DATA
dbuf
,
void
*
state
)
{
return
0
;
}
static
void
check_db
(
TDB_CONTEXT
*
the_tdb
)
{
int
tdbcount
=-
1
;
if
(
the_tdb
)
{
tdbcount
=
tdb_traverse
(
the_tdb
,
test_fn
,
NULL
);
}
else
{
if
(
!
the_tdb
)
{
printf
(
"Error: No database opened!
\n
"
);
}
if
(
tdbcount
<
0
)
{
printf
(
"Integrity check for the opened database failed.
\n
"
);
}
else
{
printf
(
"Database integrity is OK and has %d records.
\n
"
,
tdbcount
);
if
(
tdb_check
(
the_tdb
,
NULL
,
NULL
)
==
-
1
)
printf
(
"Integrity check for the opened database failed.
\n
"
);
else
printf
(
"Database integrity is OK.
\n
"
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment