[Pkg-cron-devel] [SCM] Git repository for pkg-cron branch, sf3, updated. debian/3.0pl1-109-20-gde88d23

Christian Kastner debian at kvr.at
Sat Sep 24 22:26:50 UTC 2011


The following commit has been merged in the sf3 branch:
commit d79929af497296c337152335fd03f558ce935f9d
Author: Christian Kastner <debian at kvr.at>
Date:   Sun Sep 25 00:11:50 2011 +0200

    Recover from orphans
    
    Instead of permanently failing ORPHANed crontabs, scan for adoption everytime
    cron wakes up. Fix taken from cronie.

diff --git a/debian/patches/features/recover-from-orphans b/debian/patches/features/recover-from-orphans
new file mode 100644
index 0000000..9bb8e7f
--- /dev/null
+++ b/debian/patches/features/recover-from-orphans
@@ -0,0 +1,159 @@
+Origin: http://git.fedorahosted.org/git/?p=cronie.git;a=commit;h=8b407876f276f96914111bd9954f21f627db7b11
+Subject: Check orphaned crontabs for adoption
+
+Change the default behaviour of permanently ignoring crontabs with an invalid
+owner (ie, getpwnam() fails) to checking for adoption every time cron wakes up.
+This makes more sense as nowadays such failures are often traced back to
+temporary issues, especially in the context of LDAP lookups and name-caching
+daemons.
+
+Bug-Debian: http://bugs.debian.org/634926
+Bug-Ubuntu: https://bugs.launchpad.net/bugs/27520
+
+Acked-By: Christian Kastner <debian at kvr.at>
+Last-Update: 2011-09-24
+
+Index: sf3/cron.c
+===================================================================
+--- sf3.orig/cron.c	2011-09-24 23:15:22.328004759 +0200
++++ sf3/cron.c	2011-09-24 23:25:34.252004765 +0200
+@@ -173,6 +173,7 @@
+ 		} while (clockTime == timeRunning);
+ 		timeRunning = clockTime;
+ 
++		check_orphans(&database);
+ 		load_database(&database);
+ 
+ 		/*
+Index: sf3/cron.h
+===================================================================
+--- sf3.orig/cron.h	2011-09-24 23:15:22.328004759 +0200
++++ sf3/cron.h	2011-09-24 23:25:34.252004765 +0200
+@@ -237,7 +237,8 @@
+ 		acquire_daemonlock __P((int)),
+ 		skip_comments __P((FILE *)),
+ 		log_it __P((char *, int, char *, char *)),
+-		log_close __P((void));
++		log_close __P((void)),
++		check_orphans __P((cron_db *));
+ 
+ int		job_runqueue __P((void)),
+ 		set_debug_flags __P((char *)),
+Index: sf3/database.c
+===================================================================
+--- sf3.orig/database.c	2011-09-24 23:15:03.456004765 +0200
++++ sf3/database.c	2011-09-24 23:25:34.252004765 +0200
+@@ -56,6 +56,9 @@
+ 
+ void force_rescan_user(cron_db *old_db, cron_db *new_db, const char *fname, time_t old_mtime);
+ 
++static void add_orphan(const char *uname, const char *fname, const char *tabname);
++static void free_orphan(orphan *o);
++
+ void
+ load_database(old_db)
+ 	cron_db		*old_db;
+@@ -328,7 +331,7 @@
+ {
+ 	struct passwd	*pw = NULL;
+ 	int		crontab_fd = OK - 1;
+-	user		*u;
++	user		*u = NULL;
+ 
+ #ifdef DEBIAN
+ 	/* If the name begins with *system*, don't worry about password -
+@@ -342,6 +345,7 @@
+ 		if (strncmp(fname, "tmp.", 4)) {
+ 			/* don't log these temporary files */
+ 			log_it(fname, getpid(), "ORPHAN", "no passwd entry");
++			add_orphan(uname, fname, tabname);
+ 		}
+ 		goto next_crontab;
+ 	}
+@@ -463,7 +467,10 @@
+          * 1), but this is all we've got.
+          */
+ 	Debug(DLOAD, ("\t%s:", fname))
+-	u = find_user(old_db, fname);
++
++	if (old_db != NULL)
++		u = find_user(old_db, fname);
++
+ 	if (u != NULL) {
+ 		/* if crontab has not changed since we last read it
+ 		 * in, then we can just use our existing entry.
+@@ -601,3 +608,74 @@
+         Debug(DLOAD, ("\t%s: [added empty placeholder to force rescan]\n", fname))
+ 	link_user(new_db, u);
+ }
++
++/* This fix was taken from Fedora cronie */
++static orphan *orphans;
++
++static void
++free_orphan(orphan *o) {
++        free(o->tabname);
++        free(o->fname);
++        free(o->uname);
++        free(o);
++}
++
++void
++check_orphans(cron_db *db) {
++        orphan *prev_orphan = NULL;
++        orphan *o = orphans;
++	struct stat statbuf;
++
++        while (o != NULL) {
++                if (getpwnam(o->uname) != NULL) {
++                        orphan *next = o->next;
++
++                        if (prev_orphan == NULL) {
++                                orphans = next;
++                        } else {
++                                prev_orphan->next = next;
++                        }   
++
++                        process_crontab(o->uname, o->fname, o->tabname,
++                                &statbuf, db, NULL);
++
++                        /* process_crontab could have added a new orphan */
++                        if (prev_orphan == NULL && orphans != next) {
++                                prev_orphan = orphans;
++                        }   
++                        free_orphan(o);
++                        o = next;
++                } else {
++                        prev_orphan = o;
++                        o = o->next;
++                }   
++        }   
++}
++
++static void
++add_orphan(const char *uname, const char *fname, const char *tabname) {
++        orphan *o; 
++
++        o = calloc(1, sizeof(*o));
++        if (o == NULL)
++                return;
++
++        if (uname)
++                if ((o->uname=strdup(uname)) == NULL)
++                        goto cleanup;
++
++        if (fname)
++                if ((o->fname=strdup(fname)) == NULL)
++                        goto cleanup;
++
++        if (tabname)
++                if ((o->tabname=strdup(tabname)) == NULL)
++                        goto cleanup;
++
++        o->next = orphans;
++        orphans = o;
++        return;
++
++cleanup:
++        free_orphan(o);
++}
diff --git a/debian/patches/series b/debian/patches/series
index 81b0a4f..055f76f 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -55,6 +55,7 @@ features/dont-die-on-missing-dirs
 features/crontab-refuse-eof-without-nl
 features/recover-from-errors
 features/selective-logging
+features/recover-from-orphans
 features/backport-envparser
 other/changes-to-upstream-README
 other/changes-to-cron-8

-- 
Git repository for pkg-cron



More information about the Pkg-cron-devel mailing list