From 974e68446388769f023c6c9bfb1e67ed75199618 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 14 Sep 2018 10:35:45 -0600 Subject: Unify shell-finding logic I noticed several places in gdb that were using getenv("SHELL") and then falling back to "/bin/sh" if it returned NULL. This unifies these into a single function. gdb/ChangeLog 2018-10-27 Tom Tromey * procfs.c (procfs_target::create_inferior): Use get_shell. * cli/cli-cmds.c (shell_escape): Use get_shell. * windows-nat.c (windows_nat_target::create_inferior): Use get_shell. * common/pathstuff.c (get_shell): New function. * nat/fork-inferior.c (SHELL_FILE, get_startup_shell): Remove. (fork_inferior): Use get_shell. * common/pathstuff.h (get_shell): Declare. --- gdb/common/pathstuff.c | 12 ++++++++++++ gdb/common/pathstuff.h | 5 +++++ 2 files changed, 17 insertions(+) (limited to 'gdb/common') diff --git a/gdb/common/pathstuff.c b/gdb/common/pathstuff.c index 82905c9e..6d8e53f 100644 --- a/gdb/common/pathstuff.c +++ b/gdb/common/pathstuff.c @@ -190,3 +190,15 @@ get_standard_cache_dir () return {}; } + +/* See common/pathstuff.h. */ + +const char * +get_shell () +{ + const char *ret = getenv ("SHELL"); + if (ret == NULL) + ret = "/bin/sh"; + + return ret; +} diff --git a/gdb/common/pathstuff.h b/gdb/common/pathstuff.h index a43b963..0a8caea 100644 --- a/gdb/common/pathstuff.h +++ b/gdb/common/pathstuff.h @@ -64,4 +64,9 @@ extern bool contains_dir_separator (const char *path); extern std::string get_standard_cache_dir (); +/* Return the file name of the user's shell. Normally this comes from + the SHELL environment variable. */ + +extern const char *get_shell (); + #endif /* PATHSTUFF_H */ -- cgit v1.1