mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-30 08:43:23 +00:00
Fix temporary file creation.
Obtained from: NetBSD dol.c r1.15
This commit is contained in:
parent
abeee2d84b
commit
04b3babe41
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/stable/3/; revision=68368
@ -40,6 +40,7 @@ static const char rcsid[] =
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
@ -850,13 +851,20 @@ heredoc(term)
|
||||
Char **vp;
|
||||
bool quoted;
|
||||
char *tmp;
|
||||
struct timeval tv;
|
||||
|
||||
if (creat(tmp = short2str(shtemp), 0600) < 0)
|
||||
stderror(ERR_SYSTEM, tmp, strerror(errno));
|
||||
(void) close(0);
|
||||
if (open(tmp, O_RDWR) < 0) {
|
||||
again:
|
||||
tmp = short2str(shtemp);
|
||||
if (open(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600) < 0) {
|
||||
int oerrno = errno;
|
||||
|
||||
if (errno == EEXIST) {
|
||||
if (unlink(tmp) == -1) {
|
||||
(void) gettimeofday(&tv, NULL);
|
||||
shtemp = Strspl(STRtmpsh, putn((((int)tv.tv_sec) ^
|
||||
((int)tv.tv_usec) ^ ((int)getpid())) & 0x00ffffff));
|
||||
}
|
||||
goto again;
|
||||
}
|
||||
(void) unlink(tmp);
|
||||
errno = oerrno;
|
||||
stderror(ERR_SYSTEM, tmp, strerror(errno));
|
||||
|
Loading…
Reference in New Issue
Block a user