From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id wPX+CWlGCWM1YgEAbAwnHQ (envelope-from ) for ; Sat, 27 Aug 2022 00:17:13 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id WL4RCmlGCWMNIgAA9RJhRA (envelope-from ) for ; Sat, 27 Aug 2022 00:17:13 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id ABC1018AEA for ; Sat, 27 Aug 2022 00:17:12 +0200 (CEST) Received: from localhost ([::1]:34774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oRhdX-0004rX-Da for larch@yhetil.org; Fri, 26 Aug 2022 18:17:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRhdO-0004rK-Jt for guix-patches@gnu.org; Fri, 26 Aug 2022 18:17:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36777) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oRhdO-0008HB-B5 for guix-patches@gnu.org; Fri, 26 Aug 2022 18:17:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oRhdO-0005bO-5T for guix-patches@gnu.org; Fri, 26 Aug 2022 18:17:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#57387] [PATCH] gnu: Add restartd. References: <87czcp8wet.fsf@ngraves.fr> In-Reply-To: <87czcp8wet.fsf@ngraves.fr> Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 26 Aug 2022 22:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57387 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 57387@debbugs.gnu.org Received: via spool by 57387-submit@debbugs.gnu.org id=B57387.166155221321518 (code B ref 57387); Fri, 26 Aug 2022 22:17:02 +0000 Received: (at 57387) by debbugs.gnu.org; 26 Aug 2022 22:16:53 +0000 Received: from localhost ([127.0.0.1]:54759 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oRhdE-0005ay-J9 for submit@debbugs.gnu.org; Fri, 26 Aug 2022 18:16:53 -0400 Received: from 4.mo581.mail-out.ovh.net ([178.32.122.254]:59287) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oRhd7-0005ah-DN for 57387@debbugs.gnu.org; Fri, 26 Aug 2022 18:16:50 -0400 Received: from player788.ha.ovh.net (unknown [10.111.172.29]) by mo581.mail-out.ovh.net (Postfix) with ESMTP id 54BF725C1E for <57387@debbugs.gnu.org>; Fri, 26 Aug 2022 22:16:43 +0000 (UTC) Received: from ngraves.fr (met42-h01-213-44-161-47.dsl.sta.abo.bbox.fr [213.44.161.47]) (Authenticated sender: ngraves@ngraves.fr) by player788.ha.ovh.net (Postfix) with ESMTPSA id 5D1222DE52787 for <57387@debbugs.gnu.org>; Fri, 26 Aug 2022 22:16:42 +0000 (UTC) X-OVh-ClientIp: 213.44.161.47 Date: Sat, 27 Aug 2022 00:16:41 +0200 Message-ID: <87a67qsl9y.fsf@ngraves.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 5064860734796784325 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvfedrvdejiedgtdelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvffufffkgggtgfesthhqredttddtjeenucfhrhhomheppfhitgholhgrshcuifhrrghvvghsuceonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqeenucggtffrrghtthgvrhhnpeevhffflefhhfffvedtkedvudfggfeifeeljedtueeutdeiieefueejieeuhffgieenucffohhmrghinhepghhithhhuhgsrdgtohhmpdhlrghunhgthhhprggurdhnvghtpdguvggsihgrnhdrohhrghenucfkpheptddrtddrtddrtddpvddufedrgeegrdduiedurdegjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhhtpdhhvghlohepphhlrgihvghrjeekkedrhhgrrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehnghhrrghvvghssehnghhrrghvvghsrdhfrhdpnhgspghrtghpthhtohepuddprhgtphhtthhopeehjeefkeejseguvggssghughhsrdhgnhhurdhorhhgpdfovfetjfhoshhtpehmohehkedu X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches From: Nicolas Graves via Guix-patches via X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1661552232; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=8ma+fGEx5YWDnrkAA7iOIeO4Zp53MCGAW2ZnJCcFZ64=; b=U6Qu1VK47ifmMuttyL6/pqSB6jWYP0FCCYaolQnzr1S7rDjrkLS+yZwoRGdY+spOzwQdNr cGLkpNI6a5XA2Cv9ZkMQ/wQTXYGeU98rAdrfBq9qDF1atwZqTp7H9cGwFlaMTJ3zRP4rgo BvF1aTLBLF5N5kou/sQYVbUqXqRQts7fkme/DJZcZyfC1A36vfGfwK+rtEaWb7F+t4BIUY BQKyAvgkpYzwDgFEppg/PufhnDYdqPEA5jV4VY2BbiI0/nxzAqmC1wRYjDcd6k3IkjxGJL QNBGXLhWuVu8ww3RI9GxJf0LbH4aCKcBmhDNucUz6kzY7w11+wyYxDzSOSBvPg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1661552232; a=rsa-sha256; cv=none; b=OaTtUCfNU5/gGp6H7aJj7xpOo+nkwQQptS6jxMsUzT7wc7wLyjSvjlcm2h581yTP5PAoFb pVaSgLwe9uIxVo0qTSVC5ErAkfICa//+3ljSZNBs6Sla83nKHAvzEA8eQX5x6mlceCr+7T GKc4QDyEFbaU8sJOmtwkBBJcVjG3aPrKCYlsRLotLi7z31ETvHXUdEiTHBZBsgZpkTLjSk yEF8nI9qeyUeQhQZqNTW3+lnZ9SHZ52oYDJo/0GV4tsuZtxD3wV28JxsXyHJ87zllQ87dd ggjk7O6yfnKqbd6FjUsD3IvsfRzfMA/U91sy00iKPtSB/BIHRVgqAQ7raJHAYA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.31 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: ABC1018AEA X-Spam-Score: -3.31 X-Migadu-Scanner: scn0.migadu.com X-TUID: mcM/YJcrpJBZ * gnu/packages/admin.scm (restartd): New variable. --- gnu/packages/admin.scm | 54 ++++ ...td-add-error-handling-for-robustness.patch | 242 ++++++++++++++++++ .../patches/restartd-fix-compilation.patch | 53 ++++ 3 files changed, 349 insertions(+) create mode 100644 gnu/packages/patches/restartd-add-error-handling-for-ro= bustness.patch create mode 100644 gnu/packages/patches/restartd-fix-compilation.patch diff --git a/gnu/packages/admin.scm b/gnu/packages/admin.scm index a4c5189222..57de594bee 100644 --- a/gnu/packages/admin.scm +++ b/gnu/packages/admin.scm @@ -51,6 +51,7 @@ ;;; Copyright =C2=A9 2021 Artyom V. Poptsov ;;; Copyright =C2=A9 2022 Wamm K. D. ;;; Copyright =C2=A9 2022 Roman Riabenko +;;; Copyright =C2=A9 2022 Nicolas Graves ;;; ;;; This file is part of GNU Guix. ;;; @@ -5455,6 +5456,59 @@ (define-public fail2ban mechanisms if you really want to protect services.") (license license:gpl2+))) +(define-public restartd + (let* ((commit "7044125ac55056f2663536f7137170edf92ebd75") + ;; Version is 0.2.4 in the version file in the repo + ;; but not in github tags. + ;; It is released as 0.2.3-1.1 for other distributions. + ;; Probably because of the lack of activity upstream. + (revision "1")) + (package + (name "restartd") + (version (git-version "0.2.3" revision commit)) + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/ajraymond/restartd") + (commit commit))) + (file-name (git-file-name name version)) + (sha256 + (base32 + "1m1np00b4zvvwx63gzysbi38i5vj1jsjvh2s0p9czl6dzyz582z0")) + (patches + (search-patches + "restartd-fix-compilation.patch" + "restartd-add-error-handling-for-robustness.patch")))) + (build-system gnu-build-system) + (arguments + (list + #:tests? #f ; no tests + #:make-flags + #~(list (string-append "CC=3D" #$(cc-for-target))) + #:phases + #~(modify-phases %standard-phases + (delete 'configure) + (replace 'install + (lambda _ + (install-file "restartd.conf" (string-append #$output "/et= c")) + (install-file "restartd" (string-append #$output "/sbin")) + (install-file "restartd.8" + (string-append #$output "/share/man/man8")) + (mkdir-p (string-append #$output "/share/man/fr/man8")) + (copy-file + "restartd.fr.8" + (string-append #$output "/share/man/fr/man8/restartd.8"))= ))))) + (home-page "https://launchpad.net/debian/+source/restartd") + (synopsis "Daemon for restarting processes") + (description "This package provides a daemon for checking running an= d not +running processes. It reads the /proc directory every n seconds and does a +POSIX regexp on the process names. The daemon runs an user-provided script +when it detects a program in the running processes, or an alternate script= if +it doesn't detect the program. The daemon can only be called by the root +user, but can use @code{sudo -u user} in the process called if needed.") + (license license:gpl2+)))) + (define-public rex (package (name "rex") diff --git a/gnu/packages/patches/restartd-add-error-handling-for-robustnes= s.patch b/gnu/packages/patches/restartd-add-error-handling-for-robustness.p= atch new file mode 100644 index 0000000000..33f5f06555 --- /dev/null +++ b/gnu/packages/patches/restartd-add-error-handling-for-robustness.patch @@ -0,0 +1,242 @@ +From ec606eb15091ff8ffa672500413128c29814f8ad Mon Sep 17 00:00:00 2001 +From: Maxime Devos , Yin Kangkai +Date: Thu, 25 Aug 2022 14:29:25 +0200 +Subject: [PATCH] Add some error handling for robustness. + +This patch is a merge of two pull requests for the restartd project. + +Maxime Devos +https://github.com/ajraymond/restartd/pull/8 + +This makes the code a little more robust. What if /var/run does not +exist, or we do not have permission to open +/var/run/restartd.pid (EPERM?) due to SELinux misconfiguration? + +Yin Kangkai +https://github.com/ajraymond/restartd/pull/6 + +This patch also avoids segmentation fault when run from non-root user. + +--- + config.c | 19 ++++++++++---- + config.h | 2 ++ + restartd.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++-------- + 3 files changed, 79 insertions(+), 15 deletions(-) + +diff --git a/config.c b/config.c +index f307b8a..94907e3 100644 +--- a/config.c ++++ b/config.c +@@ -57,7 +57,11 @@ int read_config(void) + config_process_number =3D 0; + + line1 =3D (char *) malloc(MAX_LINE_LENGTH); ++ if (!line1) ++ oom_failure(); + line2 =3D (char *) malloc(MAX_LINE_LENGTH); ++ if (!line2) ++ oom_failure(); + + if ((config_fd =3D fopen(config_file, "rt")) =3D=3D NULL) { + fprintf(stderr, "Error at opening config file: %s\n", config_file= ); +@@ -155,11 +159,16 @@ void dump_config(void) { + int i; + + for(i=3D0; i + * Copyright (C) 2006 Aur=C3=A9lien G=C3=89R=C3=94ME ++ * Copyright (C) 2022 Maxime Devos + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License +@@ -43,5 +44,6 @@ typedef struct config_process_type { + + int read_config(/* char *config_file */); + void dump_config(void); ++void oom_failure(void); + + #endif /* RESTARTD_CONFIG_H */ +diff --git a/restartd.c b/restartd.c +index 2aa720c..df0a6eb 100644 +--- a/restartd.c ++++ b/restartd.c +@@ -1,6 +1,8 @@ + /* restartd - Process checker and/or restarter daemon + * Copyright (C) 2000-2002 Tibor Koleszar + * Copyright (C) 2006 Aur=C3=A9lien G=C3=89R=C3=94ME ++ * Copyright (C) 2016 Yin Kangkai ++ * Copyright (C) 2022 Maxime Devos + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License +@@ -52,6 +54,17 @@ void got_signal(int sig) + } + } + ++/* Ignoring out-of-memory failures is risky on systems without virtual me= mory ++ where additionally at address 0 there is actually something important ++ mapped. Additionally, while often on Linux the OOM killer will kill pr= ocesses ++ where an OOM happens, this is not always the case and there exist othe= r systems ++ without an OOM killer (e.g. the Hurd). */ ++void oom_failure() ++{ ++ syslog(LOG_ERR, "Failed to allocate memory. Exiting."); ++ exit(1); ++} ++ + int main(int argc, char *argv[]) + { + DIR *procdir_id; +@@ -75,15 +88,21 @@ int main(int argc, char *argv[]) + + /* Options */ + config_file =3D strdup(DEFAULT_CONFIG); ++ if (!config_file) ++ oom_failure(); ++ + list_only =3D 0; + + for(i =3D 0; i < argc; i++) { + if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--config")) { + config_file =3D strdup(argv[i + 1]); ++ if (!config_file) ++ oom_failure(); + } + if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) { + printf("restard %s - Copyright 2000-2002 Tibor Koleszar \n" +- " Copyright 2006 Aur=C3=A9lien G=C3=89R= =C3=94ME \n", ++ " Copyright 2006 Aur=C3=A9lien G=C3=89R= =C3=94ME \n" ++ " Copyright 2022 Maxime Devos \n", + VERSION); + exit(0); + } +@@ -118,10 +137,13 @@ int main(int argc, char *argv[]) + " -i : the check interval in second\n" + " -l : list configuration options\n" + " -h : help\n\n", VERSION); ++ exit(0); + } + } + + config_process =3D malloc(sizeof(struct config_process_type) * 128); ++ if (!config_process) ++ oom_failure(); + + read_config(); + if (list_only) { +@@ -133,9 +155,17 @@ int main(int argc, char *argv[]) + config_process_number); + + procdir_dirent =3D malloc(sizeof(struct dirent)); ++ if (!procdir_dirent) ++ oom_failure(); + proc_cmdline_str =3D (char *) malloc(1024); ++ if (!proc_cmdline_str) ++ oom_failure(); + proc_cmdline_name =3D (char *) malloc(1024); ++ if (!proc_cmdline_name) ++ oom_failure(); + regc =3D malloc(1024); ++ if (!regc) ++ oom_failure(); + + /* Catch signals */ + signal(SIGTERM, got_signal); +@@ -187,8 +217,18 @@ int main(int argc, char *argv[]) + } + + out_proc =3D fopen("/var/run/restartd.pid", "wt"); +- fprintf(out_proc, "%d", getpid()); +- fclose(out_proc); ++ if (!out_proc) { ++ syslog(LOG_ERR, "Failed to open /var/run/restartd.pid"); ++ return -1; ++ } ++ if (fprintf(out_proc, "%d", getpid()) < 0) { ++ syslog(LOG_ERR, "Failed to write to /var/run/restartd.pid. Exiting."); ++ return -1; ++ } ++ if (fclose(out_proc) < 0) { /* errors can happen when flushing th= e buffer */ ++ syslog(LOG_ERR, "Failed to write to /var/run/restartd.pid. Exiting."); ++ return -1; ++ } + + while(1) { + if ((procdir_id =3D opendir("/proc")) =3D=3D NULL) { +@@ -237,16 +277,23 @@ int main(int argc, char *argv[]) + now =3D time(NULL); + + out_proc =3D fopen("/var/run/restartd", "wt"); ++ if (!out_proc) { ++ syslog(LOG_ERR, "Failed to open /var/run/restartd"); ++ return -1; ++ } + +- fprintf(out_proc, "%s\n", ctime(&now)); ++ if (fprintf(out_proc, "%s\n", ctime(&now)) < 0) { ++ syslog(LOG_ERR, "Failed to write to /var/run/restartd. Exiting."); ++ return -1; ++ } + + for(i=3D0; i 0) { + if (strlen(config_process[i].running) > 0) { + strcpy(config_process[i].status, "running"); +- syslog(LOG_INFO, "%s is running, executing '%s'", ++ /* syslog(LOG_INFO, "%s is running, executing '%s'= ", + config_process[i].name, +- config_process[i].running); ++ config_process[i].running); */ + system(config_process[i].running); + } else { + strcpy(config_process[i].status, "running"); +@@ -267,12 +314,18 @@ int main(int argc, char *argv[]) + strcpy(config_process[i].status, "not running"); + } + +- fprintf(out_proc, "%-12s %-12s %s\n", +- config_process[i].name, config_process[i].status, +- config_process[i].processes); ++ if (fprintf(out_proc, "%-12s %-12s %s\n", ++ config_process[i].name, config_process[i].status, ++ config_process[i].processes) < 0) { ++ syslog(LOG_ERR, "Failed to write to /var/run/restartd. Exiting."); ++ return -1; ++ } + } + +- fclose(out_proc); ++ if (fclose(out_proc) < 0) { ++ syslog(LOG_ERR, "Failed to write to /var/run/restartd.pid. Exiting= ."); ++ return -1; ++ } + + sleep(check_interval); + } +-- +2.37.2 + diff --git a/gnu/packages/patches/restartd-fix-compilation.patch b/gnu/pack= ages/patches/restartd-fix-compilation.patch new file mode 100644 index 0000000000..a380205675 --- /dev/null +++ b/gnu/packages/patches/restartd-fix-compilation.patch @@ -0,0 +1,53 @@ +From 84edc2042bb0a82e65bd4d165b706519886b4075 Mon Sep 17 00:00:00 2001 +From: Sudip Mukherjee +Date: Mon, 10 Aug 2020 19:39:30 +0100 +Subject: [PATCH] Fix build with gcc-10 + +Bug: https://bugs.debian.org/957761 +Signed-off-by: Sudip Mukherjee +--- + config.h | 12 ++++++------ + restartd.c | 7 +++++++ + 2 files changed, 13 insertions(+), 6 deletions(-) + +diff --git a/config.h b/config.h +index fabaa2b..a79b28e 100644 +--- a/config.h ++++ b/config.h +@@ -25,12 +25,12 @@ + + #define DEFAULT_CONFIG "/etc/restartd.conf" + +-int debug; +-int config_process_number; +-int check_interval; +-int foreground; +-struct config_process_type *config_process; +-char *config_file; ++extern int debug; ++extern int config_process_number; ++extern int check_interval; ++extern int foreground; ++extern struct config_process_type *config_process; ++extern char *config_file; + + typedef struct config_process_type { + char name[64]; +diff --git a/restartd.c b/restartd.c +index 2aa720c..617b298 100644 +--- a/restartd.c ++++ b/restartd.c +@@ -35,6 +35,13 @@ + + #include "config.h" + ++int debug; ++int config_process_number; ++int check_interval; ++int foreground; ++struct config_process_type *config_process; ++char *config_file; ++ + /* SIGTERM & SIGHUP handler */ + void got_signal(int sig) + { -- 2.37.2 -- Best regards, Nicolas Graves