summaryrefslogtreecommitdiff
path: root/src/machine/machinectl.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-07-15 20:02:27 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-07-15 20:03:46 +0900
commitf843f85da8814c42117ac8fdffb613a3a2f02cbf (patch)
tree4cf3db0113aa707680aa8a3dfc53e802d7cbb440 /src/machine/machinectl.c
parentfa3f917a25a015b55087307321fac6bbcc7811f8 (diff)
downloadsystemd-f843f85da8814c42117ac8fdffb613a3a2f02cbf.tar.gz
tree-wide: FORMAT_TIMESTAMP() or friends must be used as a function argument
Follow-ups for #20109.
Diffstat (limited to 'src/machine/machinectl.c')
-rw-r--r--src/machine/machinectl.c77
1 files changed, 33 insertions, 44 deletions
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index 06ca335cff..299e6d8207 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -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);
-
- 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) {
@@ -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) {