]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
update-done: minor clean-ups
authorLennart Poettering <lennart@poettering.net>
Fri, 21 Oct 2016 16:26:30 +0000 (18:26 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 24 Oct 2016 15:29:51 +0000 (17:29 +0200)
This is a follow-up for fb8b0869a7bc30e23be175cf978df23192d59118, and makes a
couple of minor clean-up changes:

- The field name in the timestamp file is changed from "TimestampNSec=" to
  "TIMESTAMP_NSEC=". This is done simply to reflect the fact that we parse the
  file with the env var file parser, and hence the contents should better
  follow the usual capitalization of env vars, i.e. be all uppercase.

- Needless negation of the errno parameter log_error_errno() and friends has
  been removed.

- Instead of manually calculating the nsec remainder of the timestamp, use
  timespec_store().

- We now check whether we were able to write the timestamp file in full with
  fflush_and_check() the way we usually do it.

src/shared/condition.c
src/update-done/update-done.c

index f13fa6a9fdc548383be77be2dbf2b706b85c1e92..69b4837e1ffdb209a0edc9655ce77c708c8d745b 100644 (file)
@@ -329,9 +329,9 @@ static int condition_test_needs_update(Condition *c) {
                 uint64_t timestamp;
                 int r;
 
-                r = parse_env_file(p, NULL, "TimestampNSec", &timestamp_str, NULL);
+                r = parse_env_file(p, NULL, "TIMESTAMP_NSEC", &timestamp_str, NULL);
                 if (r < 0) {
-                        log_error_errno(-r, "Failed to parse timestamp file '%s', using mtime: %m", p);
+                        log_error_errno(r, "Failed to parse timestamp file '%s', using mtime: %m", p);
                         return true;
                 } else if (r == 0) {
                         log_debug("No data in timestamp file '%s', using mtime", p);
@@ -340,12 +340,11 @@ static int condition_test_needs_update(Condition *c) {
 
                 r = safe_atou64(timestamp_str, &timestamp);
                 if (r < 0) {
-                        log_error_errno(-r, "Failed to parse timestamp value '%s' in file '%s', using mtime: %m",
-                                        timestamp_str, p);
+                        log_error_errno(r, "Failed to parse timestamp value '%s' in file '%s', using mtime: %m", timestamp_str, p);
                         return true;
                 }
 
-                other.st_mtim.tv_nsec = timestamp % NSEC_PER_SEC;
+                timespec_store(&other.st_mtim, timestamp);
         }
 
         return usr.st_mtim.tv_nsec > other.st_mtim.tv_nsec;
index 5cc5abfddf7fdb3b0aa0943665610974c622a220..48c2a3fff4eb048ed6c92b48a0c4102123438f7e 100644 (file)
@@ -18,6 +18,7 @@
 ***/
 
 #include "fd-util.h"
+#include "fileio.h"
 #include "io-util.h"
 #include "selinux-util.h"
 #include "util.h"
@@ -32,8 +33,8 @@ static int apply_timestamp(const char *path, struct timespec *ts) {
                 *ts,
                 *ts
         };
-        int fd = -1;
         _cleanup_fclose_ FILE *f = NULL;
+        int fd = -1;
         int r;
 
         assert(path);
@@ -59,18 +60,20 @@ static int apply_timestamp(const char *path, struct timespec *ts) {
                 return log_error_errno(errno, "Failed to create/open timestamp file %s: %m", path);
         }
 
-        f = fdopen(fd, "w");
+        f = fdopen(fd, "we");
         if (!f) {
                 safe_close(fd);
                 return log_error_errno(errno, "Failed to fdopen() timestamp file %s: %m", path);
         }
 
         (void) fprintf(f,
-                       "%s"
-                       "TimestampNSec=" NSEC_FMT "\n",
-                       MESSAGE, timespec_load_nsec(ts));
+                       MESSAGE
+                       "TIMESTAMP_NSEC=" NSEC_FMT "\n",
+                       timespec_load_nsec(ts));
 
-        fflush(f);
+        r = fflush_and_check(f);
+        if (r < 0)
+                return log_error_errno(r, "Failed to write timestamp file: %m");
 
         if (futimens(fd, twice) < 0)
                 return log_error_errno(errno, "Failed to update timestamp on %s: %m", path);