• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/timemachine/db-4.7.25.NC/docs_src/ref/transapp/
1m4_ignore([dnl
2#include <sys/types.h>
3#include <sys/stat.h>
4
5#include <errno.h>
6#include <pthread.h>
7#include <stdarg.h>
8#include <stdlib.h>
9#include <string.h>
10#include <unistd.h>
11
12#include <db.h>
13
14void *logfile_thread(void *);
15
16DB_ENV *dbenv;
17pthread_t ptid;
18int ret;
19])
20m4_indent([dnl
21int
22main(int argc, char *argv[])
23{
24m4_cbold([dnl
25	/* Start a logfile removal thread. */
26	if ((ret = pthread_create(
27	    &ptid, NULL, logfile_thread, (void *)dbenv)) != 0) {
28		fprintf(stderr,
29		    "txnapp: failed spawning log file removal thread: %s\n",
30		    strerror(ret));
31		exit (1);
32	}])
33m4_ignore([return (0);])
34}
35m4_blank
36m4_cbold([dnl
37void *
38logfile_thread(void *arg)
39{
40	DB_ENV *dbenv;
41	int ret;
42	char **begin, **list;
43m4_blank
44	dbenv = arg;
45	dbenv-__GT__errx(dbenv,
46	    "Log file removal thread: %lu", (u_long)pthread_self());
47m4_blank
48	/* Check once every 5 minutes. */
49	for (;; sleep(300)) {
50		/* Get the list of log files. */
51		if ((ret = dbenv-__GT__log_archive(dbenv, &list, DB_ARCH_ABS)) != 0) {
52			dbenv-__GT__err(dbenv, ret, "DB_ENV-__GT__log_archive");
53			exit (1);
54		}
55m4_blank
56		/* Remove the log files. */
57		if (list != NULL) {
58			for (begin = list; *list != NULL; ++list)
59				if ((ret = remove(*list)) != 0) {
60					dbenv-__GT__err(dbenv,
61					    ret, "remove %s", *list);
62					exit (1);
63				}
64			free (begin);
65		}
66	}
67	/* NOTREACHED */
68}])])
69