From owner-freebsd-bugs Tue Feb 22 21:10: 7 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 EE0FF37B89C for ; Tue, 22 Feb 2000 21:10:01 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id VAA57205; Tue, 22 Feb 2000 21:10:01 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from angmar.mel.vet.com.au (angmar.mel.vet.com.au [203.103.154.62]) by hub.freebsd.org (Postfix) with ESMTP id 4EF3737B89C for ; Tue, 22 Feb 2000 21:08:17 -0800 (PST) (envelope-from lodea@angmar.mel.vet.com.au) Received: (from lodea@localhost) by angmar.mel.vet.com.au (8.9.3/8.9.3) id QAA09369; Wed, 23 Feb 2000 16:08:12 +1100 (EST) Message-Id: <200002230508.QAA09369@angmar.mel.vet.com.au> Date: Wed, 23 Feb 2000 16:08:12 +1100 (EST) From: lodea@angmar.mel.vet.com.au Reply-To: lodea@vet.com.au To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/16924: tmpfile(3) should respect TMPDIR env variable Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 16924 >Category: bin >Synopsis: tmpfile(3) ignores TMPDIR and always uses /tmp >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Feb 22 21:10:01 PST 2000 >Closed-Date: >Last-Modified: >Originator: Lachlan O'Dea >Release: FreeBSD 3.3-STABLE i386 >Organization: Computer Associates >Environment: FreeBSD angmar.mel.vet.com.au 3.3-STABLE FreeBSD 3.3-STABLE #4: Wed Dec 1 20:06:43 EST 1999 lodea@angmar.mel.vet.com.au:/usr/src/sys/compile/ANGMAR i386 >Description: Others may disagree, but I think it would be nice if the tmpfile(3) function would use the TMPDIR environment variable if it is present. Currently it is hard-coded to use /tmp. My reason for doing this is that the Cyrus deliver program uses tmpfile to store the email that it is delivering. I don't really want to make my MFS /tmp big enough to hold the largest email messages I expect to receive. I can't see any problems caused by this change. >How-To-Repeat: Set TMPDIR to /var/tmp. Use tmpfile(3) to create a temporary file, then write 50 Mb of data to it. Chances are pretty good your /tmp will run out of space. >Fix: Here's a patch which might be satisfactory. If TMPDIR is not set, it reverts to current behaviour. Please let me know if you like the idea but not the patch. Index: tmpfile.c =================================================================== RCS file: /home/ncvs/src/lib/libc/stdio/tmpfile.c,v retrieving revision 1.4 diff -u -r1.4 tmpfile.c --- tmpfile.c 2000/01/27 23:06:46 1.4 +++ tmpfile.c 2000/02/23 04:26:46 @@ -47,6 +47,7 @@ #include #include #include +#include FILE * tmpfile() @@ -55,10 +56,24 @@ FILE *fp; int fd, sverrno; #define TRAILER "tmp.XXXXXX" - char buf[sizeof(_PATH_TMP) + sizeof(TRAILER)]; + char *buf; + char *envtmpdir; + int envtmpdirlen; - (void)memcpy(buf, _PATH_TMP, sizeof(_PATH_TMP) - 1); - (void)memcpy(buf + sizeof(_PATH_TMP) - 1, TRAILER, sizeof(TRAILER)); + if ((envtmpdir = getenv("TMPDIR")) != NULL) + { + envtmpdirlen = strlen(envtmpdir); + buf = malloc(envtmpdirlen + 1 + sizeof(TRAILER)); + (void)memcpy(buf, envtmpdir, envtmpdirlen); + buf[envtmpdirlen] = '/'; + (void)memcpy(buf + envtmpdirlen + 1, TRAILER, sizeof(TRAILER)); + } + else + { + buf = malloc(sizeof(_PATH_TMP) + sizeof(TRAILER) - 1); + (void)memcpy(buf, _PATH_TMP, sizeof(_PATH_TMP) - 1); + (void)memcpy(buf + sizeof(_PATH_TMP) - 1, TRAILER, sizeof(TRAILER)); + } sigfillset(&set); (void)sigprocmask(SIG_BLOCK, &set, &oset); @@ -66,6 +81,8 @@ fd = mkstemp(buf); if (fd != -1) (void)unlink(buf); + + free(buf); (void)sigprocmask(SIG_SETMASK, &oset, NULL); >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message