mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
Terminal: Fetch the user shell from /etc/passwd
This allows you to override the shell used by Terminal. :^)
This commit is contained in:
parent
0f5221568b
commit
c05c023664
1 changed files with 10 additions and 2 deletions
|
@ -101,13 +101,21 @@ static void run_command(int ptm_fd, String command)
|
||||||
perror("ioctl(TIOCSCTTY)");
|
perror("ioctl(TIOCSCTTY)");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
const char* args[4] = { "/bin/Shell", nullptr, nullptr, nullptr };
|
|
||||||
|
String shell = "/bin/Shell";
|
||||||
|
auto* pw = getpwuid(getuid());
|
||||||
|
if (pw && pw->pw_shell) {
|
||||||
|
shell = pw->pw_shell;
|
||||||
|
}
|
||||||
|
endpwent();
|
||||||
|
|
||||||
|
const char* args[4] = { shell.characters(), nullptr, nullptr, nullptr };
|
||||||
if (!command.is_empty()) {
|
if (!command.is_empty()) {
|
||||||
args[1] = "-c";
|
args[1] = "-c";
|
||||||
args[2] = command.characters();
|
args[2] = command.characters();
|
||||||
}
|
}
|
||||||
const char* envs[] = { "TERM=xterm", "PATH=/bin:/usr/bin:/usr/local/bin", nullptr };
|
const char* envs[] = { "TERM=xterm", "PATH=/bin:/usr/bin:/usr/local/bin", nullptr };
|
||||||
rc = execve("/bin/Shell", const_cast<char**>(args), const_cast<char**>(envs));
|
rc = execve(shell.characters(), const_cast<char**>(args), const_cast<char**>(envs));
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror("execve");
|
perror("execve");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue