mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +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 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,
|
||||
"MESSAGE_ID=" SD_MESSAGE_JOURNAL_USAGE_STR,
|
||||
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_PATH=%s", storage->path,
|
||||
"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_PRETTY=%s", FORMAT_BYTES(metrics->max_use),
|
||||
"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_PRETTY=%s", FORMAT_BYTES(storage->space.vfs_available),
|
||||
"LIMIT=%"PRIu64, storage->space.limit,
|
||||
"LIMIT_PRETTY=%s", limit,
|
||||
"LIMIT_PRETTY=%s", FORMAT_BYTES(storage->space.limit),
|
||||
"AVAILABLE=%"PRIu64, storage->space.available,
|
||||
"AVAILABLE_PRETTY=%s", available,
|
||||
"AVAILABLE_PRETTY=%s", FORMAT_BYTES(storage->space.available),
|
||||
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_message_unrefp) sd_bus_message *m = NULL;
|
||||
const char *s1, *s2;
|
||||
SessionStatusInfo i = {};
|
||||
int r;
|
||||
|
||||
@ -470,13 +469,10 @@ 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(i.timestamp.realtime);
|
||||
s2 = FORMAT_TIMESTAMP(i.timestamp.realtime);
|
||||
|
||||
if (s1)
|
||||
printf("\t Since: %s; %s\n", s2, s1);
|
||||
else if (s2)
|
||||
printf("\t Since: %s\n", s2);
|
||||
if (i.timestamp.realtime > 0 && i.timestamp.realtime < USEC_INFINITY)
|
||||
printf("\t Since: %s; %s\n",
|
||||
FORMAT_TIMESTAMP(i.timestamp.realtime),
|
||||
FORMAT_TIMESTAMP_RELATIVE(i.timestamp.realtime));
|
||||
|
||||
if (i.leader > 0) {
|
||||
_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_message_unrefp) sd_bus_message *m = NULL;
|
||||
const char *s1, *s2;
|
||||
_cleanup_(user_status_info_clear) UserStatusInfo i = {};
|
||||
int r;
|
||||
|
||||
@ -597,13 +592,10 @@ 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(i.timestamp.realtime);
|
||||
s2 = FORMAT_TIMESTAMP(i.timestamp.realtime);
|
||||
|
||||
if (s1)
|
||||
printf("\t Since: %s; %s\n", s2, s1);
|
||||
else if (s2)
|
||||
printf("\t Since: %s\n", s2);
|
||||
if (i.timestamp.realtime > 0 && i.timestamp.realtime < USEC_INFINITY)
|
||||
printf("\t Since: %s; %s\n",
|
||||
FORMAT_TIMESTAMP(i.timestamp.realtime),
|
||||
FORMAT_TIMESTAMP_RELATIVE(i.timestamp.realtime));
|
||||
|
||||
if (!isempty(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) {
|
||||
_cleanup_free_ char *addresses = NULL;
|
||||
const char *s1, *s2;
|
||||
_cleanup_free_ char *addresses = NULL, *s1 = NULL, *s2 = NULL;
|
||||
int ifi = -1;
|
||||
|
||||
assert(bus);
|
||||
@ -521,12 +520,12 @@ static void print_machine_status_info(sd_bus *bus, MachineStatusInfo *i) {
|
||||
else
|
||||
putchar('\n');
|
||||
|
||||
s1 = FORMAT_TIMESTAMP_RELATIVE(i->timestamp.realtime);
|
||||
s2 = FORMAT_TIMESTAMP(i->timestamp.realtime);
|
||||
s1 = strdup(strempty(FORMAT_TIMESTAMP_RELATIVE(i->timestamp.realtime)));
|
||||
s2 = strdup(strempty(FORMAT_TIMESTAMP(i->timestamp.realtime)));
|
||||
|
||||
if (s1)
|
||||
printf("\t Since: %s; %s\n", s2, s1);
|
||||
else if (s2)
|
||||
if (!isempty(s1))
|
||||
printf("\t Since: %s; %s\n", strna(s2), s1);
|
||||
else if (!isempty(s2))
|
||||
printf("\t Since: %s\n", s2);
|
||||
|
||||
if (i->leader > 0) {
|
||||
@ -826,8 +825,6 @@ typedef struct ImageStatusInfo {
|
||||
} ImageStatusInfo;
|
||||
|
||||
static void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) {
|
||||
const char *s1, *s2, *s3, *s4;
|
||||
|
||||
assert(bus);
|
||||
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 ? ansi_normal() : "");
|
||||
|
||||
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);
|
||||
if (i->crtime > 0 && i->crtime < USEC_INFINITY)
|
||||
printf("\t Created: %s; %s\n",
|
||||
FORMAT_TIMESTAMP(i->crtime), FORMAT_TIMESTAMP_RELATIVE(i->crtime));
|
||||
|
||||
s1 = FORMAT_TIMESTAMP_RELATIVE(i->mtime);
|
||||
s2 = FORMAT_TIMESTAMP(i->mtime);
|
||||
if (s1 && s2)
|
||||
printf("\tModified: %s; %s\n", s2, s1);
|
||||
else if (s2)
|
||||
printf("\tModified: %s\n", s2);
|
||||
if (i->mtime > 0 && i->mtime < USEC_INFINITY)
|
||||
printf("\tModified: %s; %s\n",
|
||||
FORMAT_TIMESTAMP(i->mtime), FORMAT_TIMESTAMP_RELATIVE(i->mtime));
|
||||
|
||||
s3 = FORMAT_BYTES(i->usage);
|
||||
s4 = i->usage_exclusive != i->usage ? FORMAT_BYTES(i->usage_exclusive) : NULL;
|
||||
if (s3 && s4)
|
||||
printf("\t Usage: %s (exclusive: %s)\n", s3, s4);
|
||||
else if (s3)
|
||||
printf("\t Usage: %s\n", s3);
|
||||
if (i->usage != UINT64_MAX) {
|
||||
if (i->usage_exclusive != i->usage && i->usage_exclusive != UINT64_MAX)
|
||||
printf("\t Usage: %s (exclusive: %s)\n",
|
||||
FORMAT_BYTES(i->usage), FORMAT_BYTES(i->usage_exclusive));
|
||||
else
|
||||
printf("\t Usage: %s\n", FORMAT_BYTES(i->usage));
|
||||
}
|
||||
|
||||
s3 = FORMAT_BYTES(i->limit);
|
||||
s4 = i->limit_exclusive != i->limit ? FORMAT_BYTES(i->limit_exclusive) : NULL;
|
||||
if (s3 && s4)
|
||||
printf("\t Limit: %s (exclusive: %s)\n", s3, s4);
|
||||
else if (s3)
|
||||
printf("\t Limit: %s\n", s3);
|
||||
if (i->limit != UINT64_MAX) {
|
||||
if (i->limit_exclusive != i->limit && i->limit_exclusive != UINT64_MAX)
|
||||
printf("\t Limit: %s (exclusive: %s)\n",
|
||||
FORMAT_BYTES(i->limit), FORMAT_BYTES(i->limit_exclusive));
|
||||
else
|
||||
printf("\t Limit: %s\n", FORMAT_BYTES(i->limit));
|
||||
}
|
||||
}
|
||||
|
||||
static int show_image_info(sd_bus *bus, const char *path, bool *new_line) {
|
||||
@ -934,18 +927,14 @@ typedef struct PoolStatusInfo {
|
||||
} PoolStatusInfo;
|
||||
|
||||
static void print_pool_status_info(sd_bus *bus, PoolStatusInfo *i) {
|
||||
char *s;
|
||||
|
||||
if (i->path)
|
||||
printf("\t Path: %s\n", i->path);
|
||||
|
||||
s = FORMAT_BYTES(i->usage);
|
||||
if (s)
|
||||
printf("\t Usage: %s\n", s);
|
||||
if (i->usage != UINT64_MAX)
|
||||
printf("\t Usage: %s\n", FORMAT_BYTES(i->usage));
|
||||
|
||||
s = FORMAT_BYTES(i->limit);
|
||||
if (s)
|
||||
printf("\t Limit: %s\n", s);
|
||||
if (i->limit != UINT64_MAX)
|
||||
printf("\t Limit: %s\n", FORMAT_BYTES(i->limit));
|
||||
}
|
||||
|
||||
static int show_pool_info(sd_bus *bus) {
|
||||
|
@ -300,7 +300,7 @@ static void print_status_info(
|
||||
UnitStatusInfo *i,
|
||||
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;
|
||||
ExecStatusInfo *p;
|
||||
usec_t timestamp;
|
||||
@ -418,12 +418,10 @@ static void print_status_info(
|
||||
STRPTR_IN_SET(i->active_state, "activating") ? i->inactive_exit_timestamp :
|
||||
i->active_exit_timestamp;
|
||||
|
||||
s1 = FORMAT_TIMESTAMP_RELATIVE(timestamp);
|
||||
s2 = FORMAT_TIMESTAMP_STYLE(timestamp, arg_timestamp_style);
|
||||
if (s1)
|
||||
printf(" since %s; %s\n", s2, s1);
|
||||
else if (s2)
|
||||
printf(" since %s\n", s2);
|
||||
if (timestamp > 0 && timestamp < USEC_INFINITY)
|
||||
printf(" since %s; %s\n",
|
||||
FORMAT_TIMESTAMP_STYLE(timestamp, arg_timestamp_style),
|
||||
FORMAT_TIMESTAMP_RELATIVE(timestamp));
|
||||
else
|
||||
printf("\n");
|
||||
|
||||
@ -440,18 +438,18 @@ static void print_status_info(
|
||||
}
|
||||
|
||||
if (endswith(i->id, ".timer")) {
|
||||
const char *next_time;
|
||||
dual_timestamp nw, next = {i->next_elapse_real, i->next_elapse_monotonic};
|
||||
usec_t next_elapse;
|
||||
|
||||
dual_timestamp_get(&nw);
|
||||
next_elapse = calc_next_elapse(&nw, &next);
|
||||
next_time = FORMAT_TIMESTAMP_STYLE(next_elapse, arg_timestamp_style);
|
||||
|
||||
printf(" Trigger: %s%s%s\n",
|
||||
strna(next_time),
|
||||
next_time ? "; " : "",
|
||||
next_time ? strna(FORMAT_TIMESTAMP_RELATIVE(next_elapse)) : "");
|
||||
if (next_elapse > 0 && next_elapse < USEC_INFINITY)
|
||||
printf(" Trigger: %s; %s\n",
|
||||
FORMAT_TIMESTAMP_STYLE(next_elapse, arg_timestamp_style),
|
||||
FORMAT_TIMESTAMP_RELATIVE(next_elapse));
|
||||
else
|
||||
printf(" Trigger: n/a\n");
|
||||
}
|
||||
|
||||
STRV_FOREACH(t, i->triggers) {
|
||||
@ -469,13 +467,11 @@ static void print_status_info(
|
||||
if (!i->condition_result && i->condition_timestamp > 0) {
|
||||
UnitCondition *c;
|
||||
int n = 0;
|
||||
const char *rel;
|
||||
|
||||
rel = FORMAT_TIMESTAMP_RELATIVE(i->condition_timestamp);
|
||||
printf(" Condition: start %scondition failed%s at %s%s%s\n",
|
||||
printf(" Condition: start %scondition failed%s at %s; %s\n",
|
||||
ansi_highlight_yellow(), ansi_normal(),
|
||||
FORMAT_TIMESTAMP_STYLE(i->condition_timestamp, arg_timestamp_style),
|
||||
rel ? "; " : "", strempty(rel));
|
||||
FORMAT_TIMESTAMP_RELATIVE(i->condition_timestamp));
|
||||
|
||||
LIST_FOREACH(conditions, c, i->conditions)
|
||||
if (c->tristate < 0)
|
||||
@ -492,13 +488,10 @@ static void print_status_info(
|
||||
}
|
||||
|
||||
if (!i->assert_result && i->assert_timestamp > 0) {
|
||||
const char *rel;
|
||||
|
||||
rel = FORMAT_TIMESTAMP_RELATIVE(i->assert_timestamp);
|
||||
printf(" Assert: start %sassertion failed%s at %s%s%s\n",
|
||||
printf(" Assert: start %sassertion failed%s at %s; %s\n",
|
||||
ansi_highlight_red(), ansi_normal(),
|
||||
FORMAT_TIMESTAMP_STYLE(i->assert_timestamp, arg_timestamp_style),
|
||||
rel ? "; " : "", strempty(rel));
|
||||
FORMAT_TIMESTAMP_RELATIVE(i->assert_timestamp));
|
||||
if (i->failed_assert_trigger)
|
||||
printf(" none of the trigger assertions were met\n");
|
||||
else if (i->failed_assert)
|
||||
|
@ -384,8 +384,7 @@ static void test_FORMAT_TIMESTAMP(void) {
|
||||
assert_se(parse_timestamp(buf, &y) >= 0);
|
||||
assert_se(x / USEC_PER_SEC == y / USEC_PER_SEC);
|
||||
|
||||
char *t = FORMAT_TIMESTAMP(x);
|
||||
assert_se(streq(t, buf));
|
||||
assert_se(streq(FORMAT_TIMESTAMP(x), buf));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user