mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
parent
95055d3a38
commit
0d2602c900
Notes:
sideshowbarker
2024-07-18 19:11:21 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/0d2602c9007 Pull-request: https://github.com/SerenityOS/serenity/pull/6588 Issue: https://github.com/SerenityOS/serenity/issues/6578 Reviewed-by: https://github.com/linusg
@ -1031,6 +1031,43 @@ int Shell::builtin_not(int argc, const char** argv)
|
||||
return exit_code == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
int Shell::builtin_kill(int argc, const char** argv)
|
||||
{
|
||||
// Simply translate the arguments and pass them to `kill'
|
||||
Vector<String> replaced_values;
|
||||
auto kill_path = find_in_path("kill");
|
||||
if (kill_path.is_empty()) {
|
||||
warnln("kill: `kill' not found in PATH");
|
||||
return 126;
|
||||
}
|
||||
replaced_values.append(kill_path);
|
||||
for (auto i = 1; i < argc; ++i) {
|
||||
if (auto job_id = resolve_job_spec(argv[i]); job_id.has_value()) {
|
||||
auto job = find_job(job_id.value());
|
||||
if (job) {
|
||||
replaced_values.append(String::number(job->pid()));
|
||||
} else {
|
||||
warnln("kill: Job with pid {} not found", job_id.value());
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
replaced_values.append(argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Now just run `kill'
|
||||
AST::Command command;
|
||||
command.argv = move(replaced_values);
|
||||
command.position = m_source_position.has_value() ? m_source_position->position : Optional<AST::Position> {};
|
||||
|
||||
auto exit_code = 1;
|
||||
if (auto job = run_command(command)) {
|
||||
block_on_job(job);
|
||||
exit_code = job->exit_code();
|
||||
}
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
bool Shell::run_builtin(const AST::Command& command, const NonnullRefPtrVector<AST::Rewiring>& rewirings, int& retval)
|
||||
{
|
||||
if (command.argv.is_empty())
|
||||
|
@ -1194,6 +1194,27 @@ String Shell::unescape_token(const String& token)
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
String Shell::find_in_path(const StringView& program_name)
|
||||
{
|
||||
String path = getenv("PATH");
|
||||
if (!path.is_empty()) {
|
||||
auto directories = path.split(':');
|
||||
for (const auto& directory : directories) {
|
||||
Core::DirIterator programs(directory.characters(), Core::DirIterator::SkipDots);
|
||||
while (programs.has_next()) {
|
||||
auto program = programs.next_path();
|
||||
auto program_path = String::formatted("{}/{}", directory, program);
|
||||
if (access(program_path.characters(), X_OK) != 0)
|
||||
continue;
|
||||
if (program == program_name)
|
||||
return program_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void Shell::cache_path()
|
||||
{
|
||||
if (!m_is_interactive)
|
||||
|
@ -46,7 +46,8 @@
|
||||
__ENUMERATE_SHELL_BUILTIN(fg) \
|
||||
__ENUMERATE_SHELL_BUILTIN(bg) \
|
||||
__ENUMERATE_SHELL_BUILTIN(wait) \
|
||||
__ENUMERATE_SHELL_BUILTIN(dump)
|
||||
__ENUMERATE_SHELL_BUILTIN(dump) \
|
||||
__ENUMERATE_SHELL_BUILTIN(kill)
|
||||
|
||||
#define ENUMERATE_SHELL_OPTIONS() \
|
||||
__ENUMERATE_SHELL_OPTION(inline_exec_keep_empty_segments, false, "Keep empty segments in inline execute $(...)") \
|
||||
@ -103,6 +104,8 @@ public:
|
||||
String resolve_path(String) const;
|
||||
String resolve_alias(const String&) const;
|
||||
|
||||
static String find_in_path(const StringView& program_name);
|
||||
|
||||
static bool has_history_event(StringView);
|
||||
|
||||
RefPtr<AST::Value> get_argument(size_t);
|
||||
|
Loading…
Reference in New Issue
Block a user