mirror of
https://github.com/systemd/systemd.git
synced 2025-03-31 14:50:15 +03:00
Always allow timestamps to be printed
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.
This commit is contained in:
parent
6dbef3053d
commit
d3d280242c
@ -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 */
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user