-
Notifications
You must be signed in to change notification settings - Fork 1
/
simunvacation.c
124 lines (101 loc) · 2.69 KB
/
simunvacation.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright (c) Regents of The University of Michigan
* See COPYING.
*/
#include <config.h>
#include <ctype.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/time.h>
#include <syslog.h>
#include <unistd.h>
#include "simvacation.h"
#include "vdb.h"
#include "vlu.h"
#include "vutil.h"
void usage(void);
int
main(int argc, char **argv) {
int debug = 0;
extern int optind, opterr;
extern char *optarg;
char ch;
struct vlu_backend *vlu;
VLU * vluh = NULL;
struct vdb_backend *vdb;
VDB * vdbh = NULL;
char *config_file = NULL;
yastr uniqname;
ucl_object_iter_t i;
const ucl_object_t *uniqnames;
const ucl_object_t *obj;
while ((ch = getopt(argc, argv, "c:d")) != EOF) {
switch ((char)ch) {
case 'c':
config_file = optarg;
break;
case 'd':
debug = 1;
break;
case '?':
default:
usage();
}
}
if (debug) {
openlog("simunvacation", LOG_NOWAIT | LOG_PERROR | LOG_PID,
LOG_VACATION);
} else {
openlog("simunvacation", LOG_PID, LOG_VACATION);
}
if (read_vacation_config(config_file) != VAC_RESULT_OK) {
exit(1);
}
if ((vdb = vdb_backend(ucl_object_tostring(
ucl_object_lookup_path(vac_config, "core.vdb")))) == NULL) {
exit(1);
}
if ((vdbh = vdb->init("simunvacation")) == NULL) {
exit(1);
}
uniqnames = vdb->get_names(vdbh);
if ((vlu = vlu_backend(ucl_object_tostring(
ucl_object_lookup_path(vac_config, "core.vlu")))) == NULL) {
vdb->close(vdbh);
exit(1);
}
if ((vluh = vlu->init()) == NULL) {
vdb->close(vdbh);
exit(1);
}
i = ucl_object_iterate_new(uniqnames);
while ((obj = ucl_object_iterate_safe(i, false)) != NULL) {
uniqname = yaslauto(ucl_object_tostring(obj));
switch (vlu->search(vluh, uniqname)) {
case VAC_RESULT_PERMFAIL:
syslog(LOG_INFO, "cleaning up %s", uniqname);
vdb->clean(vdbh, uniqname);
break;
case VAC_RESULT_TEMPFAIL:
syslog(LOG_ERR, "lookup error processing %s", uniqname);
break;
default:
syslog(LOG_DEBUG, "leaving %s alone", uniqname);
break;
}
yaslfree(uniqname);
}
/* Vacuum the database. */
vdb->gc(vdbh);
vdb->close(vdbh);
vlu->close(vluh);
exit(0);
}
void
usage(void) {
fprintf(stderr, "usage: simunvacation [-c config_file] [-d]\n");
exit(1);
}