Added
Link Here
|
0 |
- |
1 |
--- src/inotifywatch.c.orig 2015-11-08 15:17:11 UTC |
|
|
2 |
+++ src/inotifywatch.c |
3 |
@@ -12,6 +12,7 @@ |
4 |
#include <errno.h> |
5 |
#include <fcntl.h> |
6 |
#include <getopt.h> |
7 |
+#include <pthread.h> |
8 |
#include <regex.h> |
9 |
#include <signal.h> |
10 |
#include <stdbool.h> |
11 |
@@ -91,6 +92,7 @@ int main(int argc, char ** argv) |
12 |
done = false; |
13 |
char * regex = NULL; |
14 |
char * iregex = NULL; |
15 |
+ sigset_t set, oset; |
16 |
|
17 |
signal( SIGINT, handle_impatient_user ); |
18 |
|
19 |
@@ -109,6 +111,16 @@ int main(int argc, char ** argv) |
20 |
return EXIT_FAILURE; |
21 |
} |
22 |
|
23 |
+ // Block some signals in libinotify's worker thread, so that |
24 |
+ // handle_signal runs in the context of the main thread and |
25 |
+ // the `done' flag is actually honored. |
26 |
+ sigemptyset(&set); |
27 |
+ sigaddset(&set, SIGINT); |
28 |
+ sigaddset(&set, SIGHUP); |
29 |
+ sigaddset(&set, SIGTERM); |
30 |
+ sigaddset(&set, SIGALRM); |
31 |
+ pthread_sigmask(SIG_BLOCK, &set, &oset); |
32 |
+ |
33 |
if ( !inotifytools_initialize() ) { |
34 |
fprintf(stderr, "Couldn't initialize inotify. Are you running Linux " |
35 |
"2.6.13 or later, and was the\n" |
36 |
@@ -120,6 +132,8 @@ int main(int argc, char ** argv) |
37 |
return EXIT_FAILURE; |
38 |
} |
39 |
|
40 |
+ pthread_sigmask(SIG_SETMASK, &oset, NULL); |
41 |
+ |
42 |
// Attempt to watch file |
43 |
// If events is still 0, make it all events. |
44 |
if ( !events ) |
45 |
@@ -195,7 +209,7 @@ int main(int argc, char ** argv) |
46 |
char * moved_from = 0; |
47 |
|
48 |
do { |
49 |
- event = inotifytools_next_event( 0 ); |
50 |
+ event = inotifytools_next_event( -1 ); |
51 |
if ( !event ) { |
52 |
if ( !inotifytools_error() ) { |
53 |
return EXIT_TIMEOUT; |