aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2009-04-26 17:57:06 +0000
committerRoy Marples <roy@marples.name>2009-04-26 17:57:06 +0000
commit77c8f8abbb4034e409be2e71a22c1caaf1ce5f03 (patch)
tree5d5617b39cc5cf1512d86c96bb4f5f2f7154c3d4
parent1d4818364641c84d0e53fda90a356772299dee8e (diff)
Use /bin/bash or user shell in /etc/passwd if none set before /bin/sh.
-rw-r--r--etc/rc.conf.in2
-rw-r--r--src/rc/rc.c15
2 files changed, 15 insertions, 2 deletions
diff --git a/etc/rc.conf.in b/etc/rc.conf.in
index 173ed900..eab9c530 100644
--- a/etc/rc.conf.in
+++ b/etc/rc.conf.in
@@ -15,6 +15,8 @@
#rc_interactive="YES"
# If we need to drop to a shell, you can specify it here.
+# If not specified we use $SHELL, otherwise the one specified in /etc/passwd,
+# otherwise /bin/sh
# Linux users could specify /sbin/sulogin
#rc_shell=/bin/sh
diff --git a/src/rc/rc.c b/src/rc/rc.c
index 56d6d580..0336264c 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -53,6 +53,7 @@ const char rc_copyright[] = "Copyright (c) 2007-2008 Roy Marples";
#include <getopt.h>
#include <libgen.h>
#include <limits.h>
+#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -315,6 +316,7 @@ static void
open_shell(void)
{
const char *shell;
+ struct passwd *pw;
#ifdef __linux__
const char *sys = rc_sys();
@@ -330,8 +332,17 @@ open_shell(void)
#endif
shell = rc_conf_value("rc_shell");
- if (shell == NULL)
- shell = "/bin/sh";
+ /* No shell set, so obey env, then passwd, then default to /bin/sh */
+ if (shell == NULL) {
+ shell = getenv("SHELL");
+ if (shell == NULL) {
+ pw = getpwuid(getuid());
+ if (pw)
+ shell = pw->pw_shell;
+ if (shell == NULL)
+ shell = "/bin/sh";
+ }
+ }
run_program(shell);
}