systemd/SOURCES/0941-format-table-add-TABLE_TIMESTAMP_UTC-and-_RELATIVE.patch
2023-09-27 14:14:58 +00:00

90 lines
3.4 KiB
Diff

From 2fb7d36caf560e4ce57265673da7a518d7a5348f Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Tue, 16 Jul 2019 00:44:14 +0900
Subject: [PATCH] format-table: add TABLE_TIMESTAMP_UTC and _RELATIVE
(cherry picked from commit c5bbb2b5be079852d92d16ebc0d0840929ed82e1)
Related: #2156786
---
src/basic/format-table.c | 25 ++++++++++++++++++-------
src/basic/format-table.h | 2 ++
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/src/basic/format-table.c b/src/basic/format-table.c
index c541e92b3c..5f2e5e3d73 100644
--- a/src/basic/format-table.c
+++ b/src/basic/format-table.c
@@ -236,6 +236,8 @@ static size_t table_data_size(TableDataType type, const void *data) {
return sizeof(bool);
case TABLE_TIMESTAMP:
+ case TABLE_TIMESTAMP_UTC:
+ case TABLE_TIMESTAMP_RELATIVE:
case TABLE_TIMESPAN:
return sizeof(usec_t);
@@ -700,6 +702,8 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
break;
case TABLE_TIMESTAMP:
+ case TABLE_TIMESTAMP_UTC:
+ case TABLE_TIMESTAMP_RELATIVE:
case TABLE_TIMESPAN:
buffer.usec = va_arg(ap, usec_t);
data = &buffer.usec;
@@ -837,11 +841,9 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
return 0;
case TABLE_TIMESTAMP:
- if (a->timestamp < b->timestamp)
- return -1;
- if (a->timestamp > b->timestamp)
- return 1;
- return 0;
+ case TABLE_TIMESTAMP_UTC:
+ case TABLE_TIMESTAMP_RELATIVE:
+ return CMP(a->timestamp, b->timestamp);
case TABLE_TIMESPAN:
if (a->timespan < b->timespan)
@@ -952,14 +954,23 @@ static const char *table_data_format(TableData *d) {
case TABLE_BOOLEAN:
return yes_no(d->boolean);
- case TABLE_TIMESTAMP: {
+ case TABLE_TIMESTAMP:
+ case TABLE_TIMESTAMP_UTC:
+ case TABLE_TIMESTAMP_RELATIVE: {
_cleanup_free_ char *p;
+ char *ret;
p = new(char, FORMAT_TIMESTAMP_MAX);
if (!p)
return NULL;
- if (!format_timestamp(p, FORMAT_TIMESTAMP_MAX, d->timestamp))
+ if (d->type == TABLE_TIMESTAMP)
+ ret = format_timestamp(p, FORMAT_TIMESTAMP_MAX, d->timestamp);
+ else if (d->type == TABLE_TIMESTAMP_UTC)
+ ret = format_timestamp_utc(p, FORMAT_TIMESTAMP_MAX, d->timestamp);
+ else
+ ret = format_timestamp_relative(p, FORMAT_TIMESTAMP_MAX, d->timestamp);
+ if (!ret)
return "n/a";
d->formatted = TAKE_PTR(p);
diff --git a/src/basic/format-table.h b/src/basic/format-table.h
index 5a076b5383..1c8ab5436d 100644
--- a/src/basic/format-table.h
+++ b/src/basic/format-table.h
@@ -12,6 +12,8 @@ typedef enum TableDataType {
TABLE_STRING,
TABLE_BOOLEAN,
TABLE_TIMESTAMP,
+ TABLE_TIMESTAMP_UTC,
+ TABLE_TIMESTAMP_RELATIVE,
TABLE_TIMESPAN,
TABLE_SIZE,
TABLE_UINT32,