From patchwork Mon Jul 22 00:24:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Santos X-Patchwork-Id: 1134631 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="uPzHi5r3"; 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 45sMnC4ZRfz9s4Y for ; Mon, 22 Jul 2019 10:24:47 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 97014203BE; Mon, 22 Jul 2019 00:24:43 +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 rDG8OrAex1yp; Mon, 22 Jul 2019 00:24:40 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 8CE1121544; Mon, 22 Jul 2019 00:24:40 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 2DDFB1BF865 for ; Mon, 22 Jul 2019 00:24:39 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 2B88121544 for ; Mon, 22 Jul 2019 00:24:39 +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 7JaIwQHKFET5 for ; Mon, 22 Jul 2019 00:24:38 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by silver.osuosl.org (Postfix) with ESMTPS id 1ED4F203BE for ; Mon, 22 Jul 2019 00:24:38 +0000 (UTC) Received: by mail-qt1-f193.google.com with SMTP id w17so36780361qto.10 for ; Sun, 21 Jul 2019 17:24:38 -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; bh=PT4dd7nP+h1urZSGqf3LcZ/cfs7ldAYsCq4sHArV53U=; b=uPzHi5r34fo8XmfZ3+3mcbB4o1bbQJhGOHE2hkPDs1Oyb6W3rB7GM0awVbVqkwfvMj GYlSo03EM7nkdrdyln3EUW9zcqLLBYi0xP/rlUnZWi1MBxJ68oTdUcCUb4ryWI4QtFcm ZQzgN3ObBq97eVt6EPSJa9XqMMJ4XLbLETNSWV6F76BIbiMlAxu6BqRGZvqlleXas5Y3 EJUay27u4LRM80knIYImJ18xHYHHTSzRHLHX418WdEWE36bC78Rf144YR7PjrTh3sGVY maIOh+FKKuL42tyx8v4CXCU8MScXphLHTM4j7d+i3E+n/qQoBrl9is/ipm8wGJlr71vE l0Kg== 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; bh=PT4dd7nP+h1urZSGqf3LcZ/cfs7ldAYsCq4sHArV53U=; b=MpHlOa5SZ/ZYyBUOH2LSWuGv8ByIToMa/QgN2a+2L7GyTyxd2CawasROFYCBav+DZS nNs6RoYiKOW7W/CTZB7WLRLRlP9oDgRJX2s8B9ytdiVq5xQLzqCDUwdNom+HbTlfRju/ LiQnOmdEkoexWmQQ2cGqRxCxOMGQIv97TWO1fNwXae9nCAJwyhpyF46t8k+e028HcBR1 jLCgs104BUe9EmnERtfr6/mP0hfPmb+56UD6md2kW8NkTJJVSMQ7OHHRf3pKmTf2HM1s G7+WpgkzZph3PAysGS7EEyXlO+g92eOqvxrf7gL9KsSRPDhc6HxaGFxaPj/ZDJwvGWhV BD+Q== X-Gm-Message-State: APjAAAUUFi/e0ZvduCPtYaqRTknq1V/D+AGc50KnPLKhCq+lcYUg764Q JI+G1jEfvibonVzxoIklcrHFVZ5Tr/c= X-Google-Smtp-Source: APXvYqyjIJsY90Vt0AszpVmx6DtA8A5vY9jct1ODe5CtCdXuE0276jX1MlBJT7jWnNV4e886aFvCew== X-Received: by 2002:ac8:36b9:: with SMTP id a54mr48451320qtc.300.1563755076867; Sun, 21 Jul 2019 17:24:36 -0700 (PDT) Received: from casantos.remote.csb ([191.35.195.92]) by smtp.gmail.com with ESMTPSA id z4sm21132922qtd.60.2019.07.21.17.24.34 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 21 Jul 2019 17:24:36 -0700 (PDT) From: unixmania@gmail.com To: buildroot@buildroot.org Date: Sun, 21 Jul 2019 21:24:25 -0300 Message-Id: <20190722002425.6783-1-unixmania@gmail.com> X-Mailer: git-send-email 2.18.1 Subject: [Buildroot] [PATCH v2] package/dcron: fix startup error due to missing directories 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 , "Yann E . MORIN" MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Carlos Santos crond uses the /var/spool/cron/{crontabs,cronstamps} directories to store the per-user crontabs and timestamps for jobs, respectively. On systems with busybox or sysv init /var/spool is by default a link to /tmp (see package/skeleton-init-sysv/skeleton/). So if those directories are created at installation time they actually are under /tmp/spool and vanish at run time when a tmpfs is mounted at /tmp. In this case crond issues error messages that can't be seen. The error is hidden because we use start-stop-daemon to run crond in foreground mode to create a pid file and move crond to background. In this mode crond does not use syslog and all error messages are lost because start-stop-daemon redirects strderr to /dev/null. Getting a presistent storage for /var/spool would require customisations of the directory layout, which can not be done in a generic way, as each one will need to adapt to their own constraints. Fix these problem by means of the following changes: - Add configs for the crontabs and cronstamps paths. They can be used to move the directories to persistent filesystems, if necessary. - Change the init script and systemd unit to ensure that the directories are created before starting crond. - Start crond in daemon mode in the init script and use "pidof crond" to create the required pid file. Fixes: https://bugs.busybox.net/show_bug.cgi?id=12011 Signed-off-by: Carlos Santos --- Changes v1->v2: - Remove (partially), since the fix is now complete --- package/dcron/Config.in | 16 ++++++++++++++++ package/dcron/S90dcron | 8 +++++++- package/dcron/dcron.mk | 11 +++++++++-- package/dcron/dcron.service | 3 ++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/package/dcron/Config.in b/package/dcron/Config.in index d7f66bdb7d..1203c42dec 100644 --- a/package/dcron/Config.in +++ b/package/dcron/Config.in @@ -21,3 +21,19 @@ config BR2_PACKAGE_DCRON with sgid bit enabled. http://www.jimpryor.net/linux/dcron.html + +if BR2_PACKAGE_DCRON + +config BR2_PACKAGE_DCRON_CRONTABS_DIR + string "crontabs directory" + default "/var/spool/cron/crontabs" + help + Directory of per-user crontabs + +config BR2_PACKAGE_DCRON_CRONSTAMPS_DIR + string "cronstamps directory" + default "/var/spool/cron/cronstamps" + help + Directory of timestamps for @freq and FREQ=... jobs + +endif diff --git a/package/dcron/S90dcron b/package/dcron/S90dcron index de21d2ca13..4527277623 100644 --- a/package/dcron/S90dcron +++ b/package/dcron/S90dcron @@ -1,9 +1,15 @@ #!/bin/sh +CRONTABS_DIR=%%CRONTABS_DIR%% +CRONSTAMPS_DIR=%%CRONSTAMPS_DIR%% + case "$1" in start) printf "Starting cron ... " - start-stop-daemon -S -q -m -b -p /var/run/dcron.pid --exec /usr/sbin/crond -- -f + mkdir -p "$CRONTABS_DIR" "$CRONSTAMPS_DIR" + start-stop-daemon -S -q -p /var/run/dcron.pid -x /usr/sbin/crond \ + -- -c "$CRONTABS_DIR" -t "$CRONSTAMPS_DIR" + pidof crond > /var/run/dcron.pid || rm -f /var/run/dcron.pid echo "done." ;; stop) diff --git a/package/dcron/dcron.mk b/package/dcron/dcron.mk index 2ee0709af5..453e3acb54 100644 --- a/package/dcron/dcron.mk +++ b/package/dcron/dcron.mk @@ -19,18 +19,25 @@ define DCRON_INSTALL_TARGET_CMDS $(INSTALL) -D -m0644 $(@D)/extra/root.crontab $(TARGET_DIR)/etc/cron.d/system # Busybox provides run-parts, so there is no need to use nor install provided run-cron $(SED) 's#/usr/sbin/run-cron#/bin/run-parts#g' $(TARGET_DIR)/etc/cron.d/system - $(INSTALL) -d -m0755 $(TARGET_DIR)/var/spool/cron/crontabs \ - $(TARGET_DIR)/etc/cron.daily $(TARGET_DIR)/etc/cron.hourly \ + $(INSTALL) -d -m750 $(TARGET_DIR)/etc/cron.daily $(TARGET_DIR)/etc/cron.hourly \ $(TARGET_DIR)/etc/cron.monthly $(TARGET_DIR)/etc/cron.weekly endef define DCRON_INSTALL_INIT_SYSV $(INSTALL) -D -m 0755 package/dcron/S90dcron $(TARGET_DIR)/etc/init.d/S90dcron + $(SED) 's#%%CRONTABS_DIR%%#$(BR2_PACKAGE_DCRON_CRONTABS_DIR)#' \ + $(TARGET_DIR)/etc/init.d/S90dcron + $(SED) 's#%%CRONSTAMPS_DIR%%#$(BR2_PACKAGE_DCRON_CRONSTAMPS_DIR)#' \ + $(TARGET_DIR)/etc/init.d/S90dcron endef define DCRON_INSTALL_INIT_SYSTEMD $(INSTALL) -D -m 644 package/dcron/dcron.service \ $(TARGET_DIR)/usr/lib/systemd/system/dcron.service + $(SED) 's#%%CRONTABS_DIR%%#$(BR2_PACKAGE_DCRON_CRONTABS_DIR)#' \ + $(TARGET_DIR)/usr/lib/systemd/system/dcron.service + $(SED) 's#%%CRONSTAMPS_DIR%%#$(BR2_PACKAGE_DCRON_CRONSTAMPS_DIR)#' \ + $(TARGET_DIR)/usr/lib/systemd/system/dcron.service mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants ln -sf ../../../../usr/lib/systemd/system/dcron.service \ $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/dcron.service diff --git a/package/dcron/dcron.service b/package/dcron/dcron.service index 924ed72205..abce25ba4f 100644 --- a/package/dcron/dcron.service +++ b/package/dcron/dcron.service @@ -3,7 +3,8 @@ Description=Task scheduler daemon After=syslog.target [Service] -ExecStart=/usr/sbin/crond -S +ExecStartPre=mkdir -p %%CRONTABS_DIR%% %%CRONSTAMPS_DIR%% +ExecStart=/usr/sbin/crond -c %%CRONTABS_DIR%% -t %%CRONSTAMPS_DIR%% Type=forking [Install]