[Buildroot] [PATCH] package/openssh: fix initscript killing subprocesses

John Doe anonymous683854643863 at outlook.com
Fri Jan 1 20:31:04 UTC 2021


The initscript currently calls `killall sshd` when stopping the service, which
kills all active SSH sessions. Rewritten to use start-stop-daemon with PIDfile.

Signed-off-by: John Johnson <anonymous683854643863 at outlook.com>
---
 package/openssh/S50sshd | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/package/openssh/S50sshd b/package/openssh/S50sshd
index 22da41d1ca..77a82308ca 100644
--- a/package/openssh/S50sshd
+++ b/package/openssh/S50sshd
@@ -3,6 +3,9 @@
 # sshd        Starts sshd.
 #
 
+DAEMON="sshd"
+PIDFILE="/var/run/$DAEMON.pid"
+
 # Make sure the ssh-keygen progam exists
 [ -f /usr/bin/ssh-keygen ] || exit 0
 
@@ -13,15 +16,27 @@ start() {
 	/usr/bin/ssh-keygen -A
 
 	printf "Starting sshd: "
-	/usr/sbin/sshd
-	touch /var/lock/sshd
-	echo "OK"
+	start-stop-daemon -S -q -p "$PIDFILE" -x "/usr/sbin/sshd"
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		touch /var/lock/sshd
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
 }
 stop() {
 	printf "Stopping sshd: "
-	killall sshd
-	rm -f /var/lock/sshd
-	echo "OK"
+	start-stop-daemon -K -q -p "$PIDFILE"
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		rm -f /var/lock/sshd
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
 }
 restart() {
 	stop
-- 
2.29.2


More information about the buildroot mailing list