From: Sergio Durigan Junior <sergiodj@redhat.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v2 1/6] Unify shell-finding logic
Date: Fri, 19 Oct 2018 23:27:00 -0000 [thread overview]
Message-ID: <87tvlhv7o3.fsf@redhat.com> (raw)
In-Reply-To: <20181018223100.20693-2-tom@tromey.com> (Tom Tromey's message of "Thu, 18 Oct 2018 16:30:55 -0600")
On Thursday, October 18 2018, Tom Tromey wrote:
> 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.
Not sure if I reviewed this one before, but it LGTM (with a very small
nit below). It also can be pushed independently, IMO.
Thanks,
> gdb/ChangeLog
> 2018-10-18 Tom Tromey <tom@tromey.com>
>
> * 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/ChangeLog | 11 +++++++++++
> gdb/cli/cli-cmds.c | 6 ++----
> gdb/common/pathstuff.c | 12 ++++++++++++
> gdb/common/pathstuff.h | 4 ++++
> gdb/nat/fork-inferior.c | 21 ++-------------------
> gdb/procfs.c | 4 ++--
> gdb/windows-nat.c | 5 ++---
> 7 files changed, 35 insertions(+), 28 deletions(-)
>
> diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
> index b871e476d3..135f550b80 100644
> --- a/gdb/cli/cli-cmds.c
> +++ b/gdb/cli/cli-cmds.c
> @@ -50,6 +50,7 @@
> #include "cli/cli-utils.h"
>
> #include "extension.h"
> +#include "common/pathstuff.h"
>
> #ifdef TUI
> #include "tui/tui.h" /* For tui_active et.al. */
> @@ -726,13 +727,10 @@ shell_escape (const char *arg, int from_tty)
>
> if ((pid = vfork ()) == 0)
> {
> - const char *p, *user_shell;
> + const char *p, *user_shell = get_shell ();
>
> close_most_fds ();
>
> - if ((user_shell = getenv ("SHELL")) == NULL)
> - user_shell = "/bin/sh";
> -
> /* Get the name of the shell for arg0. */
> p = lbasename (user_shell);
>
> diff --git a/gdb/common/pathstuff.c b/gdb/common/pathstuff.c
> index 82905c9e68..6d8e53f4e1 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 a43b963651..40fbda8d85 100644
> --- a/gdb/common/pathstuff.h
> +++ b/gdb/common/pathstuff.h
> @@ -64,4 +64,8 @@ extern bool contains_dir_separator (const char *path);
>
> extern std::string get_standard_cache_dir ();
>
> +/* Return the file name of the user's shell. */
WDYT about explicitly mentioning here that "user's shell" means "the
SHELL environment variable"?
> +
> +extern const char *get_shell ();
> +
> #endif /* PATHSTUFF_H */
> diff --git a/gdb/nat/fork-inferior.c b/gdb/nat/fork-inferior.c
> index 40cd05a0f8..f1032b43c9 100644
> --- a/gdb/nat/fork-inferior.c
> +++ b/gdb/nat/fork-inferior.c
> @@ -24,16 +24,13 @@
> #include "target/target.h"
> #include "common-inferior.h"
> #include "common-gdbthread.h"
> +#include "common/pathstuff.h"
> #include "signals-state-save-restore.h"
> #include "gdb_tilde_expand.h"
> #include <vector>
>
> extern char **environ;
>
> -/* Default shell file to be used if 'startup-with-shell' is set but
> - $SHELL is not. */
> -#define SHELL_FILE "/bin/sh"
> -
> /* Build the argument vector for execv(3). */
>
> class execv_argv
> @@ -265,20 +262,6 @@ execv_argv::init_for_shell (const char *exec_file,
> m_argv.push_back (NULL);
> }
>
> -/* Return the shell that must be used to startup the inferior. The
> - first attempt is the environment variable SHELL; if it is not set,
> - then we default to SHELL_FILE. */
> -
> -static const char *
> -get_startup_shell ()
> -{
> - const char *ret = getenv ("SHELL");
> - if (ret == NULL)
> - ret = SHELL_FILE;
> -
> - return ret;
> -}
> -
> /* See nat/fork-inferior.h. */
>
> pid_t
> @@ -316,7 +299,7 @@ fork_inferior (const char *exec_file_arg, const std::string &allargs,
>
> /* Figure out what shell to start up the user program under. */
> if (shell_file == NULL)
> - shell_file = get_startup_shell ();
> + shell_file = get_shell ();
>
> gdb_assert (shell_file != NULL);
> }
> diff --git a/gdb/procfs.c b/gdb/procfs.c
> index 6ffe569e69..ca381a71ae 100644
> --- a/gdb/procfs.c
> +++ b/gdb/procfs.c
> @@ -3035,11 +3035,11 @@ procfs_target::create_inferior (const char *exec_file,
> const std::string &allargs,
> char **env, int from_tty)
> {
> - char *shell_file = getenv ("SHELL");
> + const char *shell_file = get_shell ();
> char *tryname;
> int pid;
>
> - if (shell_file != NULL && strchr (shell_file, '/') == NULL)
> + if (strchr (shell_file, '/') == NULL)
> {
>
> /* We will be looking down the PATH to find shell_file. If we
> diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
> index 0047a26418..8292cf4212 100644
> --- a/gdb/windows-nat.c
> +++ b/gdb/windows-nat.c
> @@ -68,6 +68,7 @@
> #include "complaints.h"
> #include "inf-child.h"
> #include "gdb_tilde_expand.h"
> +#include "common/pathstuff.h"
>
> #define AdjustTokenPrivileges dyn_AdjustTokenPrivileges
> #define DebugActiveProcessStop dyn_DebugActiveProcessStop
> @@ -2578,9 +2579,7 @@ windows_nat_target::create_inferior (const char *exec_file,
> }
> else
> {
> - sh = getenv ("SHELL");
> - if (!sh)
> - sh = "/bin/sh";
> + sh = get_shell ();
> if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, sh, shell, __PMAX) < 0)
> error (_("Error starting executable via shell: %d"), errno);
> #ifdef __USEWIDE
> --
> 2.17.1
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
next prev parent reply other threads:[~2018-10-19 23:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-18 22:31 [PATCH v2 0/6] A different approach to startup-with-shell on macOS Tom Tromey
2018-10-18 22:31 ` [PATCH v2 3/6] Move mkdir_recursive to common/filestuff.c Tom Tromey
2018-10-29 16:01 ` Simon Marchi
2018-10-29 22:16 ` Simon Marchi
2018-10-30 20:55 ` Tom Tromey
2018-10-30 21:04 ` Simon Marchi
2018-10-31 15:03 ` Tom Tromey
2018-11-01 19:44 ` Simon Marchi
2018-10-18 22:31 ` [PATCH v2 1/6] Unify shell-finding logic Tom Tromey
2018-10-19 23:27 ` Sergio Durigan Junior [this message]
2018-10-27 17:41 ` Tom Tromey
2018-10-18 22:31 ` [PATCH v2 4/6] Use mkostemp, not mkstemp Tom Tromey
2018-10-18 22:31 ` [PATCH v2 2/6] Move make_temp_filename to common/pathstuff.c Tom Tromey
2018-10-18 22:31 ` [PATCH v2 5/6] Do not reopen temporary files Tom Tromey
2018-10-18 22:31 ` [PATCH v2 6/6] Cache a copy of the user's shell on macOS Tom Tromey
2018-10-20 2:35 ` Simon Marchi
2018-10-27 17:43 ` Tom Tromey
2018-10-19 23:41 ` [PATCH v2 0/6] A different approach to startup-with-shell " Sergio Durigan Junior
2018-10-27 17:58 ` Tom Tromey
-- strict thread matches above, loose matches on Subject: below --
2018-10-03 21:02 [PATCH 2 0/6] A different approach to starutp-with-shell " Tom Tromey
2018-10-03 21:02 ` [PATCH v2 1/6] Unify shell-finding logic Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87tvlhv7o3.fsf@redhat.com \
--to=sergiodj@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).