summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2014-09-09 13:52:32 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2014-09-09 13:52:32 +0200
commit22da5c135a74eee8ed998806136e25b8ed038bd0 (patch)
tree2b142f8ad7fab6b1108070bf33b61abcbbf69d32
parent223ae57d468fdcac451209a095047a07a5698212 (diff)
don't call pager in non-terminals for changelog
Most pagers are nice and default to running non-interactively if they aren't connected to a terminal and we relied on that. On ci.debian.net the configured pager is printing a header out of nowhere though, so if we are printing to a non-terminal we call "cat" instead. In the rework we also "remove" the dependency on sensible-utils in sofar as we call some alternatives if calling the utils fail. This seems to be the last problem preventing a "PASS" status on ci.debian.net, so we close the associated bugreport. Closes: 755040
-rw-r--r--apt-private/private-utils.cc58
-rw-r--r--apt-private/private-utils.h4
-rwxr-xr-xtest/integration/test-apt-get-changelog5
3 files changed, 45 insertions, 22 deletions
diff --git a/apt-private/private-utils.cc b/apt-private/private-utils.cc
index 9547a1b75..34af83c08 100644
--- a/apt-private/private-utils.cc
+++ b/apt-private/private-utils.cc
@@ -8,45 +8,69 @@
#include <cstdlib>
#include <unistd.h>
-// DisplayFileInPager - Display File with pager /*{{{*/
-void DisplayFileInPager(std::string filename)
+// DisplayFileInPager - Display File with pager /*{{{*/
+void DisplayFileInPager(std::string const &filename)
{
- std::string pager = _config->Find("Dir::Bin::Pager",
- "/usr/bin/sensible-pager");
-
pid_t Process = ExecFork();
if (Process == 0)
{
const char *Args[3];
- Args[0] = pager.c_str();
Args[1] = filename.c_str();
- Args[2] = 0;
+ Args[2] = NULL;
+ if (isatty(STDOUT_FILENO) == 1)
+ {
+ // likely installed, provided by sensible-utils
+ std::string const pager = _config->Find("Dir::Bin::Pager",
+ "sensible-pager");
+ Args[0] = pager.c_str();
+ execvp(Args[0],(char **)Args);
+ // lets try some obvious alternatives
+ Args[0] = getenv("PAGER");
+ if (Args[0] != NULL)
+ execvp(Args[0],(char **)Args);
+
+ Args[0] = "pager";
+ execvp(Args[0],(char **)Args);
+ }
+ // we could read the file ourselves, but… meh
+ Args[0] = "cat";
execvp(Args[0],(char **)Args);
exit(100);
}
-
+
// Wait for the subprocess
- ExecWait(Process, "sensible-pager", false);
+ ExecWait(Process, "pager", false);
}
/*}}}*/
-// EditFileInSensibleEditor - Edit File with editor /*{{{*/
-void EditFileInSensibleEditor(std::string filename)
+// EditFileInSensibleEditor - Edit File with editor /*{{{*/
+void EditFileInSensibleEditor(std::string const &filename)
{
- std::string editor = _config->Find("Dir::Bin::Editor",
- "/usr/bin/sensible-editor");
-
pid_t Process = ExecFork();
if (Process == 0)
{
+ // likely installed, provided by sensible-utils
+ std::string const editor = _config->Find("Dir::Bin::Editor",
+ "sensible-editor");
const char *Args[3];
Args[0] = editor.c_str();
Args[1] = filename.c_str();
- Args[2] = 0;
+ Args[2] = NULL;
+ execvp(Args[0],(char **)Args);
+ // the usual suspects we can try as an alternative
+ Args[0] = getenv("VISUAL");
+ if (Args[0] != NULL)
+ execvp(Args[0],(char **)Args);
+
+ Args[0] = getenv("EDITOR");
+ if (Args[0] != NULL)
+ execvp(Args[0],(char **)Args);
+
+ Args[0] = "editor";
execvp(Args[0],(char **)Args);
exit(100);
}
-
+
// Wait for the subprocess
- ExecWait(Process, "sensible-editor", false);
+ ExecWait(Process, "editor", false);
}
/*}}}*/
diff --git a/apt-private/private-utils.h b/apt-private/private-utils.h
index 432699787..8ba480bd4 100644
--- a/apt-private/private-utils.h
+++ b/apt-private/private-utils.h
@@ -5,7 +5,7 @@
#include <string>
-APT_PUBLIC void DisplayFileInPager(std::string filename);
-APT_PUBLIC void EditFileInSensibleEditor(std::string filename);
+APT_PUBLIC void DisplayFileInPager(std::string const &filename);
+APT_PUBLIC void EditFileInSensibleEditor(std::string const &filename);
#endif
diff --git a/test/integration/test-apt-get-changelog b/test/integration/test-apt-get-changelog
index a73c3e249..4ee113482 100755
--- a/test/integration/test-apt-get-changelog
+++ b/test/integration/test-apt-get-changelog
@@ -28,9 +28,8 @@ testsuccess aptget changelog apt -d
testfileequal 'apt.changelog' "$(cat aptarchive/pool/apt_1.0/changelog)"
rm apt.changelog aptarchive/pool/apt_1.0/changelog
-aptget changelog apt -qq -o APT::Changelogs::Server='http://not-on-the-main-server:8080/' > apt.changelog
-testfileequal 'apt.changelog' "$(cat aptarchive/pool/apt_1.0.changelog)"
-rm apt.changelog
+testequal "$(cat aptarchive/pool/apt_1.0.changelog)" aptget changelog apt \
+ -qq -o APT::Changelogs::Server='http://not-on-the-main-server:8080/'
testsuccess aptget changelog apt -d
testfileequal 'apt.changelog' "$(cat aptarchive/pool/apt_1.0.changelog)"