From 2f74b0182562318fa6cc57c4018690194bad5674ce2fb0256d3a1d43886271c7 Mon Sep 17 00:00:00 2001 From: OBS User unknown Date: Wed, 14 Nov 2007 21:10:26 +0000 Subject: [PATCH] OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/less?expand=0&rev=7 --- less-409-speed.patch | 150 +++++++++++++++++++++++++++++++++++++++++++ less.changes | 6 ++ less.spec | 7 +- 3 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 less-409-speed.patch diff --git a/less-409-speed.patch b/less-409-speed.patch new file mode 100644 index 0000000..4042a31 --- /dev/null +++ b/less-409-speed.patch @@ -0,0 +1,150 @@ +--- cmdbuf.c ++++ cmdbuf.c 2007-11-14 19:07:11.216430000 +0100 +@@ -14,11 +14,16 @@ + * Used only by command() and related functions. + */ + ++#ifndef _GNU_SOURCE ++#define _GNU_SOURCE ++#endif + #include "less.h" + #include "cmd.h" + #include "charset.h" + #if HAVE_STAT ++#include + #include ++#include + #endif + + extern int sc_width; +@@ -1361,6 +1366,7 @@ init_cmdhist() + #if CMD_HISTORY + struct mlist *ml = NULL; + char line[CMDBUF_SIZE]; ++ char buf[BUFSIZ]; + char *filename; + FILE *f; + char *p; +@@ -1372,6 +1378,7 @@ init_cmdhist() + free(filename); + if (f == NULL) + return; ++ setbuf(f, buf); + if (fgets(line, sizeof(line), f) == NULL || + strncmp(line, HISTFILE_FIRST_LINE, strlen(HISTFILE_FIRST_LINE)) != 0) + { +@@ -1446,8 +1453,16 @@ save_cmdhist() + { + #if CMD_HISTORY + char *filename; ++ char *tempname; ++ char buf[BUFSIZ]; + FILE *f; +- int modified = 0; ++ int modified = 0, fd; ++ mode_t umask_save; ++#if HAVE_STAT ++ struct stat st; ++ uid_t uid; ++ gid_t gid; ++#endif + + filename = histfile_name(); + if (filename == NULL) +@@ -1460,25 +1475,50 @@ save_cmdhist() + #endif + if (!modified) + return; +- f = fopen(filename, "w"); +- free(filename); +- if (f == NULL) ++#if HAVE_STAT ++ /* Do not overwrite other users history files due `su' */ ++ st.st_dev = st.st_ino = 0; ++ st.st_mode = 0600; ++ uid = getuid(); ++ gid = getgid(); ++ if ((stat(filename, &st) == 0) && (uid != 0) && ++ !((st.st_uid == uid) ? (st.st_mode & 0200) ++ : ((st.st_gid == gid) ++ ? (st.st_mode & 0020) ++ : (st.st_mode & 0002)))) ++ { + return; +-#if HAVE_FCHMOD +- /* Make history file readable only by owner. */ +- fchmod(fileno(f), 0600); ++ } + #endif ++ tempname = malloc((strlen(filename)+strlen("XXXXXX"))*sizeof(char)+2); ++ if (tempname == NULL) ++ return; ++ sprintf(tempname, "%s.XXXXXX", filename); ++ (void)mktemp(tempname); + +- fprintf(f, "%s\n", HISTFILE_FIRST_LINE); ++ umask_save = umask(077); ++#if HAVE_STAT ++ fd = open(tempname, O_CREAT|O_EXCL|O_WRONLY|O_NOFOLLOW, (int)((st.st_mode & 0777) | 0600)); ++#else ++ fd = open(tempname, O_CREAT|O_EXCL|O_WRONLY|O_NOFOLLOW, 0600)); ++#endif ++ (void)umask(umask_save); + ++ f = fdopen(fd, "w"); ++ if (f == NULL) ++ return; ++ setbuf(f, buf); ++ fprintf(f, "%s\n", HISTFILE_FIRST_LINE); + fprintf(f, "%s\n", HISTFILE_SEARCH_SECTION); + save_mlist(&mlist_search, f); +- + #if SHELL_ESCAPE || PIPEC + fprintf(f, "%s\n", HISTFILE_SHELL_SECTION); + save_mlist(&mlist_shell, f); + #endif +- + fclose(f); ++ if (rename(tempname, filename) < 0) ++ unlink(tempname); ++ free(filename); ++ free(tempname); + #endif /* CMD_HISTORY */ + } +--- configure.ac ++++ configure.ac 2007-11-14 17:49:06.120100000 +0100 +@@ -227,7 +227,7 @@ AC_TRY_COMPILE([#include ], [tim + + # Checks for library functions. + AC_TYPE_SIGNAL +-AC_CHECK_FUNCS([fsync popen _setjmp sigprocmask sigsetmask snprintf stat system fchmod]) ++AC_CHECK_FUNCS([tcdrain popen _setjmp sigprocmask sigsetmask snprintf stat system fchmod]) + + # AC_CHECK_FUNCS may not work for inline functions, so test these separately. + AC_MSG_CHECKING(for memcpy) +--- defines.h.in ++++ defines.h.in 2007-11-14 17:48:52.622384000 +0100 +@@ -219,8 +219,8 @@ + /* Define HAVE_FILENO if you have the fileno() macro. */ + #undef HAVE_FILENO + +-/* Define to 1 if you have the `fsync' function. */ +-#undef HAVE_FSYNC ++/* Define to 1 if you have the `tcdrain' function. */ ++#undef HAVE_TCDRAIN + + /* Define to 1 if you have the header file. */ + #undef HAVE_INTTYPES_H +--- screen.c ++++ screen.c 2007-11-14 17:31:21.752727000 +0100 +@@ -431,8 +431,8 @@ raw_mode(on) + */ + s = save_term; + } +-#if HAVE_FSYNC +- fsync(tty); ++#ifdef HAVE_TCDRAIN ++ tcdrain(tty); + #endif + tcsetattr(tty, TCSADRAIN, &s); + #if MUST_SET_LINE_DISCIPLINE diff --git a/less.changes b/less.changes index beee2a8..a0cdea1 100644 --- a/less.changes +++ b/less.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Nov 14 19:10:18 CET 2007 - werner@suse.de + +- Speed up the history save by using a temorary file and make the + stream of that file a full buffered one. + ------------------------------------------------------------------- Wed Oct 31 15:53:34 CET 2007 - anosek@suse.cz diff --git a/less.spec b/less.spec index 188f373..350edeb 100644 --- a/less.spec +++ b/less.spec @@ -21,7 +21,7 @@ Provides: normal-less jless Requires: file AutoReqProv: on Version: 409 -Release: 1 +Release: 5 Summary: Text File Browser and Pager Similar to more Url: http://www.greenwoodsoftware.com/less/ Source: %{name}-%{version}.tar.bz2 @@ -31,6 +31,7 @@ Source3: lessclose.sh Source4: lesskey.src Patch1: %{name}-%{version}.patch Patch2: %{name}-%{version}-lessecho-man.patch +Patch3: %{name}-%{version}-speed.patch Patch22: %{name}-%{version}-strict_aliasing.patch Patch23: %{name}-%{version}-mouse.patch Patch24: %{name}-%{version}-terminate.patch @@ -56,6 +57,7 @@ Authors: %setup -q %patch1 %patch2 +%patch3 %patch22 %patch23 %patch24 @@ -107,6 +109,9 @@ rm -rf $RPM_BUILD_ROOT %config %{sysconfdir}/* %{prefix}/bin/* %changelog +* Wed Nov 14 2007 - werner@suse.de +- Speed up the history save by using a temorary file and make the + stream of that file a full buffered one. * Wed Oct 31 2007 - anosek@suse.cz - udpated to version 409 * fixed crash when searching text containing certain