mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 23:21:22 +03:00
tree-wide: add FORMAT_TIMESTAMP_RELATIVE()
This commit is contained in:
parent
5291f26d4a
commit
32fc5c4763
@ -129,8 +129,11 @@ static inline char* format_timestamp(char *buf, size_t l, usec_t t) {
|
||||
* see C11 §6.5.2.5, and
|
||||
* https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks */
|
||||
#define FORMAT_TIMESTAMP(t) format_timestamp((char[FORMAT_TIMESTAMP_MAX]){}, FORMAT_TIMESTAMP_MAX, t)
|
||||
#define FORMAT_TIMESTAMP_RELATIVE(t) \
|
||||
format_timestamp_relative((char[FORMAT_TIMESTAMP_RELATIVE_MAX]){}, FORMAT_TIMESTAMP_RELATIVE_MAX, t)
|
||||
#define FORMAT_TIMESPAN(t, accuracy) format_timespan((char[FORMAT_TIMESPAN_MAX]){}, FORMAT_TIMESPAN_MAX, t, accuracy)
|
||||
|
||||
|
||||
int parse_timestamp(const char *t, usec_t *usec);
|
||||
|
||||
int parse_sec(const char *t, usec_t *usec);
|
||||
|
@ -645,15 +645,11 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
|
||||
usec_t u;
|
||||
|
||||
r = safe_atou64(timestamp, &u);
|
||||
if (r >= 0) {
|
||||
char relative[FORMAT_TIMESPAN_MAX];
|
||||
if (r >= 0)
|
||||
fprintf(file, " Timestamp: %s (%s)\n",
|
||||
FORMAT_TIMESTAMP(u), FORMAT_TIMESTAMP_RELATIVE(u));
|
||||
|
||||
fprintf(file,
|
||||
" Timestamp: %s (%s)\n",
|
||||
FORMAT_TIMESTAMP(u),
|
||||
format_timestamp_relative(relative, sizeof(relative), u));
|
||||
|
||||
} else
|
||||
else
|
||||
fprintf(file, " Timestamp: %s\n", timestamp);
|
||||
}
|
||||
|
||||
|
@ -450,7 +450,6 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
|
||||
|
||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
||||
char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
|
||||
const char *s1, *s2;
|
||||
SessionStatusInfo i = {};
|
||||
int r;
|
||||
@ -471,7 +470,7 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
|
||||
else
|
||||
printf("%"PRIu32"\n", i.uid);
|
||||
|
||||
s1 = format_timestamp_relative(since1, sizeof(since1), i.timestamp.realtime);
|
||||
s1 = FORMAT_TIMESTAMP_RELATIVE(i.timestamp.realtime);
|
||||
s2 = FORMAT_TIMESTAMP(i.timestamp.realtime);
|
||||
|
||||
if (s1)
|
||||
@ -580,7 +579,6 @@ static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line)
|
||||
|
||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
||||
char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
|
||||
const char *s1, *s2;
|
||||
_cleanup_(user_status_info_clear) UserStatusInfo i = {};
|
||||
int r;
|
||||
@ -599,7 +597,7 @@ static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line)
|
||||
else
|
||||
printf("%"PRIu32"\n", i.uid);
|
||||
|
||||
s1 = format_timestamp_relative(since1, sizeof(since1), i.timestamp.realtime);
|
||||
s1 = FORMAT_TIMESTAMP_RELATIVE(i.timestamp.realtime);
|
||||
s2 = FORMAT_TIMESTAMP(i.timestamp.realtime);
|
||||
|
||||
if (s1)
|
||||
|
@ -507,7 +507,6 @@ static void machine_status_info_clear(MachineStatusInfo *info) {
|
||||
}
|
||||
|
||||
static void print_machine_status_info(sd_bus *bus, MachineStatusInfo *i) {
|
||||
char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
|
||||
_cleanup_free_ char *addresses = NULL;
|
||||
const char *s1, *s2;
|
||||
int ifi = -1;
|
||||
@ -522,7 +521,7 @@ static void print_machine_status_info(sd_bus *bus, MachineStatusInfo *i) {
|
||||
else
|
||||
putchar('\n');
|
||||
|
||||
s1 = format_timestamp_relative(since1, sizeof(since1), i->timestamp.realtime);
|
||||
s1 = FORMAT_TIMESTAMP_RELATIVE(i->timestamp.realtime);
|
||||
s2 = FORMAT_TIMESTAMP(i->timestamp.realtime);
|
||||
|
||||
if (s1)
|
||||
@ -827,7 +826,6 @@ typedef struct ImageStatusInfo {
|
||||
} ImageStatusInfo;
|
||||
|
||||
static void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) {
|
||||
char ts_relative[FORMAT_TIMESTAMP_RELATIVE_MAX];
|
||||
char bs[FORMAT_BYTES_MAX];
|
||||
char bs_exclusive[FORMAT_BYTES_MAX];
|
||||
const char *s1, *s2, *s3, *s4;
|
||||
@ -857,14 +855,14 @@ static void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) {
|
||||
i->read_only ? "read-only" : "writable",
|
||||
i->read_only ? ansi_normal() : "");
|
||||
|
||||
s1 = format_timestamp_relative(ts_relative, sizeof(ts_relative), i->crtime);
|
||||
s1 = FORMAT_TIMESTAMP_RELATIVE(i->crtime);
|
||||
s2 = FORMAT_TIMESTAMP(i->crtime);
|
||||
if (s1 && s2)
|
||||
printf("\t Created: %s; %s\n", s2, s1);
|
||||
else if (s2)
|
||||
printf("\t Created: %s\n", s2);
|
||||
|
||||
s1 = format_timestamp_relative(ts_relative, sizeof(ts_relative), i->mtime);
|
||||
s1 = FORMAT_TIMESTAMP_RELATIVE(i->mtime);
|
||||
s2 = FORMAT_TIMESTAMP(i->mtime);
|
||||
if (s1 && s2)
|
||||
printf("\tModified: %s; %s\n", s2, s1);
|
||||
|
@ -300,7 +300,7 @@ static void print_status_info(
|
||||
UnitStatusInfo *i,
|
||||
bool *ellipsized) {
|
||||
|
||||
char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], since2[FORMAT_TIMESTAMP_MAX];
|
||||
char since2[FORMAT_TIMESTAMP_MAX];
|
||||
const char *s1, *s2, *active_on, *active_off, *on, *off, *ss, *fs;
|
||||
_cleanup_free_ char *formatted_path = NULL;
|
||||
ExecStatusInfo *p;
|
||||
@ -419,7 +419,7 @@ static void print_status_info(
|
||||
STRPTR_IN_SET(i->active_state, "activating") ? i->inactive_exit_timestamp :
|
||||
i->active_exit_timestamp;
|
||||
|
||||
s1 = format_timestamp_relative(since1, sizeof(since1), timestamp);
|
||||
s1 = FORMAT_TIMESTAMP_RELATIVE(timestamp);
|
||||
s2 = format_timestamp_style(since2, sizeof(since2), timestamp, arg_timestamp_style);
|
||||
|
||||
if (s1)
|
||||
@ -442,8 +442,7 @@ static void print_status_info(
|
||||
}
|
||||
|
||||
if (endswith(i->id, ".timer")) {
|
||||
char tstamp1[FORMAT_TIMESTAMP_RELATIVE_MAX],
|
||||
tstamp2[FORMAT_TIMESTAMP_MAX];
|
||||
char tstamp2[FORMAT_TIMESTAMP_MAX];
|
||||
const char *next_rel_time, *next_time;
|
||||
dual_timestamp nw, next = {i->next_elapse_real,
|
||||
i->next_elapse_monotonic};
|
||||
@ -453,7 +452,7 @@ static void print_status_info(
|
||||
|
||||
dual_timestamp_get(&nw);
|
||||
next_elapse = calc_next_elapse(&nw, &next);
|
||||
next_rel_time = format_timestamp_relative(tstamp1, sizeof tstamp1, next_elapse);
|
||||
next_rel_time = FORMAT_TIMESTAMP_RELATIVE(next_elapse);
|
||||
next_time = format_timestamp_style(tstamp2, sizeof tstamp2, next_elapse, arg_timestamp_style);
|
||||
|
||||
if (next_time && next_rel_time)
|
||||
@ -478,7 +477,7 @@ static void print_status_info(
|
||||
UnitCondition *c;
|
||||
int n = 0;
|
||||
|
||||
s1 = format_timestamp_relative(since1, sizeof(since1), i->condition_timestamp);
|
||||
s1 = FORMAT_TIMESTAMP_RELATIVE(i->condition_timestamp);
|
||||
s2 = format_timestamp_style(since2, sizeof(since2), i->condition_timestamp, arg_timestamp_style);
|
||||
|
||||
printf(" Condition: start %scondition failed%s at %s%s%s\n",
|
||||
@ -500,7 +499,7 @@ static void print_status_info(
|
||||
}
|
||||
|
||||
if (!i->assert_result && i->assert_timestamp > 0) {
|
||||
s1 = format_timestamp_relative(since1, sizeof(since1), i->assert_timestamp);
|
||||
s1 = FORMAT_TIMESTAMP_RELATIVE(i->assert_timestamp);
|
||||
s2 = format_timestamp_style(since2, sizeof(since2), i->assert_timestamp, arg_timestamp_style);
|
||||
|
||||
printf(" Assert: start %sassertion failed%s at %s%s%s\n",
|
||||
@ -2015,7 +2014,7 @@ static int show_all(
|
||||
}
|
||||
|
||||
static int show_system_status(sd_bus *bus) {
|
||||
char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], since2[FORMAT_TIMESTAMP_MAX];
|
||||
char since2[FORMAT_TIMESTAMP_MAX];
|
||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
_cleanup_(machine_info_clear) struct machine_info mi = {};
|
||||
_cleanup_free_ char *hn = NULL;
|
||||
@ -2059,7 +2058,7 @@ static int show_system_status(sd_bus *bus) {
|
||||
|
||||
printf(" Since: %s; %s\n",
|
||||
format_timestamp_style(since2, sizeof(since2), mi.timestamp, arg_timestamp_style),
|
||||
format_timestamp_relative(since1, sizeof(since1), mi.timestamp));
|
||||
FORMAT_TIMESTAMP_RELATIVE(mi.timestamp));
|
||||
|
||||
printf(" CGroup: %s\n", mi.control_group ?: "/");
|
||||
if (IN_SET(arg_transport,
|
||||
|
Loading…
Reference in New Issue
Block a user