udev-rules: fgets() excorcism

This commit is contained in:
Lennart Poettering 2018-10-18 13:41:09 +02:00
parent 9c6f9786c5
commit fae0f8a047

View file

@ -15,9 +15,11 @@
#include "alloc-util.h" #include "alloc-util.h"
#include "conf-files.h" #include "conf-files.h"
#include "def.h"
#include "dirent-util.h" #include "dirent-util.h"
#include "escape.h" #include "escape.h"
#include "fd-util.h" #include "fd-util.h"
#include "fileio.h"
#include "fs-util.h" #include "fs-util.h"
#include "glob-util.h" #include "glob-util.h"
#include "path-util.h" #include "path-util.h"
@ -613,15 +615,25 @@ static int import_property_from_string(struct udev_device *dev, char *line) {
} }
static int import_file_into_properties(struct udev_device *dev, const char *filename) { static int import_file_into_properties(struct udev_device *dev, const char *filename) {
FILE *f; _cleanup_fclose_ FILE *f = NULL;
char line[UTIL_LINE_SIZE]; int r;
f = fopen(filename, "re"); f = fopen(filename, "re");
if (f == NULL) if (!f)
return -1; return -errno;
while (fgets(line, sizeof(line), f) != NULL)
import_property_from_string(dev, line); for (;;) {
fclose(f); _cleanup_free_ char *line = NULL;
r = read_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0)
break;
(void) import_property_from_string(dev, line);
}
return 0; return 0;
} }
@ -646,7 +658,7 @@ static int import_program_into_properties(struct udev_event *event,
pos[0] = '\0'; pos[0] = '\0';
pos = &pos[1]; pos = &pos[1];
} }
import_property_from_string(event->dev, line); (void) import_property_from_string(event->dev, line);
line = pos; line = pos;
} }
return 0; return 0;
@ -1429,8 +1441,8 @@ static int parse_file(struct udev_rules *rules, const char *filename) {
if (!f) { if (!f) {
if (errno == ENOENT) if (errno == ENOENT)
return 0; return 0;
else
return -errno; return -errno;
} }
if (null_or_empty_fd(fileno(f))) { if (null_or_empty_fd(fileno(f))) {