1 /*
2 Lock a tdb and sleep
3
4 Copyright (C) Amitay Isaacs 2012
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "replace.h"
21 #include "system/filesys.h"
22
23 #include <tdb.h>
24
25 const char *tdb_file;
26 TDB_CONTEXT *tdb;
27
signal_handler(int signum)28 static void signal_handler(int signum)
29 {
30 tdb_close(tdb);
31 }
32
33 int
main(int argc,char * argv[])34 main(int argc, char *argv[])
35 {
36 if (argc != 2) {
37 printf("Usage: %s <tdb file>\n", argv[0]);
38 exit(1);
39 }
40
41 tdb_file = argv[1];
42
43 tdb = tdb_open(tdb_file, 0, 0, O_RDWR, 0);
44 if (tdb == NULL) {
45 fprintf(stderr, "Failed to open TDB file %s\n", tdb_file);
46 exit(1);
47 }
48
49 signal(SIGINT, signal_handler);
50
51 if (tdb_lockall(tdb) != 0) {
52 fprintf(stderr, "Failed to lock database %s\n", tdb_file);
53 tdb_close(tdb);
54 exit(1);
55 }
56
57 sleep(999999);
58
59 return 0;
60 }
61