mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-10 10:09:14 +00:00
su: Allow to specify a command to be executed by -c
su -c 'echo yeah'
This commit is contained in:
parent
644a61c318
commit
a8a5707467
Notes:
sideshowbarker
2024-07-17 11:30:05 +09:00
Author: https://github.com/karolba
Commit: a8a5707467
Pull-request: https://github.com/SerenityOS/serenity/pull/17347
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/Popaulol ✅
Reviewed-by: https://github.com/kleinesfilmroellchen
1 changed files with 8 additions and 1 deletions
|
@ -21,11 +21,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
StringView first_positional;
|
||||
StringView second_positional;
|
||||
DeprecatedString command;
|
||||
bool simulate_login = false;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_positional_argument(first_positional, "See --login", "-", Core::ArgsParser::Required::No);
|
||||
args_parser.add_positional_argument(second_positional, "User to switch to (defaults to user with UID 0)", "user", Core::ArgsParser::Required::No);
|
||||
args_parser.add_option(command, "Command to execute", "command", 'c', "command");
|
||||
args_parser.add_option(simulate_login, "Simulate login", "login", 'l');
|
||||
args_parser.parse(arguments);
|
||||
|
||||
|
@ -60,6 +62,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
TRY(Core::System::setenv("HOME"sv, account.home_directory(), true));
|
||||
|
||||
TRY(Core::System::exec(account.shell(), Array<StringView, 1> { account.shell().view() }, Core::System::SearchInPath::No));
|
||||
if (command.is_null()) {
|
||||
TRY(Core::System::exec(account.shell(), Array<StringView, 1> { account.shell().view() }, Core::System::SearchInPath::No));
|
||||
} else {
|
||||
TRY(Core::System::exec(account.shell(), Array<StringView, 3> { account.shell().view(), "-c"sv, command.view() }, Core::System::SearchInPath::No));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue