From 2315616dba2bef939ede6a5476c5dd24586c83a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Poho=C5=99elsk=C3=BD?= Date: Thu, 30 Nov 2023 14:39:55 +0100 Subject: [PATCH] Add `optimization_to_close_fds.patch` --- .cronie.metadata | 1 + cronie.spec | 9 +++++- optimization_to_close_fds.patch | 52 +++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 .cronie.metadata create mode 100644 optimization_to_close_fds.patch diff --git a/.cronie.metadata b/.cronie.metadata new file mode 100644 index 0000000..13cb396 --- /dev/null +++ b/.cronie.metadata @@ -0,0 +1 @@ +0275d7c3b5376664f9e2c50b8c8cc338408b08b2 cronie-1.5.7.tar.gz diff --git a/cronie.spec b/cronie.spec index 9a2cf3c..1421368 100644 --- a/cronie.spec +++ b/cronie.spec @@ -6,7 +6,7 @@ Summary: Cron daemon for executing programs at set times Name: cronie Version: 1.5.7 -Release: 10%{?dist} +Release: 11%{?dist} License: MIT and BSD and ISC and GPLv2+ URL: https://github.com/cronie-crond/cronie Source0: https://github.com/cronie-crond/cronie/releases/download/cronie-%{version}/cronie-%{version}.tar.gz @@ -20,6 +20,9 @@ Patch: 0005-Fix-regression-in-handling-1-5-crontab-entries.patch # Add support for `-n` option in crontab entries # https://github.com/cronie-crond/cronie/commit/ce7d5bf0a43d147f8502e6424cd523b56adf5599 Patch: n_option.patch +# Optimization to close fds from /proc/self/fd in case of high nofile limit after fork +# https://github.com/cronie-crond/cronie/commit/e3682c7135b9176b60d226c60ee4e78cf1ab711b +Patch: optimization_to_close_fds.patch Requires: dailyjobs @@ -214,6 +217,10 @@ exit 0 %attr(0644,root,root) %config(noreplace) %{_sysconfdir}/cron.d/dailyjobs %changelog +* Thu Nov 30 2023 Ondřej Pohořelský - 1.5.7-11 +- Add `optimization_to_close_fds.patch` +- Resolves: RHEL-17710 + * Thu Nov 16 2023 Jan Houška - 1.5.7-10 - Related: RHEL-5372 - remove obsolete tests. diff --git a/optimization_to_close_fds.patch b/optimization_to_close_fds.patch new file mode 100644 index 0000000..b90905e --- /dev/null +++ b/optimization_to_close_fds.patch @@ -0,0 +1,52 @@ +From e3682c7135b9176b60d226c60ee4e78cf1ab711b Mon Sep 17 00:00:00 2001 +From: bwelterl +Date: Thu, 7 Sep 2023 10:05:36 +0200 +Subject: [PATCH] Optimization to close fds from /proc/self/fd in case of high + nofile limit after fork + +--- + src/do_command.c | 23 ++++++++++++++++++++--- + 1 file changed, 20 insertions(+), 3 deletions(-) + +diff --git a/src/do_command.c b/src/do_command.c +index 500f1b0..665e1f0 100644 +--- a/src/do_command.c ++++ b/src/do_command.c +@@ -30,6 +30,7 @@ + #include + #include + #include ++#include + + #include "externs.h" + #include "funcs.h" +@@ -264,10 +265,26 @@ static int child_process(entry * e, char **jobenv) { + { + char *shell = env_get("SHELL", jobenv); + int fd, fdmax = TMIN(getdtablesize(), MAX_CLOSE_FD); ++ DIR *dir; ++ struct dirent *dent; + +- /* close all unwanted open file descriptors */ +- for(fd = STDERR + 1; fd < fdmax; fd++) { +- close(fd); ++ /* ++ * if /proc is mounted, we can optimize what fd can be closed, ++ * but if it isn't available, fall back to the previous behavior. ++ */ ++ if ((dir = opendir("/proc/self/fd")) != NULL) { ++ while ((dent = readdir(dir)) != NULL) { ++ if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) ++ continue; ++ fd = atoi(dent->d_name); ++ if (fd > STDERR_FILENO) ++ close(fd); ++ } ++ } else { ++ /* close all unwanted open file descriptors */ ++ for (fd = STDERR + 1; fd < fdmax; fd++) { ++ close(fd); ++ } + } + + #if DEBUGGING