package/openssh: explicitly configure PID file directory

OpenSSH checks during ./configure if the default location /var/run
exists on the build host, and defaults to ${sysconfdir} (/etc/ssh in
Buildroot) if not. This can break e.g. in a sandbox with its own mount
namespace where there is no reason to create a /var.

On the target this leads to errors when starting/stopping the service
from the init script, which expects the PID file at /var/run/sshd.pid if
sshd is running. A "stop" (including as part of "restart") or "reload"
will always fail with

    no /usr/sbin/sshd found; none killed

from start-stop-daemon, even though sshd is running (because the PID
file doesn't exist where start-stop-daemon tries to read it).

On the other hand, a "start" command will try to start sshd even if it
is already running, because it cannot detect the running instance.
Unfortunately sshd does not fail directly in that situation (so the init
script completes), but something like the following appears in the log:

    [May 04 14:48:05] auth sshd[4592]: error: Bind to port 22 on 0.0.0.0
    failed: Address in use.
    [May 04 14:48:05] auth sshd[4592]: error: Bind to port 22 on :: failed:
    Address in use.
    [May 04 14:48:05] auth sshd[4592]: fatal: Cannot bind any address.

Explicitly setting --with-pid-dir=/var/run overrides either default,
and only logs a warning if /var/run does not exist.

[1] 5fa60ae0d2/configure.ac (L5568-L5576)

Signed-off-by: Fiona Klute <fiona.klute@gmx.de>
[Marcus: expand commit message after discussion on ML]
Signed-off-by: Marcus Hoffmann <buildroot@bubu1.eu>
This commit is contained in:
Fiona Klute
2026-05-04 01:25:04 +02:00
committed by Marcus Hoffmann
parent a52df2cc85
commit c09bec68f1

View File

@@ -20,6 +20,7 @@ OPENSSH_CONF_ENV = \
OPENSSH_CPE_ID_VENDOR = openbsd
OPENSSH_CONF_OPTS = \
--sysconfdir=/etc/ssh \
--with-pid-dir=/var/run \
--with-default-path=$(BR2_SYSTEM_DEFAULT_PATH) \
$(if $(BR2_PACKAGE_OPENSSH_SANDBOX),--with-sandbox,--without-sandbox) \
--disable-lastlog \