From patchwork Thu May 2 02:01:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Santos X-Patchwork-Id: 1093978 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ffENoN8P"; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44vdmw6Xmgz9s9T for ; Thu, 2 May 2019 12:02:06 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id C175722843; Thu, 2 May 2019 02:02:01 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id K+7P2+rpuwdl; Thu, 2 May 2019 02:01:59 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 9545D22855; Thu, 2 May 2019 02:01:59 +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 B3F991BF3C1 for ; Thu, 2 May 2019 02:01:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id B062987F79 for ; Thu, 2 May 2019 02:01:58 +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 tdLYi9LxTpct for ; Thu, 2 May 2019 02:01:58 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) by hemlock.osuosl.org (Postfix) with ESMTPS id E4897879F5 for ; Thu, 2 May 2019 02:01:57 +0000 (UTC) Received: by mail-qt1-f196.google.com with SMTP id g7so818414qtc.0 for ; Wed, 01 May 2019 19:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0SbzIShxoGKHC5NXR0FsgIXrYTFEFhqEiyR+c+bo1TU=; b=ffENoN8P3yKmua07WrhYk4k3CUzBqPNaB/IAabQF/6Y2XodgjDDsswIFWkLaMopK0X k2y0uXm5GNxJcchcA5UKtp6efXLAtw9MVmUQfhHqwLWBYSvocbW5nZ2LAVBRiUF6rPXe 1xCno80npgn3CNvVAuWP/pvzX/p2lAfO1c1MMPya59HVKdbxG0KzX0SroK7/kYAQrkSt tcJcZ41qb3zQj4sSjImck1e3efpYVkwfZi+Jdwhj5nah0FhKp4obrRnIpMNPm+8kxsxY 4Oq4MiS5F2yskVWqzPjQgMubjNSb6KKoexpWezz4LAAJW1+F+DPRA+7a42NsTIao6xna sVog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0SbzIShxoGKHC5NXR0FsgIXrYTFEFhqEiyR+c+bo1TU=; b=gE+l+B5cHgUd47UxPY50mG1LpX8y+p/UQaZ0WpFqZGczrZlO88YJFzCKtR7xPdF0Tn Q8/kL1XrvOav3CFx88sPOHmz0E+me7HDRZITepKHB//sFo1YgOM3A9u5ZV/aHpzZsI15 U/Mey9ck8X8cQZVSSJhkK5losPAl3U0rujZgeB2x3+o1qORYQBh1yQe6GQYM04j/7cij UrPv2ykqt0R7TgHDwELabohAk0ZGJ49olz/CzCtRbYRwtyjZ58fS/7wz3WdfUa1JhPyH 8qPBd13VSCPBX1Ju3cJBadSNMR6SJJUWTBMThz8pw3LUWv/1el5nFcwfqQM28nolJl78 qH8A== X-Gm-Message-State: APjAAAUyYDe1QpX/Ea15HRGuAQ8A/xH8hViW+g6HcpfbCWD4ggNp78bR uGCJOH5u0RKpZaJ/ihVqdJJNWFO/fX0A8g== X-Google-Smtp-Source: APXvYqyKHn+tSojEd72tCEiZ+qRQUzyuMyE6gDpY4soUJDO55Ak5H4c2raJ/FsBWd5lneVXk1VMO8A== X-Received: by 2002:aed:2307:: with SMTP id h7mr1086677qtc.87.1556762516690; Wed, 01 May 2019 19:01:56 -0700 (PDT) Received: from p7-1130br.casantos.org ([177.156.131.99]) by smtp.gmail.com with ESMTPSA id t2sm24635351qkd.57.2019.05.01.19.01.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 May 2019 19:01:56 -0700 (PDT) From: unixmania@gmail.com To: buildroot@buildroot.org Date: Wed, 1 May 2019 23:01:52 -0300 Message-Id: <20190502020152.32632-1-unixmania@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Buildroot] [PATCH v4] package/radvd: improve startup 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: Carlos Santos Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Carlos Santos - Add start, stop and restart/reload options, following the logic used in other init scripts (e.g. S01syslogd). - Do nothing if /etc/radvd.conf does not exist instead of printing an error message. It is valid to install radvd without a configuration file. The daemon may be started later by another service with a configuration created at run-time. - Print an error message if the kernel does not support IPv6 forwarding, which is required by radvd. Signed-off-by: Carlos Santos --- Changes v3->v4 - Changed SOB, since I don't work for DATACOM anymore. - Use the same template of other init scripts. Changes v2->v3 - Don't test if the binary is executable. It's unlikely to happen because Buildroot installs both radvd and its init script as part of the same package. But if it ever happens for some reason, the error message from start-stop-daemon should be pretty clear (Thomas Petazzoni). - Move start and stop to functions and rewrite the error handling code to improve its readability. - Add a one second sleep between stop and start, in restart, as made in several other scripts. Changes v1->v2 - Print error message is /usr/sbin/radvd is missing - Print error message if /proc/sys/net/ipv6/conf/all/forwarding is missing (kernel does not support IPv6 forwarding) - Echo "1" to /proc/sys/net/ipv6/conf/all/forwarding upon start --- package/radvd/S50radvd | 65 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/package/radvd/S50radvd b/package/radvd/S50radvd index 9f1407c95a..f73ce24ed5 100644 --- a/package/radvd/S50radvd +++ b/package/radvd/S50radvd @@ -1,18 +1,59 @@ #!/bin/sh -RADVD=/usr/sbin/radvd +DAEMON="radvd" +PIDFILE="/var/run/$DAEMON.pid" -echo "1" > /proc/sys/net/ipv6/conf/all/forwarding +RADVD_ARGS="-m syslog" -printf "Starting radvd: " -if [ ! -x "${RADVD}" ]; then - echo "missing" - exit 1 -fi +# shellcheck source=/dev/null +[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON" + +[ -f /etc/radvd.conf ] || exit 0 -if ${RADVD} ; then - echo "done" -else - echo "failed" +[ -f /proc/sys/net/ipv6/conf/all/forwarding ] || { + echo "Error: radvd requires IPv6 forwarding support." exit 1 -fi +} + +start() { + printf 'Starting %s: ' "$DAEMON" + echo "1" > /proc/sys/net/ipv6/conf/all/forwarding + # shellcheck disable=SC2086 # we need the word splitting + start-stop-daemon -S -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON" \ + -- $RADVD_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" -x "/usr/sbin/$DAEMON" + status=$? + if [ "$status" -eq 0 ]; then + echo "OK" + else + echo "FAIL" + fi + return "$status" +} + +restart() { + stop + sleep 1 + start +} + +case "$1" in + start|stop) + "$1";; + restart|reload) + restart;; + *) + echo "Usage: $0 {start|stop|restart|reload}" + exit 1 +esac