Date: Wed, 23 Feb 2000 16:08:12 +1100 (EST) From: lodea@angmar.mel.vet.com.au To: FreeBSD-gnats-submit@freebsd.org Subject: bin/16924: tmpfile(3) should respect TMPDIR env variable Message-ID: <200002230508.QAA09369@angmar.mel.vet.com.au>
next in thread | raw e-mail | index | archive | help
>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 <stdio.h> #include <string.h> #include <paths.h> +#include <stdlib.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200002230508.QAA09369>