diff options
Diffstat (limited to 'src/plugins/test_lib.c')
-rw-r--r-- | src/plugins/test_lib.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/plugins/test_lib.c b/src/plugins/test_lib.c index 97d4dc5..6cd880d 100644 --- a/src/plugins/test_lib.c +++ b/src/plugins/test_lib.c | |||
@@ -26,6 +26,9 @@ | |||
26 | #include "test_lib.h" | 26 | #include "test_lib.h" |
27 | #include <sys/types.h> | 27 | #include <sys/types.h> |
28 | #include <regex.h> | 28 | #include <regex.h> |
29 | #include <signal.h> | ||
30 | #include <stdbool.h> | ||
31 | #include <unistd.h> | ||
29 | 32 | ||
30 | /** | 33 | /** |
31 | * Function that libextractor calls for each | 34 | * Function that libextractor calls for each |
@@ -142,17 +145,31 @@ run (const char *plugin_name, | |||
142 | unsigned int i; | 145 | unsigned int i; |
143 | unsigned int j; | 146 | unsigned int j; |
144 | int ret; | 147 | int ret; |
148 | bool skipped = false; | ||
145 | 149 | ||
146 | pl = EXTRACTOR_plugin_add_config (NULL, | 150 | pl = EXTRACTOR_plugin_add_config (NULL, |
147 | plugin_name, | 151 | plugin_name, |
148 | opt); | 152 | opt); |
149 | for (i = 0; NULL != ps[i].filename; i++) | 153 | for (i = 0; NULL != ps[i].filename; i++) |
154 | { | ||
155 | if (0 != access (ps[i].filename, | ||
156 | R_OK)) | ||
157 | { | ||
158 | fprintf (stderr, | ||
159 | "Failed to access %s, skipping test\n", | ||
160 | ps[i].filename); | ||
161 | skipped = true; | ||
162 | continue; | ||
163 | } | ||
150 | EXTRACTOR_extract (pl, | 164 | EXTRACTOR_extract (pl, |
151 | ps[i].filename, | 165 | ps[i].filename, |
152 | NULL, 0, | 166 | NULL, 0, |
153 | &process_replies, | 167 | &process_replies, |
154 | ps[i].solution); | 168 | ps[i].solution); |
169 | } | ||
155 | EXTRACTOR_plugin_remove_all (pl); | 170 | EXTRACTOR_plugin_remove_all (pl); |
171 | if (skipped) | ||
172 | return 0; | ||
156 | ret = 0; | 173 | ret = 0; |
157 | for (i = 0; NULL != ps[i].filename; i++) | 174 | for (i = 0; NULL != ps[i].filename; i++) |
158 | for (j = 0; -1 != ps[i].solution[j].solved; j++) | 175 | for (j = 0; -1 != ps[i].solution[j].solved; j++) |
@@ -174,6 +191,33 @@ run (const char *plugin_name, | |||
174 | } | 191 | } |
175 | 192 | ||
176 | 193 | ||
194 | #ifndef WINDOWS | ||
195 | /** | ||
196 | * Install a signal handler to ignore SIGPIPE. | ||
197 | */ | ||
198 | static void | ||
199 | ignore_sigpipe () | ||
200 | { | ||
201 | struct sigaction oldsig; | ||
202 | struct sigaction sig; | ||
203 | |||
204 | memset (&sig, 0, sizeof (struct sigaction)); | ||
205 | sig.sa_handler = SIG_IGN; | ||
206 | sigemptyset (&sig.sa_mask); | ||
207 | #ifdef SA_INTERRUPT | ||
208 | sig.sa_flags = SA_INTERRUPT; /* SunOS */ | ||
209 | #else | ||
210 | sig.sa_flags = SA_RESTART; | ||
211 | #endif | ||
212 | if (0 != sigaction (SIGPIPE, &sig, &oldsig)) | ||
213 | fprintf (stderr, | ||
214 | "Failed to install SIGPIPE handler: %s\n", strerror (errno)); | ||
215 | } | ||
216 | |||
217 | |||
218 | #endif | ||
219 | |||
220 | |||
177 | /** | 221 | /** |
178 | * Main function to be called to test a plugin. | 222 | * Main function to be called to test a plugin. |
179 | * | 223 | * |
@@ -191,7 +235,10 @@ ET_main (const char *plugin_name, | |||
191 | /* change environment to find plugins which may not yet be | 235 | /* change environment to find plugins which may not yet be |
192 | not installed but should be in the current directory (or .libs) | 236 | not installed but should be in the current directory (or .libs) |
193 | on 'make check' */ | 237 | on 'make check' */ |
194 | if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) | 238 | #ifndef WINDOWS |
239 | ignore_sigpipe (); | ||
240 | #endif | ||
241 | if (0 != putenv ("LIBEXTRACTOR_PREFIX=./.libs/")) | ||
195 | fprintf (stderr, | 242 | fprintf (stderr, |
196 | "Failed to update my environment, plugin loading may fail: %s\n", | 243 | "Failed to update my environment, plugin loading may fail: %s\n", |
197 | strerror (errno)); | 244 | strerror (errno)); |