diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp index 83070a9bb0..7a4f31ab45 100644 --- a/Applications/Terminal/main.cpp +++ b/Applications/Terminal/main.cpp @@ -202,9 +202,17 @@ int main(int argc, char** argv) if (chdir(get_current_user_home_path().characters()) < 0) perror("chdir"); - int ptm_fd = open("/dev/ptmx", O_RDWR | O_CLOEXEC); + int ptm_fd = posix_openpt(O_RDWR | O_CLOEXEC); if (ptm_fd < 0) { - perror("open(ptmx)"); + perror("posix_openpt"); + return 1; + } + if (grantpt(ptm_fd) < 0) { + perror("grantpt"); + return 1; + } + if (unlockpt(ptm_fd) < 0) { + perror("unlockpt"); return 1; } diff --git a/DevTools/HackStudio/TerminalWrapper.cpp b/DevTools/HackStudio/TerminalWrapper.cpp index e7c5e192f9..89106673ca 100644 --- a/DevTools/HackStudio/TerminalWrapper.cpp +++ b/DevTools/HackStudio/TerminalWrapper.cpp @@ -52,9 +52,17 @@ void TerminalWrapper::run_command(const String& command) return; } - int ptm_fd = open("/dev/ptmx", O_RDWR | O_CLOEXEC); + int ptm_fd = posix_openpt(O_RDWR | O_CLOEXEC); if (ptm_fd < 0) { - perror("open(ptmx)"); + perror("posix_openpt"); + ASSERT_NOT_REACHED(); + } + if (grantpt(ptm_fd) < 0) { + perror("grantpt"); + ASSERT_NOT_REACHED(); + } + if (unlockpt(ptm_fd) < 0) { + perror("unlockpt"); ASSERT_NOT_REACHED(); } diff --git a/Libraries/LibC/stdlib.cpp b/Libraries/LibC/stdlib.cpp index 43b6e83ba7..925e8882e5 100644 --- a/Libraries/LibC/stdlib.cpp +++ b/Libraries/LibC/stdlib.cpp @@ -746,4 +746,26 @@ char* realpath(const char* pathname, char* buffer) errno = 0; return buffer; } + +int posix_openpt(int flags) +{ + if (flags & ~(O_RDWR | O_NOCTTY | O_CLOEXEC)) { + errno = EINVAL; + return -1; + } + + return open("/dev/ptmx", flags); +} + +int grantpt(int fd) +{ + (void)fd; + return 0; +} + +int unlockpt(int fd) +{ + (void)fd; + return 0; +} } diff --git a/Libraries/LibC/stdlib.h b/Libraries/LibC/stdlib.h index 69416a6df0..e9f987b3b0 100644 --- a/Libraries/LibC/stdlib.h +++ b/Libraries/LibC/stdlib.h @@ -100,4 +100,8 @@ typedef struct { } ldiv_t; ldiv_t ldiv(long, long); +int posix_openpt(int flags); +int grantpt(int fd); +int unlockpt(int fd); + __END_DECLS diff --git a/Servers/TelnetServer/main.cpp b/Servers/TelnetServer/main.cpp index fbfddbae7d..efa8468454 100644 --- a/Servers/TelnetServer/main.cpp +++ b/Servers/TelnetServer/main.cpp @@ -143,9 +143,19 @@ int main(int argc, char** argv) return; } - int ptm_fd = open("/dev/ptmx", O_RDWR); + int ptm_fd = posix_openpt(O_RDWR); if (ptm_fd < 0) { - perror("open(ptmx)"); + perror("posix_openpt"); + client_socket->close(); + return; + } + if (grantpt(ptm_fd) < 0) { + perror("grantpt"); + client_socket->close(); + return; + } + if (unlockpt(ptm_fd) < 0) { + perror("unlockpt"); client_socket->close(); return; }