From bed5d53e2507471a02fbec9aa0467c50bb3ad0d5 Mon Sep 17 00:00:00 2001 From: Fridolin Pokorny Date: Thu, 28 Mar 2013 13:22:02 +0100 Subject: [PATCH] Fix history problems (#879371 and #919452), histlist length reflects $savehist --- tcsh-6.18.00-history-file-locking.patch | 99 ++++++++++++------------- tcsh-6.18.00-history-merge.patch | 37 +++++++++ tcsh-6.18.00-history-savehist.patch | 55 ++++++++++++++ tcsh.spec | 17 ++++- 4 files changed, 153 insertions(+), 55 deletions(-) create mode 100644 tcsh-6.18.00-history-merge.patch create mode 100644 tcsh-6.18.00-history-savehist.patch diff --git a/tcsh-6.18.00-history-file-locking.patch b/tcsh-6.18.00-history-file-locking.patch index d68c7ab..83cd5e4 100644 --- a/tcsh-6.18.00-history-file-locking.patch +++ b/tcsh-6.18.00-history-file-locking.patch @@ -7,21 +7,17 @@ Originally reported at Red Hat Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=648592 Patch by Vojtech Vitek (V-Teq) ---- - sh.c | 103 +++++++++++++++++++++++++++++++++++------------- - sh.decls.h | 4 +- - sh.dol.c | 2 +- - sh.err.c | 16 ++++++++ - sh.h | 18 +++++++++ - sh.hist.c | 131 +++++++++++++++++++++++++++++++------------------------------ - sh.lex.c | 8 ++-- - sh.sem.c | 2 +- - 8 files changed, 185 insertions(+), 99 deletions(-) -diff --git a/sh.c b/sh.c -index dcd9116..7f03077 100644 ---- a/sh.c -+++ b/sh.c +Additional changes reflecting: +https://bugzilla.redhat.com/show_bug.cgi?id=879371 + +Changes by Fridolin Pokorny + +--- + +diff -upr tcsh-6.18.00_orig/sh.c tcsh-6.18.00_work/sh.c +--- tcsh-6.18.00_orig/sh.c 2013-03-28 10:06:17.969859477 +0100 ++++ tcsh-6.18.00_work/sh.c 2013-03-28 10:07:21.155082032 +0100 @@ -140,6 +140,7 @@ struct saved_state { int cantell; struct Bin B; @@ -120,7 +116,7 @@ index dcd9116..7f03077 100644 } -@@ -1544,7 +1574,7 @@ srcfile(const char *f, int onlyown, int flag, Char **av) +@@ -1544,7 +1574,7 @@ srcfile(const char *f, int onlyown, int * fd. */ static void @@ -129,7 +125,7 @@ index dcd9116..7f03077 100644 { st->insource = insource; st->SHIN = SHIN; -@@ -1593,10 +1623,14 @@ st_save(struct saved_state *st, int unit, int hflg, Char **al, Char **av) +@@ -1593,10 +1623,14 @@ st_save(struct saved_state *st, int unit st->onelflg = onelflg; st->enterhist = enterhist; st->justpr = justpr; @@ -145,7 +141,7 @@ index dcd9116..7f03077 100644 st->cantell = cantell; cpybin(st->B, B); -@@ -1635,7 +1669,7 @@ st_save(struct saved_state *st, int unit, int hflg, Char **al, Char **av) +@@ -1635,7 +1669,7 @@ st_save(struct saved_state *st, int unit evalp = 0; alvec = al; alvecp = 0; @@ -173,7 +169,7 @@ index dcd9116..7f03077 100644 { struct saved_state st; -@@ -1730,7 +1765,7 @@ srcunit(int unit, int onlyown, int hflg, Char **av) +@@ -1730,7 +1765,7 @@ srcunit(int unit, int onlyown, int hflg, } /* Save the current state and move us to a new state */ @@ -182,6 +178,15 @@ index dcd9116..7f03077 100644 /* * Now if we are allowing commands to be interrupted, we let ourselves be +@@ -2069,7 +2104,7 @@ process(int catch) + * elsewhere... + */ + if (enterhist || (catch && intty && !whyles && !tellwhat && !arun)) +- savehist(¶ml, enterhist > 1); ++ savehist(¶ml, enterhist > 1 ? HIST_MERGE : 0); + + if (Expand && seterr) + Expand = 0; @@ -2156,21 +2191,28 @@ process(int catch) void dosource(Char **t, struct command *c) @@ -233,10 +238,9 @@ index dcd9116..7f03077 100644 } /* -diff --git a/sh.decls.h b/sh.decls.h -index db90288..fb15a01 100644 ---- a/sh.decls.h -+++ b/sh.decls.h +diff -upr tcsh-6.18.00_orig/sh.decls.h tcsh-6.18.00_work/sh.decls.h +--- tcsh-6.18.00_orig/sh.decls.h 2013-03-28 10:06:17.988859538 +0100 ++++ tcsh-6.18.00_work/sh.decls.h 2013-03-28 10:06:42.897948590 +0100 @@ -38,6 +38,7 @@ */ extern Char *gethdir (const Char *); @@ -253,7 +257,7 @@ index db90288..fb15a01 100644 extern void opendir_cleanup(void *); extern void sigint_cleanup(void *); extern void sigprocmask_cleanup(void *); -@@ -219,7 +221,7 @@ extern struct Hist *enthist (int, struct wordent *, int, int, int); +@@ -219,7 +221,7 @@ extern struct Hist *enthist (int, str extern void savehist (struct wordent *, int); extern char *fmthist (int, ptr_t); extern void rechist (Char *, int); @@ -262,10 +266,9 @@ index db90288..fb15a01 100644 extern void displayHistStats(const char *); /* -diff --git a/sh.dol.c b/sh.dol.c -index 45b10e0..2ce7cb5 100644 ---- a/sh.dol.c -+++ b/sh.dol.c +diff -upr tcsh-6.18.00_orig/sh.dol.c tcsh-6.18.00_work/sh.dol.c +--- tcsh-6.18.00_orig/sh.dol.c 2013-03-28 10:06:17.988859538 +0100 ++++ tcsh-6.18.00_work/sh.dol.c 2013-03-28 10:06:42.898948594 +0100 @@ -1110,6 +1110,6 @@ again: *obp = 0; tmp = short2str(obuf); @@ -274,10 +277,9 @@ index 45b10e0..2ce7cb5 100644 + (void) lseek(0, (off_t) 0, SEEK_SET); cleanup_until(&inheredoc); } -diff --git a/sh.err.c b/sh.err.c -index e157d6a..29d41c3 100644 ---- a/sh.err.c -+++ b/sh.err.c +diff -upr tcsh-6.18.00_orig/sh.err.c tcsh-6.18.00_work/sh.err.c +--- tcsh-6.18.00_orig/sh.err.c 2013-03-28 10:06:17.972859480 +0100 ++++ tcsh-6.18.00_work/sh.err.c 2013-03-28 10:06:42.824948331 +0100 @@ -514,6 +514,22 @@ open_cleanup(void *xptr) } @@ -301,10 +303,9 @@ index e157d6a..29d41c3 100644 opendir_cleanup(void *xdir) { DIR *dir; -diff --git a/sh.h b/sh.h -index 691add3..4e3f13c 100644 ---- a/sh.h -+++ b/sh.h +diff -upr tcsh-6.18.00_orig/sh.h tcsh-6.18.00_work/sh.h +--- tcsh-6.18.00_orig/sh.h 2013-03-28 10:06:17.988859538 +0100 ++++ tcsh-6.18.00_work/sh.h 2013-03-28 10:06:42.899948597 +0100 @@ -50,6 +50,24 @@ # include #endif @@ -330,10 +331,9 @@ index 691add3..4e3f13c 100644 #if !defined(HAVE_STDINT_H) && !defined(HAVE_INTTYPES_H) && !defined(WINNT_NATIVE) typedef unsigned long intptr_t; #endif -diff --git a/sh.hist.c b/sh.hist.c -index 6a12737..7e53c65 100644 ---- a/sh.hist.c -+++ b/sh.hist.c +diff -upr tcsh-6.18.00_orig/sh.hist.c tcsh-6.18.00_work/sh.hist.c +--- tcsh-6.18.00_orig/sh.hist.c 2013-03-28 10:06:17.967859465 +0100 ++++ tcsh-6.18.00_work/sh.hist.c 2013-03-28 10:06:42.815948309 +0100 @@ -44,14 +44,6 @@ Char HistLit = 0; static int heq (const struct wordent *, const struct wordent *); static void hfree (struct Hist *); @@ -631,11 +631,10 @@ index 6a12737..7e53c65 100644 + + return fd; /* Valid/invalid file descriptor (>FSAVE, -1). Zero on error. */ } -diff --git a/sh.lex.c b/sh.lex.c -index 80643f7..57ec7a9 100644 ---- a/sh.lex.c -+++ b/sh.lex.c -@@ -1595,7 +1595,7 @@ wide_read(int fildes, Char *buf, size_t nchars, int use_fclens) +diff -upr tcsh-6.18.00_orig/sh.lex.c tcsh-6.18.00_work/sh.lex.c +--- tcsh-6.18.00_orig/sh.lex.c 2013-03-28 10:06:17.971859478 +0100 ++++ tcsh-6.18.00_work/sh.lex.c 2013-03-28 10:06:42.820948316 +0100 +@@ -1595,7 +1595,7 @@ wide_read(int fildes, Char *buf, size_t /* Throwing away possible partial multibyte characters on error if the stream is not seekable */ err = errno; @@ -671,11 +670,10 @@ index 80643f7..57ec7a9 100644 return; fbuf = xcalloc(2, sizeof(Char **)); fblocks = 1; -diff --git a/sh.sem.c b/sh.sem.c -index c880974..bc51b50 100644 ---- a/sh.sem.c -+++ b/sh.sem.c -@@ -892,7 +892,7 @@ doio(struct command *t, int *pipein, int *pipeout) +diff -upr tcsh-6.18.00_orig/sh.sem.c tcsh-6.18.00_work/sh.sem.c +--- tcsh-6.18.00_orig/sh.sem.c 2013-03-28 10:06:17.970859477 +0100 ++++ tcsh-6.18.00_work/sh.sem.c 2013-03-28 10:06:42.819948308 +0100 +@@ -892,7 +892,7 @@ doio(struct command *t, int *pipein, int fd = xopen(tmp, O_WRONLY|O_APPEND|O_LARGEFILE); #else /* !O_APPEND */ fd = xopen(tmp, O_WRONLY|O_LARGEFILE); @@ -684,6 +682,3 @@ index c880974..bc51b50 100644 #endif /* O_APPEND */ } else --- -1.7.11.7 - diff --git a/tcsh-6.18.00-history-merge.patch b/tcsh-6.18.00-history-merge.patch new file mode 100644 index 0000000..c54595a --- /dev/null +++ b/tcsh-6.18.00-history-merge.patch @@ -0,0 +1,37 @@ +diff -upr tcsh-6.18.00_orig/sh.hist.c tcsh-6.18.00_work/sh.hist.c +--- tcsh-6.18.00_orig/sh.hist.c 2013-03-28 10:13:52.165407699 +0100 ++++ tcsh-6.18.00_work/sh.hist.c 2013-03-28 10:19:49.168703936 +0100 +@@ -99,7 +99,7 @@ hremove(struct Hist *hp) + + /* Prune length of history list to specified size by history variable. */ + PG_STATIC void +-discardExcess(int histlen) ++discardExcess(int histlen, int flg) + { + struct Hist *hp, *np; + if (histTail == NULL) { +@@ -110,13 +110,13 @@ discardExcess(int histlen) + * the list is still too long scan the whole list as before. But only do a + * full scan if the list is more than 6% (1/16th) too long. */ + while (histCount > (unsigned)histlen && (np = Histlist.Hnext)) { +- if (eventno - np->Href >= histlen || histlen == 0) ++ if ((eventno - np->Href >= histlen || histlen == 0) && ! (flg & HIST_MERGE)) + hremove(np), hfree(np); + else + break; + } + while (histCount > (unsigned)histlen && (np = histTail) != &Histlist) { +- if (eventno - np->Href >= histlen || histlen == 0) ++ if ((eventno - np->Href >= histlen || histlen == 0) || flg & HIST_MERGE) + hremove(np), hfree(np); + else + break; +@@ -153,7 +153,7 @@ savehist( + } + if (sp) + (void) enthist(++eventno, sp, 1, flg, histlen); +- discardExcess(histlen); ++ discardExcess(histlen, flg); + } + + #define USE_JENKINS_HASH 1 diff --git a/tcsh-6.18.00-history-savehist.patch b/tcsh-6.18.00-history-savehist.patch new file mode 100644 index 0000000..b2178ba --- /dev/null +++ b/tcsh-6.18.00-history-savehist.patch @@ -0,0 +1,55 @@ +diff -upr tcsh-6.18.00_orig/ed.chared.c tcsh-6.18.00_work/ed.chared.c +--- tcsh-6.18.00_orig/ed.chared.c 2013-03-28 10:26:00.801939093 +0100 ++++ tcsh-6.18.00_work/ed.chared.c 2013-03-28 10:30:37.000000000 +0100 +@@ -957,6 +957,7 @@ GetHistLine() + { + struct Hist *hp; + int h; ++ int history; + + if (Hist_num == 0) { /* if really the current line */ + if (HistBuf.s != NULL) +@@ -979,8 +980,10 @@ GetHistLine() + if (hp == NULL) + return(CC_ERROR); + ++ /* access only $history commands */ ++ history = getn(varval(STRhistory)); + for (h = 1; h < Hist_num; h++) { +- if ((hp->Hnext) == NULL) { ++ if ((hp->Hnext) == NULL || h >= history) { + Hist_num = h; + return(CC_ERROR); + } +diff -upr tcsh-6.18.00_orig/sh.hist.c tcsh-6.18.00_work/sh.hist.c +--- tcsh-6.18.00_orig/sh.hist.c 2013-03-28 10:26:00.794939068 +0100 ++++ tcsh-6.18.00_work/sh.hist.c 2013-03-28 10:25:19.000000000 +0100 +@@ -138,6 +138,7 @@ savehist( + int flg) + { + int histlen = 0; ++ int savehist = 0; + Char *cp; + + /* throw away null lines */ +@@ -151,6 +152,20 @@ savehist( + } + histlen = histlen * 10 + *cp++ - '0'; + } ++ ++ /* check savehist and history and use greater value to store all commands */ ++ cp = varval(STRsavehist); ++ while (*cp) { ++ if (!Isdigit(*cp)) { ++ savehist = 0; ++ break; ++ } ++ savehist = savehist * 10 + *cp++ - '0'; ++ } ++ ++ if (savehist > histlen) ++ histlen = savehist; ++ + if (sp) + (void) enthist(++eventno, sp, 1, flg, histlen); + discardExcess(histlen, flg); diff --git a/tcsh.spec b/tcsh.spec index c45df8b..c29525d 100644 --- a/tcsh.spec +++ b/tcsh.spec @@ -3,7 +3,7 @@ Summary: An enhanced version of csh, the C shell Name: tcsh Version: 6.18.00 -Release: 6%{?dist} +Release: 7%{?dist} License: BSD Group: System Environment/Shells Source: http://ftp.funet.fi/pub/unix/shells/tcsh/old/%{name}-%{version}.tar.gz @@ -19,7 +19,9 @@ Patch28: tcsh-6.17.00-manpage-spelling.patch # Proposed upstream - http://github.com/tcsh-org/tcsh/pull/2 Patch31: tcsh-6.18.00-history-file-locking.patch # Accepted upstream - http://mx.gw.com/pipermail/tcsh-bugs/2012-December/000797.html -Patch32: tcsh-6.18.00-sigint-while-waiting-for-child.patch +#Patch32: tcsh-6.18.00-sigint-while-waiting-for-child.patch +Patch33: tcsh-6.18.00-history-merge.patch +Patch34: tcsh-6.18.00-history-savehist.patch Provides: csh = %{version} Requires(post): grep @@ -47,7 +49,9 @@ like syntax. %patch11 -p1 -b .order %patch28 -p1 -b .manpage-spelling %patch31 -p1 -b .history-file-locking -%patch32 -p1 -b .sigint-while-waiting-for-child +#%patch32 -p1 -b .sigint-while-waiting-for-child +%patch33 -p1 -b .history-merge +%patch34 -p1 -b .history-savehist for i in Fixes WishList; do iconv -f iso-8859-1 -t utf-8 "$i" > "${i}_" && \ @@ -121,6 +125,13 @@ fi %{_mandir}/man1/*.1* %changelog +* Thu Mar 28 2013 Fridolin Pokorny 6.18.00-7 +- File locking patch modified to reflect HIST_MERGE flag (#879371) +- Drop tcsh-6.18.00-sigint-while-waiting-for-child.patch, accepted by upstream +- Add tcsh-6.18.00-history-merge.patch to merge histlist properly (#919452) +- Add tcsh-6.18.00-history-savehist.patch to store history with length + $savehist, not only $history. + * Fri Feb 15 2013 Fedora Release Engineering - 6.18.00-6 - Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild