mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:54:58 +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
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