@@ -71,6 +71,7 @@ int oneshot_opt;
71
71
int postpone_opt ;
72
72
int restart_opt ;
73
73
int shell_opt ;
74
+ int winch_opt ;
74
75
int status_filter_opt ;
75
76
76
77
int termios_set ;
@@ -84,6 +85,7 @@ static char *argv0, *argv0_base;
84
85
static void usage ();
85
86
static void terminate_utility ();
86
87
static void handle_exit (int sig );
88
+ static void handle_winch (int sig );
87
89
static void proc_exit (int sig );
88
90
static void print_child_status (int status );
89
91
static int process_input (FILE * , WatchFile * [], int );
@@ -230,7 +232,7 @@ main(int argc, char *argv[]) {
230
232
void
231
233
usage () {
232
234
fprintf (stderr , "release: %s\n" , RELEASE );
233
- fprintf (stderr , "usage: entr [-acdnprsxz ] utility [argument [/_] ...] < filenames\n" );
235
+ fprintf (stderr , "usage: entr [-acdnprswxz ] utility [argument [/_] ...] < filenames\n" );
234
236
exit (1 );
235
237
}
236
238
@@ -267,6 +269,11 @@ handle_exit(int sig) {
267
269
raise (sig );
268
270
}
269
271
272
+ void
273
+ handle_winch (int sig ) {
274
+ return ;
275
+ }
276
+
270
277
void
271
278
proc_exit (int sig ) {
272
279
int status ;
@@ -411,7 +418,7 @@ set_options(char *argv[]) {
411
418
/* read arguments until we reach a command */
412
419
for (argc = 1 ; argv [argc ] != 0 && argv [argc ][0 ] == '-' ; argc ++ )
413
420
;
414
- while ((ch = getopt (argc , argv , "acdnprsxz " )) != -1 ) {
421
+ while ((ch = getopt (argc , argv , "acdnprswxz " )) != -1 ) {
415
422
switch (ch ) {
416
423
case 'a' :
417
424
aggressive_opt = 1 ;
@@ -434,6 +441,9 @@ set_options(char *argv[]) {
434
441
case 's' :
435
442
shell_opt = 1 ;
436
443
break ;
444
+ case 'w' :
445
+ winch_opt = 1 ;
446
+ break ;
437
447
case 'x' :
438
448
status_filter_opt = status_filter_opt ? 2 : 1 ;
439
449
break ;
@@ -450,6 +460,9 @@ set_options(char *argv[]) {
450
460
if (status_filter_opt && restart_opt )
451
461
errx (1 , "-r and -x may not be combined" );
452
462
463
+ if (winch_opt && restart_opt )
464
+ errx (1 , "-r and -w may not be combined" );
465
+
453
466
if ((shell_opt == 1 ) && (argv [optind + 1 ] != 0 ))
454
467
errx (1 , "-s requires commands to be formatted as a single argument" );
455
468
return optind ;
@@ -624,6 +637,7 @@ watch_loop(int kq, char *argv[]) {
624
637
int nev ;
625
638
WatchFile * file ;
626
639
int i ;
640
+ struct sigaction act ;
627
641
struct timespec evTimeout = { 0 , 1000000 };
628
642
int reopen_only = !aggressive_opt ;
629
643
int collate_only = 0 ;
@@ -634,7 +648,9 @@ watch_loop(int kq, char *argv[]) {
634
648
char c ;
635
649
struct termios character_tty ;
636
650
651
+ sigemptyset (& act .sa_mask );
637
652
leading_edge = files [0 ]; /* default */
653
+
638
654
if (postpone_opt == 0 )
639
655
run_utility (argv );
640
656
@@ -653,12 +669,26 @@ watch_loop(int kq, char *argv[]) {
653
669
if ((reopen_only == 1 ) || (collate_only == 1 )) {
654
670
nev = kevent (kq , NULL , 0 , evList , 32 , & evTimeout );
655
671
} else {
672
+ /* interrupt kevent if terminal resized */
673
+ if (winch_opt == 1 ) {
674
+ act .sa_flags = SA_RESETHAND ;
675
+ act .sa_handler = handle_winch ;
676
+ if (sigaction (SIGWINCH , & act , NULL ) != 0 )
677
+ err (1 , "Failed to set SIGWINCH handler" );
678
+ }
679
+
680
+ /* wait for events */
656
681
nev = kevent (kq , NULL , 0 , evList , 32 , NULL );
657
682
dir_modified = 0 ;
658
683
}
659
684
660
- if ((nev == -1 ) && (errno != EINTR ))
661
- warn ("kevent failed" );
685
+ if (nev == -1 ) {
686
+ if (errno == EINTR ) {
687
+ if (winch_opt == 1 )
688
+ do_exec = 1 ;
689
+ } else
690
+ warn ("kevent" );
691
+ }
662
692
663
693
for (i = 0 ; i < nev ; i ++ ) {
664
694
if (!noninteractive_opt && evList [i ].filter == EVFILT_READ ) {
0 commit comments