From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9261 invoked from network); 17 Mar 2005 02:49:45 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 17 Mar 2005 02:49:45 -0000 Received: (qmail 6056 invoked from network); 17 Mar 2005 02:49:27 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 17 Mar 2005 02:49:27 -0000 Received: (qmail 12690 invoked by alias); 17 Mar 2005 02:49:25 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 20990 Received: (qmail 12676 invoked from network); 17 Mar 2005 02:49:25 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 17 Mar 2005 02:49:25 -0000 Received: (qmail 5760 invoked from network); 17 Mar 2005 02:49:24 -0000 Received: from dsl3-63-249-88-2.cruzio.com (HELO dot.blorf.net) (63.249.88.2) by a.mx.sunsite.dk with SMTP; 17 Mar 2005 02:49:20 -0000 Received: by dot.blorf.net (Postfix, from userid 1000) id DC74BAA32; Wed, 16 Mar 2005 18:49:19 -0800 (PST) Date: Wed, 16 Mar 2005 18:49:19 -0800 From: Wayne Davison To: Geoff Wing Cc: zsh-workers@sunsite.dk Subject: Re: revisiting history-file rewriting Message-ID: <20050317024919.GD13937@blorf.net> References: <20050316204059.GA1298@blorf.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="sdtB3X0nJg68CQEu" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.6+20040907i X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 --sdtB3X0nJg68CQEu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Mar 17, 2005 at 02:09:43AM +0000, Geoff Wing wrote: > Didn't we used to do $HISTFILE. ? Is that out of favour? We used to use that idiom as a stepping stone to creating a $HISTFILE.LOCK file, but now days we use the gettempfile() function instead (since this avoids a potential problem with the same pid being allocated on different hosts). The name used once we lock down the system can be constant without clashing with another process, but I suppose it could clash with a file that the user has created. The attached patch can be applied to my previous patch to make the history code use gettempfile() to return an opened $HISTFILE.XXXXXX name for the new file instead of using $HISTFILE.new. ..wayne.. --sdtB3X0nJg68CQEu Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="hist-tempname.patch" --- Src/hist.c.new 2005-03-16 18:26:16.638813544 -0800 +++ Src/hist.c 2005-03-16 18:40:32.629680617 -0800 @@ -2049,9 +2049,14 @@ savehistfile(char *fn, int err, int writ out = fdopen(open(unmeta(fn), O_CREAT | O_WRONLY | O_TRUNC | O_NOCTTY, 0600), "w"); } else { - tmpfile = bicat(unmeta(fn), ".new"); - unlink(tmpfile); - out = fdopen(open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0600), "w"); + int fd; + if ((fd = gettempfile(fn, 0, &tmpfile)) >= 0) { + if (!(out = fdopen(fd, "w"))) + close(fd); + } else { + tmpfile = bicat(unmeta(fn), ".XXXXXX"); + out = NULL; + } } if (out) { for (; he && he->histnum <= xcurhist; he = down_histent(he)) { @@ -2097,8 +2102,10 @@ savehistfile(char *fn, int err, int writ } fclose(out); if (tmpfile) { - if (rename(tmpfile, unmeta(fn)) < 0) - zerr("can't rename %s.new to $HISTFILE", fn, 0); + if (rename(tmpfile, unmeta(fn)) < 0) { + tmpfile = metafy(tmpfile, -1, META_REALLOC); + zerr("can't rename %s to $HISTFILE", tmpfile, 0); + } free(tmpfile); } @@ -2122,7 +2129,8 @@ savehistfile(char *fn, int err, int writ } } else if (err) { if (tmpfile) { - zerr("can't write history file %s.new", fn, 0); + tmpfile = metafy(tmpfile, -1, META_REALLOC); + zerr("can't write history file %s", tmpfile, 0); free(tmpfile); } else zerr("can't write history file %s", fn, 0); --sdtB3X0nJg68CQEu--