Terminal: Fetch the user shell from /etc/passwd

This allows you to override the shell used by Terminal. :^)
This commit is contained in:
Andreas Kling 2020-01-25 12:25:43 +01:00
parent 0f5221568b
commit c05c023664
Notes: sideshowbarker 2024-07-19 09:50:20 +09:00

View file

@ -101,13 +101,21 @@ static void run_command(int ptm_fd, String command)
perror("ioctl(TIOCSCTTY)");
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()) {
args[1] = "-c";
args[2] = command.characters();
}
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) {
perror("execve");
exit(1);