From 536970d4f9828f30d508ac9143f717ea921f99c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 4 Dec 2020 19:40:46 +0100 Subject: [PATCH] hostnamed: minor style cleanups --- src/hostname/hostnamed.c | 11 ++++------- src/shared/hostname-setup.c | 1 - 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 5ada47459d..c41d5fd741 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -68,11 +68,9 @@ typedef struct Context { } Context; static void context_reset(Context *c, uint64_t mask) { - int p; - assert(c); - for (p = 0; p < _PROP_MAX; p++) { + for (int p = 0; p < _PROP_MAX; p++) { if (!FLAGS_SET(mask, UINT64_C(1) << p)) continue; @@ -366,12 +364,11 @@ static int context_write_data_static_hostname(Context *c) { assert(c); if (isempty(c->data[PROP_STATIC_HOSTNAME])) { - if (unlink("/etc/hostname") < 0) return errno == ENOENT ? 0 : -errno; - return 0; } + return write_string_file_atomic_label("/etc/hostname", c->data[PROP_STATIC_HOSTNAME]); } @@ -386,7 +383,7 @@ static int context_write_data_machine_info(Context *c) { }; _cleanup_strv_free_ char **l = NULL; - int r, p; + int r; assert(c); @@ -394,7 +391,7 @@ static int context_write_data_machine_info(Context *c) { if (r < 0 && r != -ENOENT) return r; - for (p = PROP_PRETTY_HOSTNAME; p <= PROP_LOCATION; p++) { + for (int p = PROP_PRETTY_HOSTNAME; p <= PROP_LOCATION; p++) { _cleanup_free_ char *t = NULL; char **u; diff --git a/src/shared/hostname-setup.c b/src/shared/hostname-setup.c index 19e528604b..7eccc86c3b 100644 --- a/src/shared/hostname-setup.c +++ b/src/shared/hostname-setup.c @@ -121,7 +121,6 @@ int read_etc_hostname(const char *path, char **ret) { return -errno; return read_etc_hostname_stream(f, ret); - } static bool hostname_is_set(void) {