mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 14:55:37 +03:00
tree-wide: FORMAT_TIMESTAMP() or friends must be used as a function argument
Follow-ups for #20109.
This commit is contained in:
parent
fa3f917a25
commit
f843f85da8
@ -209,19 +209,17 @@ void server_space_usage_message(Server *s, JournalStorage *storage) {
|
|||||||
|
|
||||||
const JournalMetrics *metrics = &storage->metrics;
|
const JournalMetrics *metrics = &storage->metrics;
|
||||||
|
|
||||||
const char
|
|
||||||
*vfs_used = FORMAT_BYTES(storage->space.vfs_used),
|
|
||||||
*limit = FORMAT_BYTES(storage->space.limit),
|
|
||||||
*available = FORMAT_BYTES(storage->space.available);
|
|
||||||
|
|
||||||
server_driver_message(s, 0,
|
server_driver_message(s, 0,
|
||||||
"MESSAGE_ID=" SD_MESSAGE_JOURNAL_USAGE_STR,
|
"MESSAGE_ID=" SD_MESSAGE_JOURNAL_USAGE_STR,
|
||||||
LOG_MESSAGE("%s (%s) is %s, max %s, %s free.",
|
LOG_MESSAGE("%s (%s) is %s, max %s, %s free.",
|
||||||
storage->name, storage->path, vfs_used, limit, available),
|
storage->name, storage->path,
|
||||||
|
FORMAT_BYTES(storage->space.vfs_used),
|
||||||
|
FORMAT_BYTES(storage->space.limit),
|
||||||
|
FORMAT_BYTES(storage->space.available)),
|
||||||
"JOURNAL_NAME=%s", storage->name,
|
"JOURNAL_NAME=%s", storage->name,
|
||||||
"JOURNAL_PATH=%s", storage->path,
|
"JOURNAL_PATH=%s", storage->path,
|
||||||
"CURRENT_USE=%"PRIu64, storage->space.vfs_used,
|
"CURRENT_USE=%"PRIu64, storage->space.vfs_used,
|
||||||
"CURRENT_USE_PRETTY=%s", vfs_used,
|
"CURRENT_USE_PRETTY=%s", FORMAT_BYTES(storage->space.vfs_used),
|
||||||
"MAX_USE=%"PRIu64, metrics->max_use,
|
"MAX_USE=%"PRIu64, metrics->max_use,
|
||||||
"MAX_USE_PRETTY=%s", FORMAT_BYTES(metrics->max_use),
|
"MAX_USE_PRETTY=%s", FORMAT_BYTES(metrics->max_use),
|
||||||
"DISK_KEEP_FREE=%"PRIu64, metrics->keep_free,
|
"DISK_KEEP_FREE=%"PRIu64, metrics->keep_free,
|
||||||
@ -229,9 +227,9 @@ void server_space_usage_message(Server *s, JournalStorage *storage) {
|
|||||||
"DISK_AVAILABLE=%"PRIu64, storage->space.vfs_available,
|
"DISK_AVAILABLE=%"PRIu64, storage->space.vfs_available,
|
||||||
"DISK_AVAILABLE_PRETTY=%s", FORMAT_BYTES(storage->space.vfs_available),
|
"DISK_AVAILABLE_PRETTY=%s", FORMAT_BYTES(storage->space.vfs_available),
|
||||||
"LIMIT=%"PRIu64, storage->space.limit,
|
"LIMIT=%"PRIu64, storage->space.limit,
|
||||||
"LIMIT_PRETTY=%s", limit,
|
"LIMIT_PRETTY=%s", FORMAT_BYTES(storage->space.limit),
|
||||||
"AVAILABLE=%"PRIu64, storage->space.available,
|
"AVAILABLE=%"PRIu64, storage->space.available,
|
||||||
"AVAILABLE_PRETTY=%s", available,
|
"AVAILABLE_PRETTY=%s", FORMAT_BYTES(storage->space.available),
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
||||||
const char *s1, *s2;
|
|
||||||
SessionStatusInfo i = {};
|
SessionStatusInfo i = {};
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -470,13 +469,10 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
|
|||||||
else
|
else
|
||||||
printf("%"PRIu32"\n", i.uid);
|
printf("%"PRIu32"\n", i.uid);
|
||||||
|
|
||||||
s1 = FORMAT_TIMESTAMP_RELATIVE(i.timestamp.realtime);
|
if (i.timestamp.realtime > 0 && i.timestamp.realtime < USEC_INFINITY)
|
||||||
s2 = FORMAT_TIMESTAMP(i.timestamp.realtime);
|
printf("\t Since: %s; %s\n",
|
||||||
|
FORMAT_TIMESTAMP(i.timestamp.realtime),
|
||||||
if (s1)
|
FORMAT_TIMESTAMP_RELATIVE(i.timestamp.realtime));
|
||||||
printf("\t Since: %s; %s\n", s2, s1);
|
|
||||||
else if (s2)
|
|
||||||
printf("\t Since: %s\n", s2);
|
|
||||||
|
|
||||||
if (i.leader > 0) {
|
if (i.leader > 0) {
|
||||||
_cleanup_free_ char *t = NULL;
|
_cleanup_free_ char *t = NULL;
|
||||||
@ -579,7 +575,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_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
||||||
const char *s1, *s2;
|
|
||||||
_cleanup_(user_status_info_clear) UserStatusInfo i = {};
|
_cleanup_(user_status_info_clear) UserStatusInfo i = {};
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -597,13 +592,10 @@ static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line)
|
|||||||
else
|
else
|
||||||
printf("%"PRIu32"\n", i.uid);
|
printf("%"PRIu32"\n", i.uid);
|
||||||
|
|
||||||
s1 = FORMAT_TIMESTAMP_RELATIVE(i.timestamp.realtime);
|
if (i.timestamp.realtime > 0 && i.timestamp.realtime < USEC_INFINITY)
|
||||||
s2 = FORMAT_TIMESTAMP(i.timestamp.realtime);
|
printf("\t Since: %s; %s\n",
|
||||||
|
FORMAT_TIMESTAMP(i.timestamp.realtime),
|
||||||
if (s1)
|
FORMAT_TIMESTAMP_RELATIVE(i.timestamp.realtime));
|
||||||
printf("\t Since: %s; %s\n", s2, s1);
|
|
||||||
else if (s2)
|
|
||||||
printf("\t Since: %s\n", s2);
|
|
||||||
|
|
||||||
if (!isempty(i.state))
|
if (!isempty(i.state))
|
||||||
printf("\t State: %s\n", i.state);
|
printf("\t State: %s\n", i.state);
|
||||||
|
@ -507,8 +507,7 @@ static void machine_status_info_clear(MachineStatusInfo *info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void print_machine_status_info(sd_bus *bus, MachineStatusInfo *i) {
|
static void print_machine_status_info(sd_bus *bus, MachineStatusInfo *i) {
|
||||||
_cleanup_free_ char *addresses = NULL;
|
_cleanup_free_ char *addresses = NULL, *s1 = NULL, *s2 = NULL;
|
||||||
const char *s1, *s2;
|
|
||||||
int ifi = -1;
|
int ifi = -1;
|
||||||
|
|
||||||
assert(bus);
|
assert(bus);
|
||||||
@ -521,12 +520,12 @@ static void print_machine_status_info(sd_bus *bus, MachineStatusInfo *i) {
|
|||||||
else
|
else
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
||||||
s1 = FORMAT_TIMESTAMP_RELATIVE(i->timestamp.realtime);
|
s1 = strdup(strempty(FORMAT_TIMESTAMP_RELATIVE(i->timestamp.realtime)));
|
||||||
s2 = FORMAT_TIMESTAMP(i->timestamp.realtime);
|
s2 = strdup(strempty(FORMAT_TIMESTAMP(i->timestamp.realtime)));
|
||||||
|
|
||||||
if (s1)
|
if (!isempty(s1))
|
||||||
printf("\t Since: %s; %s\n", s2, s1);
|
printf("\t Since: %s; %s\n", strna(s2), s1);
|
||||||
else if (s2)
|
else if (!isempty(s2))
|
||||||
printf("\t Since: %s\n", s2);
|
printf("\t Since: %s\n", s2);
|
||||||
|
|
||||||
if (i->leader > 0) {
|
if (i->leader > 0) {
|
||||||
@ -826,8 +825,6 @@ typedef struct ImageStatusInfo {
|
|||||||
} ImageStatusInfo;
|
} ImageStatusInfo;
|
||||||
|
|
||||||
static void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) {
|
static void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) {
|
||||||
const char *s1, *s2, *s3, *s4;
|
|
||||||
|
|
||||||
assert(bus);
|
assert(bus);
|
||||||
assert(i);
|
assert(i);
|
||||||
|
|
||||||
@ -853,33 +850,29 @@ static void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) {
|
|||||||
i->read_only ? "read-only" : "writable",
|
i->read_only ? "read-only" : "writable",
|
||||||
i->read_only ? ansi_normal() : "");
|
i->read_only ? ansi_normal() : "");
|
||||||
|
|
||||||
s1 = FORMAT_TIMESTAMP_RELATIVE(i->crtime);
|
if (i->crtime > 0 && i->crtime < USEC_INFINITY)
|
||||||
s2 = FORMAT_TIMESTAMP(i->crtime);
|
printf("\t Created: %s; %s\n",
|
||||||
if (s1 && s2)
|
FORMAT_TIMESTAMP(i->crtime), FORMAT_TIMESTAMP_RELATIVE(i->crtime));
|
||||||
printf("\t Created: %s; %s\n", s2, s1);
|
|
||||||
else if (s2)
|
|
||||||
printf("\t Created: %s\n", s2);
|
|
||||||
|
|
||||||
s1 = FORMAT_TIMESTAMP_RELATIVE(i->mtime);
|
if (i->mtime > 0 && i->mtime < USEC_INFINITY)
|
||||||
s2 = FORMAT_TIMESTAMP(i->mtime);
|
printf("\tModified: %s; %s\n",
|
||||||
if (s1 && s2)
|
FORMAT_TIMESTAMP(i->mtime), FORMAT_TIMESTAMP_RELATIVE(i->mtime));
|
||||||
printf("\tModified: %s; %s\n", s2, s1);
|
|
||||||
else if (s2)
|
|
||||||
printf("\tModified: %s\n", s2);
|
|
||||||
|
|
||||||
s3 = FORMAT_BYTES(i->usage);
|
if (i->usage != UINT64_MAX) {
|
||||||
s4 = i->usage_exclusive != i->usage ? FORMAT_BYTES(i->usage_exclusive) : NULL;
|
if (i->usage_exclusive != i->usage && i->usage_exclusive != UINT64_MAX)
|
||||||
if (s3 && s4)
|
printf("\t Usage: %s (exclusive: %s)\n",
|
||||||
printf("\t Usage: %s (exclusive: %s)\n", s3, s4);
|
FORMAT_BYTES(i->usage), FORMAT_BYTES(i->usage_exclusive));
|
||||||
else if (s3)
|
else
|
||||||
printf("\t Usage: %s\n", s3);
|
printf("\t Usage: %s\n", FORMAT_BYTES(i->usage));
|
||||||
|
}
|
||||||
|
|
||||||
s3 = FORMAT_BYTES(i->limit);
|
if (i->limit != UINT64_MAX) {
|
||||||
s4 = i->limit_exclusive != i->limit ? FORMAT_BYTES(i->limit_exclusive) : NULL;
|
if (i->limit_exclusive != i->limit && i->limit_exclusive != UINT64_MAX)
|
||||||
if (s3 && s4)
|
printf("\t Limit: %s (exclusive: %s)\n",
|
||||||
printf("\t Limit: %s (exclusive: %s)\n", s3, s4);
|
FORMAT_BYTES(i->limit), FORMAT_BYTES(i->limit_exclusive));
|
||||||
else if (s3)
|
else
|
||||||
printf("\t Limit: %s\n", s3);
|
printf("\t Limit: %s\n", FORMAT_BYTES(i->limit));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int show_image_info(sd_bus *bus, const char *path, bool *new_line) {
|
static int show_image_info(sd_bus *bus, const char *path, bool *new_line) {
|
||||||
@ -934,18 +927,14 @@ typedef struct PoolStatusInfo {
|
|||||||
} PoolStatusInfo;
|
} PoolStatusInfo;
|
||||||
|
|
||||||
static void print_pool_status_info(sd_bus *bus, PoolStatusInfo *i) {
|
static void print_pool_status_info(sd_bus *bus, PoolStatusInfo *i) {
|
||||||
char *s;
|
|
||||||
|
|
||||||
if (i->path)
|
if (i->path)
|
||||||
printf("\t Path: %s\n", i->path);
|
printf("\t Path: %s\n", i->path);
|
||||||
|
|
||||||
s = FORMAT_BYTES(i->usage);
|
if (i->usage != UINT64_MAX)
|
||||||
if (s)
|
printf("\t Usage: %s\n", FORMAT_BYTES(i->usage));
|
||||||
printf("\t Usage: %s\n", s);
|
|
||||||
|
|
||||||
s = FORMAT_BYTES(i->limit);
|
if (i->limit != UINT64_MAX)
|
||||||
if (s)
|
printf("\t Limit: %s\n", FORMAT_BYTES(i->limit));
|
||||||
printf("\t Limit: %s\n", s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int show_pool_info(sd_bus *bus) {
|
static int show_pool_info(sd_bus *bus) {
|
||||||
|
@ -300,7 +300,7 @@ static void print_status_info(
|
|||||||
UnitStatusInfo *i,
|
UnitStatusInfo *i,
|
||||||
bool *ellipsized) {
|
bool *ellipsized) {
|
||||||
|
|
||||||
const char *s1, *s2, *active_on, *active_off, *on, *off, *ss, *fs;
|
const char *active_on, *active_off, *on, *off, *ss, *fs;
|
||||||
_cleanup_free_ char *formatted_path = NULL;
|
_cleanup_free_ char *formatted_path = NULL;
|
||||||
ExecStatusInfo *p;
|
ExecStatusInfo *p;
|
||||||
usec_t timestamp;
|
usec_t timestamp;
|
||||||
@ -418,12 +418,10 @@ static void print_status_info(
|
|||||||
STRPTR_IN_SET(i->active_state, "activating") ? i->inactive_exit_timestamp :
|
STRPTR_IN_SET(i->active_state, "activating") ? i->inactive_exit_timestamp :
|
||||||
i->active_exit_timestamp;
|
i->active_exit_timestamp;
|
||||||
|
|
||||||
s1 = FORMAT_TIMESTAMP_RELATIVE(timestamp);
|
if (timestamp > 0 && timestamp < USEC_INFINITY)
|
||||||
s2 = FORMAT_TIMESTAMP_STYLE(timestamp, arg_timestamp_style);
|
printf(" since %s; %s\n",
|
||||||
if (s1)
|
FORMAT_TIMESTAMP_STYLE(timestamp, arg_timestamp_style),
|
||||||
printf(" since %s; %s\n", s2, s1);
|
FORMAT_TIMESTAMP_RELATIVE(timestamp));
|
||||||
else if (s2)
|
|
||||||
printf(" since %s\n", s2);
|
|
||||||
else
|
else
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
@ -440,18 +438,18 @@ static void print_status_info(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (endswith(i->id, ".timer")) {
|
if (endswith(i->id, ".timer")) {
|
||||||
const char *next_time;
|
|
||||||
dual_timestamp nw, next = {i->next_elapse_real, i->next_elapse_monotonic};
|
dual_timestamp nw, next = {i->next_elapse_real, i->next_elapse_monotonic};
|
||||||
usec_t next_elapse;
|
usec_t next_elapse;
|
||||||
|
|
||||||
dual_timestamp_get(&nw);
|
dual_timestamp_get(&nw);
|
||||||
next_elapse = calc_next_elapse(&nw, &next);
|
next_elapse = calc_next_elapse(&nw, &next);
|
||||||
next_time = FORMAT_TIMESTAMP_STYLE(next_elapse, arg_timestamp_style);
|
|
||||||
|
|
||||||
printf(" Trigger: %s%s%s\n",
|
if (next_elapse > 0 && next_elapse < USEC_INFINITY)
|
||||||
strna(next_time),
|
printf(" Trigger: %s; %s\n",
|
||||||
next_time ? "; " : "",
|
FORMAT_TIMESTAMP_STYLE(next_elapse, arg_timestamp_style),
|
||||||
next_time ? strna(FORMAT_TIMESTAMP_RELATIVE(next_elapse)) : "");
|
FORMAT_TIMESTAMP_RELATIVE(next_elapse));
|
||||||
|
else
|
||||||
|
printf(" Trigger: n/a\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
STRV_FOREACH(t, i->triggers) {
|
STRV_FOREACH(t, i->triggers) {
|
||||||
@ -469,13 +467,11 @@ static void print_status_info(
|
|||||||
if (!i->condition_result && i->condition_timestamp > 0) {
|
if (!i->condition_result && i->condition_timestamp > 0) {
|
||||||
UnitCondition *c;
|
UnitCondition *c;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
const char *rel;
|
|
||||||
|
|
||||||
rel = FORMAT_TIMESTAMP_RELATIVE(i->condition_timestamp);
|
printf(" Condition: start %scondition failed%s at %s; %s\n",
|
||||||
printf(" Condition: start %scondition failed%s at %s%s%s\n",
|
|
||||||
ansi_highlight_yellow(), ansi_normal(),
|
ansi_highlight_yellow(), ansi_normal(),
|
||||||
FORMAT_TIMESTAMP_STYLE(i->condition_timestamp, arg_timestamp_style),
|
FORMAT_TIMESTAMP_STYLE(i->condition_timestamp, arg_timestamp_style),
|
||||||
rel ? "; " : "", strempty(rel));
|
FORMAT_TIMESTAMP_RELATIVE(i->condition_timestamp));
|
||||||
|
|
||||||
LIST_FOREACH(conditions, c, i->conditions)
|
LIST_FOREACH(conditions, c, i->conditions)
|
||||||
if (c->tristate < 0)
|
if (c->tristate < 0)
|
||||||
@ -492,13 +488,10 @@ static void print_status_info(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!i->assert_result && i->assert_timestamp > 0) {
|
if (!i->assert_result && i->assert_timestamp > 0) {
|
||||||
const char *rel;
|
printf(" Assert: start %sassertion failed%s at %s; %s\n",
|
||||||
|
|
||||||
rel = FORMAT_TIMESTAMP_RELATIVE(i->assert_timestamp);
|
|
||||||
printf(" Assert: start %sassertion failed%s at %s%s%s\n",
|
|
||||||
ansi_highlight_red(), ansi_normal(),
|
ansi_highlight_red(), ansi_normal(),
|
||||||
FORMAT_TIMESTAMP_STYLE(i->assert_timestamp, arg_timestamp_style),
|
FORMAT_TIMESTAMP_STYLE(i->assert_timestamp, arg_timestamp_style),
|
||||||
rel ? "; " : "", strempty(rel));
|
FORMAT_TIMESTAMP_RELATIVE(i->assert_timestamp));
|
||||||
if (i->failed_assert_trigger)
|
if (i->failed_assert_trigger)
|
||||||
printf(" none of the trigger assertions were met\n");
|
printf(" none of the trigger assertions were met\n");
|
||||||
else if (i->failed_assert)
|
else if (i->failed_assert)
|
||||||
|
@ -384,8 +384,7 @@ static void test_FORMAT_TIMESTAMP(void) {
|
|||||||
assert_se(parse_timestamp(buf, &y) >= 0);
|
assert_se(parse_timestamp(buf, &y) >= 0);
|
||||||
assert_se(x / USEC_PER_SEC == y / USEC_PER_SEC);
|
assert_se(x / USEC_PER_SEC == y / USEC_PER_SEC);
|
||||||
|
|
||||||
char *t = FORMAT_TIMESTAMP(x);
|
assert_se(streq(FORMAT_TIMESTAMP(x), buf));
|
||||||
assert_se(streq(t, buf));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user