]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Move hostname setup logic to new shared/hostname-setup.[ch]
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 4 Dec 2020 17:39:23 +0000 (18:39 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 16 Dec 2020 10:02:15 +0000 (11:02 +0100)
No functional change, just moving a bunch of things around. Before
we needed a rather complicated setup to test hostname_setup(), because
the code was in src/core/. When things are moved to src/shared/
we can just test it as any function.

The test is still "unsafe" because hostname_setup() may modify the
hostname.

20 files changed:
src/basic/hostname-util.c
src/basic/hostname-util.h
src/core/hostname-setup.c [deleted file]
src/core/hostname-setup.h [deleted file]
src/core/meson.build
src/fuzz/fuzz-hostname-setup.c [moved from src/fuzz/fuzz-hostname-util.c with 96% similarity]
src/fuzz/meson.build
src/hostname/hostnamed.c
src/network/networkd-dhcp4.c
src/network/test-network.c
src/nspawn/nspawn.c
src/shared/dissect-image.c
src/shared/hostname-setup.c [new file with mode: 0644]
src/shared/hostname-setup.h [new file with mode: 0644]
src/shared/machine-image.c
src/shared/meson.build
src/test/meson.build
src/test/test-hostname-setup.c [new file with mode: 0644]
src/test/test-hostname-util.c
src/test/test-hostname.c [deleted file]

index e1e3d1b06136756b341c3c1728ba1acff236851f..d7aba2c263029b284b5f83606c3a889c810a350a 100644 (file)
@@ -7,28 +7,10 @@
 #include <unistd.h>
 
 #include "alloc-util.h"
-#include "fd-util.h"
-#include "fileio.h"
 #include "hostname-util.h"
-#include "macro.h"
 #include "string-util.h"
 #include "strv.h"
 
-bool hostname_is_set(void) {
-        struct utsname u;
-
-        assert_se(uname(&u) >= 0);
-
-        if (isempty(u.nodename))
-                return false;
-
-        /* This is the built-in kernel default hostname */
-        if (streq(u.nodename, "(none)"))
-                return false;
-
-        return true;
-}
-
 char* gethostname_malloc(void) {
         struct utsname u;
         const char *s;
@@ -208,105 +190,3 @@ bool is_localhost(const char *hostname) {
                 endswith_no_case(hostname, ".localhost.localdomain") ||
                 endswith_no_case(hostname, ".localhost.localdomain.");
 }
-
-int sethostname_idempotent(const char *s) {
-        char buf[HOST_NAME_MAX + 1] = {};
-
-        assert(s);
-
-        if (gethostname(buf, sizeof(buf)) < 0)
-                return -errno;
-
-        if (streq(buf, s))
-                return 0;
-
-        if (sethostname(s, strlen(s)) < 0)
-                return -errno;
-
-        return 1;
-}
-
-int shorten_overlong(const char *s, char **ret) {
-        char *h, *p;
-
-        /* Shorten an overlong name to HOST_NAME_MAX or to the first dot,
-         * whatever comes earlier. */
-
-        assert(s);
-
-        h = strdup(s);
-        if (!h)
-                return -ENOMEM;
-
-        if (hostname_is_valid(h, 0)) {
-                *ret = h;
-                return 0;
-        }
-
-        p = strchr(h, '.');
-        if (p)
-                *p = 0;
-
-        strshorten(h, HOST_NAME_MAX);
-
-        if (!hostname_is_valid(h, 0)) {
-                free(h);
-                return -EDOM;
-        }
-
-        *ret = h;
-        return 1;
-}
-
-int read_etc_hostname_stream(FILE *f, char **ret) {
-        int r;
-
-        assert(f);
-        assert(ret);
-
-        for (;;) {
-                _cleanup_free_ char *line = NULL;
-                char *p;
-
-                r = read_line(f, LONG_LINE_MAX, &line);
-                if (r < 0)
-                        return r;
-                if (r == 0) /* EOF without any hostname? the file is empty, let's treat that exactly like no file at all: ENOENT */
-                        return -ENOENT;
-
-                p = strstrip(line);
-
-                /* File may have empty lines or comments, ignore them */
-                if (!IN_SET(*p, '\0', '#')) {
-                        char *copy;
-
-                        hostname_cleanup(p); /* normalize the hostname */
-
-                        if (!hostname_is_valid(p, VALID_HOSTNAME_TRAILING_DOT)) /* check that the hostname we return is valid */
-                                return -EBADMSG;
-
-                        copy = strdup(p);
-                        if (!copy)
-                                return -ENOMEM;
-
-                        *ret = copy;
-                        return 0;
-                }
-        }
-}
-
-int read_etc_hostname(const char *path, char **ret) {
-        _cleanup_fclose_ FILE *f = NULL;
-
-        assert(ret);
-
-        if (!path)
-                path = "/etc/hostname";
-
-        f = fopen(path, "re");
-        if (!f)
-                return -errno;
-
-        return read_etc_hostname_stream(f, ret);
-
-}
index fe417297eeaaf4b4e45d5c004f3e87c13a69fe09..6cff9c1d4cc8cd7b4dc384860b9fbe1204e5e743 100644 (file)
@@ -7,8 +7,6 @@
 #include "macro.h"
 #include "strv.h"
 
-bool hostname_is_set(void);
-
 char* gethostname_malloc(void);
 char* gethostname_short_malloc(void);
 int gethostname_strict(char **ret);
@@ -29,10 +27,3 @@ static inline bool is_gateway_hostname(const char *hostname) {
         /* This tries to identify the valid syntaxes for the our synthetic "gateway" host. */
         return STRCASE_IN_SET(hostname, "_gateway", "_gateway.");
 }
-
-int sethostname_idempotent(const char *s);
-
-int shorten_overlong(const char *s, char **ret);
-
-int read_etc_hostname_stream(FILE *f, char **ret);
-int read_etc_hostname(const char *path, char **ret);
diff --git a/src/core/hostname-setup.c b/src/core/hostname-setup.c
deleted file mode 100644 (file)
index 6ccaa47..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "alloc-util.h"
-#include "fileio.h"
-#include "hostname-setup.h"
-#include "hostname-util.h"
-#include "log.h"
-#include "macro.h"
-#include "proc-cmdline.h"
-#include "string-util.h"
-#include "util.h"
-
-int hostname_setup(void) {
-        _cleanup_free_ char *b = NULL;
-        const char *hn = NULL;
-        bool enoent = false;
-        int r;
-
-        r = proc_cmdline_get_key("systemd.hostname", 0, &b);
-        if (r < 0)
-                log_warning_errno(r, "Failed to retrieve system hostname from kernel command line, ignoring: %m");
-        else if (r > 0) {
-                if (hostname_is_valid(b, VALID_HOSTNAME_TRAILING_DOT))
-                        hn = b;
-                else  {
-                        log_warning("Hostname specified on kernel command line is invalid, ignoring: %s", b);
-                        b = mfree(b);
-                }
-        }
-
-        if (!hn) {
-                r = read_etc_hostname(NULL, &b);
-                if (r == -ENOENT)
-                        enoent = true;
-                else if (r < 0)
-                        log_warning_errno(r, "Failed to read configured hostname, ignoring: %m");
-                else
-                        hn = b;
-        }
-
-        if (isempty(hn)) {
-                /* Don't override the hostname if it is already set and not explicitly configured */
-                if (hostname_is_set())
-                        return 0;
-
-                if (enoent)
-                        log_info("No hostname configured.");
-
-                hn = FALLBACK_HOSTNAME;
-        }
-
-        r = sethostname_idempotent(hn);
-        if (r < 0)
-                return log_warning_errno(r, "Failed to set hostname to <%s>: %m", hn);
-
-        log_info("Set hostname to <%s>.", hn);
-        return 0;
-}
diff --git a/src/core/hostname-setup.h b/src/core/hostname-setup.h
deleted file mode 100644 (file)
index 7fd0a02..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#pragma once
-
-int hostname_setup(void);
index 77767eb603397b97402ae350482311a6693548c2..662e6376f193f0834aac10727a4c732f3b902181 100644 (file)
@@ -76,8 +76,6 @@ libcore_sources = '''
         execute.h
         generator-setup.c
         generator-setup.h
-        hostname-setup.c
-        hostname-setup.h
         ima-setup.c
         ima-setup.h
         ip-address-access.c
similarity index 96%
rename from src/fuzz/fuzz-hostname-util.c
rename to src/fuzz/fuzz-hostname-setup.c
index 0a81e74424f16a5753d950bd7064566a99300a26..b8d36da54a6980d53448c4743f80ead6acfebf0c 100644 (file)
@@ -4,7 +4,7 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "fuzz.h"
-#include "hostname-util.h"
+#include "hostname-setup.h"
 
 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
         _cleanup_fclose_ FILE *f = NULL;
index 80fa0f6fccf16a40e2333d03caa4afb6ce44121d..83527a68fbb6ccfb017875c0708a980ba06ccbfb 100644 (file)
@@ -123,7 +123,7 @@ fuzzers += [
          [libshared],
          []],
 
-        [['src/fuzz/fuzz-hostname-util.c'],
+        [['src/fuzz/fuzz-hostname-setup.c'],
          [libshared],
          []],
 
index e624ace7545203c66135318b16e8ac633cbad803..10a5d31ccdca29e65a1e246b7446977d4402c4e9 100644 (file)
@@ -17,6 +17,7 @@
 #include "env-util.h"
 #include "fileio-label.h"
 #include "fileio.h"
+#include "hostname-setup.h"
 #include "hostname-util.h"
 #include "id128-util.h"
 #include "main-func.h"
index 14e7a287746448296c6b0de473846f0a16956755..080dcedab54dc93af09ebd6e66c8e66daeed903f 100644 (file)
@@ -8,6 +8,7 @@
 #include "escape.h"
 #include "alloc-util.h"
 #include "dhcp-client-internal.h"
+#include "hostname-setup.h"
 #include "hostname-util.h"
 #include "parse-util.h"
 #include "network-internal.h"
index 03c94409fa0b885244e6f10c02d60fb7e7df3d6c..45cd3fa973c5fd47abba1e16fd9c4cf6530b199b 100644 (file)
@@ -8,7 +8,7 @@
 #include "alloc-util.h"
 #include "dhcp-lease-internal.h"
 #include "ether-addr-util.h"
-#include "hostname-util.h"
+#include "hostname-setup.h"
 #include "network-internal.h"
 #include "networkd-manager.h"
 #include "string-util.h"
index cfbc8f11bf1fc23efa426bcb319313b535a31299..0f6411d1936bcc39be9a51ef2409702104f241f8 100644 (file)
@@ -46,6 +46,7 @@
 #include "fs-util.h"
 #include "gpt.h"
 #include "hexdecoct.h"
+#include "hostname-setup.h"
 #include "hostname-util.h"
 #include "id128-util.h"
 #include "io-util.h"
index 113538bb97a1add6543d53a0add2dff956a3e4a1..b1d7d689ea82fee1ca9e443802b7721d3c59a07b 100644 (file)
@@ -32,7 +32,7 @@
 #include "fsck-util.h"
 #include "gpt.h"
 #include "hexdecoct.h"
-#include "hostname-util.h"
+#include "hostname-setup.h"
 #include "id128-util.h"
 #include "mkdir.h"
 #include "mount-util.h"
diff --git a/src/shared/hostname-setup.c b/src/shared/hostname-setup.c
new file mode 100644 (file)
index 0000000..cd5ad13
--- /dev/null
@@ -0,0 +1,183 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/utsname.h>
+#include <unistd.h>
+
+#include "alloc-util.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "hostname-setup.h"
+#include "hostname-util.h"
+#include "log.h"
+#include "macro.h"
+#include "proc-cmdline.h"
+#include "string-util.h"
+#include "util.h"
+
+int sethostname_idempotent(const char *s) {
+        char buf[HOST_NAME_MAX + 1] = {};
+
+        assert(s);
+
+        if (gethostname(buf, sizeof(buf)) < 0)
+                return -errno;
+
+        if (streq(buf, s))
+                return 0;
+
+        if (sethostname(s, strlen(s)) < 0)
+                return -errno;
+
+        return 1;
+}
+
+int shorten_overlong(const char *s, char **ret) {
+        char *h, *p;
+
+        /* Shorten an overlong name to HOST_NAME_MAX or to the first dot,
+         * whatever comes earlier. */
+
+        assert(s);
+
+        h = strdup(s);
+        if (!h)
+                return -ENOMEM;
+
+        if (hostname_is_valid(h, 0)) {
+                *ret = h;
+                return 0;
+        }
+
+        p = strchr(h, '.');
+        if (p)
+                *p = 0;
+
+        strshorten(h, HOST_NAME_MAX);
+
+        if (!hostname_is_valid(h, 0)) {
+                free(h);
+                return -EDOM;
+        }
+
+        *ret = h;
+        return 1;
+}
+
+int read_etc_hostname_stream(FILE *f, char **ret) {
+        int r;
+
+        assert(f);
+        assert(ret);
+
+        for (;;) {
+                _cleanup_free_ char *line = NULL;
+                char *p;
+
+                r = read_line(f, LONG_LINE_MAX, &line);
+                if (r < 0)
+                        return r;
+                if (r == 0) /* EOF without any hostname? the file is empty, let's treat that exactly like no file at all: ENOENT */
+                        return -ENOENT;
+
+                p = strstrip(line);
+
+                /* File may have empty lines or comments, ignore them */
+                if (!IN_SET(*p, '\0', '#')) {
+                        char *copy;
+
+                        hostname_cleanup(p); /* normalize the hostname */
+
+                        if (!hostname_is_valid(p, VALID_HOSTNAME_TRAILING_DOT)) /* check that the hostname we return is valid */
+                                return -EBADMSG;
+
+                        copy = strdup(p);
+                        if (!copy)
+                                return -ENOMEM;
+
+                        *ret = copy;
+                        return 0;
+                }
+        }
+}
+
+int read_etc_hostname(const char *path, char **ret) {
+        _cleanup_fclose_ FILE *f = NULL;
+
+        assert(ret);
+
+        if (!path)
+                path = "/etc/hostname";
+
+        f = fopen(path, "re");
+        if (!f)
+                return -errno;
+
+        return read_etc_hostname_stream(f, ret);
+
+}
+
+static bool hostname_is_set(void) {
+        struct utsname u;
+
+        assert_se(uname(&u) >= 0);
+
+        if (isempty(u.nodename))
+                return false;
+
+        /* This is the built-in kernel default hostname */
+        if (streq(u.nodename, "(none)"))
+                return false;
+
+        return true;
+}
+
+int hostname_setup(void) {
+        _cleanup_free_ char *b = NULL;
+        const char *hn = NULL;
+        bool enoent = false;
+        int r;
+
+        r = proc_cmdline_get_key("systemd.hostname", 0, &b);
+        if (r < 0)
+                log_warning_errno(r, "Failed to retrieve system hostname from kernel command line, ignoring: %m");
+        else if (r > 0) {
+                if (hostname_is_valid(b, true))
+                        hn = b;
+                else  {
+                        log_warning("Hostname specified on kernel command line is invalid, ignoring: %s", b);
+                        b = mfree(b);
+                }
+        }
+
+        if (!hn) {
+                r = read_etc_hostname(NULL, &b);
+                if (r < 0) {
+                        if (r == -ENOENT)
+                                enoent = true;
+                        else
+                                log_warning_errno(r, "Failed to read configured hostname: %m");
+                } else
+                        hn = b;
+        }
+
+        if (isempty(hn)) {
+                /* Don't override the hostname if it is already set and not explicitly configured */
+                if (hostname_is_set())
+                        return 0;
+
+                if (enoent)
+                        log_info("No hostname configured.");
+
+                hn = FALLBACK_HOSTNAME;
+        }
+
+        r = sethostname_idempotent(hn);
+        if (r < 0)
+                return log_warning_errno(r, "Failed to set hostname to <%s>: %m", hn);
+
+        log_info("Set hostname to <%s>.", hn);
+        return 0;
+}
diff --git a/src/shared/hostname-setup.h b/src/shared/hostname-setup.h
new file mode 100644 (file)
index 0000000..032c7ac
--- /dev/null
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <stdio.h>
+
+int sethostname_idempotent(const char *s);
+
+int shorten_overlong(const char *s, char **ret);
+
+int read_etc_hostname_stream(FILE *f, char **ret);
+int read_etc_hostname(const char *path, char **ret);
+
+int hostname_setup(void);
index 671a56b9e990f1f80332d7358c173b3eab04ce51..0b148c067af6897699dc3ce7e6d8d42347f787fa 100644 (file)
@@ -22,7 +22,7 @@
 #include "fd-util.h"
 #include "fs-util.h"
 #include "hashmap.h"
-#include "hostname-util.h"
+#include "hostname-setup.h"
 #include "id128-util.h"
 #include "lockfile-util.h"
 #include "log.h"
index b43fe9c6d987d6bf9a2012486fd95dd421474837..b4c77513e22e1b50b81c180070c5a1c177e52043 100644 (file)
@@ -115,6 +115,8 @@ shared_sources = files('''
         gpt.h
         group-record.c
         group-record.h
+        hostname-setup.c
+        hostname-setup.h
         id128-print.c
         id128-print.h
         idn-util.c
index 0cfc709f44d494a0b2769bc800bec53ac122f5db..3dab9ace6b073976ff389a42cd41383d736a8bef 100644 (file)
@@ -105,17 +105,6 @@ tests += [
           libmount,
           libblkid]],
 
-        [['src/test/test-hostname.c'],
-         [libcore,
-          libshared],
-         [threads,
-          librt,
-          libseccomp,
-          libselinux,
-          libmount,
-          libblkid],
-         '', 'unsafe'],
-
         [['src/test/test-dns-domain.c'],
          [libcore,
           libshared],
@@ -339,6 +328,11 @@ tests += [
          [],
          []],
 
+        [['src/test/test-hostname-setup.c'],
+         [],
+         [],
+         '', 'unsafe'],
+
         [['src/test/test-hostname-util.c'],
          [],
          []],
diff --git a/src/test/test-hostname-setup.c b/src/test/test-hostname-setup.c
new file mode 100644 (file)
index 0000000..494ebb2
--- /dev/null
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <unistd.h>
+
+#include "alloc-util.h"
+#include "fileio.h"
+#include "hostname-setup.h"
+#include "string-util.h"
+#include "tests.h"
+#include "tmpfile-util.h"
+
+static void test_read_etc_hostname(void) {
+        char path[] = "/tmp/hostname.XXXXXX";
+        char *hostname;
+        int fd;
+
+        fd = mkostemp_safe(path);
+        assert(fd > 0);
+        close(fd);
+
+        /* simple hostname */
+        assert_se(write_string_file(path, "foo", WRITE_STRING_FILE_CREATE) == 0);
+        assert_se(read_etc_hostname(path, &hostname) == 0);
+        assert_se(streq(hostname, "foo"));
+        hostname = mfree(hostname);
+
+        /* with comment */
+        assert_se(write_string_file(path, "# comment\nfoo", WRITE_STRING_FILE_CREATE) == 0);
+        assert_se(read_etc_hostname(path, &hostname) == 0);
+        assert_se(hostname);
+        assert_se(streq(hostname, "foo"));
+        hostname = mfree(hostname);
+
+        /* with comment and extra whitespace */
+        assert_se(write_string_file(path, "# comment\n\n foo ", WRITE_STRING_FILE_CREATE) == 0);
+        assert_se(read_etc_hostname(path, &hostname) == 0);
+        assert_se(hostname);
+        assert_se(streq(hostname, "foo"));
+        hostname = mfree(hostname);
+
+        /* cleans up name */
+        assert_se(write_string_file(path, "!foo/bar.com", WRITE_STRING_FILE_CREATE) == 0);
+        assert_se(read_etc_hostname(path, &hostname) == 0);
+        assert_se(hostname);
+        assert_se(streq(hostname, "foobar.com"));
+        hostname = mfree(hostname);
+
+        /* no value set */
+        hostname = (char*) 0x1234;
+        assert_se(write_string_file(path, "# nothing here\n", WRITE_STRING_FILE_CREATE) == 0);
+        assert_se(read_etc_hostname(path, &hostname) == -ENOENT);
+        assert_se(hostname == (char*) 0x1234);  /* does not touch argument on error */
+
+        /* nonexisting file */
+        assert_se(read_etc_hostname("/non/existing", &hostname) == -ENOENT);
+        assert_se(hostname == (char*) 0x1234);  /* does not touch argument on error */
+
+        unlink(path);
+}
+
+static void test_hostname_setup(void) {
+        int r;
+
+        r = hostname_setup();
+        if (r < 0)
+                log_error_errno(r, "hostname: %m");
+}
+
+int main(int argc, char *argv[]) {
+        test_setup_logging(LOG_INFO);
+
+        test_read_etc_hostname();
+        test_hostname_setup();
+
+        return 0;
+}
index c7a63bd047d6788cc4263351a9b57e09b5dea678..24c8ed9e3b30f3c5d007c269beff7cf3c03a4e2d 100644 (file)
@@ -6,8 +6,8 @@
 #include "fileio.h"
 #include "hostname-util.h"
 #include "string-util.h"
+#include "tests.h"
 #include "tmpfile-util.h"
-#include "util.h"
 
 static void test_hostname_is_valid(void) {
         assert_se(hostname_is_valid("foobar", 0));
@@ -91,55 +91,6 @@ static void test_hostname_cleanup(void) {
         assert_se(streq(hostname_cleanup(s), "xxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
 }
 
-static void test_read_etc_hostname(void) {
-        char path[] = "/tmp/hostname.XXXXXX";
-        char *hostname;
-        int fd;
-
-        fd = mkostemp_safe(path);
-        assert(fd > 0);
-        close(fd);
-
-        /* simple hostname */
-        assert_se(write_string_file(path, "foo", WRITE_STRING_FILE_CREATE) == 0);
-        assert_se(read_etc_hostname(path, &hostname) == 0);
-        assert_se(streq(hostname, "foo"));
-        hostname = mfree(hostname);
-
-        /* with comment */
-        assert_se(write_string_file(path, "# comment\nfoo", WRITE_STRING_FILE_CREATE) == 0);
-        assert_se(read_etc_hostname(path, &hostname) == 0);
-        assert_se(hostname);
-        assert_se(streq(hostname, "foo"));
-        hostname = mfree(hostname);
-
-        /* with comment and extra whitespace */
-        assert_se(write_string_file(path, "# comment\n\n foo ", WRITE_STRING_FILE_CREATE) == 0);
-        assert_se(read_etc_hostname(path, &hostname) == 0);
-        assert_se(hostname);
-        assert_se(streq(hostname, "foo"));
-        hostname = mfree(hostname);
-
-        /* cleans up name */
-        assert_se(write_string_file(path, "!foo/bar.com", WRITE_STRING_FILE_CREATE) == 0);
-        assert_se(read_etc_hostname(path, &hostname) == 0);
-        assert_se(hostname);
-        assert_se(streq(hostname, "foobar.com"));
-        hostname = mfree(hostname);
-
-        /* no value set */
-        hostname = (char*) 0x1234;
-        assert_se(write_string_file(path, "# nothing here\n", WRITE_STRING_FILE_CREATE) == 0);
-        assert_se(read_etc_hostname(path, &hostname) == -ENOENT);
-        assert_se(hostname == (char*) 0x1234);  /* does not touch argument on error */
-
-        /* nonexisting file */
-        assert_se(read_etc_hostname("/non/existing", &hostname) == -ENOENT);
-        assert_se(hostname == (char*) 0x1234);  /* does not touch argument on error */
-
-        unlink(path);
-}
-
 static void test_hostname_malloc(void) {
         _cleanup_free_ char *h = NULL, *l = NULL;
 
@@ -158,12 +109,10 @@ static void test_fallback_hostname(void) {
 }
 
 int main(int argc, char *argv[]) {
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_INFO);
 
         test_hostname_is_valid();
         test_hostname_cleanup();
-        test_read_etc_hostname();
         test_hostname_malloc();
 
         test_fallback_hostname();
diff --git a/src/test/test-hostname.c b/src/test/test-hostname.c
deleted file mode 100644 (file)
index 1a925f2..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-
-#include "hostname-setup.h"
-#include "util.h"
-
-int main(int argc, char* argv[]) {
-        int r;
-
-        r = hostname_setup();
-        if (r < 0)
-                log_error_errno(r, "hostname: %m");
-
-        return 0;
-}