From f806a0bbc5f5a36327de25e4917b752db9717946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Mon, 24 Aug 2015 16:34:42 +0200 Subject: [PATCH] try to get terminal width from /dev/tty - resolves #1255930 --- ...y-to-get-terminal-width-from-dev-tty.patch | 72 +++++++++++++++++++ man-db.spec | 7 +- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 1255930-try-to-get-terminal-width-from-dev-tty.patch diff --git a/1255930-try-to-get-terminal-width-from-dev-tty.patch b/1255930-try-to-get-terminal-width-from-dev-tty.patch new file mode 100644 index 0000000..0d664b6 --- /dev/null +++ b/1255930-try-to-get-terminal-width-from-dev-tty.patch @@ -0,0 +1,72 @@ +From 80f1dc0fe23b9f6ec9eb2ea7c5a2b654e9840dd9 Mon Sep 17 00:00:00 2001 +From: Colin Watson +Date: Sat, 22 Aug 2015 11:13:11 +0000 +Subject: Try to get terminal width from /dev/tty + +If man is running within something like lesspipe, then there may be +a current tty that neither stdin nor stdout points to. Try to get +hold of it using /dev/tty. Fixes Fedora bug #1255930. + +* lib/linelength.c (get_line_length): Try /dev/tty before either +stdout or stdin. +--- +diff --git a/lib/linelength.c b/lib/linelength.c +index f2632a7..69a702f 100644 +--- a/lib/linelength.c ++++ b/lib/linelength.c +@@ -34,6 +34,13 @@ + #include + #include + #include ++#include ++#include ++#include ++ ++#ifndef _PATH_TTY ++# define _PATH_TTY "/dev/tty" ++#endif /* _PATH_TTY */ + + static int line_length = -1; + +@@ -42,7 +49,7 @@ int get_line_length (void) + const char *columns; + int width; + #ifdef TIOCGWINSZ +- int stdin_tty, stdout_tty; ++ int dev_tty, tty_fd = -1; + #endif + + if (line_length != -1) +@@ -72,14 +79,25 @@ int get_line_length (void) + * may well be because the user is trying something like + * 'MAN_KEEP_STDERR=1 man foo >/dev/null' to see just the error + * messages, so use the window size from stdin as a fallback. ++ * In some cases we may have neither (e.g. if man is running inside ++ * lesspipe); /dev/tty should be a reliable way to get to the ++ * current tty if it exists. + */ +- stdin_tty = isatty (STDIN_FILENO); +- stdout_tty = isatty (STDOUT_FILENO); +- if (stdin_tty || stdout_tty) { ++ dev_tty = open (_PATH_TTY, O_RDONLY); ++ if (dev_tty >= 0) ++ tty_fd = dev_tty; ++ else if (isatty (STDOUT_FILENO)) ++ tty_fd = STDOUT_FILENO; ++ else if (isatty (STDIN_FILENO)) ++ tty_fd = STDIN_FILENO; ++ if (tty_fd >= 0) { ++ int ret; + struct winsize wsz; + +- if (ioctl (stdout_tty ? STDOUT_FILENO : STDIN_FILENO, +- TIOCGWINSZ, &wsz)) ++ ret = ioctl (tty_fd, TIOCGWINSZ, &wsz); ++ if (dev_tty >= 0) ++ close (dev_tty); ++ if (ret) + perror ("TIOCGWINSZ failed"); + else if (wsz.ws_col) + return line_length = wsz.ws_col; +-- +cgit v0.9.0.2 diff --git a/man-db.spec b/man-db.spec index fde7553..95168fc 100644 --- a/man-db.spec +++ b/man-db.spec @@ -4,7 +4,7 @@ Summary: Tools for searching and reading man pages Name: man-db Version: 2.7.2 -Release: 2%{?dist} +Release: 3%{?dist} # GPLv2+ .. man-db # GPLv3+ .. gnulib License: GPLv2+ and GPLv3+ @@ -15,6 +15,7 @@ Source0: http://download.savannah.gnu.org/releases/%{name}/%{name}-%{version}.ta Source1: man-db.crondaily Source2: man-db.sysconfig Patch0: 1151558-switch-man-and-root-in-init-systemd-man-db.conf.patch +Patch1: 1255930-try-to-get-terminal-width-from-dev-tty.patch Obsoletes: man < 2.0 Provides: man = %{version} @@ -134,6 +135,10 @@ fi %lang(zh_CN) %{_datadir}/man/zh_CN/man*/* %changelog +* Mon Aug 24 2015 Nikola Forró - 2.7.2-3 +- try to get terminal width from /dev/tty + resolves #1255930 + * Mon Aug 24 2015 Nikola Forró - 2.7.2-2 - rebuilt with latest libpipeline