]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
condition: add debug log messages on unexpected errors
authorLennart Poettering <lennart@poettering.net>
Thu, 14 May 2020 07:20:24 +0000 (09:20 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 18 May 2020 18:17:57 +0000 (20:17 +0200)
src/shared/condition.c

index e5de303a4b66e348af32c067b90442cda17af0a9..45f36781a025b3193bfd8f2c3f2be34d71a76b80 100644 (file)
@@ -546,29 +546,40 @@ static int condition_test_capability(Condition *c, char **env) {
 }
 
 static int condition_test_needs_update(Condition *c, char **env) {
-        const char *p;
         struct stat usr, other;
+        const char *p;
+        int r;
 
         assert(c);
         assert(c->parameter);
         assert(c->type == CONDITION_NEEDS_UPDATE);
 
-        if (!path_is_absolute(c->parameter))
+        if (!path_is_absolute(c->parameter)) {
+                log_debug("Specified condition parameter '%s' is not absolute, assuming an update is needed.", c->parameter);
                 return true;
+        }
 
         /* If the file system is read-only we shouldn't suggest an update */
-        if (path_is_read_only_fs(c->parameter) > 0)
+        r = path_is_read_only_fs(c->parameter);
+        if (r < 0)
+                log_debug_errno(r, "Failed to determine if '%s' is read-only, ignoring: %m", c->parameter);
+        if (r > 0)
                 return false;
 
         /* Any other failure means we should allow the condition to be true, so that we rather invoke too
          * many update tools than too few. */
 
         p = strjoina(c->parameter, "/.updated");
-        if (lstat(p, &other) < 0)
+        if (lstat(p, &other) < 0) {
+                if (errno != ENOENT)
+                        log_debug_errno(errno, "Failed to stat() '%s', assuming an update is needed: %m", p);
                 return true;
+        }
 
-        if (lstat("/usr/", &usr) < 0)
+        if (lstat("/usr/", &usr) < 0) {
+                log_debug_errno(errno, "Failed to stat() /usr/, assuming an update is needed: %m");
                 return true;
+        }
 
         /*
          * First, compare seconds as they are always accurate...
@@ -587,7 +598,6 @@ static int condition_test_needs_update(Condition *c, char **env) {
         if (usr.st_mtim.tv_nsec > 0 && other.st_mtim.tv_nsec == 0) {
                 _cleanup_free_ char *timestamp_str = NULL;
                 uint64_t timestamp;
-                int r;
 
                 r = parse_env_file(NULL, p, "TIMESTAMP_NSEC", &timestamp_str);
                 if (r < 0) {