Skip to content

Commit 043fe5c

Browse files
committed
Remove workaround for ancient incompatibility between readline and libedit.
GNU readline defines the return value of write_history() as "zero if OK, else an errno code". libedit's version of that function used to have a different definition (to wit, "-1 if error, else the number of lines written to the file"). We tried to work around that by checking whether errno had become nonzero, but this method has never been kosher according to the published API of either library. It's reportedly completely broken in recent Ubuntu releases: psql bleats about "No such file or directory" when saving ~/.psql_history, even though the write worked fine. However, libedit has been following the readline definition since somewhere around 2006, so it seems all right to finally break compatibility with ancient libedit releases and trust that the return value is what readline specifies. (I'm not sure when the various Linux distributions incorporated this fix, but I did find that OS X has been shipping fixed versions since 10.5/Leopard.) If anyone is still using such an ancient libedit, they will find that psql complains it can't write ~/.psql_history at exit, even when the file was written correctly. This is no worse than the behavior we're fixing for current releases. Back-patch to all supported branches.
1 parent 4a4fd2b commit 043fe5c

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/bin/psql/input.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ static bool
385385
saveHistory(char *fname, int max_lines)
386386
{
387387
#ifdef USE_READLINE
388+
int errnum;
388389

389390
/*
390391
* Suppressing the write attempt when HISTFILE is set to /dev/null may
@@ -408,10 +409,6 @@ saveHistory(char *fname, int max_lines)
408409
* history from other concurrent sessions (although there are still
409410
* race conditions when two sessions exit at about the same time). If
410411
* we don't have those functions, fall back to write_history().
411-
*
412-
* Note: return value of write_history is not standardized across GNU
413-
* readline and libedit. Therefore, check for errno becoming set to
414-
* see if the write failed. Similarly for append_history.
415412
*/
416413
#if defined(HAVE_HISTORY_TRUNCATE_FILE) && defined(HAVE_APPEND_HISTORY)
417414
{
@@ -433,9 +430,8 @@ saveHistory(char *fname, int max_lines)
433430
nlines = Min(max_lines, history_lines_added);
434431
else
435432
nlines = history_lines_added;
436-
errno = 0;
437-
(void) append_history(nlines, fname);
438-
if (errno == 0)
433+
errnum = append_history(nlines, fname);
434+
if (errnum == 0)
439435
return true;
440436
}
441437
#else /* don't have append support */
@@ -444,15 +440,14 @@ saveHistory(char *fname, int max_lines)
444440
if (max_lines >= 0)
445441
stifle_history(max_lines);
446442
/* ... and overwrite file. Tough luck for concurrent sessions. */
447-
errno = 0;
448-
(void) write_history(fname);
449-
if (errno == 0)
443+
errnum = write_history(fname);
444+
if (errnum == 0)
450445
return true;
451446
}
452447
#endif
453448

454449
psql_error("could not save history to file \"%s\": %s\n",
455-
fname, strerror(errno));
450+
fname, strerror(errnum));
456451
}
457452
#endif
458453

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy