man-db-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Man-db-devel] [PATCH] Add fallback pager if the compile time default is


From: nsajko
Subject: [Man-db-devel] [PATCH] Add fallback pager if the compile time default is not executable
Date: Fri, 15 Dec 2017 23:06:07 -0800 (PST)

diff --git a/src/man.c b/src/man.c
index 6bc9642c..a3b72b96 100644
--- a/src/man.c
+++ b/src/man.c
@@ -4020,6 +4020,22 @@ static const char **get_section_list (void)
        }
 }

+static int configuredPagerIsExecutable(void)
+{
+       // The sh script to check PAGER executability.
+       //
+       // We are being quite paranoid with the unalias and unset. They guard
+       // from an sh implementation which allows exporting or initializing
+       // aliased names or functions, and the unlikely possibility of 'command'
+       // being spoofed by such an exported aliased name or function.
+       char command[] =
+               "\\unset -f unalias command less more cat\n"
+               "\\unalias -a\n"
+               "\\command -v " PAGER " 1>/dev/null 2>/dev/null\n";
+
+       return system (command) == 0;
+}
+
 int main (int argc, char *argv[])
 {
        int argc_env, exit_status = OK;
@@ -4119,8 +4135,16 @@ int main (int argc, char *argv[])
                pager = getenv ("MANPAGER");
                if (pager == NULL) {
                        pager = getenv ("PAGER");
-                       if (pager == NULL)
-                               pager = get_def_user ("pager", PAGER);
+                       if (pager == NULL) {
+                               pager = get_def_user ("pager", NULL);
+                               if (pager == NULL) {
+                                       if (configuredPagerIsExecutable ()) {
+                                               pager = PAGER;
+                                       } else {
+                                               pager = "";
+                                       }
+                               }
+                       }
                }
        }
        if (*pager == '\0')



The same patch, now with a message ;)

A problem with man-db's man is that in the case of the user giving no
configuration via conf files, argv, or environment variables; man
defaults to less as pager (PAGER); but less may not be present on the
system. Sure, other pagers may be selected in aforementioned ways, but
then the defaults are overrided, making that unsuitable for
install-time configuration.

This patch makes man check (if that becomes relevant) if PAGER is
executable, further defaulting to cat (which is basically ubiquitous,
being in original Unix, POSIX, and GNU Coreutils) if it is not. Thus
the poor beginner Unix users without less installed will  be able to
get man pages.

Regards,
Neven

reply via email to

[Prev in Thread] Current Thread [Next in Thread]