From owner-freebsd-bugs Mon Mar 13 12:50: 6 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 4030A37B62F for ; Mon, 13 Mar 2000 12:50:03 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id MAA54705; Mon, 13 Mar 2000 12:50:03 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from newbie.cho.cstone.net (newbie.cho.cstone.net [209.145.64.15]) by hub.freebsd.org (Postfix) with ESMTP id BDD1437B619 for ; 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 Reply-To: adrian@ubergeeks.com To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/17363: crontab not cleaning up tmp files properly with catching a signal Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >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