From 4fee397531c97d22e41fb3f02452e82d412fe2b5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 Oct 2015 14:57:44 +0100 Subject: [PATCH] util-lib: move fdname_is_valid() to fd-util.[ch] --- src/basic/fd-util.c | 27 +++++++++++++++++++++++++++ src/basic/fd-util.h | 2 ++ src/basic/util.c | 27 --------------------------- src/basic/util.h | 2 -- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index 830522c..d1b1db3 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -322,3 +322,30 @@ void cmsg_close_all(struct msghdr *mh) { if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) close_many((int*) CMSG_DATA(cmsg), (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int)); } + +bool fdname_is_valid(const char *s) { + const char *p; + + /* Validates a name for $LISTEN_FDNAMES. We basically allow + * everything ASCII that's not a control character. Also, as + * special exception the ":" character is not allowed, as we + * use that as field separator in $LISTEN_FDNAMES. + * + * Note that the empty string is explicitly allowed + * here. However, we limit the length of the names to 255 + * characters. */ + + if (!s) + return false; + + for (p = s; *p; p++) { + if (*p < ' ') + return false; + if (*p >= 127) + return false; + if (*p == ':') + return false; + } + + return p - s < 256; +} diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h index be00d88..1ca10f0 100644 --- a/src/basic/fd-util.h +++ b/src/basic/fd-util.h @@ -67,3 +67,5 @@ int close_all_fds(const int except[], unsigned n_except); int same_fd(int a, int b); void cmsg_close_all(struct msghdr *mh); + +bool fdname_is_valid(const char *s); diff --git a/src/basic/util.c b/src/basic/util.c index 7d9dad4..08bdcd2 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -838,30 +838,3 @@ int version(void) { SYSTEMD_FEATURES); return 0; } - -bool fdname_is_valid(const char *s) { - const char *p; - - /* Validates a name for $LISTEN_FDNAMES. We basically allow - * everything ASCII that's not a control character. Also, as - * special exception the ":" character is not allowed, as we - * use that as field separator in $LISTEN_FDNAMES. - * - * Note that the empty string is explicitly allowed - * here. However, we limit the length of the names to 255 - * characters. */ - - if (!s) - return false; - - for (p = s; *p; p++) { - if (*p < ' ') - return false; - if (*p >= 127) - return false; - if (*p == ':') - return false; - } - - return p - s < 256; -} diff --git a/src/basic/util.h b/src/basic/util.h index 57dc5e8..2c2cb36 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -194,5 +194,3 @@ union inotify_event_buffer { }; int version(void); - -bool fdname_is_valid(const char *s); -- 2.7.4