This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=ce9b2e88602dcdff93963b9cb8aef302179b81c9

commit ce9b2e88602dcdff93963b9cb8aef302179b81c9
Author: Guillem Jover <[email protected]>
AuthorDate: Fri Oct 5 02:01:28 2018 +0200

    libdpkg: Pass the file contents to the pager instead of the filename
    
    Let's just handle opening the file and passing its data to the pager
    ourselves, as that gives us more control, and then can decide not to
    run a pager at all, and do not need to mess with arguments which might
    need to be passed to «sh -c».
---
 debian/changelog |  1 +
 lib/dpkg/file.c  | 17 ++++++++++++++++-
 lib/dpkg/pager.c |  5 ++---
 lib/dpkg/pager.h |  2 +-
 src/configure.c  |  2 +-
 src/querycmd.c   |  2 +-
 6 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 52a48cc4c..eb7c52735 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -30,6 +30,7 @@ dpkg (1.19.2) UNRELEASED; urgency=medium
   * Code internals:
     - dpkg-split: Use nfstrnsave() instead of nfmalloc() + memcpy().
     - libdpkg: Add new fsys-dir module.
+    - libdpkg: Pass the file contents to the pager instead of the filename.
   * Build system:
     - Distribute a LICENSE file on CPAN.
     - Do not make the Build.PL script executable.
diff --git a/lib/dpkg/file.c b/lib/dpkg/file.c
index 4b3a24fed..a949bd49e 100644
--- a/lib/dpkg/file.c
+++ b/lib/dpkg/file.c
@@ -33,6 +33,7 @@
 #include <dpkg/i18n.h>
 #include <dpkg/pager.h>
 #include <dpkg/fdio.h>
+#include <dpkg/buffer.h>
 #include <dpkg/file.h>
 
 /**
@@ -200,10 +201,24 @@ void
 file_show(const char *filename)
 {
        struct pager *pager;
+       struct dpkg_error err;
+       int fd, rc;
 
        if (filename == NULL)
                internerr("filename is NULL");
 
-       pager = pager_spawn(_("pager to show file"), filename);
+       fd = open(filename, O_RDONLY);
+       if (fd < 0)
+               ohshite(_("cannot open file %s"), filename);
+
+       pager = pager_spawn(_("pager to show file"));
+       rc = fd_fd_copy(fd, STDOUT_FILENO, -1, &err);
        pager_reap(pager);
+
+       close(fd);
+
+       if (rc < 0 && err.syserrno != EPIPE) {
+               errno = err.syserrno;
+               ohshite(_("cannot write file %s into the pager"), filename);
+       }
 }
diff --git a/lib/dpkg/pager.c b/lib/dpkg/pager.c
index c9adf5bce..bdbce06c9 100644
--- a/lib/dpkg/pager.c
+++ b/lib/dpkg/pager.c
@@ -63,12 +63,12 @@ struct pager {
 };
 
 struct pager *
-pager_spawn(const char *desc, const char *filename)
+pager_spawn(const char *desc)
 {
        struct pager *pager;
 
        pager = m_calloc(1, sizeof(*pager));
-       pager->used = filename || (isatty(0) && isatty(1));
+       pager->used = isatty(0) && isatty(1);
        pager->desc = desc;
 
        if (!pager->used)
@@ -89,7 +89,6 @@ pager_spawn(const char *desc, const char *filename)
 
                command_init(&cmd, exec, desc);
                command_add_arg(&cmd, exec);
-               command_add_arg(&cmd, filename);
                command_exec(&cmd);
        }
 
diff --git a/lib/dpkg/pager.h b/lib/dpkg/pager.h
index 7d7ea0dff..34bcf2fd5 100644
--- a/lib/dpkg/pager.h
+++ b/lib/dpkg/pager.h
@@ -37,7 +37,7 @@ const char *
 pager_get_exec(void);
 
 struct pager *
-pager_spawn(const char *desc, const char *filename);
+pager_spawn(const char *desc);
 
 void
 pager_reap(struct pager *pager);
diff --git a/src/configure.c b/src/configure.c
index 66019071b..0da9723f6 100644
--- a/src/configure.c
+++ b/src/configure.c
@@ -201,7 +201,7 @@ show_diff(const char *old, const char *new)
        struct pager *pager;
        pid_t pid;
 
-       pager = pager_spawn(_("conffile difference visualizer"), NULL);
+       pager = pager_spawn(_("conffile difference visualizer"));
 
        pid = subproc_fork();
        if (!pid) {
diff --git a/src/querycmd.c b/src/querycmd.c
index 415235bff..a62b27655 100644
--- a/src/querycmd.c
+++ b/src/querycmd.c
@@ -265,7 +265,7 @@ listpackages(const char *const *argv)
 
   memset(&fmt, 0, sizeof(fmt));
 
-  pager = pager_spawn(_("showing package list on pager"), NULL);
+  pager = pager_spawn(_("showing package list on pager"));
 
   if (!*argv) {
     for (i = 0; i < array.n_pkgs; i++) {

-- 
Dpkg.Org's dpkg

Reply via email to