Skip to content

Commit 0981c87

Browse files
committed
patch 8.2.1513: cannot interrupt shell used for filename expansion
Problem: Cannot interrupt shell used for filename expansion. (Dominique Pellé) Solution: Do set tmode in mch_delay(). (closes #6770)
1 parent 69e4455 commit 0981c87

12 files changed

Lines changed: 41 additions & 26 deletions

File tree

src/channel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ channel_connect(
904904
*waittime -= elapsed_msec;
905905
if (waitnow > 0)
906906
{
907-
mch_delay((long)waitnow, TRUE);
907+
mch_delay((long)waitnow, MCH_DELAY_IGNOREINPUT);
908908
ui_breakcheck();
909909
*waittime -= waitnow;
910910
}

src/if_cscope.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,7 +2243,7 @@ cs_release_csp(int i, int freefnpp)
22432243
waitpid_errno = errno;
22442244
if (pid != 0)
22452245
break; // break unless the process is still running
2246-
mch_delay(50L, FALSE); // sleep 50 ms
2246+
mch_delay(50L, 0); // sleep 50 ms
22472247
}
22482248
# endif
22492249
/*
@@ -2278,7 +2278,7 @@ cs_release_csp(int i, int freefnpp)
22782278
alive = FALSE; // cscope process no longer exists
22792279
break;
22802280
}
2281-
mch_delay(50L, FALSE); // sleep 50ms
2281+
mch_delay(50L, 0); // sleep 50 ms
22822282
}
22832283
}
22842284
if (alive)

src/os_amiga.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,18 @@ mch_avail_mem(int special)
222222

223223
/*
224224
* Waits a specified amount of time, or until input arrives if
225-
* ignoreinput is FALSE.
225+
* flags does not have MCH_DELAY_IGNOREINPUT.
226226
*/
227227
void
228-
mch_delay(long msec, int ignoreinput)
228+
mch_delay(long msec, int flags)
229229
{
230230
#ifndef LATTICE // SAS declares void Delay(ULONG)
231231
void Delay(long);
232232
#endif
233233

234234
if (msec > 0)
235235
{
236-
if (ignoreinput)
236+
if (flags & MCH_DELAY_IGNOREINPUT)
237237
Delay(msec / 20L); // Delay works with 20 msec intervals
238238
else
239239
WaitForChar(raw_in, msec * 1000L);

src/os_unix.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -577,23 +577,28 @@ mch_total_mem(int special UNUSED)
577577
}
578578
#endif
579579

580+
/*
581+
* "flags": MCH_DELAY_IGNOREINPUT - don't read input
582+
* MCH_DELAY_SETTMODE - use settmode() even for short delays
583+
*/
580584
void
581-
mch_delay(long msec, int ignoreinput)
585+
mch_delay(long msec, int flags)
582586
{
583587
tmode_T old_tmode;
584588
#ifdef FEAT_MZSCHEME
585589
long total = msec; // remember original value
586590
#endif
587591

588-
if (ignoreinput)
592+
if (flags & MCH_DELAY_IGNOREINPUT)
589593
{
590594
// Go to cooked mode without echo, to allow SIGINT interrupting us
591595
// here. But we don't want QUIT to kill us (CTRL-\ used in a
592596
// shell may produce SIGQUIT).
593597
// Only do this if sleeping for more than half a second.
594598
in_mch_delay = TRUE;
595599
old_tmode = mch_cur_tmode;
596-
if (mch_cur_tmode == TMODE_RAW && msec > 500)
600+
if (mch_cur_tmode == TMODE_RAW
601+
&& (msec > 500 || (flags & MCH_DELAY_SETTMODE)))
597602
settmode(TMODE_SLEEP);
598603

599604
/*
@@ -636,10 +641,8 @@ mch_delay(long msec, int ignoreinput)
636641

637642
tv.tv_sec = msec / 1000;
638643
tv.tv_usec = (msec % 1000) * 1000;
639-
/*
640-
* NOTE: Solaris 2.6 has a bug that makes select() hang here. Get
641-
* a patch from Sun to fix this. Reported by Gunnar Pedersen.
642-
*/
644+
// NOTE: Solaris 2.6 has a bug that makes select() hang here. Get
645+
// a patch from Sun to fix this. Reported by Gunnar Pedersen.
643646
select(0, NULL, NULL, NULL, &tv);
644647
}
645648
# endif // HAVE_SELECT
@@ -650,7 +653,7 @@ mch_delay(long msec, int ignoreinput)
650653
while (total > 0);
651654
#endif
652655

653-
if (msec > 500)
656+
if (msec > 500 || (flags & MCH_DELAY_SETTMODE))
654657
settmode(old_tmode);
655658
in_mch_delay = FALSE;
656659
}
@@ -1284,7 +1287,7 @@ mch_suspend(void)
12841287
long wait_time;
12851288

12861289
for (wait_time = 0; !sigcont_received && wait_time <= 3L; wait_time++)
1287-
mch_delay(wait_time, FALSE);
1290+
mch_delay(wait_time, 0);
12881291
}
12891292
# endif
12901293
in_mch_suspend = FALSE;
@@ -4170,7 +4173,7 @@ wait4pid(pid_t child, waitstatus *status)
41704173
if (wait_pid == 0)
41714174
{
41724175
// Wait for 1 to 10 msec before trying again.
4173-
mch_delay(delay_msec, TRUE);
4176+
mch_delay(delay_msec, MCH_DELAY_IGNOREINPUT | MCH_DELAY_SETTMODE);
41744177
if (++delay_msec > 10)
41754178
delay_msec = 10;
41764179
continue;
@@ -5262,6 +5265,9 @@ mch_call_shell_fork(
52625265
{
52635266
long delay_msec = 1;
52645267

5268+
out_str(T_CTE); // possibly disables modifyOtherKeys, so that
5269+
// the system can recognize CTRL-C
5270+
52655271
/*
52665272
* Similar to the loop above, but only handle X events, no
52675273
* I/O.
@@ -5295,11 +5301,14 @@ mch_call_shell_fork(
52955301
clip_update();
52965302

52975303
// Wait for 1 to 10 msec. 1 is faster but gives the child
5298-
// less time.
5299-
mch_delay(delay_msec, TRUE);
5304+
// less time, gradually wait longer.
5305+
mch_delay(delay_msec,
5306+
MCH_DELAY_IGNOREINPUT | MCH_DELAY_SETTMODE);
53005307
if (++delay_msec > 10)
53015308
delay_msec = 10;
53025309
}
5310+
5311+
out_str(T_CTI); // possibly enables modifyOtherKeys again
53035312
}
53045313
# endif
53055314

@@ -6710,7 +6719,7 @@ mch_expand_wildcards(
67106719
// When running in the background, give it some time to create the temp
67116720
// file, but don't wait for it to finish.
67126721
if (ampersand)
6713-
mch_delay(10L, TRUE);
6722+
mch_delay(10L, MCH_DELAY_IGNOREINPUT);
67146723

67156724
extra_shell_arg = NULL; // cleanup
67166725
show_shell_mess = TRUE;

src/os_win32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6739,7 +6739,7 @@ mch_write(
67396739
void
67406740
mch_delay(
67416741
long msec,
6742-
int ignoreinput UNUSED)
6742+
int flags UNUSED)
67436743
{
67446744
#if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
67456745
Sleep((int)msec); // never wait for input
@@ -6751,7 +6751,7 @@ mch_delay(
67516751
return;
67526752
}
67536753
# endif
6754-
if (ignoreinput)
6754+
if (flags & MCH_DELAY_IGNOREINPUT)
67556755
# ifdef FEAT_MZSCHEME
67566756
if (mzthreads_allowed() && p_mzq > 0 && msec > p_mzq)
67576757
{

src/proto/os_amiga.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ void mch_write(char_u *p, int len);
55
int mch_inchar(char_u *buf, int maxlen, long time, int tb_change_cnt);
66
int mch_char_avail(void);
77
long_u mch_avail_mem(int special);
8-
void mch_delay(long msec, int ignoreinput);
8+
void mch_delay(long msec, int flags);
99
void mch_suspend(void);
1010
void mch_init(void);
1111
int mch_check_win(int argc, char **argv);

src/proto/os_unix.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ int mch_inchar(char_u *buf, int maxlen, long wtime, int tb_change_cnt);
55
int mch_char_avail(void);
66
int mch_check_messages(void);
77
long_u mch_total_mem(int special);
8-
void mch_delay(long msec, int ignoreinput);
8+
void mch_delay(long msec, int flags);
99
int mch_stackcheck(char *p);
1010
void mch_suspend(void);
1111
void mch_init(void);

src/proto/os_win32.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int mch_signal_job(job_T *job, char_u *how);
5353
void mch_clear_job(job_T *job);
5454
void mch_set_normal_colors(void);
5555
void mch_write(char_u *s, int len);
56-
void mch_delay(long msec, int ignoreinput);
56+
void mch_delay(long msec, int flags);
5757
int mch_remove(char_u *name);
5858
void mch_breakcheck(int force);
5959
long_u mch_total_mem(int special);

src/term.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3598,7 +3598,7 @@ stoptermcap(void)
35983598
{
35993599
# ifdef UNIX
36003600
// Give the terminal a chance to respond.
3601-
mch_delay(100L, FALSE);
3601+
mch_delay(100L, 0);
36023602
# endif
36033603
# ifdef TCIFLUSH
36043604
// Discard data received but not read.

src/ui.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ ui_delay(long msec_arg, int ignoreinput)
539539
gui_wait_for_chars(msec, typebuf.tb_change_cnt);
540540
else
541541
#endif
542-
mch_delay(msec, ignoreinput);
542+
mch_delay(msec, ignoreinput ? MCH_DELAY_IGNOREINPUT : 0);
543543
}
544544

545545
/*

0 commit comments

Comments
 (0)