mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
Shell: Port to LibMain
This commit is contained in:
parent
3fa5be655d
commit
ed0f4bdfaf
3 changed files with 17 additions and 29 deletions
|
@ -498,7 +498,7 @@ if (BUILD_LAGOM)
|
||||||
|
|
||||||
add_executable(shell_lagom ../../Userland/Shell/main.cpp)
|
add_executable(shell_lagom ../../Userland/Shell/main.cpp)
|
||||||
set_target_properties(shell_lagom PROPERTIES OUTPUT_NAME shell)
|
set_target_properties(shell_lagom PROPERTIES OUTPUT_NAME shell)
|
||||||
target_link_libraries(shell_lagom LagomCore LagomShell)
|
target_link_libraries(shell_lagom LagomCore LagomShell LagomMain)
|
||||||
|
|
||||||
add_executable(wasm_lagom ../../Userland/Utilities/wasm.cpp)
|
add_executable(wasm_lagom ../../Userland/Utilities/wasm.cpp)
|
||||||
set_target_properties(wasm_lagom PROPERTIES OUTPUT_NAME wasm)
|
set_target_properties(wasm_lagom PROPERTIES OUTPUT_NAME wasm)
|
||||||
|
|
|
@ -24,7 +24,7 @@ set(SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_bin(Shell)
|
serenity_bin(Shell)
|
||||||
target_link_libraries(Shell LibShell)
|
target_link_libraries(Shell LibShell LibMain)
|
||||||
|
|
||||||
install(DIRECTORY Tests/ DESTINATION usr/Tests/Shell
|
install(DIRECTORY Tests/ DESTINATION usr/Tests/Shell
|
||||||
PATTERN "Tests/*"
|
PATTERN "Tests/*"
|
||||||
|
|
|
@ -9,17 +9,17 @@
|
||||||
#include <LibCore/Event.h>
|
#include <LibCore/Event.h>
|
||||||
#include <LibCore/EventLoop.h>
|
#include <LibCore/EventLoop.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <errno.h>
|
#include <LibCore/System.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
RefPtr<Line::Editor> editor;
|
RefPtr<Line::Editor> editor;
|
||||||
Shell::Shell* s_shell;
|
Shell::Shell* s_shell;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
Core::EventLoop loop;
|
Core::EventLoop loop;
|
||||||
|
|
||||||
|
@ -42,10 +42,7 @@ int main(int argc, char** argv)
|
||||||
});
|
});
|
||||||
|
|
||||||
#ifdef __serenity__
|
#ifdef __serenity__
|
||||||
if (pledge("stdio rpath wpath cpath proc exec tty sigaction unix fattr", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio rpath wpath cpath proc exec tty sigaction unix fattr", nullptr));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RefPtr<::Shell::Shell> shell;
|
RefPtr<::Shell::Shell> shell;
|
||||||
|
@ -104,38 +101,29 @@ int main(int argc, char** argv)
|
||||||
parser.add_positional_argument(file_to_read_from, "File to read commands from", "file", Core::ArgsParser::Required::No);
|
parser.add_positional_argument(file_to_read_from, "File to read commands from", "file", Core::ArgsParser::Required::No);
|
||||||
parser.add_positional_argument(script_args, "Extra arguments to pass to the script (via $* and co)", "argument", Core::ArgsParser::Required::No);
|
parser.add_positional_argument(script_args, "Extra arguments to pass to the script (via $* and co)", "argument", Core::ArgsParser::Required::No);
|
||||||
|
|
||||||
parser.parse(argc, argv);
|
parser.parse(arguments);
|
||||||
|
|
||||||
if (format) {
|
if (format) {
|
||||||
auto file = Core::File::open(format, Core::OpenMode::ReadOnly);
|
auto file = TRY(Core::File::open(format, Core::OpenMode::ReadOnly));
|
||||||
if (file.is_error()) {
|
|
||||||
warnln("Error: {}", file.error());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
ssize_t cursor = -1;
|
ssize_t cursor = -1;
|
||||||
puts(shell->format(file.value()->read_all(), cursor).characters());
|
puts(shell->format(file->read_all(), cursor).characters());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pid = getpid();
|
auto pid = getpid();
|
||||||
if (auto sid = getsid(pid); sid == 0) {
|
if (auto sid = getsid(pid); sid == 0) {
|
||||||
if (setsid() < 0) {
|
if (auto res = Core::System::setsid(); res.is_error())
|
||||||
perror("setsid");
|
dbgln("{}", res.release_error());
|
||||||
// Let's just hope that it's ok.
|
|
||||||
}
|
|
||||||
} else if (sid != pid) {
|
} else if (sid != pid) {
|
||||||
if (getpgid(pid) != pid) {
|
if (getpgid(pid) != pid) {
|
||||||
if (setpgid(pid, sid) < 0) {
|
if (auto res = Core::System::setpgid(pid, sid); res.is_error())
|
||||||
auto strerr = strerror(errno);
|
dbgln("{}", res.release_error());
|
||||||
dbgln("couldn't setpgid: {}", strerr);
|
|
||||||
}
|
if (auto res = Core::System::setsid(); res.is_error())
|
||||||
if (setsid() < 0) {
|
dbgln("{}", res.release_error());
|
||||||
auto strerr = strerror(errno);
|
|
||||||
dbgln("couldn't setsid: {}", strerr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +138,7 @@ int main(int argc, char** argv)
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
shell->set_live_formatting(should_format_live);
|
shell->set_live_formatting(should_format_live);
|
||||||
shell->current_script = argv[0];
|
shell->current_script = arguments.strings[0];
|
||||||
|
|
||||||
if (!skip_rc_files) {
|
if (!skip_rc_files) {
|
||||||
auto run_rc_file = [&](auto& name) {
|
auto run_rc_file = [&](auto& name) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue