bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Small TMPDIR fixes, take 2


From: Mark Haigh
Subject: [PATCH] Small TMPDIR fixes, take 2
Date: Sun, 4 Aug 2002 19:17:57 -0700
User-agent: KMail/1.4.1

Sorry about that, folks.  That one got munched by a webmail app.  Hopefully 
this will make it through unscathed...

From: Mark Haigh (mfhaigh@DIRECTVInternet.com)
To: bug-bash@gnu.org
Subject: [PATCH] Small TMPDIR fixes.

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DSHELL -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib  -g -O2
uname output: Linux markh-laptop 2.4.19-gentoo-r7 #1 SMP Mon Jun 24 08:29:19 
PDT 2002 i686 GenuineIntel
Machine Type: i686-pc-linux-gnu

Bash Version: 2.05b
Patch Level: 0
Release Status: release

Description:
        Bash still uses the system tmp directory rather than the one specified
        in TMPDIR in several situations.  When there's no system tmp dir in
        the usual places, or you're using per-user tmp directories, this can
        cause problems.

Repeat-By:
        In Linux:
        $ export TMPDIR=/home/mark/tmp
        $ sleep 1234 << EOF &
        > EOF
        [1] 13170
        su -c lsof -p 13170 | grep /tmp
        sleep   13170 mark    0r   REG    3,3      25 325386 
/tmp/sh-thd-1028495363 (deleted)

        This should be /home/mark/tmp/sh-thd-1028495363.

        In Cygwin, there's also _cygwin_check_tmp () to muck things up.

Fix:
        Remove the MT_USETMPDIR flag, and always use TMPDIR by default.
        Fall back to the current behavior if TMPDIR is not set.  This has
        been tested on Linux and Cygwin.  This patch applies cleanly to
        bash-2.05b.0(1)-release.  I've tried to respect the style and 
        intent of the code being patched.  Let me know if there's something
        you would like changed with it, and I'd be happy to do it in order
        to get this included.  Thanks.

        Mark Haigh
        mfhaigh@DIRECTVInternet.com
        

--- externs.h.orig      Sun Aug  4 16:17:25 2002
+++ externs.h   Sun Aug  4 16:19:54 2002
@@ -315,9 +315,8 @@
 extern void print_timeval ();
 
 /* declarations for functions defined in lib/sh/tmpfile.c */
-#define MT_USETMPDIR           0x0001
-#define MT_READWRITE           0x0002
-#define MT_USERANDOM           0x0004
+#define MT_READWRITE           0x0001
+#define MT_USERANDOM           0x0002
 
 extern char *sh_mktmpname __P((char *, int));
 extern int sh_mktmpfd __P((char *, int, char **));
--- builtins/fc.def.orig        Sun Aug  4 16:10:04 2002
+++ builtins/fc.def     Sun Aug  4 16:10:54 2002
@@ -332,7 +332,7 @@
   else
     {
       numbering = 0;
-      stream = sh_mktmpfp ("bash-fc", MT_USERANDOM|MT_USETMPDIR, &fn);
+      stream = sh_mktmpfp ("bash-fc", MT_USERANDOM, &fn);
       if (stream == 0)
        {
          builtin_error ("cannot open temp file %s", fn ? fn : "");
--- lib/sh/tmpfile.c.orig       Sun Aug  4 16:25:22 2002
+++ lib/sh/tmpfile.c    Sun Aug  4 16:25:27 2002
@@ -89,7 +89,7 @@
 {
   char *tdir;
 
-  tdir = (flags & MT_USETMPDIR) ? get_string_value ("TMPDIR") : (char *)NULL;
+  tdir = get_string_value ("TMPDIR");
   if (tdir == 0)
     tdir = get_sys_tmpdir ();
 
--- shell.c.orig        Sun Aug  4 17:15:42 2002
+++ shell.c     Sun Aug  4 17:30:12 2002
@@ -286,12 +286,16 @@
 {
   struct stat sb;
 
-  if (stat ("/tmp", &sb) < 0)
-    internal_warning ("could not find /tmp, please create!");
-  else
+  /* Only check for /tmp if TMPDIR is not set. */
+  if (getenv("TMPDIR") == NULL)
     {
-      if (S_ISDIR (sb.st_mode) == 0)
-       internal_warning ("/tmp must be a valid directory name");
+      if (stat ("/tmp", &sb) < 0)
+        internal_warning ("TMPDIR or /tmp not found. (hint: create /tmp)");
+      else
+        {
+          if (S_ISDIR (sb.st_mode) == 0)
+            internal_warning ("/tmp must be a valid directory name.");
+        }
     }
 }
 #endif /* __CYGWIN__ */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]