Debian Codegraph @

src/db_disk.c

raw symbols SCIP
1 /*
2 * AIDE (Advanced Intrusion Detection Environment)
3 *
4 * Copyright (C) 1999-2006, 2010-2011, 2016-2017, 2019-2025 Rami Lehti,
5 * Pablo Virolainen, Mike Markley, Richard van den Berg,
6 * Hannes von Haugwitz
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #include "config.h"cxx . . $ `<file>/include/config.h`/
24 #include <dirent.h>
25 #include <errno.h>
26 #include <fcntl.h>
27 #include <pthread.h>
28 #include <stdbool.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <sys/stat.h>
33 #ifdef HAVE_FSTYPEcxx . . $ `include/config.h:53:9`!
34 #include <sys/vfs.h>
35 #endif
36 #include <unistd.h>
37 #include "aide.h"cxx . . $ `<file>/include/aide.h`/
38 #include "attributes.h"cxx . . $ `<file>/include/attributes.h`/
39 #include "do_md.h"cxx . . $ `<file>/include/do_md.h`/
40 #include "db.h"cxx . . $ `<file>/include/db.h`/
41 #include "db_config.h"cxx . . $ `<file>/include/db_config.h`/
42 #include "db_disk.h"cxx . . $ `<file>/include/db_disk.h`/
43 #include "db_line.h"cxx . . $ `<file>/include/db_line.h`/
44 #include "errorcodes.h"cxx . . $ `<file>/include/errorcodes.h`/
45 #include "file.h"cxx . . $ `<file>/include/file.h`/
46 #include "gen_list.h"cxx . . $ `<file>/include/gen_list.h`/
47 #include "log.h"cxx . . $ `<file>/include/log.h`/
48 #include "queue.h"cxx . . $ `<file>/include/queue.h`/
49 #include "rx_rule.h"cxx . . $ `<file>/include/rx_rule.h`/
50 #include "seltree_struct.h"cxx . . $ `<file>/include/seltree_struct.h`/
51 #include "util.h"cxx . . $ `<file>/include/util.h`/
52
53 queue_ts_tcxx . . $ queue_ts_t# *queue_worker_entriescxx . . $ queue_worker_entries. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
54
55 struct worker_argscxx . . $ worker_args# {
56 long worker_indexcxx . . $ worker_args#worker_index.;
57 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! dry_runcxx . . $ worker_args#dry_run.;
58 };
59
60 typedef struct worker_threadcxx . . $ worker_thread# {
61 pthread_tcxx . . $ pthread_t# threadcxx . . $ worker_thread#thread.;
62 struct worker_argscxx . . $ worker_args# argscxx . . $ worker_thread#args.;
63 } worker_threadcxx . . $ worker_thread#;
64
65 static char *name_constructcxx . . $ name_construct(a713fe7b9a57cf96). (const char *dirpath, const char *filename) {
66 int dirpath_len = strlencxx . . $ strlen(751346f8406fd082). (dirpath);
67 int len = dirpath_len + strlencxx . . $ strlen(751346f8406fd082).(filename) + (dirpath[dirpath_len-1] != '/'?1:0) + 1;
68 char *ret = checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(len);
69 snprintfcxx . . $ snprintf(ea502d73e74c754c).(ret, len, "%s%s%s", dirpath, dirpath[dirpath_len-1] != '/'?"/":"", filename);
70 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_TRACEcxx . . $ LOG_LEVEL_TRACE.,"name_construct: dir: '%s' (%p) + filename: '%s' (%p): '%s' (%p)", dirpath, (void*) dirpath, filename, (void*) filename, ret, (void*) ret);
71 return ret;
72 }
73
74 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! open_for_readingcxx . . $ open_for_reading(b003e59a46c5d1d3).(disk_entrycxx . . $ disk_entry# *entry, boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! dir_rec, const char *whoami) {
75 int fd = -1;
76 struct statcxx . . $ stat# fs;
77 char* failure_str = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
78 char* error_str = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
79
80 DB_ATTR_TYPEcxx . . $ `include/attributes.h:25:9`! attrs_req_read = entry->attrscxx . . $ disk_entry#attrs. & (get_hashescxx . . $ get_hashes(48b6f722ee11d9bd).(falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)
81 #ifdef WITH_E2FSATTRS
82 | ATTR(attr_e2fsattrs)
83 #endif
84 #ifndef O_PATHcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:148:10`!
85 #ifdef WITH_POSIX_ACL
86 | ATTR(attr_acl)
87 #endif
88 #ifdef WITH_XATTR
89 | ATTR(attr_xattrs)
90 #endif
91 #ifdef WITH_CAPABILITIES
92 | ATTR(attr_capabilities)
93 #endif
94 #endif
95 );
96 if (attrs_req_read || dir_rec) {
97 #ifdef O_NOATIMEcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:147:10`!
98 if ((fd = opencxx . . $ open(e156e3aa1e5c4ad1).(entry->filenamecxx . . $ disk_entry#filename., O_NOFOLLOWcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:141:10`! | O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`! | O_NOATIMEcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:147:10`! | O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!)) == -1) {
99 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "%s> open() with O_NOATIME flag failed: %s (retrying without O_NOATIME)", entry->filename, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
100 #endif
101 fd = opencxx . . $ open(e156e3aa1e5c4ad1).(entry->filenamecxx . . $ disk_entry#filename., O_NOFOLLOWcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:141:10`! | O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`! | O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!);
102 #ifdef O_NOATIMEcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:147:10`!
103 }
104 #endif
105 if (fd == -1) {
106 failure_str = "open() failed";
107 error_str = checked_strdupcxx . . $ checked_strdup(42228c1987407501).(strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
108 } else {
109 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_TRACE, "%s> open() returned O_RDONLY fd %d", entry->filename, fd);
110 if (fstatcxx . . $ fstat(a43660ce2f600cb5).(fd, &fs) != 0) {
111 failure_str = "fstat() failed";
112 error_str = checked_strdupcxx . . $ checked_strdup(42228c1987407501).(strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
113 if (closecxx . . $ close(7864480464b09eea).(fd) < 0) {
114 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "close() failed for '%s' (fd: %d): %s", entry->filenamecxx . . $ disk_entry#filename., fd, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
115 }
116 fd = -1;
117 } else {
118 if(!(entry->attrscxx . . $ disk_entry#attrs.&ATTRcxx . . $ `include/attributes.h:28:9`!(attr_rdev))) {
119 fs.st_rdevcxx . . $ stat#st_rdev.=0;
120 }
121 DB_ATTR_TYPEcxx . . $ `include/attributes.h:25:9`! stat_diff;
122 if ((stat_diff = stat_cmpcxx . . $ stat_cmp(5f41c328ced4dd81).(&entry->fscxx . . $ disk_entry#fs., &fs, entry->attrscxx . . $ disk_entry#attrs.&ATTRcxx . . $ `include/attributes.h:28:9`!(attr_growing))) != RETOKcxx . . $ `include/db_config.h:45:9`!) {
123 failure_str = "stat fields changed";
124 error_str = diff_attributescxx . . $ diff_attributes(39cd1df6f24d7ad6).(0, stat_diff);
125 if (closecxx . . $ close(7864480464b09eea).(fd) < 0) {
126 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "close() failed for '%s' (fd: %d): %s", entry->filenamecxx . . $ disk_entry#filename., fd, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
127 }
128 fd = -1;
129 }
130 }
131 }
132
133 if (fd == -1) {
134 char *attrs_str = diff_attributescxx . . $ diff_attributes(39cd1df6f24d7ad6).(0, attrs_req_read);
135 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING.,
136 "failed to open %s '%s' for reading: %s: %s (%s%s%s%s)",
137 get_f_type_string_from_permcxx . . $ get_f_type_string_from_perm(f109d7e0a0ca42b3).(entry->fscxx . . $ disk_entry#fs..st_modecxx . . $ stat#st_mode.), entry->filenamecxx . . $ disk_entry#filename.,
138 failure_str,
139 error_str,
140 dir_rec ? "skipping recursion" : "",
141 dir_rec && attrs_req_read ? ", " : "",
142 attrs_req_read ? "disabling attrs requiring read permissions: " : "",
143 attrs_req_read ? attrs_str : ""
144 );
145 freecxx . . $ free(5d22bdacc48458e8).(error_str);
146 freecxx . . $ free(5d22bdacc48458e8).(attrs_str);
147 entry->attrscxx . . $ disk_entry#attrs. &= ~attrs_req_read;
148 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
149 } else {
150 if (entry->fdcxx . . $ disk_entry#fd. >= 0) {
151 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_TRACE, "%s> replace O_PATH fd %d with O_RDONLY fd %d", entry->filename, entry->fd, fd);
152 if (closecxx . . $ close(7864480464b09eea).(entry->fdcxx . . $ disk_entry#fd.) < 0) {
153 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "close() failed for '%s' (fd: %d): %s", entry->filenamecxx . . $ disk_entry#filename., entry->fdcxx . . $ disk_entry#fd., strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
154 }
155 }
156 entry->fdcxx . . $ disk_entry#fd. = fd;
157 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
158 }
159 }
160 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
161 }
162
163 static void process_pathcxx . . $ process_path(4f119e8029492b52).(char *path, boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! dry_run, const char *whoami) {
164 db_linecxx . . $ db_line# *line = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
165
166 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "process '%s' (fullpath: '%s')", &path[conf->root_prefix_length], path);
167
168 struct statcxx . . $ stat# stat;
169 int fd = -1;
170 #ifdef O_PATHcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:148:10`!
171 fd = opencxx . . $ open(e156e3aa1e5c4ad1).(path, O_NOFOLLOWcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:141:10`! | O_PATHcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:148:10`!);
172 if (fd == -1) {
173 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "failed to access '%s': %s (skipping)", path, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
174 return;
175 }
176 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_TRACE, "%s> open() returned O_PATH fd %d", path, fd);
177 if (fstatcxx . . $ fstat(a43660ce2f600cb5).(fd, &stat) == -1) {
178 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "fstat() failed for %s: %s (skipping)", path, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
179 } else {
180 #else
181 if(lstat(path, &stat) == -1) {
182 log_msg(LOG_LEVEL_WARNING, "lstat() failed for '%s': %s (skipping)", path, strerror(errno));
183 } else {
184 #endif
185 file_tcxx . . $ file_t# file = {
186 .name = &path[confcxx . . $ conf.->root_prefix_lengthcxx . . $ db_config#root_prefix_length.],
187 .type = get_f_type_from_permcxx . . $ get_f_type_from_perm(2141b656ce2cc063).(stat.st_modecxx . . $ stat#st_mode.),
188 #ifdef HAVE_FSTYPEcxx . . $ `./include/config.h:53:9`!
189 .fs_type = 0UL,
190 #endif
191 };
192 #ifdef HAVE_FSTYPEcxx . . $ `./include/config.h:53:9`!
193 struct statfscxx . . $ statfs# statfs;
194 if (fstatfscxx . . $ fstatfs(cd92bacb16ee1aa).(fd, &statfs) == -1) {
195 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "fstatfs() failed for %s: %s (file system type information missing)", path, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
196 } else {
197 file.fs_typecxx . . $ file_t#fs_type. = statfs.f_typecxx . . $ statfs#f_type.;
198 }
199 #endif
200 match_tcxx . . $ match_t# path_match = check_rxtreecxx . . $ check_rxtree(30f8ca777f09528f).(file, confcxx . . $ conf.->treecxx . . $ db_config#tree., "disk", falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, whoami);
201 char *attrs_str = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
202 disk_entrycxx . . $ disk_entry# entry = {
203 .filename = path,
204 .fs = stat,
205 .attrs = 0LLU,
206 #ifdef HAVE_FSTYPEcxx . . $ `./include/config.h:53:9`!
207 .fs_type = file.fs_typecxx . . $ file_t#fs_type.,
208 #endif
209 .fd = fd,
210 };
211 if (!dry_run && path_match.resultcxx . . $ match_t#result. & (RESULT_SELECTIVE_MATCHcxx . . $ RESULT_SELECTIVE_MATCH.|RESULT_EQUAL_MATCHcxx . . $ RESULT_EQUAL_MATCH.)) {
212 entry.attrscxx . . $ disk_entry#attrs. = path_match.rulecxx . . $ match_t#rule.->attrcxx . . $ rx_rule#attr.;
213
214 /* disable unsupported attributes */
215 DB_ATTR_TYPEcxx . . $ `include/attributes.h:25:9`! attrs_to_disable;
216 LOG_LEVELcxx . . $ LOG_LEVEL# log_level_unavailable = LOG_LEVEL_DEBUGcxx . . $ LOG_LEVEL_DEBUG.;
217 if (!S_ISREGcxx . . $ `<external>/531885356569766532/stat.h:128:9`!(stat.st_mode)) {
218 /* hashsum attributes */
219 attrs_to_disable = entry.attrscxx . . $ disk_entry#attrs. & get_hashescxx . . $ get_hashes(48b6f722ee11d9bd).(falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
220 if (attrs_to_disable) {
221 attrs_str = diff_attributescxx . . $ diff_attributes(39cd1df6f24d7ad6).(0, attrs_to_disable);
222 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(log_level_unavailable, "%s> disabling hashsum attribute(s) for non-regular file: %s)",
223 path, attrs_str);
224 freecxx . . $ free(5d22bdacc48458e8).(attrs_str);
225 entry.attrscxx . . $ disk_entry#attrs. &= ~attrs_to_disable;
226 }
227 #ifdef WITH_CAPABILITIES
228 /* capability attribute */
229 attrs_to_disable = entry.attrs & ATTR(attr_capabilities);
230 if (attrs_to_disable) {
231 LOG_WHOAMI(log_level_unavailable, "%s> disabling capability attribute for non-regular file", path);
232 entry.attrs &= ~attrs_to_disable;
233 }
234 #endif
235 }
236 if (!S_ISLNKcxx . . $ `<external>/531885356569766532/stat.h:133:10`!(stat.st_mode)) {
237 /* linkname attribute */
238 attrs_to_disable = entry.attrscxx . . $ disk_entry#attrs. & ATTRcxx . . $ `include/attributes.h:28:9`!(attr_linkname);
239 if (attrs_to_disable) {
240 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(log_level_unavailable, "%s> disabling linkname attribute for non-symlink file", path);
241 entry.attrscxx . . $ disk_entry#attrs. &= ~attrs_to_disable;
242 }
243 }
244 #ifdef WITH_E2FSATTRS
245 if (!(S_ISDIR(stat.st_mode) || S_ISREG(stat.st_mode))) {
246 /* e2fsattrs attribute */
247 attrs_to_disable = entry.attrs & ATTR(attr_e2fsattrs);
248 if (attrs_to_disable) {
249 LOG_WHOAMI(log_level_unavailable,
250 "%s> disabling e2fsattrs attribute for non-directory/non-regular file", path);
251 entry.attrs &= ~attrs_to_disable;
252 }
253 }
254 #endif
255 }
256 if(!(entry.attrscxx . . $ disk_entry#attrs.&ATTRcxx . . $ `include/attributes.h:28:9`!(attr_rdev))) {
257 entry.fscxx . . $ disk_entry#fs..st_rdevcxx . . $ stat#st_rdev.=0;
258 }
259 if (S_ISDIRcxx . . $ `<external>/531885356569766532/stat.h:125:9`!(stat.st_mode)) {
260 const char * whoami_log_thread = whoami ? whoami : "(main)";
261 DIRcxx . . $ DIR# *dir = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
262 switch (path_match.resultcxx . . $ match_t#result.) {
263 case RESULT_SELECTIVE_MATCHcxx . . $ RESULT_SELECTIVE_MATCH.:
264 case RESULT_EQUAL_MATCHcxx . . $ RESULT_EQUAL_MATCH.:
265 case RESULT_PARTIAL_MATCHcxx . . $ RESULT_PARTIAL_MATCH.:
266 case RESULT_RECURSIVE_NEGATIVE_MATCHcxx . . $ RESULT_RECURSIVE_NEGATIVE_MATCH.:
267 case RESULT_PARTIAL_LIMIT_MATCHcxx . . $ RESULT_PARTIAL_LIMIT_MATCH.:
268 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "read directory contents of '%s' (reason: %s)", path, get_match_result_desc(path_match.result));
269 if (open_for_readingcxx . . $ open_for_reading(b003e59a46c5d1d3).(&entry, truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!, whoami)) {
270 int dupfd = dupcxx . . $ dup(7864480464b09eea).(entry.fdcxx . . $ disk_entry#fd.);
271 if (dupfd == -1) {
272 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "'%s': failed to duplicate file descriptor: %s", path, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
273 } else {
274 if ((dir = fdopendircxx . . $ fdopendir(77538171e493e8a7).(dupfd)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
275 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "failed to open directory '%s' for reading directory contents: %s (skipping recursion)",
276 path, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
277 } else {
278 const struct direntcxx . . $ dirent# *entp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
279 while ((entp = readdircxx . . $ readdir(ffbaae344e1a615a).(dir)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
280 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(entp->d_namecxx . . $ dirent#d_name., ".") != 0 && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(entp->d_namecxx . . $ dirent#d_name., "..") != 0) {
281 char *entry_full_path = name_constructcxx . . $ name_construct(a713fe7b9a57cf96).(path, entp->d_namecxx . . $ dirent#d_name.);
282 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_THREADcxx . . $ LOG_LEVEL_THREAD.,
283 "%10s: add entry %p to queue of worker entries (filename: '%s')", whoami_log_thread,
284 (void *)entry_full_path, entry_full_path);
285 queue_ts_enqueuecxx . . $ queue_ts_enqueue(b12881b4bc859e3c).(queue_worker_entriescxx . . $ queue_worker_entries., entry_full_path, whoami_log_thread);
286 }
287 }
288 if (closedircxx . . $ closedir(ac30a447bc7c2f80).(dir) < 0) {
289 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "closedir() failed for '%s': %s", path, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
290 }
291 }
292 }
293 }
294 break;
295 case RESULT_NON_RECURSIVE_NEGATIVE_MATCHcxx . . $ RESULT_NON_RECURSIVE_NEGATIVE_MATCH.:
296 case RESULT_NEGATIVE_PARENT_MATCHcxx . . $ RESULT_NEGATIVE_PARENT_MATCH.:
297 case RESULT_NO_RULE_MATCHcxx . . $ RESULT_NO_RULE_MATCH.:
298 case RESULT_PART_LIMIT_AND_NO_RECURSE_MATCHcxx . . $ RESULT_PART_LIMIT_AND_NO_RECURSE_MATCH.:
299 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "do NOT read directory contents of '%s' (reason: %s)", path, get_match_result_desc(path_match.result));
300 break;
301 case RESULT_NO_LIMIT_MATCHcxx . . $ RESULT_NO_LIMIT_MATCH.:
302 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_LIMIT, "do NOT read directory contents of '%s' (reason: %s)", path, get_match_result_desc(path_match.result));
303 break;
304 }
305 }
306 if (dry_run) {
307 print_matchcxx . . $ print_match(409851dd7b7ab465).(file, path_match);
308 } else {
309 DB_ATTR_TYPEcxx . . $ `include/attributes.h:25:9`! transition_hashsums = 0LL;
310
311 if (path_match.resultcxx . . $ match_t#result. & (RESULT_SELECTIVE_MATCHcxx . . $ RESULT_SELECTIVE_MATCH.|RESULT_EQUAL_MATCHcxx . . $ RESULT_EQUAL_MATCH.)) {
312 if (S_ISREGcxx . . $ `<external>/531885356569766532/stat.h:128:9`!(stat.st_mode)) {
313 if (open_for_readingcxx . . $ open_for_reading(b003e59a46c5d1d3).(&entry, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, whoami)) {
314 if (confcxx . . $ conf.->actioncxx . . $ db_config#action. & DO_COMPAREcxx . . $ `include/db_config.h:49:9`! && entry.attrscxx . . $ disk_entry#attrs. & get_hashescxx . . $ get_hashes(48b6f722ee11d9bd).(falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!)) {
315 const seltreecxx . . $ seltree# *node = get_seltree_nodecxx . . $ get_seltree_node(e2ef57450a84c6c6).(confcxx . . $ conf.->treecxx . . $ db_config#tree., &path[confcxx . . $ conf.->root_prefix_lengthcxx . . $ db_config#root_prefix_length.]);
316 if (node && node->old_datacxx . . $ seltree#old_data.) {
317 transition_hashsums = get_transition_hashsumscxx . . $ get_transition_hashsums(d940f40586ac8d6a).(
318 (node->old_datacxx . . $ seltree#old_data.)->filenamecxx . . $ db_line#filename., (node->old_datacxx . . $ seltree#old_data.)->attrcxx . . $ db_line#attr., &path[confcxx . . $ conf.->root_prefix_lengthcxx . . $ db_config#root_prefix_length.], entry.attrscxx . . $ disk_entry#attrs.);
319 }
320 }
321 }
322 }
323
324 attrs_str = diff_attributescxx . . $ diff_attributes(39cd1df6f24d7ad6).(0, entry.attrscxx . . $ disk_entry#attrs.);
325 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "%s> requested attributes: %s", entry.filename, attrs_str);
326 freecxx . . $ free(5d22bdacc48458e8).(attrs_str);
327
328 line = get_file_attrscxx . . $ get_file_attrs(38115f8814b417cb).(&entry, entry.attrscxx . . $ disk_entry#attrs., transition_hashsums, whoami);
329
330 /* attr_filename is always needed/returned but never requested */
331 DB_ATTR_TYPEcxx . . $ `include/attributes.h:25:9`! returned_attr = (~ATTRcxx . . $ `include/attributes.h:28:9`!(attr_filename) & line->attrcxx . . $ db_line#attr.);
332 attrs_str = diff_attributescxx . . $ diff_attributes(39cd1df6f24d7ad6).(0, returned_attr);
333 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "%s> returned attributes: %llu (%s)", entry.filename, returned_attr, attrs_str);
334 freecxx . . $ free(5d22bdacc48458e8).(attrs_str);
335 if (returned_attr ^ entry.attrscxx . . $ disk_entry#attrs.) {
336 attrs_str = diff_attributescxx . . $ diff_attributes(39cd1df6f24d7ad6).(entry.attrscxx . . $ disk_entry#attrs., returned_attr);
337 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "%s> requested (%llu) and returned (%llu) attributes are not equal: %s", entry.filename, entry.attrs, returned_attr, attrs_str);
338 freecxx . . $ free(5d22bdacc48458e8).(attrs_str);
339 }
340
341 add_file_to_treecxx . . $ add_file_to_tree(def11f63420acca9).(confcxx . . $ conf.->treecxx . . $ db_config#tree., line, DB_NEWcxx . . $ `include/db.h:59:9`! | DB_DISKcxx . . $ `include/db.h:58:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &entry, whoami);
342 }
343 }
344 if (entry.fdcxx . . $ disk_entry#fd. != -1) {
345 if (closecxx . . $ close(7864480464b09eea).(entry.fdcxx . . $ disk_entry#fd.) < 0) {
346 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "close() failed for '%s': %s", path, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
347 }
348 }
349 }
350 }
351
352 static void process_disk_entriescxx . . $ process_disk_entries(ee90985596e8b4f9).(boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! dry_run, const char *whoami) {
353 const char * whoami_log_thread = whoami ? whoami : "(main)";
354 while (1) {
355 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_THREADcxx . . $ LOG_LEVEL_THREAD., "%10s: process_disk_entries: wait for entries", whoami_log_thread);
356 char *data = queue_ts_dequeue_waitcxx . . $ queue_ts_dequeue_wait(45dab9fcfc1afe1).(queue_worker_entriescxx . . $ queue_worker_entries., whoami_log_thread);
357 if (data) {
358 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_THREADcxx . . $ LOG_LEVEL_THREAD., "%10s: process_disk_entries: got entry %p from queue of worker entries (path: '%s')", whoami_log_thread, (void*) data, data);
359 process_pathcxx . . $ process_path(4f119e8029492b52).(data, dry_run, whoami);
360 freecxx . . $ free(5d22bdacc48458e8).(data);
361 } else {
362 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_THREADcxx . . $ LOG_LEVEL_THREAD., "%10s: process_disk_entries: queue empty", whoami_log_thread);
363 break;
364 }
365 }
366 }
367
368 static void * workercxx . . $ worker(9f162e79bfc6c74).(void *arg) {
369 struct worker_argscxx . . $ worker_args# args = *(struct worker_argscxx . . $ worker_args# *)arg;
370 char whoami[32];
371 snprintfcxx . . $ snprintf(ea502d73e74c754c).(whoami, 32, "(work-%03li)", args.worker_indexcxx . . $ worker_args#worker_index.);
372
373 mask_sigcxx . . $ mask_sig(85c52e162fed56f9).(whoami);
374
375 queue_ts_registercxx . . $ queue_ts_register(cf5a74e7b45a2e30).(queue_worker_entriescxx . . $ queue_worker_entries., whoami);
376
377 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_THREADcxx . . $ LOG_LEVEL_THREAD., "%10s: worker: initialized worker thread #%ld", whoami, args.worker_indexcxx . . $ worker_args#worker_index.);
378
379 process_disk_entriescxx . . $ process_disk_entries(ee90985596e8b4f9).(args.dry_runcxx . . $ worker_args#dry_run., whoami);
380
381 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_THREADcxx . . $ LOG_LEVEL_THREAD., "%10s: worker: exit thread", whoami);
382 return (void *) pthread_selfcxx . . $ pthread_self(f708dce9a8856c70).();
383 }
384
385 void db_scan_diskcxx . . $ db_scan_disk(b45ddcbc8423892c).(boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! dry_run) {
386 const char *whoami_main = "(main)";
387
388 char* full_path=checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).((confcxx . . $ conf.->root_prefix_lengthcxx . . $ db_config#root_prefix_length.+2)*sizeof(char)); /* freed in process_disk_entries() */
389 strncpycxx . . $ strncpy(255158a415b673b0).(full_path, confcxx . . $ conf.->root_prefixcxx . . $ db_config#root_prefix., confcxx . . $ conf.->root_prefix_lengthcxx . . $ db_config#root_prefix_length.+1);
390 strcatcxx . . $ strcat(b7b3a83273496486). (full_path, "/");
391
392 if (dry_run || confcxx . . $ conf.->num_workerscxx . . $ db_config#num_workers. == 0) {
393 queue_worker_entriescxx . . $ queue_worker_entries. = queue_ts_initcxx . . $ queue_ts_init(26178f4c59431c2a).(); /* freed below */
394 queue_ts_enqueuecxx . . $ queue_ts_enqueue(b12881b4bc859e3c).(queue_worker_entriescxx . . $ queue_worker_entries., full_path, whoami_main);
395 queue_ts_releasecxx . . $ queue_ts_release(cf5a74e7b45a2e30).(queue_worker_entriescxx . . $ queue_worker_entries., whoami_main);
396
397 process_disk_entriescxx . . $ process_disk_entries(ee90985596e8b4f9).(dry_run, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
398
399 queue_ts_freecxx . . $ queue_ts_free(b1ab4594e88bd087).(queue_worker_entriescxx . . $ queue_worker_entries.);
400 } else {
401 queue_worker_entriescxx . . $ queue_worker_entries. = queue_ts_initcxx . . $ queue_ts_init(26178f4c59431c2a).(); /* freed below */
402 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_THREADcxx . . $ LOG_LEVEL_THREAD., "%10s: initialized worker entries queue %p", whoami_main, (void*) queue_worker_entriescxx . . $ queue_worker_entries.);
403
404 worker_threadcxx . . $ worker_thread# *worker_threads = checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(confcxx . . $ conf.->num_workerscxx . . $ db_config#num_workers. * sizeof(worker_threadcxx . . $ worker_thread#)); /* freed below */
405
406 for (int i = 0 ; i < confcxx . . $ conf.->num_workerscxx . . $ db_config#num_workers. ; ++i) {
407 worker_threads[i].argscxx . . $ worker_thread#args..worker_indexcxx . . $ worker_args#worker_index. = i + 1L;
408 worker_threads[i].argscxx . . $ worker_thread#args..dry_runcxx . . $ worker_args#dry_run. = dry_run;
409 if (pthread_createcxx . . $ pthread_create(2141a84bcac899e5).(&worker_threads[i].threadcxx . . $ worker_thread#thread., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, &workercxx . . $ worker(9f162e79bfc6c74)., (void *) &worker_threads[i].argscxx . . $ worker_thread#args.) != 0) {
410 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "failed to start file attributes worker thread #%d", i+1);
411 exitcxx . . $ exit(3ca292c338df9bb3).(THREAD_ERRORcxx . . $ `include/errorcodes.h:34:9`!);
412 }
413 }
414
415 queue_ts_enqueuecxx . . $ queue_ts_enqueue(b12881b4bc859e3c).(queue_worker_entriescxx . . $ queue_worker_entries., full_path, whoami_main);
416 queue_ts_releasecxx . . $ queue_ts_release(cf5a74e7b45a2e30).(queue_worker_entriescxx . . $ queue_worker_entries., whoami_main);
417
418 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_THREADcxx . . $ LOG_LEVEL_THREAD., "%10s: wait for worker threads to be finished", whoami_main);
419 for (int i = 0 ; i < confcxx . . $ conf.->num_workerscxx . . $ db_config#num_workers. ; ++i) {
420 if (pthread_joincxx . . $ pthread_join(269902cf949f12c5).(worker_threads[i].threadcxx . . $ worker_thread#thread., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) != 0) {
421 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "failed to join file attributes thread #%d", i);
422 }
423 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_THREADcxx . . $ LOG_LEVEL_THREAD., "%10s: worker thread #%d finished", whoami_main, i);
424 }
425 freecxx . . $ free(5d22bdacc48458e8).(worker_threads);
426 queue_ts_freecxx . . $ queue_ts_free(b1ab4594e88bd087).(queue_worker_entriescxx . . $ queue_worker_entries.);
427 }
428 }