From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
Subject: Re: [RFC 6/6] Cache a copy of the user's shell on macOS
Date: Sat, 29 Sep 2018 03:37:00 -0000 [thread overview]
Message-ID: <e52963a9-c023-cd9d-6f87-2d823f4f81cc@simark.ca> (raw)
In-Reply-To: <20180926111130.18956-7-tom@tromey.com>
On 2018-09-26 7:11 a.m., Tom Tromey wrote:
> +/* If $SHELL is restricted, try to cache a copy. Starting with El
> + Capitan, macOS introduced System Integrity Protection. Among other
> + things, this prevents certain executables from being ptrace'd. In
> + particular, executables in /bin, like most shells, are affected.
> + To work around this, while preserving command-line glob expansion
> + and redirections, gdb will cache a copy of the shell. Return true
> + if all is well -- either the shell is not subject to SIP or it has
> + been successfully cached. Returns false if something failed. */
> +
> +static bool
> +maybe_cache_shell ()
> +{
> + /* SF_RESTRICTED is defined in sys/stat.h and lets us determine if a
> + given file is subject to SIP. */
> +#ifdef SF_RESTRICTED
> +
> + /* If a check fails we want to revert -- maybe the user deleted the
> + cache while gdb was running, or something like that. */
> + copied_shell = nullptr;
> +
> + const char *shell = get_shell ();
> + if (!IS_ABSOLUTE_PATH (shell))
> + {
> + warning (_("This version of macOS has System Integrity Protection.\n\
> +Normally gdb would try to work around this by caching a copy of your shell,\n\
> +but because your shell (%s) is not an absolute path, this is being skipped."),
> + shell);
> + return false;
> + }
> +
> + struct stat sb;
> + if (stat (shell, &sb) < 0)
> + {
> + warning (_("This version of macOS has System Integrity Protection.\n\
> +Normally gdb would try to work around this by caching a copy of your shell,\n\
> +but because gdb could not stat your shell (%s), this is being skipped.\n\
> +The error was: %s"),
> + shell, safe_strerror (errno));
> + return false;
> + }
> +
> + if ((sb.st_flags & SF_RESTRICTED) == 0)
> + return true;
> +
> + /* Put the copy somewhere like ~/Library/Caches/gdb/bin/sh. */
> + std::string new_name = get_standard_cache_dir ();
> + if (!IS_DIR_SEPARATOR (new_name.back ()) && !IS_ABSOLUTE_PATH (shell))
I believe this !IS_ABSOLUTE_PATH check can never be true, since we would
have returned early if it was the case? If so, this append is not needed
> + new_name.push_back ('/');
> + new_name.append (shell);
> +
> + /* Maybe it was cached by some earlier gdb. */
> + if (stat (new_name.c_str (), &sb) != 0 || !S_ISREG (sb.st_mode))
> + {
> + TRY
> + {
> + copy_shell_to_cache (shell, new_name);
> + }
> + CATCH (ex, RETURN_MASK_ERROR)
> + {
> + warning (_("This version of macOS has System Integrity Protection.\n\
> +Because `startup-with-shell' is enabled, gdb tried to work around SIP by\n\
> +caching a copy of your shell. However, this failed:\n\
> +%s\n\
> +If you correct the problem, gdb will automatically try again the next time\n\
> +you \"run\". To prevent these attempts, you can use:\n\
> + set startup-with-shell off"),
> + ex.message);
> + return false;
> + }
> + END_CATCH
> +
> + printf_filtered (_("Note: this version of macOS has System Integrity Protection.\n\
> +Because `startup-with-shell' is enabled, gdb has worked around this by\n\
> +caching a copy of your shell. The shell used by \"run\" is now:\n\
> + %s\n"),
> + new_name.c_str ());
I am not on Mac right now so I can't test, but I was wondering how
annoying it is to have this message every time you run and it succeeds.
I like that we explain what's happening when things go wrong, but is
it useful to explain it as well when everything works well? Will the
user care?
Otherwise, this looks good to me, thanks!
Simon
next prev parent reply other threads:[~2018-09-29 3:37 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-26 11:12 [RFC 0/6] A different approach to startup-with-shell " Tom Tromey
2018-09-26 11:11 ` [RFC 1/6] Unify shell-finding logic Tom Tromey
2018-09-28 21:39 ` Simon Marchi
2018-09-26 11:12 ` [RFC 2/6] Move make_temp_filename to common/pathstuff.c Tom Tromey
2018-09-26 11:12 ` [RFC 4/6] Use mkostemp, not mkstemp Tom Tromey
2018-09-29 3:09 ` Simon Marchi
2018-09-29 12:49 ` Tom Tromey
2018-09-29 14:04 ` Simon Marchi
2018-09-26 11:12 ` [RFC 5/6] Do not reopen temporary files Tom Tromey
2018-09-26 14:12 ` Eli Zaretskii
2018-09-26 21:44 ` Tom Tromey
2018-09-29 3:22 ` Simon Marchi
2018-10-01 9:15 ` Tom Tromey
2018-09-26 11:20 ` [RFC 3/6] Move mkdir_recursive to common/filestuff.c Tom Tromey
2018-09-26 22:11 ` Tom Tromey
2018-09-26 23:16 ` Tom Tromey
2018-09-26 11:20 ` [RFC 6/6] Cache a copy of the user's shell on macOS Tom Tromey
2018-09-29 3:37 ` Simon Marchi [this message]
2018-10-01 19:27 ` Tom Tromey
2018-10-01 19:31 ` Simon Marchi
2018-09-28 21:21 ` [RFC 0/6] A different approach to startup-with-shell " Simon Marchi
2018-09-29 18:43 ` Pedro Alves
2018-09-29 19:50 ` Simon Marchi
2018-09-29 20:38 ` Pedro Alves
2018-10-01 9:12 ` 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=e52963a9-c023-cd9d-6f87-2d823f4f81cc@simark.ca \
--to=simark@simark.ca \
--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