diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-07-19 13:27:32 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2014-07-19 13:27:32 -0400 |
commit | e0f01e5b67dfbe41ff810f466e2173390f8d37a7 (patch) | |
tree | 29ee85767f0d859e3f91199c747d5896aa3ac71e /src/udev | |
parent | 54fac72da7156f18870ed6a53ea1ccfa80b6a1f6 (diff) |
Be more careful when checking for empty files
If we want to avoid reading a totally empty file, it seems better
to check after we have opened the file, not before.
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/udev')
-rw-r--r-- | src/udev/udev-rules.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 652ac411e1..c47d025846 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1538,15 +1538,19 @@ static int parse_file(struct udev_rules *rules, const char *filename) int line_nr = 0; unsigned int i; - if (null_or_empty_path(filename)) { - log_debug("skip empty file: %s", filename); - return 0; + f = fopen(filename, "re"); + if (!f) { + if (errno == ENOENT) + return 0; + else + return -errno; } - log_debug("read rules file: %s", filename); - f = fopen(filename, "re"); - if (f == NULL) - return -1; + if (null_or_empty_fd(fileno(f))) { + log_debug("Skipping empty file: %s", filename); + return 0; + } else + log_debug("Reading rules file: %s", filename); first_token = rules->token_cur; filename_off = rules_add_string(rules, filename); |