|
rpm-build |
ca8475 |
#include "../common/tdb_private.h"
|
|
rpm-build |
ca8475 |
#include "../common/io.c"
|
|
rpm-build |
ca8475 |
#include "../common/tdb.c"
|
|
rpm-build |
ca8475 |
#include "../common/lock.c"
|
|
rpm-build |
ca8475 |
#include "../common/freelist.c"
|
|
rpm-build |
ca8475 |
#include "../common/traverse.c"
|
|
rpm-build |
ca8475 |
#include "../common/transaction.c"
|
|
rpm-build |
ca8475 |
#include "../common/error.c"
|
|
rpm-build |
ca8475 |
#include "../common/open.c"
|
|
rpm-build |
ca8475 |
#include "../common/check.c"
|
|
rpm-build |
ca8475 |
#include "../common/hash.c"
|
|
rpm-build |
ca8475 |
#include "../common/mutex.c"
|
|
rpm-build |
ca8475 |
#include "tap-interface.h"
|
|
rpm-build |
ca8475 |
#include <stdlib.h>
|
|
rpm-build |
ca8475 |
#include <sys/types.h>
|
|
rpm-build |
ca8475 |
#include <sys/wait.h>
|
|
rpm-build |
ca8475 |
#include <stdarg.h>
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
static TDB_DATA key, data;
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
static void log_fn(struct tdb_context *tdb, enum tdb_debug_level level,
|
|
rpm-build |
ca8475 |
const char *fmt, ...)
|
|
rpm-build |
ca8475 |
{
|
|
rpm-build |
ca8475 |
va_list ap;
|
|
rpm-build |
ca8475 |
va_start(ap, fmt);
|
|
rpm-build |
ca8475 |
vfprintf(stderr, fmt, ap);
|
|
rpm-build |
ca8475 |
va_end(ap);
|
|
rpm-build |
ca8475 |
}
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
static int do_child(int tdb_flags, int to, int from)
|
|
rpm-build |
ca8475 |
{
|
|
rpm-build |
ca8475 |
struct tdb_context *tdb;
|
|
rpm-build |
ca8475 |
unsigned int log_count;
|
|
rpm-build |
ca8475 |
struct tdb_logging_context log_ctx = { log_fn, &log_count };
|
|
rpm-build |
ca8475 |
int ret;
|
|
rpm-build |
ca8475 |
char c = 0;
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
tdb = tdb_open_ex("mutex1.tdb", 0, tdb_flags,
|
|
rpm-build |
ca8475 |
O_RDWR|O_CREAT, 0755, &log_ctx, NULL);
|
|
rpm-build |
ca8475 |
ok(tdb, "tdb_open_ex should succeed");
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
ret = tdb_chainlock(tdb, key);
|
|
rpm-build |
ca8475 |
ok(ret == 0, "tdb_chainlock should succeed");
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
write(to, &c, sizeof(c));
|
|
rpm-build |
ca8475 |
read(from, &c, sizeof(c));
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
ret = tdb_chainunlock(tdb, key);
|
|
rpm-build |
ca8475 |
ok(ret == 0, "tdb_chainunlock should succeed");
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
write(to, &c, sizeof(c));
|
|
rpm-build |
ca8475 |
read(from, &c, sizeof(c));
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
ret = tdb_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_WAIT, false);
|
|
rpm-build |
ca8475 |
ok(ret == 0, "tdb_allrecord_lock should succeed");
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
write(to, &c, sizeof(c));
|
|
rpm-build |
ca8475 |
read(from, &c, sizeof(c));
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
ret = tdb_allrecord_unlock(tdb, F_WRLCK, false);
|
|
rpm-build |
ca8475 |
ok(ret == 0, "tdb_allrecord_lock should succeed");
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
return 0;
|
|
rpm-build |
ca8475 |
}
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
/* The code should barf on TDBs created with rwlocks. */
|
|
rpm-build |
ca8475 |
int main(int argc, char *argv[])
|
|
rpm-build |
ca8475 |
{
|
|
rpm-build |
ca8475 |
struct tdb_context *tdb;
|
|
rpm-build |
ca8475 |
unsigned int log_count;
|
|
rpm-build |
ca8475 |
struct tdb_logging_context log_ctx = { log_fn, &log_count };
|
|
rpm-build |
ca8475 |
int ret, status;
|
|
rpm-build |
ca8475 |
pid_t child, wait_ret;
|
|
rpm-build |
ca8475 |
int fromchild[2];
|
|
rpm-build |
ca8475 |
int tochild[2];
|
|
rpm-build |
ca8475 |
char c;
|
|
rpm-build |
ca8475 |
int tdb_flags;
|
|
rpm-build |
ca8475 |
bool runtime_support;
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
runtime_support = tdb_runtime_check_for_robust_mutexes();
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
if (!runtime_support) {
|
|
rpm-build |
ca8475 |
skip(1, "No robust mutex support");
|
|
rpm-build |
ca8475 |
return exit_status();
|
|
rpm-build |
ca8475 |
}
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
key.dsize = strlen("hi");
|
|
rpm-build |
ca8475 |
key.dptr = discard_const_p(uint8_t, "hi");
|
|
rpm-build |
ca8475 |
data.dsize = strlen("world");
|
|
rpm-build |
ca8475 |
data.dptr = discard_const_p(uint8_t, "world");
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
pipe(fromchild);
|
|
rpm-build |
ca8475 |
pipe(tochild);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
tdb_flags = TDB_INCOMPATIBLE_HASH|
|
|
rpm-build |
ca8475 |
TDB_MUTEX_LOCKING|
|
|
rpm-build |
ca8475 |
TDB_CLEAR_IF_FIRST;
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
child = fork();
|
|
rpm-build |
ca8475 |
if (child == 0) {
|
|
rpm-build |
ca8475 |
close(fromchild[0]);
|
|
rpm-build |
ca8475 |
close(tochild[1]);
|
|
rpm-build |
ca8475 |
return do_child(tdb_flags, fromchild[1], tochild[0]);
|
|
rpm-build |
ca8475 |
}
|
|
rpm-build |
ca8475 |
close(fromchild[1]);
|
|
rpm-build |
ca8475 |
close(tochild[0]);
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
read(fromchild[0], &c, sizeof(c));
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
tdb = tdb_open_ex("mutex1.tdb", 0, tdb_flags,
|
|
rpm-build |
ca8475 |
O_RDWR|O_CREAT, 0755, &log_ctx, NULL);
|
|
rpm-build |
ca8475 |
ok(tdb, "tdb_open_ex should succeed");
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
write(tochild[1], &c, sizeof(c));
|
|
rpm-build |
ca8475 |
read(fromchild[0], &c, sizeof(c));
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
ret = tdb_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_WAIT, false);
|
|
rpm-build |
ca8475 |
ok(ret == 0, "tdb_allrecord_lock should succeed");
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
ret = tdb_store(tdb, key, data, 0);
|
|
rpm-build |
ca8475 |
ok(ret == 0, "tdb_store should succeed");
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
ret = tdb_allrecord_unlock(tdb, F_WRLCK, false);
|
|
rpm-build |
ca8475 |
ok(ret == 0, "tdb_allrecord_unlock should succeed");
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
write(tochild[1], &c, sizeof(c));
|
|
rpm-build |
ca8475 |
read(fromchild[0], &c, sizeof(c));
|
|
rpm-build |
ca8475 |
write(tochild[1], &c, sizeof(c));
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
ret = tdb_delete(tdb, key);
|
|
rpm-build |
ca8475 |
ok(ret == 0, "tdb_delete should succeed");
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
wait_ret = wait(&status);
|
|
rpm-build |
ca8475 |
ok(wait_ret == child, "child should have exited correctly");
|
|
rpm-build |
ca8475 |
|
|
rpm-build |
ca8475 |
diag("done");
|
|
rpm-build |
ca8475 |
return exit_status();
|
|
rpm-build |
ca8475 |
}
|