From: Daniel Foster Date: Mon, 26 May 2025 14:29:13 +0000 (+1000) Subject: socket-activate: validate more argument combinations earlier in runtime X-Git-Tag: v258-rc1~318^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dfbda58c3373828d7770ab6c6cfa4bfb77fcc3df;p=thirdparty%2Fsystemd.git socket-activate: validate more argument combinations earlier in runtime Check user configuration errors and warnings (e.g. more than one socket passed with --inetd) earlier in runtime. There's no reason not to do this, and it means invalid configuration will be reported to the user earlier. Also let the user know that --fdname= has no effect with --inetd. --- diff --git a/src/socket-activate/socket-activate.c b/src/socket-activate/socket-activate.c index ada289ded3e..e62b762c950 100644 --- a/src/socket-activate/socket-activate.c +++ b/src/socket-activate/socket-activate.c @@ -102,6 +102,21 @@ static int open_sockets(int *ret_epoll_fd) { log_set_open_when_needed(false); } + if (count > 1 && !arg_accept && arg_inetd) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "--inetd only supported with a single file descriptor, or with --accept."); + + if (arg_fdnames && !arg_inetd) { + size_t n_fdnames = strv_length(arg_fdnames); + + if (!arg_accept && n_fdnames != (size_t) count) + log_warning("The number of fd names is different from the number of fds: %zu vs %i", + n_fdnames, count); + + if (arg_accept && n_fdnames > 1) + log_warning("More than one fd name specified with --accept."); + } + epoll_fd = epoll_create1(EPOLL_CLOEXEC); if (epoll_fd < 0) return log_error_errno(errno, "Failed to create epoll object: %m"); @@ -129,10 +144,6 @@ static int exec_process(char * const *argv, int start_fd, size_t n_fds) { assert(start_fd >= 0); assert(n_fds > 0); - if (arg_inetd && n_fds != 1) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "--inetd only supported for single file descriptors."); - FOREACH_STRING(var, "TERM", "COLORTERM", "NO_COLOR", "PATH", "USER", "HOME") { const char *n; @@ -181,8 +192,6 @@ static int exec_process(char * const *argv, int start_fd, size_t n_fds) { if (r < 0) return log_oom(); } - else if (len != n_fds) - log_warning("The number of fd names is different than number of fds: %zu vs %zu", len, n_fds); names = strv_join(arg_fdnames, ":"); if (!names) @@ -440,6 +449,9 @@ static int parse_argv(int argc, char *argv[]) { "Datagram sockets do not accept connections. " "The --datagram and --accept options may not be combined."); + if (arg_fdnames && arg_inetd) + log_warning("--fdname= has no effect with --inetd present."); + return 1 /* work to do */; }