diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Makemodule.am | 1 | ||||
| -rw-r--r-- | lib/exec_shell.c | 8 | ||||
| -rw-r--r-- | lib/meson.build | 1 | ||||
| -rw-r--r-- | lib/shells.c | 26 |
4 files changed, 30 insertions, 6 deletions
diff --git a/lib/Makemodule.am b/lib/Makemodule.am index a9da577348..1d598faa28 100644 --- a/lib/Makemodule.am +++ b/lib/Makemodule.am @@ -49,6 +49,7 @@ libcommon_la_SOURCES = \ if LINUX libcommon_la_SOURCES += \ lib/linux_version.c \ + lib/shells.c \ lib/loopdev.c endif diff --git a/lib/exec_shell.c b/lib/exec_shell.c index ffe65f006e..8f10ea4df4 100644 --- a/lib/exec_shell.c +++ b/lib/exec_shell.c @@ -26,19 +26,15 @@ #include "xalloc.h" #include "exec_shell.h" - -#define DEFAULT_SHELL "/bin/sh" +#include "shells.h" void __attribute__((__noreturn__)) exec_shell(void) { - const char *shell = getenv("SHELL"); + const char *shell = ul_default_shell(0, NULL); char *shellc; const char *shell_basename; char *arg0; - if (!shell) - shell = DEFAULT_SHELL; - shellc = xstrdup(shell); shell_basename = basename(shellc); xasprintf(&arg0, "-%s", shell_basename); diff --git a/lib/meson.build b/lib/meson.build index 0f94a9b99b..cb35ecbd60 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -25,6 +25,7 @@ lib_common_sources = ''' randutils.c sha1.c sha256.c + shells.c signames.c strutils.c strv.c diff --git a/lib/shells.c b/lib/shells.c index 13f293c5e0..ef2aecd0f5 100644 --- a/lib/shells.c +++ b/lib/shells.c @@ -1,6 +1,11 @@ /* * SPDX-License-Identifier: GPL-2.0-or-later */ +#include <sys/types.h> +#include <pwd.h> +#include <stdlib.h> +#include <paths.h> +#include <unistd.h> #include <sys/syslog.h> #if defined (HAVE_LIBECONF) && defined (USE_VENDORDIR) #include <libeconf.h> @@ -116,3 +121,24 @@ extern int is_known_shell(const char *shell_name) #endif return ret; } + +const char *ul_default_shell(int flags, const struct passwd *pw) +{ + const char *shell = NULL; + + if (!(flags & UL_SHELL_NOENV)) { + shell = getenv("SHELL"); + if (shell && *shell) + return shell; + } + if (!(flags & UL_SHELL_NOPWD)) { + if (!pw) + pw = getpwuid(getuid()); + if (pw) + shell = pw->pw_shell; + if (shell && *shell) + return shell; + } + + return _PATH_BSHELL; +} |
