process-util: FOREACH_LINE excorcism
authorLennart Poettering <lennart@poettering.net>
Thu, 18 Oct 2018 14:08:51 +0000 (16:08 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 18 Oct 2018 14:23:45 +0000 (16:23 +0200)
src/basic/process-util.c

index a02ceb7..b2aab85 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "alloc-util.h"
 #include "architecture.h"
+#include "def.h"
 #include "escape.h"
 #include "fd-util.h"
 #include "fileio.h"
@@ -514,8 +515,8 @@ int get_process_exe(pid_t pid, char **name) {
 
 static int get_process_id(pid_t pid, const char *field, uid_t *uid) {
         _cleanup_fclose_ FILE *f = NULL;
-        char line[LINE_MAX];
         const char *p;
+        int r;
 
         assert(field);
         assert(uid);
@@ -533,9 +534,16 @@ static int get_process_id(pid_t pid, const char *field, uid_t *uid) {
 
         (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
 
-        FOREACH_LINE(line, f, return -errno) {
+        for (;;) {
+                _cleanup_free_ char *line = NULL;
                 char *l;
 
+                r = read_line(f, LONG_LINE_MAX, &line);
+                if (r < 0)
+                        return r;
+                if (r == 0)
+                        break;
+
                 l = strstrip(line);
 
                 if (startswith(l, field)) {