]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
modules-load: fgets() excorcism
authorLennart Poettering <lennart@poettering.net>
Thu, 18 Oct 2018 11:40:21 +0000 (13:40 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 18 Oct 2018 11:40:21 +0000 (13:40 +0200)
src/modules-load/modules-load.c

index bd4513b823f44e6726762452ba6636d4d0e0de84..01d909ff191dfc6504ddd1206de1b1677d59b8e7 100644 (file)
@@ -72,25 +72,25 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
                 if (ignore_enoent && r == -ENOENT)
                         return 0;
 
-                return log_error_errno(r, "Failed to open %s, ignoring: %m", path);
+                return log_error_errno(r, "Failed to open %s: %m", path);
         }
 
         log_debug("apply: %s", path);
         for (;;) {
-                char line[LINE_MAX], *l;
+                _cleanup_free_ char *line = NULL;
+                char *l;
                 int k;
 
-                if (!fgets(line, sizeof(line), f)) {
-                        if (feof(f))
-                                break;
-
-                        return log_error_errno(errno, "Failed to read file '%s', ignoring: %m", path);
-                }
+                r = read_line(f, LONG_LINE_MAX, &line);
+                if (r < 0)
+                        return log_error_errno(errno, "Failed to read file '%s': %m", path);
+                if (r == 0)
+                        break;
 
                 l = strstrip(line);
-                if (!*l)
+                if (isempty(l))
                         continue;
-                if (strchr(COMMENTS "\n", *l))
+                if (strchr(COMMENTS, *l))
                         continue;
 
                 k = module_load_and_warn(ctx, l, true);