1 #include "../common/tdb_private.h"
2 #include "../common/io.c"
3 #include "../common/tdb.c"
4 #include "../common/lock.c"
5 #include "../common/freelist.c"
6 #include "../common/traverse.c"
7 #include "../common/transaction.c"
8 #include "../common/error.c"
9 #include "../common/open.c"
10 #include "../common/check.c"
11 #include "../common/hash.c"
12 #include "../common/mutex.c"
13 #include "tap-interface.h"
15 #include <sys/types.h>
20 static TDB_DATA key
, data
;
22 static void log_void(struct tdb_context
*tdb
, enum tdb_debug_level level
,
27 static void log_fn(struct tdb_context
*tdb
, enum tdb_debug_level level
,
32 vfprintf(stderr
, fmt
, ap
);
36 static int do_child(int fd
)
38 struct tdb_context
*tdb
;
39 unsigned int log_count
;
40 struct tdb_logging_context log_ctx
= { log_fn
, &log_count
};
41 struct tdb_logging_context nolog_ctx
= { log_void
, NULL
};
46 tdb
= tdb_open_ex("mutex-openflags2.tdb", 0,
48 O_RDWR
|O_CREAT
, 0755, &nolog_ctx
, NULL
);
49 ok((tdb
== NULL
) && (errno
== EINVAL
), "TDB_DEFAULT without "
50 "TDB_MUTEX_LOCKING should fail with EINVAL - %d", errno
);
52 tdb
= tdb_open_ex("mutex-openflags2.tdb", 0,
54 O_RDWR
|O_CREAT
, 0755, &nolog_ctx
, NULL
);
55 ok((tdb
== NULL
) && (errno
== EINVAL
), "TDB_CLEAR_IF_FIRST without "
56 "TDB_MUTEX_LOCKING should fail with EINVAL - %d", errno
);
58 tdb
= tdb_open_ex("mutex-openflags2.tdb", 0,
62 O_RDWR
|O_CREAT
, 0755, &nolog_ctx
, NULL
);
63 ok((tdb
== NULL
) && (errno
== EINVAL
), "TDB_MUTEX_LOCKING with "
64 "TDB_INTERNAL should fail with EINVAL - %d", errno
);
66 tdb
= tdb_open_ex("mutex-openflags2.tdb", 0,
70 O_RDWR
|O_CREAT
, 0755, &nolog_ctx
, NULL
);
71 ok((tdb
== NULL
) && (errno
== EINVAL
), "TDB_MUTEX_LOCKING with "
72 "TDB_NOMMAP should fail with EINVAL - %d", errno
);
74 tdb
= tdb_open_ex("mutex-openflags2.tdb", 0,
77 O_RDONLY
, 0755, &nolog_ctx
, NULL
);
78 ok((tdb
!= NULL
), "TDB_MUTEX_LOCKING with "
79 "O_RDONLY should work - %d", errno
);
82 tdb
= tdb_open_ex("mutex-openflags2.tdb", 0,
85 O_RDWR
|O_CREAT
, 0755, &log_ctx
, NULL
);
86 ok((tdb
!= NULL
), "TDB_MUTEX_LOCKING with TDB_CLEAR_IF_FIRST"
87 "TDB_NOMMAP should work - %d", errno
);
92 /* The code should barf on TDBs created with rwlocks. */
93 int main(int argc
, char *argv
[])
95 struct tdb_context
*tdb
;
96 unsigned int log_count
;
97 struct tdb_logging_context log_ctx
= { log_fn
, &log_count
};
98 struct tdb_logging_context nolog_ctx
= { log_void
, NULL
};
100 pid_t child
, wait_ret
;
103 bool runtime_support
;
105 runtime_support
= tdb_runtime_check_for_robust_mutexes();
110 key
.dsize
= strlen("hi");
111 key
.dptr
= discard_const_p(uint8_t, "hi");
112 data
.dsize
= strlen("world");
113 data
.dptr
= discard_const_p(uint8_t, "world");
115 if (!runtime_support
) {
116 tdb
= tdb_open_ex("mutex-openflags2.tdb", 0,
119 O_RDWR
|O_CREAT
, 0755, &nolog_ctx
, NULL
);
120 ok((tdb
== NULL
) && (errno
== ENOSYS
), "TDB_MUTEX_LOCKING without "
121 "runtime support should fail with ENOSYS - %d", errno
);
123 skip(1, "No robust mutex support");
124 return exit_status();
129 return do_child(pipefd
[0]);
132 tdb
= tdb_open_ex("mutex-openflags2.tdb", 0,
135 O_RDWR
|O_CREAT
, 0755, &log_ctx
, NULL
);
136 ok((tdb
!= NULL
), "tdb_open_ex with mutexes should succeed");
138 write(pipefd
[1], &c
, 1);
140 wait_ret
= wait(&status
);
141 ok((wait_ret
== child
) && (status
== 0),
142 "child should have exited correctly");
145 return exit_status();