This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=0802cf6f4ed444b377cd68dd0a85cd36e8c88143 commit 0802cf6f4ed444b377cd68dd0a85cd36e8c88143 Author: Guillem Jover <[email protected]> AuthorDate: Sun Aug 4 14:08:01 2024 +0200 libdpkg: Check for pager presence and fallback to less, more and cat If the PAGER pointed by the environment variable is not present, fallback to use DPKG_DEFAULT_PAGER («pager»), otherwise try «less», then «more», and finally fallback to «cat». This should cover the cases where these programs are either not present or they are a dangling symlink during an upgrade. Closes: #856216 --- lib/dpkg/dpkg.h | 2 ++ lib/dpkg/pager.c | 28 +++++++++++++++++++++------- man/dpkg-query.pod | 7 +++++++ man/dpkg.pod | 7 +++++++ 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/lib/dpkg/dpkg.h b/lib/dpkg/dpkg.h index ee6fd3b00..c832359ef 100644 --- a/lib/dpkg/dpkg.h +++ b/lib/dpkg/dpkg.h @@ -107,6 +107,8 @@ DPKG_BEGIN_DECLS #define DEBSIGVERIFY "debsig-verify" #define RM "rm" +#define LESS "less" +#define MORE "more" #define CAT "cat" #define DIFF "diff" diff --git a/lib/dpkg/pager.c b/lib/dpkg/pager.c index 08eb8d028..7a07069a3 100644 --- a/lib/dpkg/pager.c +++ b/lib/dpkg/pager.c @@ -52,18 +52,32 @@ pager_enable(bool enable) const char * pager_get_exec(void) { - const char *pager; + const char *envvars[] = { + "DPKG_PAGER", + "PAGER", + }; + const char *fallback[] = { + DPKG_DEFAULT_PAGER, + LESS, + MORE, + }; + size_t i; if (!isatty(0) || !isatty(1)) return CAT; - pager = getenv("DPKG_PAGER"); - if (str_is_unset(pager)) - pager = getenv("PAGER"); - if (str_is_unset(pager)) - pager = DPKG_DEFAULT_PAGER; + for (i = 0; i < array_count(envvars); i++) { + const char *pager = getenv(envvars[i]); - return pager; + if (str_is_set(pager) && command_in_path(pager)) + return pager; + } + + for (i = 0; i < array_count(fallback); i++) + if (command_in_path(fallback[i])) + return fallback[i]; + + return CAT; } struct pager { diff --git a/man/dpkg-query.pod b/man/dpkg-query.pod index e45d8bf92..7ceec09a2 100644 --- a/man/dpkg-query.pod +++ b/man/dpkg-query.pod @@ -527,8 +527,15 @@ Sets the program to execute when spawning a command via a shell Sets the pager command to use (since dpkg 1.19.1), which will be executed with «B<$SHELL -c>». If B<SHELL> is not set, «B<%DPKG_DEFAULT_SHELL%>» will be used instead. + The B<DPKG_PAGER> overrides the B<PAGER> environment variable (since dpkg 1.19.2). +If none of the programs pointed by B<DPKG_PAGER> or B<PAGER> are present, +the following programs will be tried in order (since dpkg 1.22.12): +the default pager B<%DPKG_DEFAULT_PAGER%>, +then B<less>, +B<more>, +and finally B<cat>. =item B<DPKG_ROOT> diff --git a/man/dpkg.pod b/man/dpkg.pod index a9795a4d6..97efad46d 100644 --- a/man/dpkg.pod +++ b/man/dpkg.pod @@ -1353,8 +1353,15 @@ The program B<dpkg> will execute when running a pager, which will be executed with «B<$SHELL -c>», for example when displaying the conffile differences. If B<SHELL> is not set, «B<%DPKG_DEFAULT_SHELL%>» will be used instead. + The B<DPKG_PAGER> overrides the B<PAGER> environment variable (since dpkg 1.19.2). +If none of the programs pointed by B<DPKG_PAGER> or B<PAGER> are present, +the following programs will be tried in order (since dpkg 1.22.12): +the default pager B<%DPKG_DEFAULT_PAGER%>, +then B<less>, +B<more>, +and finally B<cat>. =item B<DPKG_COLORS> -- Dpkg.Org's dpkg

