diff options
author | Wayne Davison <wayned@users.sourceforge.net> | 2004-10-18 19:07:30 +0000 |
---|---|---|
committer | Wayne Davison <wayned@users.sourceforge.net> | 2004-10-18 19:07:30 +0000 |
commit | 945a40f7e69dcbd194a2a45889512c8849dce2c9 (patch) | |
tree | c183ce003231fd705e1b426b1223c78a89ce6cf5 /Src | |
parent | b115ca307adf7ef9dca13f6e7ce40768bc0b2b75 (diff) | |
download | zsh-945a40f7e69dcbd194a2a45889512c8849dce2c9.tar.gz zsh-945a40f7e69dcbd194a2a45889512c8849dce2c9.tar.xz zsh-945a40f7e69dcbd194a2a45889512c8849dce2c9.zip |
- Improved lockhistfile() to use the new gettempname() for a unique
filename instead of a .PID suffix. - Use bicat() to build the $HISTFILE.LOCK filename. - Put the $HOST value into $HISTFILE.LOCK in addition to the PID.
Diffstat (limited to 'Src')
-rw-r--r-- | Src/hist.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/Src/hist.c b/Src/hist.c index da1e15ccc..3f7927010 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -2129,23 +2129,22 @@ lockhistfile(char *fn, int keep_trying) return 0; if (!lockhistct++) { struct stat sb; - int fd, len; + int fd; char *lockfile; #ifdef HAVE_LINK char *tmpfile; #endif - fn = unmeta(fn); - len = strlen(fn); - lockfile = zalloc(len + 5 + 1); - sprintf(lockfile, "%s.LOCK", fn); + lockfile = bicat(unmeta(fn), ".LOCK"); #ifdef HAVE_LINK - tmpfile = zalloc(len + 10 + 1); - sprintf(tmpfile, "%s.%ld", fn, (long)mypid); - unlink(tmpfile); /* NFS's O_EXCL is often broken... */ + tmpfile = gettempname(fn, 0); if ((fd = open(tmpfile, O_WRONLY|O_CREAT|O_EXCL, 0644)) >= 0) { - write(fd, tmpfile+len+1, strlen(tmpfile+len+1)); - close(fd); + FILE *out = fdopen(fd, "w"); + if (out) { + fprintf(out, "%ld %s\n", (long)getpid(), getsparam("HOST")); + fclose(out); + } else + close(fd); while (link(tmpfile, lockfile) < 0) { if (errno != EEXIST || !keep_trying) ; @@ -2183,10 +2182,12 @@ lockhistfile(char *fn, int keep_trying) if (fd < 0) lockhistct--; else { - char buf[16]; - sprintf(buf, "%ld", (long)mypid); - write(fd, buf, strlen(buf)); - close(fd); + FILE *out = fdopen(fd, "w"); + if (out) { + fprintf(out, "%ld %s\n", (long)mypid, getsparam("HOST")); + fclose(out); + } else + close(fd); } #endif /* not HAVE_LINK */ free(lockfile); |