From ubergeek@newbie.cho.cstone.net  Mon Mar 13 12:48:17 2000
Return-Path: <ubergeek@newbie.cho.cstone.net>
Received: from newbie.cho.cstone.net (newbie.cho.cstone.net [209.145.64.15])
	by hub.freebsd.org (Postfix) with ESMTP id BDD1437B619
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 13 Mar 2000 12:48:10 -0800 (PST)
	(envelope-from ubergeek@newbie.cho.cstone.net)
Received: (from ubergeek@localhost)
	by newbie.cho.cstone.net (8.9.3/8.9.3) id PAA81871;
	Mon, 13 Mar 2000 15:47:08 -0500 (EST)
	(envelope-from ubergeek)
Message-Id: <200003132047.PAA81871@newbie.cho.cstone.net>
Date: Mon, 13 Mar 2000 15:47:08 -0500 (EST)
From: adrian@ubergeeks.com
Sender: ubergeek@newbie.cho.cstone.net
Reply-To: adrian@ubergeeks.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: crontab not cleaning up tmp files properly with catching a signal
X-Send-Pr-Version: 3.2

>Number:         17363
>Category:       bin
>Synopsis:       [patch] crontab(1) leaves files in /var/cron/tabs when interrupted
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Mar 13 12:50:02 PST 2000
>Closed-Date:    Fri Nov 02 22:17:59 UTC 2012
>Last-Modified:  Fri Nov 02 22:17:59 UTC 2012
>Originator:     Adrian Filipi-Martin
>Release:        FreeBSD 3.4-RELEASE i386
>Organization:
Ubergeeks Consulting
>Environment:

	3.4-RELEASE

>Description:

	crontab(1) does not clean up temp files when it catches a INT, TERM or
	HUP signal.  This causes files to slowly accumilate in /var/cron/tabs.

>How-To-Repeat:

	# Run crontab reading frmo stdin and interrupt it with a signal.
	crontab -
	^C
	ls /var/cron/tabs
	tmp.81593

>Fix:
	
	Apply this patch.  It's not great, but it gets the job done with
	a minimum of fuss.

--- crontab.c.orig	Mon Mar 13 14:22:40 2000
+++ crontab.c	Mon Mar 13 15:39:03 2000
@@ -452,6 +452,17 @@
 }
 
 
+static char *_tmp_path = 0;
+void
+static remove_tmp(int sig)
+{
+	if (_tmp_path) {
+		unlink(_tmp_path);
+	}
+	exit(ERROR_EXIT);
+}
+
+
 /* returns	0	on success
  *		-1	on syntax error
  *		-2	on install error
@@ -464,6 +475,7 @@
 	entry	*e;
 	time_t	now = time(NULL);
 	char	**envp = env_init();
+	void (*f[4])();
 
 	if (envp == NULL) {
 		warnx("cannot allocate memory");
@@ -472,6 +484,13 @@
 
 	(void) sprintf(n, "tmp.%d", Pid);
 	(void) sprintf(tn, CRON_TAB(n));
+
+	/* Set up to remove the temp file if interrupted by a signal. */
+	f[0] = signal(SIGHUP, remove_tmp);
+	f[1] = signal(SIGINT, remove_tmp);
+	f[2] = signal(SIGTERM, remove_tmp);
+	_tmp_path = tn;
+
 	if (!(tmp = fopen(tn, "w+"))) {
 		warn("%s", tn);
 		return (-2);
@@ -564,6 +583,13 @@
 		unlink(tn);
 		return (-2);
 	}
+
+	/* Restore the default signal handlers. */
+	_tmp_path = 0;
+	signal(SIGHUP, f[0]);
+	signal(SIGINT, f[1]);
+	signal(SIGTERM, f[2]);
+
 	log_it(RealUser, Pid, "REPLACE", User);
 
 	poke_daemon();

>Release-Note:
>Audit-Trail:

From: Yoshihiro Ota <ota@j.email.ne.jp>
To: bug-followup@FreeBSD.org
Cc: adrian@ubergeeks.com
Subject: Re: bin/17363: crontab(1) leaves files in /var/cron/tabs when
 interrupted
Date: Thu, 24 Apr 2008 04:52:16 -0400

 This bug still exists and the patch is still appricable.
 
 Why don't we apply this to the CURRENT?
 
 Hiro
Responsible-Changed-From-To: freebsd-bugs->matteo 
Responsible-Changed-By: matteo 
Responsible-Changed-When: Mar 9 Set 2008 19:03:18 UTC 
Responsible-Changed-Why:  
I'll see what can be done with this PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=17363 
State-Changed-From-To: open->patched 
State-Changed-By: matteo 
State-Changed-When: Dom 9 Nov 2008 07:35:28 UTC 
State-Changed-Why:  
Committed to head. MFC planned in 3 days. Thanks 

http://www.freebsd.org/cgi/query-pr.cgi?pr=17363 

From: Yoshihiro Ota <ota@j.email.ne.jp>
To: bug-followup@FreeBSD.org, matteo@FreeBSD.org
Cc: adrian@ubergeeks.com
Subject: Re: bin/17363: crontab(1) leaves files in /var/cron/tabs when
 interrupted
Date: Wed, 25 Feb 2009 21:38:10 -0500

 It looks this was patched but not yet MFCed.
 
 http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.sbin/cron/crontab/crontab.c#rev1.28
 
 It seems there are other changes that was planed MFC but not done yet.
 
 Regards,
 Hiro
Responsible-Changed-From-To: matteo->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Jun 19 04:37:38 UTC 2010 
Responsible-Changed-Why:  
Reset PR assigned to inactive committer. 

Hat:	gnats-admin 

http://www.freebsd.org/cgi/query-pr.cgi?pr=17363 
State-Changed-From-To: patched->closed 
State-Changed-By: eadler 
State-Changed-When: Fri Nov 2 22:17:59 UTC 2012 
State-Changed-Why:  
MFCed/fixed by now 

http://www.freebsd.org/cgi/query-pr.cgi?pr=17363 
>Unformatted:
