Mercurial > vim
comparison src/os_unix.c @ 26825:3c1dcb63f579 v8.2.3941
patch 8.2.3941: SIGTSTP is not handled
Commit: https://github.com/vim/vim/commit/ab16ad33ba10dd12ff6660fa57b88f1a30ddd8ba
Author: dbivolaru <dbivolaru@jacobs-alumni.de>
Date: Wed Dec 29 19:41:47 2021 +0000
patch 8.2.3941: SIGTSTP is not handled
Problem: SIGTSTP is not handled.
Solution: Handle SIGTSTP like pressing CTRL-Z. (closes https://github.com/vim/vim/issues/9422)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 29 Dec 2021 20:45:03 +0100 |
parents | fc859aea8cec |
children | 06a137af96f8 |
comparison
equal
deleted
inserted
replaced
26824:6dccddda8bbc | 26825:3c1dcb63f579 |
---|---|
155 static void handle_resize(void); | 155 static void handle_resize(void); |
156 | 156 |
157 #if defined(SIGWINCH) | 157 #if defined(SIGWINCH) |
158 static RETSIGTYPE sig_winch SIGPROTOARG; | 158 static RETSIGTYPE sig_winch SIGPROTOARG; |
159 #endif | 159 #endif |
160 #if defined(SIGTSTP) | |
161 static RETSIGTYPE sig_tstp SIGPROTOARG; | |
162 // volatile because it is used in signal handler sig_tstp() and sigcont_handler(). | |
163 static volatile sig_atomic_t in_mch_suspend = FALSE; | |
164 #endif | |
160 #if defined(SIGINT) | 165 #if defined(SIGINT) |
161 static RETSIGTYPE catch_sigint SIGPROTOARG; | 166 static RETSIGTYPE catch_sigint SIGPROTOARG; |
162 #endif | 167 #endif |
163 #if defined(SIGUSR1) | 168 #if defined(SIGUSR1) |
164 static RETSIGTYPE catch_sigusr1 SIGPROTOARG; | 169 static RETSIGTYPE catch_sigusr1 SIGPROTOARG; |
195 # define SIG_ERR ((RETSIGTYPE (*)())-1) | 200 # define SIG_ERR ((RETSIGTYPE (*)())-1) |
196 #endif | 201 #endif |
197 | 202 |
198 // volatile because it is used in signal handler sig_winch(). | 203 // volatile because it is used in signal handler sig_winch(). |
199 static volatile sig_atomic_t do_resize = FALSE; | 204 static volatile sig_atomic_t do_resize = FALSE; |
205 // volatile because it is used in signal handler sig_tstp(). | |
206 static volatile sig_atomic_t got_tstp = FALSE; | |
200 static char_u *extra_shell_arg = NULL; | 207 static char_u *extra_shell_arg = NULL; |
201 static int show_shell_mess = TRUE; | 208 static int show_shell_mess = TRUE; |
202 // volatile because it is used in signal handler deathtrap(). | 209 // volatile because it is used in signal handler deathtrap(). |
203 static volatile sig_atomic_t deadly_signal = 0; // The signal we caught | 210 static volatile sig_atomic_t deadly_signal = 0; // The signal we caught |
204 // volatile because it is used in signal handler deathtrap(). | 211 // volatile because it is used in signal handler deathtrap(). |
845 sig_winch SIGDEFARG(sigarg) | 852 sig_winch SIGDEFARG(sigarg) |
846 { | 853 { |
847 // this is not required on all systems, but it doesn't hurt anybody | 854 // this is not required on all systems, but it doesn't hurt anybody |
848 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); | 855 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); |
849 do_resize = TRUE; | 856 do_resize = TRUE; |
857 SIGRETURN; | |
858 } | |
859 #endif | |
860 | |
861 #if defined(SIGTSTP) | |
862 static RETSIGTYPE | |
863 sig_tstp SIGDEFARG(sigarg) | |
864 { | |
865 // Second time we get called we actually need to suspend | |
866 if (in_mch_suspend) | |
867 { | |
868 signal(SIGTSTP, ignore_sigtstp ? SIG_IGN : SIG_DFL); | |
869 raise(sigarg); | |
870 } | |
871 | |
872 // this is not required on all systems, but it doesn't hurt anybody | |
873 signal(SIGTSTP, (RETSIGTYPE (*)())sig_tstp); | |
874 got_tstp = TRUE; | |
850 SIGRETURN; | 875 SIGRETURN; |
851 } | 876 } |
852 #endif | 877 #endif |
853 | 878 |
854 #if defined(SIGINT) | 879 #if defined(SIGINT) |
1156 did_check_timestamps = FALSE; | 1181 did_check_timestamps = FALSE; |
1157 } | 1182 } |
1158 | 1183 |
1159 #if defined(SIGCONT) | 1184 #if defined(SIGCONT) |
1160 static RETSIGTYPE sigcont_handler SIGPROTOARG; | 1185 static RETSIGTYPE sigcont_handler SIGPROTOARG; |
1161 static volatile sig_atomic_t in_mch_suspend = FALSE; | |
1162 | 1186 |
1163 /* | 1187 /* |
1164 * With multi-threading, suspending might not work immediately. Catch the | 1188 * With multi-threading, suspending might not work immediately. Catch the |
1165 * SIGCONT signal, which will be used as an indication whether the suspending | 1189 * SIGCONT signal, which will be used as an indication whether the suspending |
1166 * has been done or not. | 1190 * has been done or not. |
1351 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); | 1375 signal(SIGWINCH, (RETSIGTYPE (*)())sig_winch); |
1352 #endif | 1376 #endif |
1353 | 1377 |
1354 #ifdef SIGTSTP | 1378 #ifdef SIGTSTP |
1355 // See mch_init() for the conditions under which we ignore SIGTSTP. | 1379 // See mch_init() for the conditions under which we ignore SIGTSTP. |
1356 signal(SIGTSTP, ignore_sigtstp ? SIG_IGN : SIG_DFL); | 1380 signal(SIGTSTP, ignore_sigtstp ? SIG_IGN : (RETSIGTYPE (*)())sig_tstp); |
1357 #endif | 1381 #endif |
1358 #if defined(SIGCONT) | 1382 #if defined(SIGCONT) |
1359 signal(SIGCONT, sigcont_handler); | 1383 signal(SIGCONT, sigcont_handler); |
1360 #endif | 1384 #endif |
1361 #ifdef SIGPIPE | 1385 #ifdef SIGPIPE |
6384 *interrupted = TRUE; | 6408 *interrupted = TRUE; |
6385 | 6409 |
6386 # ifdef EINTR | 6410 # ifdef EINTR |
6387 if (ret == -1 && errno == EINTR) | 6411 if (ret == -1 && errno == EINTR) |
6388 { | 6412 { |
6413 // Check whether the EINTR is caused by SIGTSTP | |
6414 if (got_tstp && !in_mch_suspend) | |
6415 { | |
6416 exarg_T ea; | |
6417 ea.forceit = TRUE; | |
6418 ex_stop(&ea); | |
6419 got_tstp = FALSE; | |
6420 } | |
6421 | |
6389 // Check whether window has been resized, EINTR may be caused by | 6422 // Check whether window has been resized, EINTR may be caused by |
6390 // SIGWINCH. | 6423 // SIGWINCH. |
6391 if (do_resize) | 6424 if (do_resize) |
6392 handle_resize(); | 6425 handle_resize(); |
6393 | 6426 |
7174 // gpm library tries to handling TSTP causes | 7207 // gpm library tries to handling TSTP causes |
7175 // problems. Anyways, we close connection to Gpm whenever | 7208 // problems. Anyways, we close connection to Gpm whenever |
7176 // we are going to suspend or starting an external process | 7209 // we are going to suspend or starting an external process |
7177 // so we shouldn't have problem with this | 7210 // so we shouldn't have problem with this |
7178 # ifdef SIGTSTP | 7211 # ifdef SIGTSTP |
7179 signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL); | 7212 signal(SIGTSTP, restricted ? SIG_IGN : (RETSIGTYPE (*)())sig_tstp); |
7180 # endif | 7213 # endif |
7181 return 1; // succeed | 7214 return 1; // succeed |
7182 } | 7215 } |
7183 if (gpm_fd == -2) | 7216 if (gpm_fd == -2) |
7184 Gpm_Close(); // We don't want to talk to xterm via gpm | 7217 Gpm_Close(); // We don't want to talk to xterm via gpm |