[cronie/f15] fix inotify support to not leak fds (#717505)

Tomáš Mráz tmraz at fedoraproject.org
Wed Jun 29 12:49:59 UTC 2011


commit ffcc868c4cc61c277bee58c25b997be41db2ec32
Author: Tomas Mraz <tmraz at fedoraproject.org>
Date:   Wed Jun 29 14:37:04 2011 +0200

    fix inotify support to not leak fds (#717505)

 cronie-1.4.8-inotify-fix.patch |   94 ++++++++++++++++++++++++++++++++++++++++
 cronie.spec                    |    7 +++-
 2 files changed, 100 insertions(+), 1 deletions(-)
---
diff --git a/cronie-1.4.8-inotify-fix.patch b/cronie-1.4.8-inotify-fix.patch
new file mode 100644
index 0000000..edfe274
--- /dev/null
+++ b/cronie-1.4.8-inotify-fix.patch
@@ -0,0 +1,94 @@
+diff --git a/src/cron.c b/src/cron.c
+index 7dc2958..7917589 100644
+--- a/src/cron.c
++++ b/src/cron.c
+@@ -64,11 +64,19 @@ static int DisableInotify;
+ int wd[NUM_WATCHES];
+ const char *watchpaths[NUM_WATCHES] = {SPOOL_DIR, SYS_CROND_DIR, SYSCRONTAB};
+ 
++static void reset_watches(void) {
++	int i;
++
++	for (i = 0; i < sizeof (wd) / sizeof (wd[0]); ++i) {
++		wd[i] = -2;
++	}
++}
++
+ void set_cron_unwatched(int fd) {
+ 	int i;
+ 
+ 	for (i = 0; i < sizeof (wd) / sizeof (wd[0]); ++i) {
+-		if (wd[i] < 0) {
++		if (wd[i] > 0) {
+ 			inotify_rm_watch(fd, wd[i]);
+ 			wd[i] = -1;
+ 		}
+@@ -87,22 +95,21 @@ void set_cron_watched(int fd) {
+ 	for (i = 0; i < sizeof (wd) / sizeof (wd[0]); ++i) {
+ 		int w;
+ 
+-		if (open(watchpaths[i], O_RDONLY | O_NONBLOCK, 0) != -1) {
+-			w = inotify_add_watch(fd, watchpaths[i],
+-				IN_CREATE | IN_CLOSE_WRITE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO |
+-				IN_MOVED_FROM | IN_MOVE_SELF | IN_DELETE | IN_DELETE_SELF);
+-			if (w < 0) {
+-				if (wd[i] != -1) {
+-					log_it("CRON", pid, "This directory or file can't be watched",
+-						watchpaths[i], errno);
+-					log_it("CRON", pid, "INFO", "running without inotify support", 0);
+-				}
+-				inotify_enabled = 0;
+-				set_cron_unwatched(fd);
+-				return;
++		w = inotify_add_watch(fd, watchpaths[i],
++			IN_CREATE | IN_CLOSE_WRITE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO |
++			IN_MOVED_FROM | IN_MOVE_SELF | IN_DELETE | IN_DELETE_SELF);
++		if (w < 0 && errno != ENOENT) {
++			if (wd[i] != -1) {
++				log_it("CRON", pid, "This directory or file can't be watched",
++					watchpaths[i], errno);
++				log_it("CRON", pid, "INFO", "running without inotify support",
++					0);
+ 			}
+-			wd[i] = w;
++			inotify_enabled = 0;
++			set_cron_unwatched(fd);
++			return;
+ 		}
++		wd[i] = w;
+ 	}
+ 
+ 	if (!inotify_enabled) {
+@@ -120,6 +127,7 @@ static void handle_signals(cron_db * database) {
+ 		/* watches must be reinstated on reload */
+ 		if (inotify_enabled && (EnableClustering != 1)) {
+ 			set_cron_unwatched(database->ifd);
++			reset_watches();
+ 			inotify_enabled = 0;
+ 		}
+ #endif
+@@ -158,9 +166,6 @@ int main(int argc, char *argv[]) {
+ 	char *cs;
+ 	pid_t pid = getpid();
+ 	long oldGMToff;
+-#if defined WITH_INOTIFY
+-	int i;
+-#endif
+ 
+ 	ProgramName = argv[0];
+ 	MailCmd[0] = '\0';
+@@ -261,13 +266,7 @@ int main(int argc, char *argv[]) {
+ 			"", 0);
+ 	}
+ 	else {
+-		for (i = 0; i < sizeof (wd) / sizeof (wd[0]); ++i) {
+-			/* initialize to negative number other than -1
+-			 * so an eventual error is reported for the first time
+-			 */
+-			wd[i] = -2;
+-		}
+-
++		reset_watches();
+ 		database.ifd = fd = inotify_init();
+ 		fcntl(fd, F_SETFD, FD_CLOEXEC);
+ 		if (fd < 0)
diff --git a/cronie.spec b/cronie.spec
index c815539..e9cdf13 100644
--- a/cronie.spec
+++ b/cronie.spec
@@ -7,12 +7,13 @@
 Summary:   Cron daemon for executing programs at set times
 Name:      cronie
 Version:   1.4.8
-Release:   1%{?dist}
+Release:   2%{?dist}
 License:   MIT and BSD and ISC and GPLv2
 Group:     System Environment/Base
 URL:       https://fedorahosted.org/cronie
 Source0:   https://fedorahosted.org/releases/c/r/cronie/%{name}-%{version}.tar.gz
 Source1:   cronie.systemd
+Patch1:    cronie-1.4.8-inotify-fix.patch
 
 Requires:  syslog, bash >= 2.0
 Conflicts: sysklogd < 1.4.1
@@ -80,6 +81,7 @@ Old style of {hourly,daily,weekly,monthly}.jobs without anacron. No features.
 
 %prep
 %setup -q
+%patch1 -p1 -b .inotify
 
 %build
 %configure \
@@ -244,6 +246,9 @@ service crond condrestart > /dev/null 2>&1 ||:
 %attr(0644,root,root) %{_sysconfdir}/cron.d/dailyjobs
 
 %changelog
+* Wed Jun 29 2011 Tomáš Mráz <tmraz at redhat.com> - 1.4.8-2
+- fix inotify support to not leak fds (#717505)
+
 * Tue Jun 28 2011 Marcela Mašláňová <mmaslano at redhat.com> - 1.4.8-1
 - minor bugfix release 1.4.8
 


More information about the scm-commits mailing list