aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-19 19:03:51 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-21 14:58:16 +0100
commit322fc9a9acd2cfed2c3b7c70ee022e34fc1fd1f7 (patch)
treee9f6943b1c3f007e2c70cea75336a6278f0e5ef4
parent1bb84c09850dcf2136bc9134ead3409a3ccaf547 (diff)
downloadpaludis-322fc9a9acd2cfed2c3b7c70ee022e34fc1fd1f7.tar.gz
paludis-322fc9a9acd2cfed2c3b7c70ee022e34fc1fd1f7.tar.xz
Process::use_ptys
-rw-r--r--paludis/util/process.cc24
-rw-r--r--paludis/util/process.hh1
-rw-r--r--paludis/util/process_TEST.cc30
3 files changed, 51 insertions, 4 deletions
diff --git a/paludis/util/process.cc b/paludis/util/process.cc
index 0da85b0..f93eeb8 100644
--- a/paludis/util/process.cc
+++ b/paludis/util/process.cc
@@ -21,6 +21,7 @@
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/thread.hh>
#include <paludis/util/pipe.hh>
+#include <paludis/util/pty.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/stringify.hh>
@@ -100,10 +101,10 @@ namespace paludis
Pipe ctl_pipe;
std::ostream * capture_stdout;
- std::unique_ptr<Pipe> capture_stdout_pipe;
+ std::unique_ptr<Channel> capture_stdout_pipe;
std::ostream * capture_stderr;
- std::unique_ptr<Pipe> capture_stderr_pipe;
+ std::unique_ptr<Channel> capture_stderr_pipe;
/* must be last, so the thread gets join()ed before its FDs vanish */
std::unique_ptr<Thread> thread;
@@ -204,6 +205,7 @@ namespace paludis
ProcessCommand command;
bool need_thread;
+ bool use_ptys;
std::ostream * capture_stdout;
std::ostream * capture_stderr;
@@ -213,6 +215,7 @@ namespace paludis
Imp(ProcessCommand && c) :
command(std::move(c)),
need_thread(false),
+ use_ptys(false),
capture_stdout(0),
capture_stderr(0)
{
@@ -240,13 +243,19 @@ Process::run()
if (_imp->capture_stdout)
{
thread->capture_stdout = _imp->capture_stdout;
- thread->capture_stdout_pipe.reset(new Pipe(true));
+ if (_imp->use_ptys)
+ thread->capture_stdout_pipe.reset(new Pty(true));
+ else
+ thread->capture_stdout_pipe.reset(new Pipe(true));
}
if (_imp->capture_stderr)
{
thread->capture_stderr = _imp->capture_stderr;
- thread->capture_stderr_pipe.reset(new Pipe(true));
+ if (_imp->use_ptys)
+ thread->capture_stderr_pipe.reset(new Pty(true));
+ else
+ thread->capture_stderr_pipe.reset(new Pipe(true));
}
}
@@ -323,6 +332,13 @@ Process::chdir(const FSEntry & f)
return *this;
}
+Process &
+Process::use_ptys()
+{
+ _imp->use_ptys = true;
+ return *this;
+}
+
namespace paludis
{
template <>
diff --git a/paludis/util/process.hh b/paludis/util/process.hh
index 6e71264..0478b9b 100644
--- a/paludis/util/process.hh
+++ b/paludis/util/process.hh
@@ -76,6 +76,7 @@ namespace paludis
Process & capture_stderr(std::ostream &);
Process & setenv(const std::string &, const std::string &);
Process & chdir(const FSEntry &);
+ Process & use_ptys();
};
class PALUDIS_VISIBLE RunningProcessHandle :
diff --git a/paludis/util/process_TEST.cc b/paludis/util/process_TEST.cc
index a882151..1c344b0 100644
--- a/paludis/util/process_TEST.cc
+++ b/paludis/util/process_TEST.cc
@@ -178,5 +178,35 @@ namespace test_cases
TEST_CHECK_EQUAL(stdout_stream.str(), "/\n");
}
} test_chdir;
+
+ struct NoPtyTest : TestCase
+ {
+ NoPtyTest() : TestCase("no pty") { }
+
+ void run()
+ {
+ std::stringstream stdout_stream, stderr_stream;
+ Process test_t_process(ProcessCommand({"test", "-t", "1", "-o", "-t", "2"}));
+ test_t_process.capture_stdout(stdout_stream);
+ test_t_process.capture_stderr(stderr_stream);
+ TEST_CHECK_EQUAL(test_t_process.run().wait(), 1);
+ }
+ } test_no_pty;
+
+ struct PtyTest : TestCase
+ {
+ PtyTest() : TestCase("pty") { }
+
+ void run()
+ {
+ std::stringstream stdout_stream, stderr_stream;
+ Process test_t_process(ProcessCommand({"test", "-t", "1", "-a", "-t", "2"}));
+ test_t_process.capture_stdout(stdout_stream);
+ test_t_process.capture_stderr(stderr_stream);
+ test_t_process.use_ptys();
+
+ TEST_CHECK_EQUAL(test_t_process.run().wait(), 0);
+ }
+ } test_ptys;
}