]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/pager: Apply pager-specific fixes only when needed
authorDragan Simic <dsimic@manjaro.org>
Tue, 4 Jul 2023 09:14:30 +0000 (11:14 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 11 Jul 2023 09:29:05 +0000 (11:29 +0200)
Currently defined output filter quirk fixes and environment variable
tweaks apply to less(1) only, so let's don't apply them when the pager
is actually configured to something else.

While there, rename the less(1)-specific callback function to make
clear what it applies to, and to make adding any posible additional
pager-specific callback functions a bit easier.

Signed-off-by: Dragan Simic <dsimic@manjaro.org>
lib/pager.c

index db7a989df4bed2a4ed4489623fa49ba111612c6a..98814b54922ad4304e889d5c1e47f9fb799b1a45 100644 (file)
@@ -85,7 +85,9 @@ static int start_command(struct child_process *cmd)
                        close(cmd->in);
                }
 
-               cmd->preexec_cb();
+               if (cmd->preexec_cb)
+                       cmd->preexec_cb();
+
                execvp(cmd->argv[0], (char *const*) cmd->argv);
                errexec(cmd->argv[0]);
        }
@@ -140,7 +142,7 @@ static int finish_command(struct child_process *cmd)
        return wait_or_whine(cmd->pid);
 }
 
-static void pager_preexec(void)
+static void pager_preexec_less(void)
 {
        /*
         * Work around bug in "less" by not starting it until we
@@ -240,7 +242,11 @@ static void __setup_pager(void)
        pager_argv[2] = pager;
        pager_process.argv = pager_argv;
        pager_process.in = -1;
-       pager_process.preexec_cb = pager_preexec;
+
+       if (!strncmp(pager, "less", 4))
+               pager_process.preexec_cb = pager_preexec_less;
+       else
+               pager_process.preexec_cb = NULL;
 
        if (start_command(&pager_process))
                return;