Skip to content

Commit b872843

Browse files
committed
fuzz: allow logging to be configured, disable in fuzz-unit-file
fuzz-unit-file generated too much logs about invalid config lines. This just slows things down and fills the logs. If necessary, it's better to rerun the interesting cases with SYSTEMD_LOG_LEVEL=debug.
1 parent af7bce4 commit b872843

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/fuzz/fuzz-main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ int main(int argc, char **argv) {
3333
char *name;
3434

3535
log_set_max_level(LOG_DEBUG);
36+
log_parse_environment();
37+
log_open();
38+
3639
for (i = 1; i < argc; i++) {
3740
_cleanup_free_ char *buf = NULL;
3841

@@ -47,5 +50,6 @@ int main(int argc, char **argv) {
4750
(void) LLVMFuzzerTestOneInput((uint8_t*)buf, size);
4851
printf("ok\n");
4952
}
53+
5054
return EXIT_SUCCESS;
5155
}

src/fuzz/fuzz-unit-file.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
3535
if (!unit_vtable[t]->load)
3636
return 0;
3737

38+
/* We don't want to fill the logs with messages about parse errors.
39+
* Disable most logging if not running standalone */
40+
if (!getenv("SYSTEMD_LOG_LEVEL"))
41+
log_set_max_level(LOG_CRIT);
42+
3843
assert_se(manager_new(UNIT_FILE_SYSTEM, MANAGER_TEST_RUN_MINIMAL, &m) >= 0);
3944

4045
name = strjoina("a.", unit_type_to_string(t));

0 commit comments

Comments
 (0)