Follow-ups for #20109.
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,
"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);
}
_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;
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;
_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;
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);
}
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);
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) {
} ImageStatusInfo;
static void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) {
- const char *s1, *s2, *s3, *s4;
-
assert(bus);
assert(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);
-
- 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);
-
- 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);
-
- 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->crtime > 0 && i->crtime < USEC_INFINITY)
+ printf("\t Created: %s; %s\n",
+ FORMAT_TIMESTAMP(i->crtime), FORMAT_TIMESTAMP_RELATIVE(i->crtime));
+
+ if (i->mtime > 0 && i->mtime < USEC_INFINITY)
+ printf("\tModified: %s; %s\n",
+ FORMAT_TIMESTAMP(i->mtime), FORMAT_TIMESTAMP_RELATIVE(i->mtime));
+
+ 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));
+ }
+
+ 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) {
} 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) {
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;
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");
}
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) {
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)
}
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)
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));
}
}