chiark / gitweb /
fileio: accept FILE* in addition to path in parse_env_file()
authorLennart Poettering <lennart@poettering.net>
Fri, 23 Mar 2018 20:31:14 +0000 (21:31 +0100)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
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
src/basic/fileio.h
src/basic/util.c
src/libelogind/sd-login/sd-login.c
src/login/logind-inhibit.c
src/login/logind-session.c
src/login/logind-user.c
src/shared/udev-util.c

index 43c804472feb870c788020728f09b2e7d9c2632e..0efda65aec69fe598d61851d96c6a75e1975a12f 100644 (file)
@@ -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;
index 8ee246c5760526bd77f927d6a7a5e50fde305b1f..e34bd388bc9841d6c6cb90e6dd24219e0a0437ba 100644 (file)
@@ -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
index 6d85c0a6acf044fa03ddd4c78cbe3839583052f4..635d1672a83894ecd3251aecb8db9f1f06284084 100644 (file)
@@ -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)
index 9fdb3bc7350315338d80f4992a0cba58beaed951..f733fb1718c881a916b9ac8f2888c05634e94d92 100644 (file)
@@ -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)
index 0938f2f101ed30abfe733baae96afac0d699fc1c..8bf3e72d22f69dbd66c160426b040b8ff372dd4d 100644 (file)
@@ -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,
index 857f43827ad2c9929087667b9f46f75f91b0deda..e5adbdcf7ee325a252f6315b4c246c51f0bc1e3f 100644 (file)
@@ -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
index b7bac297c3eeb4dbf2dc00ed2d62bd1b27ba4b7c..57c4b8ca97d7f97772ace96ab19d2968362557d4 100644 (file)
@@ -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,
index 14f2c19288a1029a9099cbad8a2de6d2fecd23c5..81fc805d25c0b1e56da71eed83d0497bcba48336 100644 (file)
@@ -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)