Re: [PATCH v3 4/4] terminal: restore settings on SIGTSTP
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 15, 2022, 17:51 UTC
- Message-ID
- <xmqqr173drza.fsf@gitster.g>
- In-Reply-To
- <20220315105723.19398-5-phillip.wood123@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> writes:
Show 7 quoted lines
> @@ -23,6 +23,101 @@ static void restore_term_on_signal(int sig) > static int term_fd = -1; > static struct termios old_term; > > +static const char *background_resume_msg; > +static const char *restore_error_msg; > +static volatile sig_atomic_t ttou_received;
It is a good idea to have a comment here to say why we had to reinvent a subset of error(), instead of forcing curious readers to "git blame" the log message for this commit (I am assuming that "this is called from a signal handler and uses only functions that are safe in that context" is the reason).
Show 30 quoted lines
> +static void write_err(const char *msg)
> +{
> + write_in_full(2, "error: ", strlen("error: "));
> + write_in_full(2, msg, strlen(msg));
> + write_in_full(2, "\n", 1);
> +}
> +
> +static void print_background_resume_msg(int signo)
> +{
> + int saved_errno = errno;
> + sigset_t mask;
> + struct sigaction old_sa;
> + struct sigaction sa = { .sa_handler = SIG_DFL };
> +
> + ttou_received = 1;
> + write_err(background_resume_msg);
> + sigaction(signo, &sa, &old_sa);
> + raise(signo);
> + sigemptyset(&mask);
> + sigaddset(&mask, signo);
> + sigprocmask(SIG_UNBLOCK, &mask, NULL);
> + /* Stopped here */
> + sigprocmask(SIG_BLOCK, &mask, NULL);
> + sigaction(signo, &old_sa, NULL);
> + errno = saved_errno;
> +}
> ...
> + /* avoid calling gettext() from signal handler */
> + background_resume_msg = _("cannot resume in the background, please use 'fg' to resume");
> + restore_error_msg = _("cannot restore terminal settings");Nice to see such an attention to detail here.
Thanks.