Re: [PATCH] fix mktemp (remove mktemp ;)

2005-04-16 Thread Jan-Benedict Glaw
On Sat, 2005-04-16 16:27:43 -0700, Paul Jackson [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]: Index: git-pasky-0.4/gitcommit.sh === --- git-pasky-0.4.orig/gitcommit.sh 2005-04-12 10:39:14.0 -0700 +++

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Petr Baudis
Dear diary, on Sun, Apr 17, 2005 at 01:27:43AM CEST, I got a letter where Paul Jackson [EMAIL PROTECTED] told me that... Remove mktemp usage - it doesn't work on some Mandrakes, nor on my SuSE 8.2 with mktemp-1.5-531. Replace with simple use of $$ (pid). I've been using this same pattern

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Paul Jackson
And racy. And not guaranteed to come up with fresh new files. In theory perhaps. In practice no. Even mktemp(1) can collide, in theory, since there is no practical way in shell scripts to hold open and locked the file from the instant of it is determined to be a unique name. The window of

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Dave Jones
On Sat, Apr 16, 2005 at 05:02:21PM -0700, Paul Jackson wrote: And racy. And not guaranteed to come up with fresh new files. In theory perhaps. In practice no. Even mktemp(1) can collide, in theory, since there is no practical way in shell scripts to hold open and locked the file

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Erik van Konijnenburg
On Sat, Apr 16, 2005 at 08:33:25PM -0400, Dave Jones wrote: On Sat, Apr 16, 2005 at 05:02:21PM -0700, Paul Jackson wrote: And racy. And not guaranteed to come up with fresh new files. In theory perhaps. In practice no. Even mktemp(1) can collide, in theory, since there is no

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Paul Jackson
Dave wrote: http://www.linuxsecurity.com/content/view/115462/151/ Nice - thanks. Pasky - would you be interested in a patch that used a more robust tmp file creation, along the lines of replacing t=${TMPDIR:-/usr/tmp}/gitdiff.$$ trap 'set +f; rm -fr $t.?; trap 0; exit 0' 0 1 2

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Paul Jackson
Erik wrote: How about putting using .git/tmp.$$ or similar as tempfile? One could, but best to normally honor the users TMPDIR setting. Could one 'git diff' a readonly git repository? Perhaps someone has a reason for putting their tmp files where they choose - say a local file system in a

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Brian O'Mahoney
No, you have to: (a) create a unique, pid specific file name /var/tmp/myapp.$$.xyzzy (b) create it in O_EXCL mode, so you wont smash another's held lock (b-1) It worked, OK (b-2) open failed, try ...xyzzz repeat until (b-1) There are thousands of examples of how to do this with bash. Paul

Re: fix mktemp (remove mktemp ;)

2005-04-16 Thread Paul Jackson
No, you have to: How does this compare with the one I posted about 1 hour 30 minuts ago: tmp=${TMPDIR-/tmp} tmp=$tmp/gitdiff-do.$RANDOM.$RANDOM.$RANDOM.$$ (umask 077 mkdir $tmp) || { echo Could not create temporary directory! Exiting. 12