Lines 9-33
Link Here
|
9 |
|
9 |
|
10 |
#ifdef APPLET_qcheck |
10 |
#ifdef APPLET_qcheck |
11 |
|
11 |
|
12 |
#define QCHECK_FLAGS "eauAHTB" COMMON_FLAGS |
12 |
#define QCHECK_FLAGS "aes:uABHT" COMMON_FLAGS |
13 |
static struct option const qcheck_long_opts[] = { |
13 |
static struct option const qcheck_long_opts[] = { |
14 |
{"exact", no_argument, NULL, 'e'}, |
|
|
15 |
{"all", no_argument, NULL, 'a'}, |
14 |
{"all", no_argument, NULL, 'a'}, |
|
|
15 |
{"exact", no_argument, NULL, 'e'}, |
16 |
{"skip", a_argument, NULL, 's'}, |
16 |
{"update", no_argument, NULL, 'u'}, |
17 |
{"update", no_argument, NULL, 'u'}, |
17 |
{"noafk", no_argument, NULL, 'A'}, |
18 |
{"noafk", no_argument, NULL, 'A'}, |
|
|
19 |
{"badonly", no_argument, NULL, 'B'}, |
18 |
{"nohash", no_argument, NULL, 'H'}, |
20 |
{"nohash", no_argument, NULL, 'H'}, |
19 |
{"nomtime", no_argument, NULL, 'T'}, |
21 |
{"nomtime", no_argument, NULL, 'T'}, |
20 |
{"badonly", no_argument, NULL, 'B'}, |
|
|
21 |
COMMON_LONG_OPTS |
22 |
COMMON_LONG_OPTS |
22 |
}; |
23 |
}; |
23 |
static const char *qcheck_opts_help[] = { |
24 |
static const char *qcheck_opts_help[] = { |
24 |
"Exact match (only CAT/PN or PN without PV)", |
|
|
25 |
"List all packages", |
25 |
"List all packages", |
|
|
26 |
"Exact match (only CAT/PN or PN without PV)", |
27 |
"Ignore files matching the regular expression <arg>", |
26 |
"Update missing files, chksum and mtimes for packages", |
28 |
"Update missing files, chksum and mtimes for packages", |
27 |
"Ignore missing files", |
29 |
"Ignore missing files", |
|
|
30 |
"Only print pkgs containing bad files", |
28 |
"Ignore differing/unknown file chksums", |
31 |
"Ignore differing/unknown file chksums", |
29 |
"Ignore differing file mtimes", |
32 |
"Ignore differing file mtimes", |
30 |
"Only print pkgs containing bad files excluding /etc.", |
|
|
31 |
COMMON_OPTS_HELP |
33 |
COMMON_OPTS_HELP |
32 |
}; |
34 |
}; |
33 |
static const char qcheck_rcsid[] = "$Id: qcheck.c,v 1.42 2010/01/13 18:17:23 vapier Exp $"; |
35 |
static const char qcheck_rcsid[] = "$Id: qcheck.c,v 1.42 2010/01/13 18:17:23 vapier Exp $"; |
Lines 36-41
Link Here
|
36 |
short bad_only = 0; |
38 |
short bad_only = 0; |
37 |
#define qcprintf(fmt, args...) if (!bad_only) printf( _( fmt ), ## args) |
39 |
#define qcprintf(fmt, args...) if (!bad_only) printf( _( fmt ), ## args) |
38 |
|
40 |
|
|
|
41 |
static void qcheck_cleanup(regex_t **regex_head, const size_t regex_count) |
42 |
{ |
43 |
size_t i; |
44 |
if (regex_head == NULL) { |
45 |
return; |
46 |
} |
47 |
for (i = 0; i < regex_count; i++) { |
48 |
regfree(regex_head[i]); |
49 |
free(regex_head[i]); |
50 |
} |
51 |
free(regex_head); |
52 |
} |
53 |
|
39 |
int qcheck_main(int argc, char **argv) |
54 |
int qcheck_main(int argc, char **argv) |
40 |
{ |
55 |
{ |
41 |
DIR *dir, *dirp; |
56 |
DIR *dir, *dirp; |
Lines 50-55
Link Here
|
50 |
size_t num_files, num_files_ok, num_files_unknown, num_files_ignored; |
65 |
size_t num_files, num_files_ok, num_files_unknown, num_files_ignored; |
51 |
char buf[_Q_PATH_MAX], filename[_Q_PATH_MAX]; |
66 |
char buf[_Q_PATH_MAX], filename[_Q_PATH_MAX]; |
52 |
char buffer[_Q_PATH_MAX]; |
67 |
char buffer[_Q_PATH_MAX]; |
|
|
68 |
regex_t **regex_head = NULL; |
69 |
size_t regex_count = 0; |
53 |
|
70 |
|
54 |
DBG("argc=%d argv[0]=%s argv[1]=%s", |
71 |
DBG("argc=%d argv[0]=%s argv[1]=%s", |
55 |
argc, argv[0], argc > 1 ? argv[1] : "NULL?"); |
72 |
argc, argv[0], argc > 1 ? argv[1] : "NULL?"); |
Lines 57-78
Link Here
|
57 |
while ((i = GETOPT_LONG(QCHECK, qcheck, "")) != -1) { |
74 |
while ((i = GETOPT_LONG(QCHECK, qcheck, "")) != -1) { |
58 |
switch (i) { |
75 |
switch (i) { |
59 |
COMMON_GETOPTS_CASES(qcheck) |
76 |
COMMON_GETOPTS_CASES(qcheck) |
60 |
case 'e': exact = 1; break; |
|
|
61 |
case 'a': search_all = 1; break; |
77 |
case 'a': search_all = 1; break; |
|
|
78 |
case 'e': exact = 1; break; |
79 |
case 's': { |
80 |
int regex_val; |
81 |
regex_head = (regex_t **) xrealloc(regex_head, |
82 |
(regex_count + 1) * sizeof(regex_t *)); |
83 |
regex_head[regex_count] = (regex_t *) xmalloc(sizeof(regex_t)); |
84 |
regex_val = regcomp(regex_head[regex_count], optarg, |
85 |
REG_EXTENDED|REG_NOSUB); |
86 |
if (regex_val != 0) { |
87 |
char errbuf[256]; |
88 |
if (regerror(regex_val, regex_head[regex_count], errbuf, |
89 |
sizeof(errbuf))) { |
90 |
qcheck_cleanup(regex_head, regex_count + 1); |
91 |
err("Invalid regexp: %s -- %s\n", optarg, errbuf); |
92 |
} else { |
93 |
qcheck_cleanup(regex_head, regex_count + 1); |
94 |
err("Invalid regexp: %s\n", optarg); |
95 |
} |
96 |
} |
97 |
regex_count++; |
98 |
} |
99 |
break; |
62 |
case 'u': qc_update = 1; break; |
100 |
case 'u': qc_update = 1; break; |
63 |
case 'A': chk_afk = 0; break; |
101 |
case 'A': chk_afk = 0; break; |
|
|
102 |
case 'B': bad_only = 1; break; |
64 |
case 'H': chk_hash = 0; break; |
103 |
case 'H': chk_hash = 0; break; |
65 |
case 'T': chk_mtime = 0; break; |
104 |
case 'T': chk_mtime = 0; break; |
66 |
case 'B': bad_only = 1; break; |
|
|
67 |
} |
105 |
} |
68 |
} |
106 |
} |
69 |
if ((argc == optind) && !search_all) |
107 |
if ((argc == optind) && !search_all) { |
|
|
108 |
qcheck_cleanup(regex_head, regex_count); |
70 |
qcheck_usage(EXIT_FAILURE); |
109 |
qcheck_usage(EXIT_FAILURE); |
|
|
110 |
} |
71 |
|
111 |
|
72 |
xchdir(portroot); |
112 |
xchdir(portroot); |
73 |
xchdir(portvdb); |
113 |
xchdir(portvdb); |
74 |
if ((dir = opendir(".")) == NULL) |
114 |
if ((dir = opendir(".")) == NULL) { |
|
|
115 |
qcheck_cleanup(regex_head, regex_count); |
75 |
return EXIT_FAILURE; |
116 |
return EXIT_FAILURE; |
|
|
117 |
} |
76 |
|
118 |
|
77 |
/* open /var/db/pkg */ |
119 |
/* open /var/db/pkg */ |
78 |
while ((dentry = q_vdb_get_next_dir(dir))) { |
120 |
while ((dentry = q_vdb_get_next_dir(dir))) { |
Lines 138-146
Link Here
|
138 |
e = contents_parse_line(buf); |
180 |
e = contents_parse_line(buf); |
139 |
if (!e) |
181 |
if (!e) |
140 |
continue; |
182 |
continue; |
141 |
if (bad_only && strncmp(e->name, "/etc", 4) == 0) { |
|
|
142 |
continue; |
143 |
} |
144 |
if (strcmp(portroot, "/") != 0) { |
183 |
if (strcmp(portroot, "/") != 0) { |
145 |
snprintf(filename, sizeof(filename), "%s%s", portroot, e->name); |
184 |
snprintf(filename, sizeof(filename), "%s%s", portroot, e->name); |
146 |
e->name = filename; |
185 |
e->name = filename; |
Lines 148-153
Link Here
|
148 |
|
187 |
|
149 |
/* run our little checks */ |
188 |
/* run our little checks */ |
150 |
++num_files; |
189 |
++num_files; |
|
|
190 |
if (regex_count > 0) { |
191 |
char match = 0; |
192 |
size_t j; |
193 |
for (j = 0; j < regex_count; j++) { |
194 |
if (regexec(regex_head[j], e->name, 0, NULL, 0) == 0) { |
195 |
match = 1; |
196 |
break; |
197 |
} |
198 |
} |
199 |
if (match == 1) { |
200 |
--num_files; |
201 |
++num_files_ignored; |
202 |
continue; |
203 |
} |
204 |
} |
151 |
if (lstat(e->name, &st)) { |
205 |
if (lstat(e->name, &st)) { |
152 |
/* make sure file exists */ |
206 |
/* make sure file exists */ |
153 |
if (chk_afk) { |
207 |
if (chk_afk) { |
Lines 302-307
Link Here
|
302 |
xchdir(".."); |
356 |
xchdir(".."); |
303 |
} |
357 |
} |
304 |
|
358 |
|
|
|
359 |
qcheck_cleanup(regex_head, regex_count); |
305 |
return EXIT_SUCCESS; |
360 |
return EXIT_SUCCESS; |
306 |
} |
361 |
} |
307 |
|
362 |
|