]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/pager: Remove struct field preexec_cb
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 19 Jan 2026 18:09:07 +0000 (19:09 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 20 Jan 2026 16:36:45 +0000 (17:36 +0100)
The struct field preexec_cb is always set to pager_preexec. Simplify the
code by calling this function directly.

Removes function pointer handling.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
lib/pager.c

index cbd08964e82ba34c26622a79a44681894f926c20..b753c5f6d271d56685e62dbe38e808ed2dedbf4e 100644 (file)
@@ -42,7 +42,6 @@ struct child_process {
        struct sigaction orig_sigpipe;
 
        bool no_stdin;
-       void (*preexec_cb)(void);
 };
 static struct child_process pager_process;
 
@@ -52,6 +51,24 @@ static inline void close_pair(int fd[2])
        close(fd[1]);
 }
 
+static void pager_preexec(void)
+{
+       /*
+        * Work around bug in "less" by not starting it until we
+        * have real input
+        */
+       fd_set in, ex;
+
+       FD_ZERO(&in);
+       FD_SET(STDIN_FILENO, &in);
+       ex = in;
+
+       select(STDIN_FILENO + 1, &in, NULL, &ex, NULL);
+
+       if (setenv("LESS", "FRSX", 0) != 0)
+               warn(_("failed to set the %s environment variable"), "LESS");
+}
+
 static int start_command(struct child_process *cmd)
 {
        int need_in;
@@ -79,7 +96,7 @@ static int start_command(struct child_process *cmd)
                        close(cmd->in);
                }
 
-               cmd->preexec_cb();
+               pager_preexec();
                execvp(cmd->argv[0], (char *const*) cmd->argv);
                errexec(cmd->argv[0]);
        }
@@ -134,24 +151,6 @@ static int finish_command(struct child_process *cmd)
        return wait_or_whine(cmd->pid);
 }
 
-static void pager_preexec(void)
-{
-       /*
-        * Work around bug in "less" by not starting it until we
-        * have real input
-        */
-       fd_set in, ex;
-
-       FD_ZERO(&in);
-       FD_SET(STDIN_FILENO, &in);
-       ex = in;
-
-       select(STDIN_FILENO + 1, &in, NULL, &ex, NULL);
-
-       if (setenv("LESS", "FRSX", 0) != 0)
-               warn(_("failed to set the %s environment variable"), "LESS");
-}
-
 static void wait_for_pager(void)
 {
        if (pager_process.pid == 0)
@@ -235,7 +234,6 @@ 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 (start_command(&pager_process))
                return;