summaryrefslogtreecommitdiffstats
path: root/lldb/tools/debugserver/source/PseudoTerminal.cpp
diff options
context:
space:
mode:
authorKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
committerKate Stone <katherine.stone@apple.com>2016-09-06 20:57:50 +0000
commitb9c1b51e45b845debb76d8658edabca70ca56079 (patch)
treedfcb5a13ef2b014202340f47036da383eaee74aa /lldb/tools/debugserver/source/PseudoTerminal.cpp
parentd5aa73376966339caad04013510626ec2e42c760 (diff)
downloadbcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz
bcm5719-llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip
*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has *** two obvious implications: Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751
Diffstat (limited to 'lldb/tools/debugserver/source/PseudoTerminal.cpp')
-rw-r--r--lldb/tools/debugserver/source/PseudoTerminal.cpp199
1 files changed, 84 insertions, 115 deletions
diff --git a/lldb/tools/debugserver/source/PseudoTerminal.cpp b/lldb/tools/debugserver/source/PseudoTerminal.cpp
index f1b505cabd4..616aec989c8 100644
--- a/lldb/tools/debugserver/source/PseudoTerminal.cpp
+++ b/lldb/tools/debugserver/source/PseudoTerminal.cpp
@@ -19,11 +19,8 @@
//----------------------------------------------------------------------
// PseudoTerminal constructor
//----------------------------------------------------------------------
-PseudoTerminal::PseudoTerminal() :
- m_master_fd(invalid_fd),
- m_slave_fd(invalid_fd)
-{
-}
+PseudoTerminal::PseudoTerminal()
+ : m_master_fd(invalid_fd), m_slave_fd(invalid_fd) {}
//----------------------------------------------------------------------
// Destructor
@@ -32,36 +29,29 @@ PseudoTerminal::PseudoTerminal() :
// to release any file descriptors that are needed beyond the lifespan
// of this object.
//----------------------------------------------------------------------
-PseudoTerminal::~PseudoTerminal()
-{
- CloseMaster();
- CloseSlave();
+PseudoTerminal::~PseudoTerminal() {
+ CloseMaster();
+ CloseSlave();
}
//----------------------------------------------------------------------
// Close the master file descriptor if it is valid.
//----------------------------------------------------------------------
-void
-PseudoTerminal::CloseMaster()
-{
- if (m_master_fd > 0)
- {
- ::close (m_master_fd);
- m_master_fd = invalid_fd;
- }
+void PseudoTerminal::CloseMaster() {
+ if (m_master_fd > 0) {
+ ::close(m_master_fd);
+ m_master_fd = invalid_fd;
+ }
}
//----------------------------------------------------------------------
// Close the slave file descriptor if it is valid.
//----------------------------------------------------------------------
-void
-PseudoTerminal::CloseSlave()
-{
- if (m_slave_fd > 0)
- {
- ::close (m_slave_fd);
- m_slave_fd = invalid_fd;
- }
+void PseudoTerminal::CloseSlave() {
+ if (m_slave_fd > 0) {
+ ::close(m_slave_fd);
+ m_slave_fd = invalid_fd;
+ }
}
//----------------------------------------------------------------------
@@ -75,31 +65,26 @@ PseudoTerminal::CloseSlave()
// RETURNS:
// Zero when successful, non-zero indicating an error occurred.
//----------------------------------------------------------------------
-PseudoTerminal::Error
-PseudoTerminal::OpenFirstAvailableMaster(int oflag)
-{
- // Open the master side of a pseudo terminal
- m_master_fd = ::posix_openpt (oflag);
- if (m_master_fd < 0)
- {
- return err_posix_openpt_failed;
- }
+PseudoTerminal::Error PseudoTerminal::OpenFirstAvailableMaster(int oflag) {
+ // Open the master side of a pseudo terminal
+ m_master_fd = ::posix_openpt(oflag);
+ if (m_master_fd < 0) {
+ return err_posix_openpt_failed;
+ }
- // Grant access to the slave pseudo terminal
- if (::grantpt (m_master_fd) < 0)
- {
- CloseMaster();
- return err_grantpt_failed;
- }
+ // Grant access to the slave pseudo terminal
+ if (::grantpt(m_master_fd) < 0) {
+ CloseMaster();
+ return err_grantpt_failed;
+ }
- // Clear the lock flag on the slave pseudo terminal
- if (::unlockpt (m_master_fd) < 0)
- {
- CloseMaster();
- return err_unlockpt_failed;
- }
+ // Clear the lock flag on the slave pseudo terminal
+ if (::unlockpt(m_master_fd) < 0) {
+ CloseMaster();
+ return err_unlockpt_failed;
+ }
- return success;
+ return success;
}
//----------------------------------------------------------------------
@@ -112,27 +97,23 @@ PseudoTerminal::OpenFirstAvailableMaster(int oflag)
// RETURNS:
// Zero when successful, non-zero indicating an error occurred.
//----------------------------------------------------------------------
-PseudoTerminal::Error
-PseudoTerminal::OpenSlave(int oflag)
-{
- CloseSlave();
+PseudoTerminal::Error PseudoTerminal::OpenSlave(int oflag) {
+ CloseSlave();
- // Open the master side of a pseudo terminal
- const char *slave_name = SlaveName();
+ // Open the master side of a pseudo terminal
+ const char *slave_name = SlaveName();
- if (slave_name == NULL)
- return err_ptsname_failed;
+ if (slave_name == NULL)
+ return err_ptsname_failed;
- m_slave_fd = ::open (slave_name, oflag);
+ m_slave_fd = ::open(slave_name, oflag);
- if (m_slave_fd < 0)
- return err_open_slave_failed;
+ if (m_slave_fd < 0)
+ return err_open_slave_failed;
- return success;
+ return success;
}
-
-
//----------------------------------------------------------------------
// Get the name of the slave pseudo terminal. A master pseudo terminal
// should already be valid prior to calling this function (see
@@ -144,15 +125,12 @@ PseudoTerminal::OpenSlave(int oflag)
// that comes from static memory, so a copy of the string should be
// made as subsequent calls can change this value.
//----------------------------------------------------------------------
-const char*
-PseudoTerminal::SlaveName() const
-{
- if (m_master_fd < 0)
- return NULL;
- return ::ptsname (m_master_fd);
+const char *PseudoTerminal::SlaveName() const {
+ if (m_master_fd < 0)
+ return NULL;
+ return ::ptsname(m_master_fd);
}
-
//----------------------------------------------------------------------
// Fork a child process that and have its stdio routed to a pseudo
// terminal.
@@ -175,53 +153,44 @@ PseudoTerminal::SlaveName() const
// in the child process: zero
//----------------------------------------------------------------------
-pid_t
-PseudoTerminal::Fork(PseudoTerminal::Error& error)
-{
- pid_t pid = invalid_pid;
- error = OpenFirstAvailableMaster (O_RDWR|O_NOCTTY);
-
- if (error == 0)
- {
- // Successfully opened our master pseudo terminal
-
- pid = ::fork ();
- if (pid < 0)
- {
- // Fork failed
- error = err_fork_failed;
- }
- else if (pid == 0)
- {
- // Child Process
- ::setsid();
-
- error = OpenSlave (O_RDWR);
- if (error == 0)
- {
- // Successfully opened slave
- // We are done with the master in the child process so lets close it
- CloseMaster ();
-
-#if defined (TIOCSCTTY)
- // Acquire the controlling terminal
- if (::ioctl (m_slave_fd, TIOCSCTTY, (char *)0) < 0)
- error = err_failed_to_acquire_controlling_terminal;
+pid_t PseudoTerminal::Fork(PseudoTerminal::Error &error) {
+ pid_t pid = invalid_pid;
+ error = OpenFirstAvailableMaster(O_RDWR | O_NOCTTY);
+
+ if (error == 0) {
+ // Successfully opened our master pseudo terminal
+
+ pid = ::fork();
+ if (pid < 0) {
+ // Fork failed
+ error = err_fork_failed;
+ } else if (pid == 0) {
+ // Child Process
+ ::setsid();
+
+ error = OpenSlave(O_RDWR);
+ if (error == 0) {
+ // Successfully opened slave
+ // We are done with the master in the child process so lets close it
+ CloseMaster();
+
+#if defined(TIOCSCTTY)
+ // Acquire the controlling terminal
+ if (::ioctl(m_slave_fd, TIOCSCTTY, (char *)0) < 0)
+ error = err_failed_to_acquire_controlling_terminal;
#endif
- // Duplicate all stdio file descriptors to the slave pseudo terminal
- if (::dup2 (m_slave_fd, STDIN_FILENO) != STDIN_FILENO)
- error = error ? error : err_dup2_failed_on_stdin;
- if (::dup2 (m_slave_fd, STDOUT_FILENO) != STDOUT_FILENO)
- error = error ? error : err_dup2_failed_on_stdout;
- if (::dup2 (m_slave_fd, STDERR_FILENO) != STDERR_FILENO)
- error = error ? error : err_dup2_failed_on_stderr;
- }
- }
- else
- {
- // Parent Process
- // Do nothing and let the pid get returned!
- }
+ // Duplicate all stdio file descriptors to the slave pseudo terminal
+ if (::dup2(m_slave_fd, STDIN_FILENO) != STDIN_FILENO)
+ error = error ? error : err_dup2_failed_on_stdin;
+ if (::dup2(m_slave_fd, STDOUT_FILENO) != STDOUT_FILENO)
+ error = error ? error : err_dup2_failed_on_stdout;
+ if (::dup2(m_slave_fd, STDERR_FILENO) != STDERR_FILENO)
+ error = error ? error : err_dup2_failed_on_stderr;
+ }
+ } else {
+ // Parent Process
+ // Do nothing and let the pid get returned!
}
- return pid;
+ }
+ return pid;
}
OpenPOWER on IntegriCloud