chiark / gitweb /
Be more careful when checking for empty files
[elogind.git] / src / udev / net / link-config.c
index fe916a4326755e7fc0be49d2c89d77db6e831533..512885f9c8604ced0757f4dd476133e7b3ab9dc8 100644 (file)
@@ -153,11 +153,6 @@ static int load_link(link_config_ctx *ctx, const char *filename) {
         assert(ctx);
         assert(filename);
 
-        if (null_or_empty_path(filename)) {
-                log_debug("skipping empty file: %s", filename);
-                return 0;
-        }
-
         file = fopen(filename, "re");
         if (!file) {
                 if (errno == ENOENT)
@@ -166,6 +161,11 @@ static int load_link(link_config_ctx *ctx, const char *filename) {
                         return -errno;
         }
 
+        if (null_or_empty_fd(fileno(file))) {
+                log_debug("Skipping empty file: %s", filename);
+                return 0;
+        }
+
         link = new0(link_config, 1);
         if (!link)
                 return log_oom();
@@ -177,11 +177,10 @@ static int load_link(link_config_ctx *ctx, const char *filename) {
         r = config_parse(NULL, filename, file,
                          "Match\0Link\0Ethernet\0",
                          config_item_perf_lookup, link_config_gperf_lookup,
-                         false, false, link);
-        if (r < 0) {
-                log_warning("Could not parse config file %s: %s", filename, strerror(-r));
+                         false, false, true, link);
+        if (r < 0)
                 return r;
-        else
+        else
                 log_debug("Parsed configuration file %s", filename);
 
         link->filename = strdup(filename);