summaryrefslogtreecommitdiffstats
path: root/examples/code/modules/sample-module/templates
diff options
context:
space:
mode:
Diffstat (limited to 'examples/code/modules/sample-module/templates')
0 files changed, 0 insertions, 0 deletions
2'>62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#include "config.h"
#include "ntdb.h"
#include "private.h"
#include "tap-interface.h"
#include "external-agent.h"
#include "logging.h"

#define KEY_STR "key"

static enum NTDB_ERROR clear_if_first(int fd, void *arg)
{
/* We hold a lock offset 4 always, so we can tell if anyone is holding it.
 * (This is compatible with tdb's TDB_CLEAR_IF_FIRST flag).  */
	struct flock fl;

	if (arg != clear_if_first)
		return NTDB_ERR_CORRUPT;

	fl.l_type = F_WRLCK;
	fl.l_whence = SEEK_SET;
	fl.l_start = 4;
	fl.l_len = 1;

	if (fcntl(fd, F_SETLK, &fl) == 0) {
		/* We must be first ones to open it! */
		diag("truncating file!");
		if (ftruncate(fd, 0) != 0) {
			return NTDB_ERR_IO;
		}
	}
	fl.l_type = F_RDLCK;
	if (fcntl(fd, F_SETLKW, &fl) != 0) {
		return NTDB_ERR_IO;
	}
	return NTDB_SUCCESS;
}

int main(int argc, char *argv[])
{
	unsigned int i;
	struct ntdb_context *ntdb, *ntdb2;
	struct agent *agent;
	union ntdb_attribute cif;
	NTDB_DATA key = ntdb_mkdata(KEY_STR, strlen(KEY_STR));
	int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
			NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };

	cif.openhook.base.attr = NTDB_ATTRIBUTE_OPENHOOK;
	cif.openhook.base.next = &tap_log_attr;
	cif.openhook.fn = clear_if_first;
	cif.openhook.data = clear_if_first;

	agent = prepare_external_agent();