summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-05-24 09:36:56 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-05-31 14:30:23 +0200
commit4d9685be5f9174d38f87a2e6ab1a4bca72639774 (patch)
treeab9354a4b1e01634eb341221550e294e7778a1df
parentd3d280242cc9cdfaf0184860029ddd738b6fa952 (diff)
downloadsystemd-4d9685be5f9174d38f87a2e6ab1a4bca72639774.tar.gz
Use const char* for timestamp strings which we don't plan to modify
Makes the intent a bit clearer.
-rw-r--r--src/login/loginctl.c10
-rw-r--r--src/machine/machinectl.c14
-rw-r--r--src/shared/bus-util.c3
-rw-r--r--src/systemctl/systemctl.c14
-rw-r--r--src/test/test-time-util.c19
5 files changed, 29 insertions, 31 deletions
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 8cea282988..43edbb02fc 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -474,8 +474,9 @@ 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], *s1;
- char since2[FORMAT_TIMESTAMP_MAX], *s2;
+ char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
+ char since2[FORMAT_TIMESTAMP_MAX];
+ const char *s1, *s2;
SessionStatusInfo i = {};
int r;
@@ -605,8 +606,9 @@ 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], *s1;
- char since2[FORMAT_TIMESTAMP_MAX], *s2;
+ char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
+ char since2[FORMAT_TIMESTAMP_MAX];
+ const char *s1, *s2;
_cleanup_(user_status_info_clear) UserStatusInfo i = {};
int r;
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index eb68eb192b..d12c7d646b 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -556,8 +556,9 @@ 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], *s1;
- char since2[FORMAT_TIMESTAMP_MAX], *s2;
+ char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
+ char since2[FORMAT_TIMESTAMP_MAX];
+ const char *s1, *s2;
int ifi = -1;
assert(bus);
@@ -902,10 +903,11 @@ typedef struct ImageStatusInfo {
} ImageStatusInfo;
static void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) {
- char ts_relative[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1;
- char ts_absolute[FORMAT_TIMESTAMP_MAX], *s2;
- char bs[FORMAT_BYTES_MAX], *s3;
- char bs_exclusive[FORMAT_BYTES_MAX], *s4;
+ char ts_relative[FORMAT_TIMESTAMP_RELATIVE_MAX];
+ char ts_absolute[FORMAT_TIMESTAMP_MAX];
+ char bs[FORMAT_BYTES_MAX];
+ char bs_exclusive[FORMAT_BYTES_MAX];
+ const char *s1, *s2, *s3, *s4;
assert(bus);
assert(i);
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
index a1d3ea2fb5..e150c8728e 100644
--- a/src/shared/bus-util.c
+++ b/src/shared/bus-util.c
@@ -697,7 +697,8 @@ int bus_print_property(const char *name, sd_bus_message *m, bool value, bool all
* should it turn out to not be sufficient */
if (endswith(name, "Timestamp") || STR_IN_SET(name, "NextElapseUSecRealtime", "LastTriggerUSec")) {
- char timestamp[FORMAT_TIMESTAMP_MAX], *t;
+ char timestamp[FORMAT_TIMESTAMP_MAX];
+ const char *t;
t = format_timestamp(timestamp, sizeof(timestamp), u);
if (t || all)
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 60861dd791..ff9c3b9170 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -3948,8 +3948,8 @@ static void print_status_info(
UnitStatusInfo *i,
bool *ellipsized) {
- char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1, since2[FORMAT_TIMESTAMP_MAX], *s2;
- const char *active_on, *active_off, *on, *off, *ss;
+ char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], since2[FORMAT_TIMESTAMP_MAX];
+ const char *s1, *s2, *active_on, *active_off, *on, *off, *ss;
_cleanup_free_ char *formatted_path = NULL;
ExecStatusInfo *p;
usec_t timestamp;
@@ -4077,7 +4077,7 @@ static void print_status_info(
if (endswith(i->id, ".timer")) {
char tstamp1[FORMAT_TIMESTAMP_RELATIVE_MAX],
tstamp2[FORMAT_TIMESTAMP_MAX];
- char *next_rel_time, *next_time;
+ const char *next_rel_time, *next_time;
dual_timestamp nw, next = {i->next_elapse_real,
i->next_elapse_monotonic};
usec_t next_elapse;
@@ -4086,12 +4086,8 @@ 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_time = format_timestamp(tstamp2,
- sizeof(tstamp2),
- next_elapse);
+ next_rel_time = format_timestamp_relative(tstamp1, sizeof tstamp1, next_elapse);
+ next_time = format_timestamp(tstamp2, sizeof tstamp2, next_elapse);
if (next_time && next_rel_time)
printf("%s; %s\n", next_time, next_rel_time);
diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c
index ab4b7ce282..00d583182d 100644
--- a/src/test/test-time-util.c
+++ b/src/test/test-time-util.c
@@ -120,18 +120,16 @@ static void test_parse_nsec(void) {
}
static void test_format_timespan_one(usec_t x, usec_t accuracy) {
- char *r;
char l[FORMAT_TIMESPAN_MAX];
+ const char *t;
usec_t y;
log_info(USEC_FMT" (at accuracy "USEC_FMT")", x, accuracy);
- r = format_timespan(l, sizeof(l), x, accuracy);
- assert_se(r);
+ assert_se(t = format_timespan(l, sizeof l, x, accuracy));
+ log_info(" = <%s>", t);
- log_info(" = <%s>", l);
-
- assert_se(parse_sec(l, &y) >= 0);
+ assert_se(parse_sec(t, &y) >= 0);
log_info(" = "USEC_FMT, y);
@@ -271,13 +269,12 @@ static void test_format_timestamp(void) {
}
}
-static void test_format_timestamp_utc_one(usec_t t, const char *result) {
+static void test_format_timestamp_utc_one(usec_t val, const char *result) {
char buf[FORMAT_TIMESTAMP_MAX];
+ const char *t;
- assert_se(!format_timestamp_utc(buf, sizeof(buf), t) == !result);
-
- if (result)
- assert_se(streq(result, buf));
+ t = format_timestamp_utc(buf, sizeof(buf), val);
+ assert_se(streq_ptr(t, result));
}
static void test_format_timestamp_utc(void) {