From patchwork Thu Jan 23 12:17:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ignacy_Gaw=C4=99dzki?= X-Patchwork-Id: 1227840 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=green-communications.fr Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 483Ls35jmDz9sQp for ; Thu, 23 Jan 2020 23:18:14 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 2D5BB869E1; Thu, 23 Jan 2020 12:18:12 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IsWFUfO1rLN9; Thu, 23 Jan 2020 12:18:11 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 910E1869E2; Thu, 23 Jan 2020 12:18:11 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 376B51BF3C6 for ; Thu, 23 Jan 2020 12:18:10 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 32DDC883CD for ; Thu, 23 Jan 2020 12:18:10 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YSxJTmnOHjsD for ; Thu, 23 Jan 2020 12:18:09 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from smtp6-g21.free.fr (smtp6-g21.free.fr [212.27.42.6]) by hemlock.osuosl.org (Postfix) with ESMTPS id CF4858837C for ; Thu, 23 Jan 2020 12:18:08 +0000 (UTC) Received: from mail.qult.net (unknown [78.193.33.39]) by smtp6-g21.free.fr (Postfix) with ESMTPS id AF5FA780395 for ; Thu, 23 Jan 2020 13:18:05 +0100 (CET) Received: from zenon.in.qult.net ([192.168.64.1]) by mail.qult.net with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1iubQz-0002B5-GE for buildroot@buildroot.org; Thu, 23 Jan 2020 13:18:05 +0100 Received: from ig by zenon.in.qult.net with local (Exim 4.92.1) (envelope-from ) id 1iubQp-0007DT-M3 for buildroot@buildroot.org; Thu, 23 Jan 2020 13:17:55 +0100 Date: Thu, 23 Jan 2020 13:17:55 +0100 From: Ignacy =?utf-8?b?R2F3xJlkemtp?= To: buildroot@buildroot.org Message-ID: <20200123121755.vp2n7mx3xxpbrbyz@zenon.in.qult.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20180716 Subject: [Buildroot] [PATCH 1/1] package/openssh: improve init script X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" The current init script for sshd is too simplistic and its use of killall to terminate the daemon has the annoying downside of killing every instance of sshd, possibly including the one spawned for the interactive session in which the script itself is started. If the intention was to simply restart the daemon, killing the current session ultimately kills the script and the daemon is not properly started again. Improve the init script in the following ways: Use start-stop-daemon to avoid running the daemon more than once and to safely send termination signals to the right process. Add a proper reload action, by sending the daemon the SIGHUP signal. During restart, check that the daemon has properly terminated and if not, wait one second before sending it the SIGKILL signal. Signed-off-by: Ignacy Gawędzki --- package/openssh/S50sshd | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/package/openssh/S50sshd b/package/openssh/S50sshd index 22da41d1ca..66cdd5e291 100644 --- a/package/openssh/S50sshd +++ b/package/openssh/S50sshd @@ -13,20 +13,29 @@ start() { /usr/bin/ssh-keygen -A printf "Starting sshd: " - /usr/sbin/sshd - touch /var/lock/sshd - echo "OK" + start-stop-daemon -S -q -x /usr/sbin/sshd -p /run/sshd.pid && + { touch /var/lock/sshd; echo "OK"; } || echo "FAIL" } stop() { printf "Stopping sshd: " - killall sshd - rm -f /var/lock/sshd - echo "OK" + start-stop-daemon -K -q -x /usr/sbin/sshd -p /run/sshd.pid && + { rm -f /var/lock/sshd; echo "OK"; } || echo "FAIL" } restart() { stop + # Ensure the daemon has terminated before calling start again. + if start-stop-daemon -K -q -x /usr/sbin/sshd -p /run/sshd.pid -t; then + sleep 1 + start-stop-daemon -K -s KILL -q -x /usr/sbin/sshd \ + -p /run/sshd.pid + fi start } +reload() { + printf "Reloading sshd: " + start-stop-daemon -K -s HUP -q -x /usr/sbin/sshd -p /run/sshd.pid && + echo "OK" || echo "FAIL" +} case "$1" in start) @@ -35,13 +44,15 @@ case "$1" in stop) stop ;; - restart|reload) + reload) + reload + ;; + restart) restart ;; *) - echo "Usage: $0 {start|stop|restart}" + echo "Usage: $0 {start|stop|reload|restart}" exit 1 esac exit $? -