diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-12-25 14:49:38 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-12-27 22:00:01 +0100 |
commit | 143f820c68e3d15d8864211eb51d1e2c2548937b (patch) | |
tree | be8ead101bfc4706d934f5690ef5645158969c6b /Userland | |
parent | 98c8eca70c5b5a48de4e55b3ed864c93f6c831c4 (diff) | |
download | serenity-143f820c68e3d15d8864211eb51d1e2c2548937b.zip |
TelnetServer: Port to LibMain
This is only a very basic change, since the fallible function calls are
all inside the `on_ready_to_accept` callback.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Services/TelnetServer/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/Services/TelnetServer/main.cpp | 21 |
2 files changed, 9 insertions, 14 deletions
diff --git a/Userland/Services/TelnetServer/CMakeLists.txt b/Userland/Services/TelnetServer/CMakeLists.txt index 9f0ebb5414..061e22a03e 100644 --- a/Userland/Services/TelnetServer/CMakeLists.txt +++ b/Userland/Services/TelnetServer/CMakeLists.txt @@ -10,4 +10,4 @@ set(SOURCES ) serenity_bin(TelnetServer) -target_link_libraries(TelnetServer LibCore) +target_link_libraries(TelnetServer LibCore LibMain) diff --git a/Userland/Services/TelnetServer/main.cpp b/Userland/Services/TelnetServer/main.cpp index 534f264942..7d274c98a2 100644 --- a/Userland/Services/TelnetServer/main.cpp +++ b/Userland/Services/TelnetServer/main.cpp @@ -11,6 +11,7 @@ #include <LibCore/ArgsParser.h> #include <LibCore/EventLoop.h> #include <LibCore/TCPServer.h> +#include <LibMain/Main.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> @@ -21,7 +22,7 @@ static void run_command(int ptm_fd, String command) { pid_t pid = fork(); if (pid == 0) { - const char* tty_name = ptsname(ptm_fd); + char const* tty_name = ptsname(ptm_fd); if (!tty_name) { perror("ptsname"); exit(1); @@ -65,12 +66,12 @@ static void run_command(int ptm_fd, String command) perror("ioctl(TIOCSCTTY)"); exit(1); } - const char* args[4] = { "/bin/Shell", nullptr, nullptr, nullptr }; + char const* args[4] = { "/bin/Shell", nullptr, nullptr, nullptr }; if (!command.is_empty()) { args[1] = "-c"; args[2] = command.characters(); } - const char* envs[] = { "TERM=xterm", "PATH=/usr/local/bin:/usr/bin:/bin", nullptr }; + char const* envs[] = { "TERM=xterm", "PATH=/usr/local/bin:/usr/bin:/bin", nullptr }; rc = execve("/bin/Shell", const_cast<char**>(args), const_cast<char**>(envs)); if (rc < 0) { perror("execve"); @@ -80,15 +81,15 @@ static void run_command(int ptm_fd, String command) } } -int main(int argc, char** argv) +ErrorOr<int> serenity_main(Main::Arguments arguments) { int port = 23; - const char* command = ""; + char const* command = ""; Core::ArgsParser args_parser; args_parser.add_option(port, "Port to listen on", nullptr, 'p', "port"); args_parser.add_option(command, "Program to run on connection", nullptr, 'c', "command"); - args_parser.parse(argc, argv); + args_parser.parse(arguments); if ((u16)port != port) { warnln("Invalid port number: {}", port); @@ -148,11 +149,5 @@ int main(int argc, char** argv) clients.set(id, client); }; - int rc = event_loop.exec(); - if (rc != 0) { - fprintf(stderr, "event loop exited badly; rc=%d", rc); - exit(1); - } - - return 0; + return event_loop.exec(); } |