diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-08-23 14:30:52 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-08-24 22:46:45 +0200 |
commit | 25300b5a1fcf54674a69d0f4ab08925be00b0227 (patch) | |
tree | a29da7b64948e59d558fe4051893e1161e2df4e6 | |
parent | b59abc4d1e5c8e99323f404ef4a09bd6da68064f (diff) |
util: make machine_name_is_valid() a macro and move it to hostname-util.h
As it turns out machine_name_is_valid() does the exact same thing as
hostname_is_valid() these days, as it just invoked that and checked the
name length was < 64. However, hostname_is_valid() checks the length
against HOST_NAME_MAX anyway (which is 64 on Linux), hence any
additional check is redundant.
We hence replace machine_name_is_valid() by a macro that simply maps it
to hostname_is_valid() but sets the allow_trailing_dot parameter to
false. We also move this this call to hostname-util.h, to the same place
as the hostname_is_valid() declaration.
-rw-r--r-- | src/basic/hostname-util.h | 2 | ||||
-rw-r--r-- | src/basic/util.c | 15 | ||||
-rw-r--r-- | src/basic/util.h | 2 | ||||
-rw-r--r-- | src/import/export.c | 1 | ||||
-rw-r--r-- | src/import/import-raw.c | 1 | ||||
-rw-r--r-- | src/import/import-tar.c | 1 | ||||
-rw-r--r-- | src/import/import.c | 1 | ||||
-rw-r--r-- | src/import/importd.c | 1 | ||||
-rw-r--r-- | src/import/pull-raw.c | 1 | ||||
-rw-r--r-- | src/import/pull-tar.c | 3 | ||||
-rw-r--r-- | src/import/pull.c | 1 | ||||
-rw-r--r-- | src/journal/sd-journal.c | 1 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/sd-bus.c | 1 | ||||
-rw-r--r-- | src/libsystemd/sd-login/sd-login.c | 1 | ||||
-rw-r--r-- | src/machine/machinectl.c | 1 | ||||
-rw-r--r-- | src/machine/machined-dbus.c | 1 | ||||
-rw-r--r-- | src/machine/machined.c | 1 | ||||
-rw-r--r-- | src/nss-mymachines/nss-mymachines.c | 1 | ||||
-rw-r--r-- | src/shared/logs-show.c | 1 |
19 files changed, 19 insertions, 18 deletions
diff --git a/src/basic/hostname-util.h b/src/basic/hostname-util.h index 7c50260d73..d4f5bfe45e 100644 --- a/src/basic/hostname-util.h +++ b/src/basic/hostname-util.h @@ -32,6 +32,8 @@ char* gethostname_malloc(void); bool hostname_is_valid(const char *s, bool allow_trailing_dot) _pure_; char* hostname_cleanup(char *s); +#define machine_name_is_valid(s) hostname_is_valid(s, false) + bool is_localhost(const char *hostname); bool is_gateway_hostname(const char *hostname); diff --git a/src/basic/util.c b/src/basic/util.c index 9571f0ab12..deff68073c 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -3006,21 +3006,6 @@ char* strshorten(char *s, size_t l) { return s; } -bool machine_name_is_valid(const char *s) { - - if (!hostname_is_valid(s, false)) - return false; - - /* Machine names should be useful hostnames, but also be - * useful in unit names, hence we enforce a stricter length - * limitation. */ - - if (strlen(s) > 64) - return false; - - return true; -} - int pipe_eof(int fd) { struct pollfd pollfd = { .fd = fd, diff --git a/src/basic/util.h b/src/basic/util.h index 8f21d56ed8..1ead7b5419 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -394,8 +394,6 @@ bool nulstr_contains(const char*nulstr, const char *needle); bool plymouth_running(void); -bool machine_name_is_valid(const char *s) _pure_; - char* strshorten(char *s, size_t l); int symlink_idempotent(const char *from, const char *to); diff --git a/src/import/export.c b/src/import/export.c index ec7dbe210a..b88d71fec6 100644 --- a/src/import/export.c +++ b/src/import/export.c @@ -24,6 +24,7 @@ #include "sd-event.h" #include "event-util.h" #include "signal-util.h" +#include "hostname-util.h" #include "verbs.h" #include "build.h" #include "machine-image.h" diff --git a/src/import/import-raw.c b/src/import/import-raw.c index 43cd413042..a27e81bbd4 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -26,6 +26,7 @@ #include "util.h" #include "path-util.h" #include "btrfs-util.h" +#include "hostname-util.h" #include "copy.h" #include "mkdir.h" #include "rm-rf.h" diff --git a/src/import/import-tar.c b/src/import/import-tar.c index 2bf0b0680c..7ffe83cc33 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -26,6 +26,7 @@ #include "util.h" #include "path-util.h" #include "btrfs-util.h" +#include "hostname-util.h" #include "copy.h" #include "mkdir.h" #include "rm-rf.h" diff --git a/src/import/import.c b/src/import/import.c index b7772390e9..929a840298 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -26,6 +26,7 @@ #include "verbs.h" #include "build.h" #include "signal-util.h" +#include "hostname-util.h" #include "machine-image.h" #include "import-util.h" #include "import-tar.h" diff --git a/src/import/importd.c b/src/import/importd.c index dd314f5b00..8b508eaeec 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -35,6 +35,7 @@ #include "import-util.h" #include "process-util.h" #include "signal-util.h" +#include "hostname-util.h" typedef struct Transfer Transfer; typedef struct Manager Manager; diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c index 5bfaf012c0..d0e0faa261 100644 --- a/src/import/pull-raw.c +++ b/src/import/pull-raw.c @@ -33,6 +33,7 @@ #include "mkdir.h" #include "rm-rf.h" #include "path-util.h" +#include "hostname-util.h" #include "import-util.h" #include "import-common.h" #include "curl-util.h" diff --git a/src/import/pull-tar.c b/src/import/pull-tar.c index 71b8908a58..d38a2158c4 100644 --- a/src/import/pull-tar.c +++ b/src/import/pull-tar.c @@ -32,13 +32,14 @@ #include "mkdir.h" #include "rm-rf.h" #include "path-util.h" +#include "process-util.h" +#include "hostname-util.h" #include "import-util.h" #include "import-common.h" #include "curl-util.h" #include "pull-job.h" #include "pull-common.h" #include "pull-tar.h" -#include "process-util.h" typedef enum TarProgress { TAR_DOWNLOADING, diff --git a/src/import/pull.c b/src/import/pull.c index ca7be6be85..e13cd6af97 100644 --- a/src/import/pull.c +++ b/src/import/pull.c @@ -26,6 +26,7 @@ #include "verbs.h" #include "build.h" #include "signal-util.h" +#include "hostname-util.h" #include "machine-image.h" #include "import-util.h" #include "pull-tar.h" diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index bfd1901e16..13fa9b52fc 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -43,6 +43,7 @@ #include "replace-var.h" #include "fileio.h" #include "formats-util.h" +#include "hostname-util.h" #define JOURNAL_FILES_MAX 7168 diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index db4f21e9ff..31cdcb4e5b 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -33,6 +33,7 @@ #include "missing.h" #include "def.h" #include "cgroup-util.h" +#include "hostname-util.h" #include "bus-label.h" #include "sd-bus.h" diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index 9bbf8974dd..5f290573cb 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -32,6 +32,7 @@ #include "fileio.h" #include "login-util.h" #include "formats-util.h" +#include "hostname-util.h" #include "sd-login.h" _public_ int sd_pid_get_session(pid_t pid, char **session) { diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 8e75508444..72b9a619d2 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -56,6 +56,7 @@ #include "terminal-util.h" #include "signal-util.h" #include "env-util.h" +#include "hostname-util.h" static char **arg_property = NULL; static bool arg_all = false; diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c index 93514986f3..03625ba4cd 100644 --- a/src/machine/machined-dbus.c +++ b/src/machine/machined-dbus.c @@ -33,6 +33,7 @@ #include "btrfs-util.h" #include "formats-util.h" #include "process-util.h" +#include "hostname-util.h" #include "machine-image.h" #include "machine-pool.h" #include "image-dbus.h" diff --git a/src/machine/machined.c b/src/machine/machined.c index c8ad157326..109bab76c5 100644 --- a/src/machine/machined.c +++ b/src/machine/machined.c @@ -30,6 +30,7 @@ #include "label.h" #include "formats-util.h" #include "signal-util.h" +#include "hostname-util.h" #include "machine-image.h" #include "machined.h" diff --git a/src/nss-mymachines/nss-mymachines.c b/src/nss-mymachines/nss-mymachines.c index cdec83d074..5758ea1569 100644 --- a/src/nss-mymachines/nss-mymachines.c +++ b/src/nss-mymachines/nss-mymachines.c @@ -30,6 +30,7 @@ #include "bus-util.h" #include "bus-common-errors.h" #include "in-addr-util.h" +#include "hostname-util.h" NSS_GETHOSTBYNAME_PROTOTYPES(mymachines); NSS_GETPW_PROTOTYPES(mymachines); diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 60144ab8a6..9a5ffb7a6c 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -34,6 +34,7 @@ #include "formats-util.h" #include "process-util.h" #include "terminal-util.h" +#include "hostname-util.h" /* up to three lines (each up to 100 characters), or 300 characters, whichever is less */ |