summaryrefslogtreecommitdiff
path: root/apt-private/private-utils.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@ubuntu.com>2014-10-27 15:57:12 +0100
committerMichael Vogt <mvo@ubuntu.com>2014-10-27 15:57:12 +0100
commite29a7a394cfd41e8bad81535e0a8c07654f34bf6 (patch)
treec317e2f45aa1c96300028fb830555f248db5771e /apt-private/private-utils.cc
parentbc5095b7d708c7e376f98be6edc2ad7cceca57ed (diff)
parent28460cb27846b2437010b08adf10bde18e370974 (diff)
Merge remote-tracking branch 'upstream/debian/sid' into debian/sid
Diffstat (limited to 'apt-private/private-utils.cc')
-rw-r--r--apt-private/private-utils.cc58
1 files changed, 41 insertions, 17 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);
}
/*}}}*/