From ff922b481d88c83594c4a97352067f5b17b74e67 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 23 Mar 2018 21:31:14 +0100 Subject: [PATCH] fileio: accept FILE* in addition to path in parse_env_file() Most our other parsing functions do this, let's do this here too, internally we accept that anyway. Also, the closely related load_env_file() and load_env_file_pairs() also do this, so let's be systematic. --- src/basic/fileio.c | 3 ++- src/basic/fileio.h | 2 +- src/basic/util.c | 2 +- src/libelogind/sd-login/sd-login.c | 28 ++++++++++++++-------------- src/login/logind-inhibit.c | 2 +- src/login/logind-session.c | 2 +- src/login/logind-user.c | 2 +- src/shared/udev-util.c | 2 +- 8 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 43c804472..0efda65ae 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -677,6 +677,7 @@ static int parse_env_file_push( } int parse_env_file( + FILE *f, const char *fname, const char *newline, ...) { @@ -687,7 +688,7 @@ int parse_env_file( newline = NEWLINE; va_start(ap, newline); - r = parse_env_file_internal(NULL, fname, newline, parse_env_file_push, &ap, &n_pushed); + r = parse_env_file_internal(f, fname, newline, parse_env_file_push, &ap, &n_pushed); va_end(ap); return r < 0 ? r : n_pushed; diff --git a/src/basic/fileio.h b/src/basic/fileio.h index 8ee246c57..e34bd388b 100644 --- a/src/basic/fileio.h +++ b/src/basic/fileio.h @@ -45,7 +45,7 @@ int read_full_stream(FILE *f, char **contents, size_t *size); int verify_file(const char *fn, const char *blob, bool accept_extra_nl); -int parse_env_file(const char *fname, const char *separator, ...) _sentinel_; +int parse_env_file(FILE *f, const char *fname, const char *separator, ...) _sentinel_; #if 0 /// UNNEEDED by elogind int load_env_file(FILE *f, const char *fname, const char *separator, char ***l); #endif // 0 diff --git a/src/basic/util.c b/src/basic/util.c index 6d85c0a6a..635d1672a 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -270,7 +270,7 @@ int container_get_leader(const char *machine, pid_t *pid) { return -EINVAL; p = strjoina("/run/systemd/machines/", machine); - r = parse_env_file(p, NEWLINE, "LEADER", &s, "CLASS", &class, NULL); + r = parse_env_file(NULL, p, NEWLINE, "LEADER", &s, "CLASS", &class, NULL); if (r == -ENOENT) return -EHOSTDOWN; if (r < 0) diff --git a/src/libelogind/sd-login/sd-login.c b/src/libelogind/sd-login/sd-login.c index 9fdb3bc73..f733fb171 100644 --- a/src/libelogind/sd-login/sd-login.c +++ b/src/libelogind/sd-login/sd-login.c @@ -303,7 +303,7 @@ _public_ int sd_uid_get_state(uid_t uid, char**state) { if (r < 0) return r; - r = parse_env_file(p, NEWLINE, "STATE", &s, NULL); + r = parse_env_file(NULL, p, NEWLINE, "STATE", &s, NULL); if (r == -ENOENT) { free(s); s = strdup("offline"); @@ -334,7 +334,7 @@ _public_ int sd_uid_get_display(uid_t uid, char **session) { if (r < 0) return r; - r = parse_env_file(p, NEWLINE, "DISPLAY", &s, NULL); + r = parse_env_file(NULL, p, NEWLINE, "DISPLAY", &s, NULL); if (r == -ENOENT) return -ENODATA; if (r < 0) @@ -389,7 +389,7 @@ _public_ int sd_uid_is_on_seat(uid_t uid, int require_active, const char *seat) variable = require_active ? "ACTIVE_UID" : "UIDS"; - r = parse_env_file(p, NEWLINE, variable, &s, NULL); + r = parse_env_file(NULL, p, NEWLINE, variable, &s, NULL); if (r == -ENOENT) return 0; if (r < 0) @@ -418,7 +418,7 @@ static int uid_get_array(uid_t uid, const char *variable, char ***array) { if (r < 0) return r; - r = parse_env_file(p, NEWLINE, variable, &s, NULL); + r = parse_env_file(NULL, p, NEWLINE, variable, &s, NULL); if (r == -ENOENT || (r >= 0 && isempty(s))) { if (array) *array = NULL; @@ -496,7 +496,7 @@ _public_ int sd_session_is_active(const char *session) { if (r < 0) return r; - r = parse_env_file(p, NEWLINE, "ACTIVE", &s, NULL); + r = parse_env_file(NULL, p, NEWLINE, "ACTIVE", &s, NULL); if (r == -ENOENT) return -ENXIO; if (r < 0) @@ -515,7 +515,7 @@ _public_ int sd_session_is_remote(const char *session) { if (r < 0) return r; - r = parse_env_file(p, NEWLINE, "REMOTE", &s, NULL); + r = parse_env_file(NULL, p, NEWLINE, "REMOTE", &s, NULL); if (r == -ENOENT) return -ENXIO; if (r < 0) @@ -536,7 +536,7 @@ _public_ int sd_session_get_state(const char *session, char **state) { if (r < 0) return r; - r = parse_env_file(p, NEWLINE, "STATE", &s, NULL); + r = parse_env_file(NULL, p, NEWLINE, "STATE", &s, NULL); if (r == -ENOENT) return -ENXIO; if (r < 0) @@ -559,7 +559,7 @@ _public_ int sd_session_get_uid(const char *session, uid_t *uid) { if (r < 0) return r; - r = parse_env_file(p, NEWLINE, "UID", &s, NULL); + r = parse_env_file(NULL, p, NEWLINE, "UID", &s, NULL); if (r == -ENOENT) return -ENXIO; if (r < 0) @@ -581,7 +581,7 @@ static int session_get_string(const char *session, const char *field, char **val if (r < 0) return r; - r = parse_env_file(p, NEWLINE, field, &s, NULL); + r = parse_env_file(NULL, p, NEWLINE, field, &s, NULL); if (r == -ENOENT) return -ENXIO; if (r < 0) @@ -673,7 +673,7 @@ _public_ int sd_seat_get_active(const char *seat, char **session, uid_t *uid) { if (r < 0) return r; - r = parse_env_file(p, NEWLINE, + r = parse_env_file(NULL, p, NEWLINE, "ACTIVE", &s, "ACTIVE_UID", &t, NULL); @@ -711,7 +711,7 @@ _public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui if (r < 0) return r; - r = parse_env_file(p, NEWLINE, + r = parse_env_file(NULL, p, NEWLINE, "SESSIONS", &s, "UIDS", &t, NULL); @@ -780,7 +780,7 @@ static int seat_get_can(const char *seat, const char *variable) { if (r < 0) return r; - r = parse_env_file(p, NEWLINE, + r = parse_env_file(NULL, p, NEWLINE, variable, &s, NULL); if (r == -ENOENT) @@ -929,7 +929,7 @@ _public_ int sd_machine_get_class(const char *machine, char **class) { assert_return(class, -EINVAL); p = strjoina("/run/systemd/machines/", machine); - r = parse_env_file(p, NEWLINE, "CLASS", &c, NULL); + r = parse_env_file(NULL, p, NEWLINE, "CLASS", &c, NULL); if (r == -ENOENT) return -ENXIO; if (r < 0) @@ -953,7 +953,7 @@ _public_ int sd_machine_get_ifindices(const char *machine, int **ifindices) { assert_return(ifindices, -EINVAL); p = strjoina("/run/systemd/machines/", machine); - r = parse_env_file(p, NEWLINE, "NETIF", &netif, NULL); + r = parse_env_file(NULL, p, NEWLINE, "NETIF", &netif, NULL); if (r == -ENOENT) return -ENXIO; if (r < 0) diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 0938f2f10..8bf3e72d2 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -198,7 +198,7 @@ int inhibitor_load(Inhibitor *i) { char *cc; int r; - r = parse_env_file(i->state_file, NEWLINE, + r = parse_env_file(NULL, i->state_file, NEWLINE, "WHAT", &what, "UID", &uid, "PID", &pid, diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 857f43827..e5adbdcf7 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -372,7 +372,7 @@ int session_load(Session *s) { assert(s); - r = parse_env_file(s->state_file, NEWLINE, + r = parse_env_file(NULL, s->state_file, NEWLINE, "REMOTE", &remote, "SCOPE", &s->scope, #if 0 /// elogind does not support systemd scope_jobs diff --git a/src/login/logind-user.c b/src/login/logind-user.c index b7bac297c..57c4b8ca9 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -291,7 +291,7 @@ int user_load(User *u) { assert(u); - r = parse_env_file(u->state_file, NEWLINE, + r = parse_env_file(NULL, u->state_file, NEWLINE, #if 0 /// elogind neither supports service nor slice jobs "SERVICE_JOB", &u->service_job, "SLICE_JOB", &u->slice_job, diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index 14f2c1928..81fc805d2 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -21,7 +21,7 @@ int udev_parse_config(void) { size_t n; int r; - r = parse_env_file("/etc/udev/udev.conf", NEWLINE, "udev_log", &val, NULL); + r = parse_env_file(NULL, "/etc/udev/udev.conf", NEWLINE, "udev_log", &val, NULL); if (r == -ENOENT || !val) return 0; if (r < 0) -- 2.30.2