summaryrefslogtreecommitdiff
path: root/Servers
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-05 21:17:41 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-05 21:17:41 +0100
commitf2a087126c30c5c1525b8e6ba46af635e2fab2b4 (patch)
tree609bc5ff372f64925db9c09c606f5d47e1fea47e /Servers
parent6d1740e4be041e7f68c8e05f4f0cbcc7f91ae22b (diff)
downloadserenity-f2a087126c30c5c1525b8e6ba46af635e2fab2b4.zip
LibC: Add posix_openpt(), grantpt() and unlockpt()
This makes getting a pseudoterminal pair a little bit more portable. Note that grantpt() and unlockpt() are currently no-ops, since we've already granted the pseudoterminal slave to the calling user. We also accept O_CLOEXEC to posix_openpt(), unlike some systems. :^)
Diffstat (limited to 'Servers')
-rw-r--r--Servers/TelnetServer/main.cpp14
1 files changed, 12 insertions, 2 deletions
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;
}