summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-05-09 17:59:47 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-05-09 17:59:47 +0200
commit2c3def62144c9d689ddda88a866b1e623074eaae (patch)
tree50ff2d77e99bc6d7fa9d10d9767d6d39fb41da17
parenttree-wide: use strv_free_and_replace() macro (diff)
downloadsystemd-2c3def62144c9d689ddda88a866b1e623074eaae.tar.xz
systemd-2c3def62144c9d689ddda88a866b1e623074eaae.zip
timedate: use free_and_strdup()
-rw-r--r--src/timedate/timedated.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 59a642cac7..93810d43d3 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -532,10 +532,8 @@ static int property_get_ntp(
static int method_set_timezone(sd_bus_message *m, void *userdata, sd_bus_error *error) {
Context *c = userdata;
+ int interactive, r;
const char *z;
- int interactive;
- char *t;
- int r;
assert(m);
assert(c);
@@ -547,7 +545,10 @@ static int method_set_timezone(sd_bus_message *m, void *userdata, sd_bus_error *
if (!timezone_is_valid(z))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid time zone '%s'", z);
- if (streq_ptr(z, c->zone))
+ r = free_and_strdup(&c->zone, z);
+ if (r < 0)
+ return r;
+ if (r == 0)
return sd_bus_reply_method_return(m, NULL);
r = bus_verify_polkit_async(
@@ -564,13 +565,6 @@ static int method_set_timezone(sd_bus_message *m, void *userdata, sd_bus_error *
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
- t = strdup(z);
- if (!t)
- return -ENOMEM;
-
- free(c->zone);
- c->zone = t;
-
/* 1. Write new configuration file */
r = context_write_data_timezone(c);
if (r < 0) {