Date: Mon, 13 Mar 2000 15:47:08 -0500 (EST) From: adrian@ubergeeks.com To: FreeBSD-gnats-submit@freebsd.org Subject: bin/17363: crontab not cleaning up tmp files properly with catching a signal Message-ID: <200003132047.PAA81871@newbie.cho.cstone.net>
next in thread | raw e-mail | index | archive | help
>Number: 17363
>Category: bin
>Synopsis: crontab(1) leaves files in /var/cron/tabs when interrupted
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Mon Mar 13 12:50:02 PST 2000
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200003132047.PAA81871>
