Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2cb76fa

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 adifferent definition (to wit, "-1 if error, else the number of lineswritten to the file"). We tried to work around that by checking whethererrno had become nonzero, but this method has never been kosher accordingto the published API of either library. It's reportedly completely brokenin 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 somewherearound 2006, so it seems all right to finally break compatibility withancient libedit releases and trust that the return value is what readlinespecifies. (I'm not sure when the various Linux distributions incorporatedthis fix, but I did find that OS X has been shipping fixed versions since10.5/Leopard.)If anyone is still using such an ancient libedit, they will find that psqlcomplains it can't write ~/.psql_history at exit, even when the file waswritten correctly. This is no worse than the behavior we're fixing forcurrent releases.Back-patch to all supported branches.
1 parent089b371 commit2cb76fa

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
@@ -386,6 +386,7 @@ static bool
386386
saveHistory(char*fname,intmax_lines)
387387
{
388388
#ifdefUSE_READLINE
389+
interrnum;
389390

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

455450
psql_error("could not save history to file \"%s\": %s\n",
456-
fname,strerror(errno));
451+
fname,strerror(errnum));
457452
}
458453
#endif
459454

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp