From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by melb.werple.net.au (8.7.5/8.7.3) with ESMTP id DAA00390 for ; Thu, 23 May 1996 03:10:31 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id MAA21789; Wed, 22 May 1996 12:06:15 -0400 (EDT) Resent-Date: Wed, 22 May 1996 12:06:15 -0400 (EDT) From: Zoltan Hidvegi Message-Id: <199605221606.SAA29528@bolyai.cs.elte.hu> Subject: Re: Bogus tempfile names in beta18 To: acs@world.std.com Date: Wed, 22 May 1996 18:06:15 +0200 (MET DST) Cc: zsh-workers@math.gatech.edu In-Reply-To: <9605221509.AA19240@spacely.afive> from Vinnie Shelton at "May 22, 96 11:09:17 am" Organization: Dept. of Comp. Sci., Eotvos University, Budapest, Hungary Phone: (36 1)2669833 ext: 2667, home phone: (36 1) 2752368 X-Mailer: ELM [version 2.4ME+ PL16 (25)] MIME-Version: 1.0 Content-Type: application/pgp; format=text; x-action=sign Content-Transfer-Encoding: 7bit Resent-Message-ID: <"4GxuA3.0.NK5.njpen"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/1117 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu -----BEGIN PGP SIGNED MESSAGE----- > This bug has been around for awhile. Someone (Peter?) sent a fix, but I > foolishly discarded it, assuming that fix would be incorporated in beta18. > Basically, the bug is that filenames for =() substitution are not unique. Eg: This bug is fixed in beta18. > spacely% echo =(ls /tmp) =(ls) > /tmp/zsha19197 /tmp/zshb19197 Did you notice that these filenames are different? In some cases it may really happen that the two filenames are the same but that's a different bug than the one reported earlier. The problem is that the file is created by the child and when the child is slow the parent may call getoutputfile before the child created the file. In this case mktemp() may return the same filename. The fix is to move the open before the fork. Zoltan *** Src/exec.c 1996/05/14 00:03:57 2.28 --- Src/exec.c 1996/05/22 15:51:16 *************** *** 5,11 **** * * This file is part of zsh, the Z shell. * ! * Copyright (c) 1992-1995 Paul Falstad * All rights reserved. * * Permission is hereby granted, without written agreement and without --- 5,11 ---- * * This file is part of zsh, the Z shell. * ! * Copyright (c) 1992-1996 Paul Falstad * All rights reserved. * * Permission is hereby granted, without written agreement and without *************** *** 2014,2019 **** --- 2014,2020 ---- pid_t pid; char *nam; List list; + int fd; if (thisjob == -1) return NULL; *************** *** 2027,2041 **** addlinknode(jobtab[thisjob].filelist, nam); heapalloc(); child_block(); ! if ((cmdoutpid = pid = zfork()) == -1) { ! /* fork error */ popheap(); child_unblock(); return nam; } else if (pid) { int os; popheap(); os = jobtab[thisjob].stat; waitforpid(pid); --- 2028,2044 ---- addlinknode(jobtab[thisjob].filelist, nam); heapalloc(); child_block(); + fd = open(nam, O_WRONLY | O_CREAT | O_EXCL, 0600); /* create the file */ ! if (fd < 0 || (cmdoutpid = pid = zfork()) == -1) { ! /* fork or open error */ popheap(); child_unblock(); return nam; } else if (pid) { int os; + close(fd); popheap(); os = jobtab[thisjob].stat; waitforpid(pid); *************** *** 2045,2054 **** } /* pid == 0 */ ! close(1); entersubsh(Z_SYNC, 1, 0); signal_ignore(SIGTSTP); - (void) open(nam, O_WRONLY | O_CREAT | O_EXCL, 0600); /* create the file */ execlist(list, 0, 1); close(1); _exit(lastval); --- 2048,2056 ---- } /* pid == 0 */ ! redup(fd, 1); entersubsh(Z_SYNC, 1, 0); signal_ignore(SIGTSTP); execlist(list, 0, 1); close(1); _exit(lastval); -----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: noconv iQCVAwUBMaM7dgupSCiLN749AQEpRgP/VtynYVDDtI1bYg1K7kXtK4xz3AU/tWQW TByMcVdBGEhq663HTN1NV9ph0bjOXOAkhjITqxKQeyy0EZ/SZrdxY2gOs5FyvF/p ZJR+ePL1da94T5wo3anuOLdfFOr64ZP2VE0zSXzhbLU5/YS5Kt51LYYb2paP5AW2 P+dY97Tcr7Q= =FC8k -----END PGP SIGNATURE-----