aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-19 19:03:44 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-21 14:58:15 +0100
commitadda76229c6a59054e137fcc3120891d2c1aa9c8 (patch)
tree88dcb9f019b822e82b76766c3e0379baf5ade42f
parent7c6ec0fd835409d0ab1bca8924ce4ac5916b4e25 (diff)
downloadpaludis-adda76229c6a59054e137fcc3120891d2c1aa9c8.tar.gz
paludis-adda76229c6a59054e137fcc3120891d2c1aa9c8.tar.xz
Allow Pty to O_CLOEXEC
-rw-r--r--paludis/util/pty.cc19
-rw-r--r--paludis/util/pty.hh6
2 files changed, 20 insertions, 5 deletions
diff --git a/paludis/util/pty.cc b/paludis/util/pty.cc
index 7973456..294f54b 100644
--- a/paludis/util/pty.cc
+++ b/paludis/util/pty.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2006, 2007, 2008 Ciaran McCreesh
+ * Copyright (c) 2006, 2007, 2008, 2010 Ciaran McCreesh
* Copyright (c) 2009 David Leverton
*
* This file is part of the Paludis package manager. Paludis is free software;
@@ -40,9 +40,20 @@ PtyError::PtyError(const std::string & our_message) throw () :
Pty::Pty()
{
+ _init(false);
+}
+
+Pty::Pty(const bool close_exec)
+{
+ _init(close_exec);
+}
+
+void
+Pty::_init(const bool close_exec)
+{
Context context("When creating pty FDs:");
- _fds[0] = posix_openpt(O_RDWR | O_NOCTTY);
+ _fds[0] = posix_openpt(O_RDWR | O_NOCTTY | (close_exec ? O_CLOEXEC : 0));
if (-1 == _fds[0])
throw PtyError("posix_openpt(3) failed (is /dev/pts mounted?): " + std::string(std::strerror(errno)));
if (-1 == grantpt(_fds[0]))
@@ -69,7 +80,7 @@ Pty::Pty()
throw PtyError("ptsname_r(3) failed: " + std::string(std::strerror(errno)));
}
}
- _fds[1] = open(&name[0], O_WRONLY | O_NOCTTY);
+ _fds[1] = open(&name[0], O_WRONLY | O_NOCTTY | (close_exec ? O_CLOEXEC : 0));
#else
const char * name(ptsname(_fds[0]));
if (0 == name)
@@ -77,7 +88,7 @@ Pty::Pty()
close(_fds[0]);
throw PtyError("ptsname(3) failed: " + std::string(std::strerror(errno)));
}
- _fds[1] = open(name, O_WRONLY | O_NOCTTY);
+ _fds[1] = open(name, O_WRONLY | O_NOCTTY | (close_exec ? O_CLOEXEC : 0));
#endif
if (-1 == _fds[1])
diff --git a/paludis/util/pty.hh b/paludis/util/pty.hh
index 0870f9f..94406fe 100644
--- a/paludis/util/pty.hh
+++ b/paludis/util/pty.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2006, 2007 Ciaran McCreesh
+ * Copyright (c) 2006, 2007, 2010 Ciaran McCreesh
* Copyright (c) 2009 David Leverton
*
* This file is part of the Paludis package manager. Paludis is free software;
@@ -64,11 +64,15 @@ namespace paludis
class PALUDIS_VISIBLE Pty :
public Channel
{
+ private:
+ void _init(const bool);
+
public:
///\name Basic operations
///\{
Pty();
+ explicit Pty(const bool close_exec);
virtual ~Pty();