From patchwork Sun Nov 4 10:14:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Dedecker X-Patchwork-Id: 992720 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Y4G9aAnP"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="W90jnn9J"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42nsBZ6r0kzB6Kd for ; Sun, 4 Nov 2018 21:15:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:Message-Id:Date:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=IEEkDyiWBXvRIvz9fVDlrxM2aa4xA5prDki+KnU/fxc=; b=Y4G9aAnP30Wqeh 9kXXNwQdxcAbLO153D6yeYwqo6EX1xTvXL2qU/M79DfRLfZg3DQRV1l23p6fc3kOWj9oUESps1URg pNAFmjEVi7Fm6zWNeyoSYpn9LhoHFlU6NxG5Mz7GHkbAc8YGaYZ90HBvu+W+YM36Tqgtm1JX37Qhu xte4fKYtE7Gy2VjYzb1dV2hLZZ97fHFOwGkBhcncuwQNQhGBk6+XL9uncT/k+5Hij4q8bkgvMEh7F R8pTHYkmK4oRgn8/9Q5wlL2WCvhRjNV2PhVmR0S8wGqid/gBCmz2i1Gqwt1aQB8kjqySAS8hpdxGZ QASa1aPenX0VZvRUGKvA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gJFQk-0006Eu-5x; Sun, 04 Nov 2018 10:14:54 +0000 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gJFQh-0006Dx-DD for openwrt-devel@lists.openwrt.org; Sun, 04 Nov 2018 10:14:52 +0000 Received: by mail-ed1-x543.google.com with SMTP id w19-v6so5128924eds.1 for ; Sun, 04 Nov 2018 02:14:38 -0800 (PST) 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=j8V7b+qm2XGAwWbm0bnMp68PTXcNWXHvhkLmGZnn1Ts=; b=W90jnn9JJPE+CWoBfC2XhBSfL5zabbTmIHwT6rWOK5JtxAlP+QIztQeT0XdK44RkZB lqVvtpO8kdTS7Q4enxxxj0uPRyHjaitvcn2k4CoXsku2V2NL6PU0wGSrSWtRy002c+Iq /2JTE39JEg9r2zzbGO8p4+2MY0JN21guAx0GNnUx2PABMhC5Hh9FAqpgrIDyvBiizOHp vzGQVg1o9jUTZ9EFLMVNY4wlv1yOx85Y4wnO6PfKx1b9EdsbO1fQl00fuELPlkrRw9io GwR0sK1oE3A7gLbLCmRec+OfQU9vG2LRvC0cvEuZVJ0+B6gtdgOXYKh6bPOgaBEyY0Kd jIkg== 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=j8V7b+qm2XGAwWbm0bnMp68PTXcNWXHvhkLmGZnn1Ts=; b=mniTgEDxdHauRTkxPpJ+QaLLbJGNUdkTalNcvJwunKSKdWv0TTFbxdF9Alt3XX6a/b t15AfLNOqj/fzlzfmM6/MHokd4QAUirPq3OucdktGGA334jM20xetmWlMKfMwbngHBEy twcTQFsH2vJJ6bWcCLf2rvv3bzXAz0OATt28PCYqGi5FnvcOF/HKeZx9x3tUk/miVWvi N2p3jfyR8ts/mxMzHUUdr3xOfNfbXLKqjD7L1x5uBTFzLfqPDynMcIk7dLm349hMNknB eqn1iZebgzLqyZ/pRyph/B2DTmOmXvMMMDdE5+QiX6SITI3D0T0nZ14quAS8bJq+LRla 6G0A== X-Gm-Message-State: AGRZ1gIXFaE9NjMFODj9tLmv8CA06iMlSHUAWXisX/H/GvIQyoTOxhFu xhuzgqsuvt32ijBCI8mCEvbzQmaE8i8= X-Google-Smtp-Source: AJdET5c2V3LA6ThnJQDLNh/GhZ4QY6R8ZAdNSfsvPxq5ns/w1Vb256ZkaYA56Iz9d8muXVDHqgq76A== X-Received: by 2002:a50:8b61:: with SMTP id l88-v6mr6029511edl.52.1541326476478; Sun, 04 Nov 2018 02:14:36 -0800 (PST) Received: from dedeckeh-X556UV.lan (ptr-fvl7vtaywk41j7qmqoq.18120a2.ip6.access.telenet.be. [2a02:1812:1128:fb00:240f:f5f2:c445:769a]) by smtp.gmail.com with ESMTPSA id t1-v6sm9449817eds.44.2018.11.04.02.14.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Nov 2018 02:14:35 -0800 (PST) From: Hans Dedecker To: openwrt-devel@lists.openwrt.org, john@phrozen.org Date: Sun, 4 Nov 2018 11:14:31 +0100 Message-Id: <20181104101431.7489-1-dedeckeh@gmail.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181104_021451_472238_A27E493F X-CRM114-Status: GOOD ( 14.75 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:543 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (dedeckeh[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain Subject: [OpenWrt-Devel] [PATCH procd] watchdog: improve seting watchdog timeout and frequency X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hans Dedecker Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Due to the watchdog file descriptor check in both watchdog_timeout and watchdog_frequency it's impossible to set the timeout/frequency via ubus in case the watchdog was stopped. Fix this by removing the watchdog file descriptor check in both functions and by caching locally the set watchdog driver timeout value. The latter will be used to set the watchdog driver timeout value in case the watchdog is active or when the watchdog is started. In addition when parsing the watchdog ubus call check if timeout attribute is set so the correct value is used when doing the frequency sanity check. Signed-off-by: Hans Dedecker --- system.c | 3 ++- watchdog.c | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/system.c b/system.c index 46c420b..8ed3f93 100644 --- a/system.c +++ b/system.c @@ -304,7 +304,8 @@ static int watchdog_set(struct ubus_context *ctx, struct ubus_object *obj, blobmsg_parse(watchdog_policy, __WDT_MAX, tb, blob_data(msg), blob_len(msg)); if (tb[WDT_FREQUENCY]) { - unsigned int timeout = watchdog_timeout(0); + unsigned int timeout = tb[WDT_TIMEOUT] ? blobmsg_get_u32(tb[WDT_TIMEOUT]) : + watchdog_timeout(0); unsigned int freq = blobmsg_get_u32(tb[WDT_FREQUENCY]); if (freq) { diff --git a/watchdog.c b/watchdog.c index 7493a0f..9d770b4 100644 --- a/watchdog.c +++ b/watchdog.c @@ -30,6 +30,7 @@ static struct uloop_timeout wdt_timeout; static int wdt_fd = -1; +static int wdt_drv_timeout = 30; static int wdt_frequency = 5; static bool wdt_magicclose = false; @@ -84,6 +85,14 @@ static void watchdog_close(void) wdt_fd = -1; } +static int watchdog_set_drv_timeout(void) +{ + if (wdt_fd < 0) + return -1; + + return ioctl(wdt_fd, WDIOC_SETTIMEOUT, &wdt_drv_timeout); +} + void watchdog_set_magicclose(bool val) { wdt_magicclose = val; @@ -104,6 +113,7 @@ void watchdog_set_stopped(bool val) } else { watchdog_open(true); + watchdog_set_drv_timeout(); watchdog_timeout_cb(&wdt_timeout); } } @@ -115,23 +125,19 @@ bool watchdog_get_stopped(void) int watchdog_timeout(int timeout) { - if (wdt_fd < 0) - return 0; - if (timeout) { DEBUG(4, "Set watchdog timeout: %ds\n", timeout); - ioctl(wdt_fd, WDIOC_SETTIMEOUT, &timeout); + wdt_drv_timeout = timeout; + + if (wdt_fd >= 0) + watchdog_set_drv_timeout(); } - ioctl(wdt_fd, WDIOC_GETTIMEOUT, &timeout); - return timeout; + return wdt_drv_timeout; } int watchdog_frequency(int frequency) { - if (wdt_fd < 0) - return 0; - if (frequency) { DEBUG(4, "Set watchdog frequency: %ds\n", frequency); wdt_frequency = frequency; @@ -160,7 +166,7 @@ void watchdog_init(int preinit) return; LOG("- watchdog -\n"); - watchdog_timeout(30); + watchdog_set_drv_timeout(); watchdog_timeout_cb(&wdt_timeout); DEBUG(4, "Opened watchdog with timeout %ds\n", watchdog_timeout(0));