summaryrefslogtreecommitdiff
path: root/Applications/Terminal/main.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-01-25 12:25:43 +0100
committerAndreas Kling <kling@serenityos.org>2020-01-25 12:25:43 +0100
commitc05c0236647b40b2bba83889540c50803a8b5850 (patch)
tree9b027cc1de092fa64df0810c1aa012aa3f2193f7 /Applications/Terminal/main.cpp
parent0f5221568b3aef8f7c7bdc4cc85b7bec0e00759b (diff)
downloadserenity-c05c0236647b40b2bba83889540c50803a8b5850.zip
Terminal: Fetch the user shell from /etc/passwd
This allows you to override the shell used by Terminal. :^)
Diffstat (limited to 'Applications/Terminal/main.cpp')
-rw-r--r--Applications/Terminal/main.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp
index d8d18d064f..94b1c5903b 100644
--- a/Applications/Terminal/main.cpp
+++ b/Applications/Terminal/main.cpp
@@ -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);