]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Always allow timestamps to be printed
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 21 May 2018 18:39:09 +0000 (20:39 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 31 May 2018 12:30:23 +0000 (14:30 +0200)
If the timestamp is above 9999-12-30, (or 2038-something-something on 32 bit),
use XXXX-XX-XX XX:XX:XX as the replacement.

The problem with refusing to print timestamps is that our code accepts such
timestamps, so we can't really just refuse to process them afterwards. Also, it
makes journal files non-portable, because suddently we might completely refuse
to print entries which are totally OK on a different machine.

src/basic/time-util.c
src/shared/logs-show.c
src/test/test-time-util.c

index 5d278d42cb83e1d02ba383c4b1e1ff07fdfe56a9..0601d4fa92d7b72cfdab772953eeb93d3e8dd017 100644 (file)
@@ -282,8 +282,11 @@ static char *format_timestamp_internal(
                 return NULL; /* Timestamp is unset */
 
         /* Let's not format times with years > 9999 */
-        if (t > USEC_TIMESTAMP_FORMATTABLE_MAX)
-                return NULL;
+        if (t > USEC_TIMESTAMP_FORMATTABLE_MAX) {
+                assert(l >= strlen("--- XXXX-XX-XX XX:XX:XX") + 1);
+                strcpy(buf, "--- XXXX-XX-XX XX:XX:XX");
+                return buf;
+        }
 
         sec = (time_t) (t / USEC_PER_SEC); /* Round down */
 
index 365c91300979561ae646d0617ac4acf282fe6385..401f3630527a7d02ee216f436b15293762b0db07 100644 (file)
@@ -301,11 +301,6 @@ static int output_timestamp_realtime(FILE *f, sd_journal *j, OutputMode mode, Ou
         if (r < 0)
                 return log_error_errno(r, "Failed to get realtime timestamp: %m");
 
-        if (x > USEC_TIMESTAMP_FORMATTABLE_MAX) {
-                log_error("Timestamp cannot be printed");
-                return -EINVAL;
-        }
-
         if (IN_SET(mode, OUTPUT_SHORT_FULL, OUTPUT_WITH_UNIT)) {
                 const char *k;
 
@@ -314,7 +309,7 @@ static int output_timestamp_realtime(FILE *f, sd_journal *j, OutputMode mode, Ou
                 else
                         k = format_timestamp(buf, sizeof(buf), x);
                 if (!k) {
-                        log_error("Failed to format timestamp.");
+                        log_error("Failed to format timestamp: %"PRIu64, x);
                         return -EINVAL;
                 }
 
index 5b8e7c7b35d74572d878af77cc4dd865048a723d..ab4b7ce282fe2310288e65e19e7aef5565ea0938 100644 (file)
@@ -287,11 +287,12 @@ static void test_format_timestamp_utc(void) {
 
 #if SIZEOF_TIME_T == 8
         test_format_timestamp_utc_one(USEC_TIMESTAMP_FORMATTABLE_MAX, "Thu 9999-12-30 23:59:59 UTC");
+        test_format_timestamp_utc_one(USEC_TIMESTAMP_FORMATTABLE_MAX + 1, "--- XXXX-XX-XX XX:XX:XX");
 #elif SIZEOF_TIME_T == 4
         test_format_timestamp_utc_one(USEC_TIMESTAMP_FORMATTABLE_MAX, "Tue 2038-01-19 03:14:07 UTC");
+        test_format_timestamp_utc_one(USEC_TIMESTAMP_FORMATTABLE_MAX + 1, "--- XXXX-XX-XX XX:XX:XX");
 #endif
 
-        test_format_timestamp_utc_one(USEC_TIMESTAMP_FORMATTABLE_MAX+1, NULL);
         test_format_timestamp_utc_one(USEC_INFINITY, NULL);
 }