@@ -94,31 +94,16 @@ llvm::Error PseudoTerminal::OpenFirstAvailablePrimary(int oflag) {
94
94
#endif
95
95
}
96
96
97
- // Open the secondary pseudo terminal for the current primary pseudo terminal. A
98
- // primary pseudo terminal should already be valid prior to calling this
99
- // function (see OpenFirstAvailablePrimary()). The file descriptor is stored
100
- // this object's member variables and can be accessed via the
101
- // GetSecondaryFileDescriptor(), or released using the
102
- // ReleaseSecondaryFileDescriptor() member function.
103
- //
104
- // RETURNS:
105
- // True when successful, false indicating an error occurred.
106
- bool PseudoTerminal::OpenSecondary (int oflag, char *error_str,
107
- size_t error_len) {
108
- if (error_str)
109
- error_str[0 ] = ' \0 ' ;
110
-
97
+ llvm::Error PseudoTerminal::OpenSecondary (int oflag) {
111
98
CloseSecondaryFileDescriptor ();
112
99
113
100
std::string name = GetSecondaryName ();
114
101
m_secondary_fd = llvm::sys::RetryAfterSignal (-1 , ::open, name.c_str (), oflag);
115
- if (m_secondary_fd < 0 ) {
116
- if (error_str)
117
- ErrnoToStr (error_str, error_len);
118
- return false ;
119
- }
102
+ if (m_secondary_fd >= 0 )
103
+ return llvm::Error::success ();
120
104
121
- return true ;
105
+ return llvm::errorCodeToError (
106
+ std::error_code (errno, std::generic_category ()));
122
107
}
123
108
124
109
std::string PseudoTerminal::GetSecondaryName () const {
@@ -174,35 +159,36 @@ lldb::pid_t PseudoTerminal::Fork(char *error_str, size_t error_len) {
174
159
// Child Process
175
160
::setsid ();
176
161
177
- if (OpenSecondary (O_RDWR, error_str, error_len)) {
178
- // Successfully opened secondary
162
+ if (llvm::Error Err = OpenSecondary (O_RDWR)) {
163
+ snprintf (error_str, error_len, " %s" , toString (std::move (Err)).c_str ());
164
+ return LLDB_INVALID_PROCESS_ID;
165
+ }
179
166
180
- // Primary FD should have O_CLOEXEC set, but let's close it just in
181
- // case...
182
- ClosePrimaryFileDescriptor ();
167
+ // Primary FD should have O_CLOEXEC set, but let's close it just in
168
+ // case...
169
+ ClosePrimaryFileDescriptor ();
183
170
184
171
#if defined(TIOCSCTTY)
185
- // Acquire the controlling terminal
186
- if (::ioctl (m_secondary_fd, TIOCSCTTY, (char *)0 ) < 0 ) {
187
- if (error_str)
188
- ErrnoToStr (error_str, error_len);
189
- }
172
+ // Acquire the controlling terminal
173
+ if (::ioctl (m_secondary_fd, TIOCSCTTY, (char *)0 ) < 0 ) {
174
+ if (error_str)
175
+ ErrnoToStr (error_str, error_len);
176
+ }
190
177
#endif
191
- // Duplicate all stdio file descriptors to the secondary pseudo terminal
192
- if (::dup2 (m_secondary_fd, STDIN_FILENO) != STDIN_FILENO) {
193
- if (error_str && !error_str[0 ])
194
- ErrnoToStr (error_str, error_len);
195
- }
196
-
197
- if (::dup2 (m_secondary_fd, STDOUT_FILENO) != STDOUT_FILENO) {
198
- if (error_str && !error_str[0 ])
199
- ErrnoToStr (error_str, error_len);
200
- }
201
-
202
- if (::dup2 (m_secondary_fd, STDERR_FILENO) != STDERR_FILENO) {
203
- if (error_str && !error_str[0 ])
204
- ErrnoToStr (error_str, error_len);
205
- }
178
+ // Duplicate all stdio file descriptors to the secondary pseudo terminal
179
+ if (::dup2 (m_secondary_fd, STDIN_FILENO) != STDIN_FILENO) {
180
+ if (error_str && !error_str[0 ])
181
+ ErrnoToStr (error_str, error_len);
182
+ }
183
+
184
+ if (::dup2 (m_secondary_fd, STDOUT_FILENO) != STDOUT_FILENO) {
185
+ if (error_str && !error_str[0 ])
186
+ ErrnoToStr (error_str, error_len);
187
+ }
188
+
189
+ if (::dup2 (m_secondary_fd, STDERR_FILENO) != STDERR_FILENO) {
190
+ if (error_str && !error_str[0 ])
191
+ ErrnoToStr (error_str, error_len);
206
192
}
207
193
} else {
208
194
// Parent Process
0 commit comments