From 846ad932726ec5261464fa19615e1b1f4a27e6cb Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Thu, 14 May 2020 11:36:16 +0100 Subject: [PATCH] Fix 'print -s -f' This fix is backported from the Vashisht/Rader ksh2020 branch. src/cmd/ksh93/bltins/print.c: - Fix syncing history when print -s -f is used. For example, the following now correctly adds a 'cd' command to the history: print -s -f 'cd -- %q\n' "$PWD" Ref.: https://github.com/att/ast/issues/425 https://github.com/att/ast/pull/442 src/cmd/ksh93/include/version.h: - Version date bump. (cherry picked from commit 46ba7ecdc5c14cd73f6cb24b16c50bdc331a000e) --- NEWS | 8 ++++++++ src/cmd/ksh93/bltins/print.c | 8 +++++++- src/cmd/ksh93/include/version.h | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 7deccf3f4..a907545f3 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,14 @@ For full details, see the git log at: Any uppercase BUG_* names are modernish shell bug IDs. +2020-05-14: + +- Fix syncing history when print -s -f is used. For example, the + following now correctly adds a 'cd' command to the history: + print -s -f 'cd -- %q\n' "$PWD" + Ref.: https://github.com/att/ast/issues/425 + https://github.com/att/ast/pull/442 + 2020-05-13: - Fix BUG_CASELIT: an undocumented 'case' pattern matching misbehaviour that diff --git a/src/cmd/ksh93/bltins/print.c b/src/cmd/ksh93/bltins/print.c index eecee9cb7..ee6f2fdf0 100644 --- a/src/cmd/ksh93/bltins/print.c +++ b/src/cmd/ksh93/bltins/print.c @@ -329,7 +329,13 @@ skip2: } while(*pdata.nextarg && pdata.nextarg!=argv); if(pdata.nextarg == nullarg && pdata.argsize>0) sfwrite(outfile,stakptr(staktell()),pdata.argsize); - if(sffileno(outfile)!=sffileno(sfstderr)) + /* + * -f flag skips adding newline at the end of output, which causes issues + * with syncing history if -s and -f are used together. So don't sync now + * if sflag was given. History is synced later with hist_flush() function. + * https://github.com/att/ast/issues/425 + */ + if(!sflag && sffileno(outfile)!=sffileno(sfstderr)) sfsync(outfile); sfpool(sfstderr,pool,SF_WRITE); exitval = pdata.err; diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index a70f7fef3..8ccada637 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -17,4 +17,4 @@ * David Korn * * * ***********************************************************************/ -#define SH_RELEASE "93u+m 2020-05-13" +#define SH_RELEASE "93u+m 2020-05-14"