From c05c0236647b40b2bba83889540c50803a8b5850 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 25 Jan 2020 12:25:43 +0100 Subject: [PATCH] Terminal: Fetch the user shell from /etc/passwd This allows you to override the shell used by Terminal. :^) --- Applications/Terminal/main.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp index d8d18d064fe..94b1c5903b2 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(args), const_cast(envs)); + rc = execve(shell.characters(), const_cast(args), const_cast(envs)); if (rc < 0) { perror("execve"); exit(1);