From patchwork Tue Sep 29 16:22:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Jones X-Patchwork-Id: 1373516 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=meshplusplus.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=C+1VN38p; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=meshplusplus-com.20150623.gappssmtp.com header.i=@meshplusplus-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=LESiJ5c+; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C14Sq6kD9z9sSJ for ; Wed, 30 Sep 2020 02:23:39 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe :List-Id:MIME-Version:Date:Message-ID:To:Subject:From:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=ucmNy1HYlzZf9rJP8QQwMWsniDgu9KhSiPZ2WOUKjcw=; b=C+1VN38pN1Lv7fHQdtFpEYriEK c5R/hk9wGs+b6Yb48Ns8vx9dgns/W54tYqGB1axV9tHKMhrtCig9GpEYmQUqfNE5wDCNcA6PRELND 4pkUe4KIMiWSSY0vwscGhKDYgn28G5/R+bVQez3VA0QK66R6A6I80/ppR+OrNIV2WYftPQDmqV8cO kVtQu8JnoqMGpALydU3V4gP6YA5koJexkR9mGbv/I+LiaU0dB4ZJolCehXlHAJds/W7SmsfFqnUDC I+ZFNzSj/L9j53Vu8noIaURFKouAlHE0RnhbGU5jbEXZAyG8m5dOKNK/rYcq9NasfSIyT3njTBOWN uvqhohsQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNIOd-00010N-Qp; Tue, 29 Sep 2020 16:22:31 +0000 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNIOb-0000yY-23 for openwrt-devel@lists.openwrt.org; Tue, 29 Sep 2020 16:22:30 +0000 Received: by mail-io1-xd41.google.com with SMTP id y13so5428588iow.4 for ; Tue, 29 Sep 2020 09:22:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meshplusplus-com.20150623.gappssmtp.com; s=20150623; h=from:subject:to:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=aLROUHisSvHw90jyRn3PaiKP8hP8eIaR+nGNDmnXt9I=; b=LESiJ5c+jEPlN0K/GHUMJhi5RqGfijGAXl1MTby6bzVNJdUaLh9sOw33dCyRl0dxAq VS7q+pBQIpI73lTp6sT7nL5Tlt8euo2ieLeshKyedE1N1WI7mfiwLt7t1t/Rtwjl48n1 K1fSippQtJw4XZM8X6zWN6jlp7xBwKAtHIQjQ4E6iuun/yNb0oYOQWCAozEZAHhRWHXX uBYvm0D08MCxKrahuwAgk8h8m/c5h0lqmRGEJOdHnAA5B8G9mt5i+eQZSpB3LHndx8oo VbmOkBVCeptl5DuM7Havi2495jzh9eGTxbUsFIAZMms5LTVgVcOQKdE9rFGIwoCglB4A yisg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=aLROUHisSvHw90jyRn3PaiKP8hP8eIaR+nGNDmnXt9I=; b=BD7d9rr+YGbHYR4rylfat0Bx5lA/xWkseH3kFZ+U+QTYBGjWIqFCVfTHRGh6xgpI7Z w4N7/nT0IZQV9Ld+hJI/k7jiRRyx2HrRCz+OP6zYu7keUx1Ltep9tLUFafFZ9xk/1wgV H8+C9GrZOqyKiV9KRm1NKPybBOz+nIbnXgA4os5P/CNKkA5RBYbBuSpH2JqOQLo5LJVX fG0yBk0nrWEeROCv44VFFng6G1EHDkhgoz1QYQZJ0xLatasBormJ8fv8O8QwEDRoEyYd e8W2F6XxXxrTTUHZea7/kw+GL01fy2fTg7iExom+WwA0IyuP85DUgJDWxdKnvM73fM3d Ifbg== X-Gm-Message-State: AOAM532ZMkGzKNJsB3mPuG/mq1NGRi+vBvYYiOJsUFdIoU5Wyg/Yc1Qq piByPQXxD+t+WCf3eWTWqCz+UAnYnKQSIjpE X-Google-Smtp-Source: ABdhPJxISvoxJUDBYBqvtLbLnVoYrCFJ0jS+AOew9dpnTRZF1XvbT09RNMp2Wu+Y+2bQU4pFhwLp0Q== X-Received: by 2002:a5e:9319:: with SMTP id k25mr1387932iom.153.1601396546918; Tue, 29 Sep 2020 09:22:26 -0700 (PDT) Received: from ?IPv6:2601:248:4200:25a::71? ([2601:248:4200:25a::71]) by smtp.gmail.com with ESMTPSA id s1sm2595053iln.22.2020.09.29.09.22.25 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 29 Sep 2020 09:22:25 -0700 (PDT) From: Michael Jones Subject: [PATCH 5/5] initd: Convert the watchdog_fd return value from char* to int To: openwrt-devel@lists.openwrt.org Message-ID: <156b08bb-28f9-946f-134a-3d425d518fe3@meshplusplus.com> Date: Tue, 29 Sep 2020 11:22:24 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200929_122229_141963_0823BBF7 X-CRM114-Status: GOOD ( 17.62 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:d41 listed in] [list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This change improves the frequently called path of determining if the watchdog is alive when responding to ubus transactions at the expense of complicating the less frequently called code of transitioning to the upgraded binary, and transitioning from pre-init to procd. Signed-off-by: Michael Jones ---  initd/preinit.c | 11 ++++++++---  system.c        |  2 +-  sysupgrade.c    |  8 +++++---  watchdog.c      | 11 ++---------  watchdog.h      |  6 +++---  5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/initd/preinit.c b/initd/preinit.c index 9dfe5c1..255ceeb 100644 --- a/initd/preinit.c +++ b/initd/preinit.c @@ -90,7 +90,7 @@ fail:  static void  spawn_procd(struct uloop_process *proc, int ret)  { -    char *wdt_fd = watchdog_fd(); +    int wdt_fd = watchdog_fd();      char *argv[] = { "/sbin/procd", NULL};      char dbg[2];   @@ -104,8 +104,13 @@ spawn_procd(struct uloop_process *proc, int ret)      check_sysupgrade();        DEBUG(2, "Exec to real procd now\n"); -    if (wdt_fd) -        setenv("WDTFD", wdt_fd, 1); + +    if (wdt_fd >= 0) { +        char fd_buf[12]; +        snprintf(fd_buf, sizeof(fd_buf), "%d", wdt_fd); +        setenv("WDTFD", fd_buf, 1); +    } +      check_dbglvl();      if (debug > 0) {          snprintf(dbg, 2, "%d", debug); diff --git a/system.c b/system.c index ef7943a..caae0ec 100644 --- a/system.c +++ b/system.c @@ -378,7 +378,7 @@ static int watchdog_set(struct ubus_context *ctx, struct ubus_object *obj,      if (tb[WDT_STOP])          watchdog_set_stopped(blobmsg_get_bool(tb[WDT_STOP]));   -    if (watchdog_fd() == NULL) +    if (watchdog_fd() < 0)          status = "offline";      else if (watchdog_get_stopped())          status = "stopped"; diff --git a/sysupgrade.c b/sysupgrade.c index fc588b0..20e1ef0 100644 --- a/sysupgrade.c +++ b/sysupgrade.c @@ -29,7 +29,7 @@ void sysupgrade_exec_upgraded(const char *prefix, char *path,                    const char *backup, char *command,                    struct blob_attr *options)  { -    char *wdt_fd = watchdog_fd(); +    int wdt_fd = watchdog_fd();      char *argv[] = { "/sbin/upgraded", NULL, NULL, NULL};      struct blob_attr *option;      int rem; @@ -44,9 +44,11 @@ void sysupgrade_exec_upgraded(const char *prefix, char *path,      argv[1] = path;      argv[2] = command;   -    if (wdt_fd) { +    if (wdt_fd >= 0) { +        char fd_buf[12]; +        snprintf(fd_buf, sizeof(fd_buf), "%d", wdt_fd);          watchdog_set_cloexec(false); -        setenv("WDTFD", wdt_fd, 1); +        setenv("WDTFD", fd_buf, 1);      }        if (backup) diff --git a/watchdog.c b/watchdog.c index ac5b656..3c565d2 100644 --- a/watchdog.c +++ b/watchdog.c @@ -146,16 +146,9 @@ int watchdog_frequency(int frequency)      return wdt_frequency;  }   -char* watchdog_fd(void) +int watchdog_fd(void)  { -    static char fd_buf[12]; - -    if (wdt_fd < 0) -        return NULL; - -    snprintf(fd_buf, sizeof(fd_buf), "%d", wdt_fd); - -    return fd_buf; +    return wdt_fd;  }    void watchdog_init(int preinit) diff --git a/watchdog.h b/watchdog.h index 73c75d5..3c35d9a 100644 --- a/watchdog.h +++ b/watchdog.h @@ -19,7 +19,7 @@    #ifndef DISABLE_INIT  void watchdog_init(int preinit); -char* watchdog_fd(void); +int watchdog_fd(void);  int watchdog_timeout(int timeout);  int watchdog_frequency(int frequency);  void watchdog_set_magicclose(bool val); @@ -33,9 +33,9 @@ static inline void watchdog_init(int preinit)  {  }   -static inline char* watchdog_fd(void) +static inline int watchdog_fd(void)  { -    return ""; +    return -1;  }    static inline int watchdog_timeout(int timeout)