{ "Bootchart", "ControlGroup", config_parse_bool, 0, &arg_show_cgroup },
{ NULL, NULL, NULL, 0, NULL }
};
- _cleanup_fclose_ FILE *f;
- int r;
-
- f = fopen(BOOTCHART_CONF, "re");
- if (!f)
- return;
- r = config_parse(NULL, BOOTCHART_CONF, f,
- NULL, config_item_table_lookup, items, true, false, NULL);
- if (r < 0)
- log_warning("Failed to parse configuration file: %s", strerror(-r));
+ config_parse(NULL, BOOTCHART_CONF, NULL,
+ NULL,
+ config_item_table_lookup, items,
+ true, false, true, NULL);
if (init != NULL)
strscpy(arg_init_path, sizeof(arg_init_path), init);
STRV_FOREACH(f, u->dropin_paths) {
config_parse(u->id, *f, NULL,
- UNIT_VTABLE(u)->sections, config_item_perf_lookup,
- load_fragment_gperf_lookup, false, false, u);
+ UNIT_VTABLE(u)->sections,
+ config_item_perf_lookup, load_fragment_gperf_lookup,
+ false, false, false, u);
}
u->dropin_mtime = now(CLOCK_REALTIME);
u->load_state = UNIT_LOADED;
/* Now, parse the file contents */
- r = config_parse(u->id, filename, f, UNIT_VTABLE(u)->sections,
- config_item_perf_lookup,
- load_fragment_gperf_lookup, false, true, u);
+ r = config_parse(u->id, filename, f,
+ UNIT_VTABLE(u)->sections,
+ config_item_perf_lookup, load_fragment_gperf_lookup,
+ false, true, false, u);
if (r < 0)
return r;
}
{}
};
- _cleanup_fclose_ FILE *f;
const char *fn;
- int r;
fn = arg_running_as == SYSTEMD_SYSTEM ? PKGSYSCONFDIR "/system.conf" : PKGSYSCONFDIR "/user.conf";
- f = fopen(fn, "re");
- if (!f) {
- if (errno == ENOENT)
- return 0;
-
- log_warning("Failed to open configuration file '%s': %m", fn);
- return 0;
- }
-
- r = config_parse(NULL, fn, f, "Manager\0", config_item_table_lookup, items, false, false, NULL);
- if (r < 0)
- log_warning("Failed to parse configuration file: %s", strerror(-r));
+ config_parse(NULL, fn, NULL,
+ "Manager\0",
+ config_item_table_lookup, items,
+ false, false, true, NULL);
return 0;
}
{ "D-BUS Service", "SystemdService", config_parse_string, 0, &service },
};
- _cleanup_fclose_ FILE *f = NULL;
- _cleanup_free_ char *p = NULL;
+ char *p;
int r;
assert(path);
assert(fname);
- p = strjoin(path, "/", fname, NULL);
- if (!p)
- return log_oom();
-
- f = fopen(p, "re");
- if (!f) {
- if (errno == -ENOENT)
- return 0;
-
- log_error("Failed to read %s: %m", p);
- return -errno;
- }
-
- r = config_parse(NULL, p, f, "D-BUS Service\0", config_item_table_lookup, table, true, false, NULL);
+ p = strappenda3(path, "/", fname);
+ r = config_parse(NULL, p, NULL,
+ "D-BUS Service\0",
+ config_item_table_lookup, table,
+ true, false, true, NULL);
if (r < 0)
return r;
{ "Remote", "ServerCertificateFile", config_parse_path, 0, &arg_cert },
{ "Remote", "TrustedCertificateFile", config_parse_path, 0, &arg_trust },
{}};
- int r;
-
- r = config_parse(NULL, PKGSYSCONFDIR "/journal-remote.conf", NULL,
- "Remote\0",
- config_item_table_lookup, items,
- false, false, NULL);
- if (r < 0)
- log_error("Failed to parse configuration file: %s", strerror(-r));
- return r;
+ return config_parse(NULL, PKGSYSCONFDIR "/journal-remote.conf", NULL,
+ "Remote\0",
+ config_item_table_lookup, items,
+ false, false, true, NULL);
}
static void help(void) {
{ "Upload", "ServerCertificateFile", config_parse_path, 0, &arg_cert },
{ "Upload", "TrustedCertificateFile", config_parse_path, 0, &arg_trust },
{}};
- int r;
-
- r = config_parse(NULL, PKGSYSCONFDIR "/journal-upload.conf", NULL,
- "Upload\0",
- config_item_table_lookup, items,
- false, false, NULL);
- if (r < 0)
- log_error("Failed to parse configuration file: %s", strerror(-r));
- return r;
+ return config_parse(NULL, PKGSYSCONFDIR "/journal-upload.conf", NULL,
+ "Upload\0",
+ config_item_table_lookup, items,
+ false, false, true, NULL);
}
static void help(void) {
{}
};
- return config_parse(
- NULL,
- "/etc/systemd/coredump.conf",
- NULL,
- "Coredump\0",
- config_item_table_lookup,
- items,
- false,
- false,
- NULL);
+ return config_parse(NULL, "/etc/systemd/coredump.conf", NULL,
+ "Coredump\0",
+ config_item_table_lookup, items,
+ false, false, true, NULL);
}
static int fix_acl(int fd, uid_t uid) {
}
static int server_parse_config_file(Server *s) {
- static const char fn[] = "/etc/systemd/journald.conf";
- _cleanup_fclose_ FILE *f = NULL;
- int r;
-
assert(s);
- f = fopen(fn, "re");
- if (!f) {
- if (errno == ENOENT)
- return 0;
-
- log_warning("Failed to open configuration file %s: %m", fn);
- return -errno;
- }
-
- r = config_parse(NULL, fn, f, "Journal\0", config_item_perf_lookup,
- journald_gperf_lookup, false, false, s);
- if (r < 0)
- log_warning("Failed to parse configuration file: %s", strerror(-r));
-
- return r;
+ return config_parse(NULL, "/etc/systemd/journald.conf", NULL,
+ "Journal\0",
+ config_item_perf_lookup, journald_gperf_lookup,
+ false, false, true, s);
}
static int server_dispatch_sync(sd_event_source *es, usec_t t, void *userdata) {
}
static int manager_parse_config_file(Manager *m) {
- static const char fn[] = "/etc/systemd/logind.conf";
- _cleanup_fclose_ FILE *f = NULL;
- int r;
-
assert(m);
- f = fopen(fn, "re");
- if (!f) {
- if (errno == ENOENT)
- return 0;
-
- log_warning("Failed to open configuration file %s: %m", fn);
- return -errno;
- }
-
- r = config_parse(NULL, fn, f, "Login\0", config_item_perf_lookup,
- logind_gperf_lookup, false, false, m);
- if (r < 0)
- log_warning("Failed to parse configuration file: %s", strerror(-r));
-
- return r;
+ return config_parse(NULL, "/etc/systemd/logind.conf", NULL,
+ "Login\0",
+ config_item_perf_lookup, logind_gperf_lookup,
+ false, false, true, m);
}
int main(int argc, char *argv[]) {
r = config_parse(NULL, filename, file,
"Match\0NetDev\0VLAN\0MACVLAN\0VXLAN\0Tunnel\0Peer\0Tun\0Tap\0Bond\0",
config_item_perf_lookup, network_netdev_gperf_lookup,
- false, false, netdev);
- if (r < 0) {
- log_warning("Could not parse config file %s: %s", filename, strerror(-r));
+ false, false, true, netdev);
+ if (r < 0)
return r;
- }
/* skip out early if configuration does not match the environment */
if (net_match_config(NULL, NULL, NULL, NULL, NULL,
r = config_parse(NULL, filename, file,
"Match\0Network\0Address\0Route\0DHCP\0DHCPv4\0",
config_item_perf_lookup, network_network_gperf_lookup,
- false, false, network);
- if (r < 0) {
- log_warning("Could not parse config file %s: %s", filename, strerror(-r));
+ false, false, true, network);
+ if (r < 0)
return r;
- }
LIST_PREPEND(networks, manager->networks, network);
}
int manager_parse_config_file(Manager *m) {
- int r;
-
assert(m);
- r = config_parse(NULL, "/etc/systemd/resolved.conf", NULL,
- "Resolve\0",
- config_item_perf_lookup, resolved_gperf_lookup,
- false, false, m);
- if (r < 0)
- log_warning("Failed to parse configuration file: %s", strerror(-r));
-
- return 0;
+ return config_parse(NULL, "/etc/systemd/resolved.conf", NULL,
+ "Resolve\0",
+ config_item_perf_lookup, resolved_gperf_lookup,
+ false, false, true, m);
}
int manager_new(Manager **ret) {
if (!fn)
return -ENOMEM;
- return config_parse(unit, fn, NULL, sections, lookup, table, relaxed, false, userdata);
+ return config_parse(unit, fn, NULL, sections, lookup, table, relaxed, false, false, userdata);
}
if (*l == '[') {
const void *table,
bool relaxed,
bool allow_include,
+ bool warn,
void *userdata) {
_cleanup_free_ char *section = NULL, *continuation = NULL;
if (!f) {
f = ours = fopen(filename, "re");
if (!f) {
- log_full(errno == ENOENT ? LOG_DEBUG : LOG_ERR, "Failed to open configuration file '%s': %m", filename);
+ /* Only log on request, except for ENOENT,
+ * since we return 0 to the caller. */
+ if (warn || errno == ENOENT)
+ log_full(errno == ENOENT ? LOG_DEBUG : LOG_ERR,
+ "Failed to open configuration file '%s': %m", filename);
return errno == ENOENT ? 0 : -errno;
}
}
if (continuation) {
c = strappend(continuation, l);
- if (!c)
+ if (!c) {
+ if (warn)
+ log_oom();
return -ENOMEM;
+ }
free(continuation);
continuation = NULL;
continuation = c;
else {
continuation = strdup(l);
- if (!continuation)
+ if (!continuation) {
+ if (warn)
+ log_oom();
return -ENOMEM;
+ }
}
continue;
userdata);
free(c);
- if (r < 0)
+ if (r < 0) {
+ if (warn)
+ log_warning("Failed to parse file '%s': %s",
+ filename, strerror(-r));
return r;
+ }
}
return 0;
const void *table,
bool relaxed,
bool allow_include,
+ bool warn,
void *userdata);
/* Generic parsers */
return -ENOMEM;
}
- r = config_parse(NULL, path, f, NULL, config_item_table_lookup, items, true, true, info);
+ r = config_parse(NULL, path, f,
+ NULL,
+ config_item_table_lookup, items,
+ true, true, false, info);
if (r < 0)
return r;
{}
};
- int r;
- _cleanup_fclose_ FILE *f;
-
- f = fopen(PKGSYSCONFDIR "/sleep.conf", "re");
- if (!f)
- log_full(errno == ENOENT ? LOG_DEBUG: LOG_WARNING,
- "Failed to open configuration file " PKGSYSCONFDIR "/sleep.conf: %m");
- else {
- r = config_parse(NULL, PKGSYSCONFDIR "/sleep.conf", f, "Sleep\0",
- config_item_table_lookup, items, false, false, NULL);
- if (r < 0)
- log_warning("Failed to parse configuration file: %s", strerror(-r));
- }
+ config_parse(NULL, PKGSYSCONFDIR "/sleep.conf", NULL,
+ "Sleep\0",
+ config_item_table_lookup, items, false, false, true, NULL);
if (streq(verb, "suspend")) {
/* empty by default */
}
static int manager_parse_config_file(Manager *m) {
- static const char fn[] = "/etc/systemd/timesyncd.conf";
- _cleanup_fclose_ FILE *f = NULL;
- int r;
-
- assert(m);
-
- f = fopen(fn, "re");
- if (!f) {
- if (errno == ENOENT)
- return 0;
-
- log_warning("Failed to open configuration file %s: %m", fn);
- return -errno;
- }
-
- r = config_parse(NULL, fn, f, "Time\0", config_item_perf_lookup,
- timesyncd_gperf_lookup, false, false, m);
- if (r < 0)
- log_warning("Failed to parse configuration file: %s", strerror(-r));
-
- return r;
+ return config_parse(NULL, "/etc/systemd/timesyncd.conf", NULL,
+ "Time\0",
+ config_item_perf_lookup, timesyncd_gperf_lookup,
+ false, false, true, m);
}
static bool network_is_online(void) {
{ NULL, NULL, NULL, 0, NULL }
};
- FILE *f;
int r;
assert(filename);
- f = fopen(filename, "re");
- if (!f) {
- if (errno == ENOENT)
- return 0;
-
- log_error("open(%s): %m", filename);
- return -errno;
- }
-
- r = config_parse(NULL, filename, f, NULL, config_item_table_lookup, items, true, false, NULL);
- if (r < 0) {
- log_error("Failed to parse password file %s: %s", filename, strerror(-r));
- goto finish;
- }
+ r = config_parse(NULL, filename, NULL,
+ NULL,
+ config_item_table_lookup, items,
+ true, false, true, NULL);
+ if (r < 0)
+ return r;
if (!socket_name) {
log_error("Invalid password file %s", filename);
}
finish:
- fclose(f);
-
safe_close(socket_fd);
free(packet);
r = config_parse(NULL, filename, file,
"Match\0Link\0Ethernet\0",
config_item_perf_lookup, link_config_gperf_lookup,
- false, false, link);
- if (r < 0) {
- log_warning("Could not parse config file %s: %s", filename, strerror(-r));
+ false, false, true, link);
+ if (r < 0)
return r;
- } else
+ else
log_debug("Parsed configuration file %s", filename);
link->filename = strdup(filename);