From 947f9f01a187702dd01c2a8cb348a2f4164acd94 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 9 May 2018 22:50:07 +0900 Subject: [PATCH 1/3] time-util: fix indentation for comments --- src/basic/time-util.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 0880d00ef36..fa7cda5d2cd 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -614,8 +614,7 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) { int r, weekday = -1, dst = -1; size_t i; - /* - * Allowed syntaxes: + /* Allowed syntaxes: * * 2012-09-22 16:34:22 * 2012-09-22 16:34 (seconds will be set to 0) @@ -629,7 +628,6 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) { * +5min * -5days * @2147483647 (seconds since epoch) - * */ assert(t); @@ -688,10 +686,10 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) { tzset(); /* See if the timestamp is suffixed by either the DST or non-DST local timezone. Note that we only - * support the local timezones here, nothing else. Not because we wouldn't want to, but simply because - * there are no nice APIs available to cover this. By accepting the local time zone strings, we make - * sure that all timestamps written by format_timestamp() can be parsed correctly, even though we don't - * support arbitrary timezone specifications. */ + * support the local timezones here, nothing else. Not because we wouldn't want to, but simply because + * there are no nice APIs available to cover this. By accepting the local time zone strings, we make + * sure that all timestamps written by format_timestamp() can be parsed correctly, even though we don't + * support arbitrary timezone specifications. */ for (j = 0; j <= 1; j++) { @@ -903,10 +901,10 @@ int parse_timestamp(const char *t, usec_t *usec) { tzset(); /* If there is a timezone that matches the tzname fields, leave the parsing to the implementation. - * Otherwise just cut it off */ + * Otherwise just cut it off. */ with_tz = !STR_IN_SET(tz, tzname[0], tzname[1]); - /*cut off the timezone if we dont need it*/ + /* Cut off the timezone if we dont need it. */ if (with_tz) t = strndupa(t, last_space - t); From 130d3d22e97114fc0b9c685aa8db437454a10635 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 10 May 2018 00:34:46 +0900 Subject: [PATCH 2/3] tree-wide: use strv_free_and_replace() macro --- src/core/dbus-execute.c | 8 ++---- src/core/execute.c | 13 +++------ src/core/locale-setup.c | 3 +-- src/hostname/hostnamed.c | 3 +-- src/libsystemd-network/sd-dhcp6-lease.c | 6 ++--- src/libsystemd/sd-bus/sd-bus.c | 5 +--- src/locale/keymap-util.c | 9 +++---- src/nspawn/nspawn.c | 36 +++++++------------------ src/shared/bus-util.c | 4 +-- 9 files changed, 24 insertions(+), 63 deletions(-) diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index e36a050bdd8..9d302b0a114 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -2023,9 +2023,7 @@ int bus_exec_context_set_transient_property( if (!e) return -ENOMEM; - strv_free(c->environment); - c->environment = e; - + strv_free_and_replace(c->environment, e); unit_write_settingf(u, flags, name, "Environment=%s", joined); } } @@ -2059,9 +2057,7 @@ int bus_exec_context_set_transient_property( if (!e) return -ENOMEM; - strv_free(c->unset_environment); - c->unset_environment = e; - + strv_free_and_replace(c->unset_environment, e); unit_write_settingf(u, flags, name, "UnsetEnvironment=%s", joined); } } diff --git a/src/core/execute.c b/src/core/execute.c index 11bf176f6be..ecc7e8821a2 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1287,10 +1287,7 @@ static int setup_pam( if (!barrier_place_and_sync(&barrier)) log_error("PAM initialization failed"); - strv_free(*env); - *env = e; - - return 0; + return strv_free_and_replace(*env, e); fail: if (pam_code != PAM_SUCCESS) { @@ -3379,8 +3376,7 @@ static int exec_child( return log_oom(); } - strv_free(accum_env); - accum_env = ee; + strv_free_and_replace(accum_env, ee); } final_argv = replace_env_argv(argv, accum_env); @@ -4492,10 +4488,7 @@ int exec_command_set(ExecCommand *c, const char *path, ...) { free(c->path); c->path = p; - strv_free(c->argv); - c->argv = l; - - return 0; + return strv_free_and_replace(c->argv, l); } int exec_command_append(ExecCommand *c, const char *path, ...) { diff --git a/src/core/locale-setup.c b/src/core/locale-setup.c index 42acb632931..705dd95de1b 100644 --- a/src/core/locale-setup.c +++ b/src/core/locale-setup.c @@ -97,8 +97,7 @@ int locale_setup(char ***environment) { goto finish; } - strv_free(*environment); - *environment = e; + strv_free_and_replace(*environment, e); } r = 0; diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index d9ad2fb2fe4..f3deece5b0b 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -338,8 +338,7 @@ static int context_write_data_machine_info(Context *c) { if (!u) return -ENOMEM; - strv_free(l); - l = u; + strv_free_and_replace(l, u); } if (strv_isempty(l)) { diff --git a/src/libsystemd-network/sd-dhcp6-lease.c b/src/libsystemd-network/sd-dhcp6-lease.c index 88c0b1fbd2b..fc77a788f42 100644 --- a/src/libsystemd-network/sd-dhcp6-lease.c +++ b/src/libsystemd-network/sd-dhcp6-lease.c @@ -248,8 +248,7 @@ int dhcp6_lease_set_domains(sd_dhcp6_lease *lease, uint8_t *optval, if (r < 0) return 0; - strv_free(lease->domains); - lease->domains = domains; + strv_free_and_replace(lease->domains, domains); lease->domains_count = r; return r; @@ -308,8 +307,7 @@ int dhcp6_lease_set_ntp(sd_dhcp6_lease *lease, uint8_t *optval, size_t optlen) { if (r < 0) return 0; - lease->ntp_fqdn = strv_free(lease->ntp_fqdn); - lease->ntp_fqdn = servers; + strv_free_and_replace(lease->ntp_fqdn, servers); lease->ntp_fqdn_count = r; break; diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index b77fdb98bb5..dee1c877578 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -310,10 +310,7 @@ _public_ int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[]) return -ENOMEM; free_and_replace(bus->exec_path, p); - - strv_free(bus->exec_argv); - bus->exec_argv = a; - + strv_free_and_replace(bus->exec_argv, a); return 0; } diff --git a/src/locale/keymap-util.c b/src/locale/keymap-util.c index 5e38061f518..09bd4499257 100644 --- a/src/locale/keymap-util.c +++ b/src/locale/keymap-util.c @@ -250,8 +250,7 @@ int locale_write_data(Context *c, char ***settings) { if (!u) return -ENOMEM; - strv_free(l); - l = u; + strv_free_and_replace(l, u); } if (strv_isempty(l)) { @@ -291,8 +290,7 @@ int vconsole_write_data(Context *c) { if (!u) return -ENOMEM; - strv_free(l); - l = u; + strv_free_and_replace(l, u); } if (isempty(c->vc_keymap_toggle)) @@ -309,8 +307,7 @@ int vconsole_write_data(Context *c) { if (!u) return -ENOMEM; - strv_free(l); - l = u; + strv_free_and_replace(l, u); } if (strv_isempty(l)) { diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index d7ceb4ed445..12eaa6c0d74 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -818,9 +818,7 @@ static int parse_argv(int argc, char *argv[]) { if (!n) return log_oom(); - strv_free(arg_setenv); - arg_setenv = n; - + strv_free_and_replace(arg_setenv, n); arg_settings_mask |= SETTING_ENVIRONMENT; break; } @@ -3120,9 +3118,7 @@ static int load_settings(void) { if ((arg_settings_mask & SETTING_START_MODE) == 0 && settings->start_mode >= 0) { arg_start_mode = settings->start_mode; - - strv_free(arg_parameters); - arg_parameters = TAKE_PTR(settings->parameters); + strv_free_and_replace(arg_parameters, settings->parameters); } if ((arg_settings_mask & SETTING_PIVOT_ROOT) == 0 && @@ -3136,10 +3132,8 @@ static int load_settings(void) { free_and_replace(arg_chdir, settings->working_directory); if ((arg_settings_mask & SETTING_ENVIRONMENT) == 0 && - settings->environment) { - strv_free(arg_setenv); - arg_setenv = TAKE_PTR(settings->environment); - } + settings->environment) + strv_free_and_replace(arg_setenv, settings->environment); if ((arg_settings_mask & SETTING_USER) == 0 && settings->user) @@ -3215,17 +3209,10 @@ static int load_settings(void) { arg_network_veth = settings_network_veth(settings); arg_private_network = settings_private_network(settings); - strv_free(arg_network_interfaces); - arg_network_interfaces = TAKE_PTR(settings->network_interfaces); - - strv_free(arg_network_macvlan); - arg_network_macvlan = TAKE_PTR(settings->network_macvlan); - - strv_free(arg_network_ipvlan); - arg_network_ipvlan = TAKE_PTR(settings->network_ipvlan); - - strv_free(arg_network_veth_extra); - arg_network_veth_extra = TAKE_PTR(settings->network_veth_extra); + strv_free_and_replace(arg_network_interfaces, settings->network_interfaces); + strv_free_and_replace(arg_network_macvlan, settings->network_macvlan); + strv_free_and_replace(arg_network_ipvlan, settings->network_ipvlan); + strv_free_and_replace(arg_network_veth_extra, settings->network_veth_extra); free_and_replace(arg_network_bridge, settings->network_bridge); free_and_replace(arg_network_zone, settings->network_zone); @@ -3264,11 +3251,8 @@ static int load_settings(void) { if (!arg_settings_trusted && !strv_isempty(arg_syscall_whitelist)) log_warning("Ignoring SystemCallFilter= settings, file %s is not trusted.", p); else { - strv_free(arg_syscall_whitelist); - strv_free(arg_syscall_blacklist); - - arg_syscall_whitelist = TAKE_PTR(settings->syscall_whitelist); - arg_syscall_blacklist = TAKE_PTR(settings->syscall_blacklist); + strv_free_and_replace(arg_syscall_whitelist, settings->syscall_whitelist); + strv_free_and_replace(arg_syscall_blacklist, settings->syscall_blacklist); } } diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index af18a674c1d..66724d0e784 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -1078,9 +1078,7 @@ static int map_basic(sd_bus *bus, const char *member, sd_bus_message *m, unsigne if (r < 0) return r; - strv_free(*p); - *p = TAKE_PTR(l); - return 0; + return strv_free_and_replace(*p, l); } case SD_BUS_TYPE_BOOLEAN: { From 2c3def62144c9d689ddda88a866b1e623074eaae Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 10 May 2018 00:59:47 +0900 Subject: [PATCH 3/3] timedate: use free_and_strdup() --- src/timedate/timedated.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 59a642cac75..93810d43d37 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) {