git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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.
Previous: Phillip WoodNext: Phillip Wood
Message 47 of 53 in “builtin add -p: hopefully final readkey fixes”
  1. 0/4 builtin add -p: hopefully final readkey fixesPhillip Wood, Mar 4, 2022
  2. 1/4 terminal: use flags for save_term()Phillip Wood, Mar 4, 2022
  3. Ramsay JonesMar 4, 2022
  4. Phillip WoodMar 7, 2022
  5. Ramsay JonesMar 7, 2022
  6. Phillip WoodMar 8, 2022
  7. Ævar Arnfjörð BjarmasonMar 5, 2022
  8. Phillip WoodMar 7, 2022
  9. Ævar Arnfjörð BjarmasonMar 7, 2022
  10. 3/4 terminal: work around macos poll() bugPhillip Wood, Mar 4, 2022
  11. 2/4 terminal: don't assume stdin is /dev/ttyPhillip Wood, Mar 4, 2022
  12. Ramsay JonesMar 4, 2022
  13. 4/4 terminal: restore settings on SIGTSTPPhillip Wood, Mar 4, 2022
  14. Ævar Arnfjörð BjarmasonMar 5, 2022
  15. Phillip WoodMar 7, 2022
  16. Ævar Arnfjörð BjarmasonMar 7, 2022
  17. Phillip WoodMar 7, 2022
  18. Ævar Arnfjörð BjarmasonMar 7, 2022
  19. Phillip WoodMar 8, 2022
  20. Johannes SchindelinMar 9, 2022
  21. Phillip WoodMar 10, 2022
  22. 0/4 builtin add -p: hopefully final readkey fixesPhillip Wood, Mar 9, 2022
  23. 1/4 terminal: use flags for save_term()Phillip Wood, Mar 9, 2022
  24. Carlo ArenasMar 11, 2022
  25. Phillip WoodMar 14, 2022
  26. 2/4 terminal: don't assume stdin is /dev/ttyPhillip Wood, Mar 9, 2022
  27. 3/4 terminal: work around macos poll() bugPhillip Wood, Mar 9, 2022
  28. Ævar Arnfjörð BjarmasonMar 10, 2022
  29. Phillip WoodMar 10, 2022
  30. Junio C HamanoMar 10, 2022
  31. 4/4 terminal: restore settings on SIGTSTPPhillip Wood, Mar 9, 2022
  32. Junio C HamanoMar 9, 2022
  33. Junio C HamanoMar 9, 2022
  34. Phillip WoodMar 10, 2022
  35. Phillip WoodMar 10, 2022
  36. Junio C HamanoMar 10, 2022
  37. Johannes SchindelinMar 10, 2022
  38. Phillip WoodMar 10, 2022
  39. 0/4 builtin add -p: hopefully final readkey fixesPhillip Wood, Mar 15, 2022
  40. 2/4 terminal: don't assume stdin is /dev/ttyPhillip Wood, Mar 15, 2022
  41. Junio C HamanoMar 15, 2022
  42. rsbecker@nexbridge.comMar 15, 2022
  43. Junio C HamanoMar 15, 2022
  44. rsbecker@nexbridge.comMar 15, 2022
  45. 1/4 terminal: use flags for save_term()Phillip Wood, Mar 15, 2022
  46. 4/4 terminal: restore settings on SIGTSTPPhillip Wood, Mar 15, 2022
  47. Junio C HamanoMar 15, 2022
  48. 3/4 terminal: work around macos poll() bugPhillip Wood, Mar 15, 2022
  49. 0/4 builtin add -p: hopefully final readkey fixesPhillip Wood, Mar 16, 2022
  50. 1/4 terminal: use flags for save_term()Phillip Wood, Mar 16, 2022
  51. 2/4 terminal: don't assume stdin is /dev/ttyPhillip Wood, Mar 16, 2022
  52. 3/4 terminal: work around macos poll() bugPhillip Wood, Mar 16, 2022
  53. 4/4 terminal: restore settings on SIGTSTPPhillip Wood, Mar 16, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.