From patchwork Mon Dec 21 18:28:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Niestroj X-Patchwork-Id: 1419186 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.138; helo=whitealder.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=grinn-global.com Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D07KP734Cz9sVM for ; Tue, 22 Dec 2020 05:29:13 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 5165886A26; Mon, 21 Dec 2020 18:29:10 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xlOYgsytaVpT; Mon, 21 Dec 2020 18:29:08 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id D8F6486976; Mon, 21 Dec 2020 18:29:07 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 906F41BF3E0 for ; Mon, 21 Dec 2020 18:29:06 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 8D3FB86483 for ; Mon, 21 Dec 2020 18:29:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Q7c9WtV5XoCW for ; Mon, 21 Dec 2020 18:29:05 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from smtp2.megiteam.pl (smtp2.megiteam.pl [213.189.52.193]) by whitealder.osuosl.org (Postfix) with ESMTPS id 2DB1F805B1 for ; Mon, 21 Dec 2020 18:29:05 +0000 (UTC) Received: from [95.143.241.142] (helo=localhost.localdomain) by smtp.megiteam.pl with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86.2_XX) (envelope-from ) id 1krPva-0002D3-E6; Mon, 21 Dec 2020 19:29:02 +0100 From: Marcin Niestroj To: buildroot@buildroot.org Date: Mon, 21 Dec 2020 19:28:58 +0100 Message-Id: <20201221182858.66326-1-m.niestroj@grinn-global.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Subject: [Buildroot] [PATCH] package/connman: improve SysV 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: , Cc: Marcin Niestroj , Martin Bark Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" Use a more generic template for SysV init script, similar to packages like syslog-ng. This includes adding support for both reload and restart. Add support for sourcing /etc/default/connmand file, so that new commandline arguments can be added more easily. Signed-off-by: Marcin Niestroj --- package/connman/S45connman | 64 ++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/package/connman/S45connman b/package/connman/S45connman index d3d4bd5df4..c8e913d3a1 100644 --- a/package/connman/S45connman +++ b/package/connman/S45connman @@ -1,22 +1,52 @@ #!/bin/sh +DAEMON="connmand" +PIDFILE="/var/run/$DAEMON.pid" + +CONNMAND_ARGS="-n" + +# shellcheck source=/dev/null +[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON" + +start() { + printf 'Starting %s: ' "$DAEMON" + # shellcheck disable=SC2086 # we need the word splitting + start-stop-daemon -S -q -m -b -p "$PIDFILE" -x "/usr/sbin/$DAEMON" \ + -- $CONNMAND_ARGS + status=$? + if [ "$status" -eq 0 ]; then + echo "OK" + else + echo "FAIL" + fi + return "$status" +} + +stop() { + printf 'Stopping %s: ' "$DAEMON" + start-stop-daemon -K -q -p "$PIDFILE" + status=$? + if [ "$status" -eq 0 ]; then + echo "OK" + else + echo "FAIL" + fi + return "$status" +} + +restart() { + stop + sleep 1 + start +} + case "$1" in - start) - printf "Starting connman ... " - start-stop-daemon -S -q -m -b -p /var/run/connmand.pid --exec /usr/sbin/connmand -- -n - echo "done." - ;; - stop) - printf "Stopping connman ..." - start-stop-daemon -K -q -p /var/run/connmand.pid - echo "done." - ;; - restart) - $0 stop - sleep 1 - $0 start - ;; + start|stop|restart) + "$1";; + reload) + # Restart, since there is no true "reload" feature. + restart;; *) - echo "usage: $0 {start|stop|restart}" - ;; + echo "Usage: $0 {start|stop|restart|reload}" + exit 1 esac