diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-07-30 14:46:36 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-07-30 14:46:36 +0000 |
commit | b57601ab81464c1539f14a763f35fccba751f6c1 (patch) | |
tree | f35a18a139b4dbcf690ac48308ada78ca46f664c | |
parent | 9cb851a3d59e4287837d3a49699e60d0494af6a4 (diff) | |
download | libextractor-b57601ab81464c1539f14a763f35fccba751f6c1.tar.gz libextractor-b57601ab81464c1539f14a763f35fccba751f6c1.zip |
adding logging
-rw-r--r-- | src/main/extractor.c | 8 | ||||
-rw-r--r-- | src/main/extractor_common.c | 19 | ||||
-rw-r--r-- | src/main/extractor_common.h | 6 | ||||
-rw-r--r-- | src/main/extractor_datasource.c | 163 | ||||
-rw-r--r-- | src/main/extractor_ipc.c | 12 | ||||
-rw-r--r-- | src/main/extractor_ipc_gnu.c | 40 | ||||
-rw-r--r-- | src/main/extractor_logging.h | 13 | ||||
-rw-r--r-- | src/main/extractor_plugin_main.c | 128 | ||||
-rw-r--r-- | src/main/extractor_plugins.c | 80 | ||||
-rw-r--r-- | src/main/extractor_plugpath.c | 57 | ||||
-rw-r--r-- | src/main/extractor_print.c | 10 |
11 files changed, 385 insertions, 151 deletions
diff --git a/src/main/extractor.c b/src/main/extractor.c index bbe661c..2c69f3f 100644 --- a/src/main/extractor.c +++ b/src/main/extractor.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <ltdl.h> | 27 | #include <ltdl.h> |
28 | #include "extractor_datasource.h" | 28 | #include "extractor_datasource.h" |
29 | #include "extractor_ipc.h" | 29 | #include "extractor_ipc.h" |
30 | #include "extractor_logging.h" | ||
30 | #include "extractor_plugpath.h" | 31 | #include "extractor_plugpath.h" |
31 | #include "extractor_plugins.h" | 32 | #include "extractor_plugins.h" |
32 | 33 | ||
@@ -87,6 +88,7 @@ send_update_message (struct EXTRACTOR_PluginList *plugin, | |||
87 | &um, | 88 | &um, |
88 | sizeof (um)) ) | 89 | sizeof (um)) ) |
89 | { | 90 | { |
91 | LOG ("Failed to send UPDATED_SHM message to plugin\n"); | ||
90 | EXTRACTOR_IPC_channel_destroy_ (plugin->channel); | 92 | EXTRACTOR_IPC_channel_destroy_ (plugin->channel); |
91 | plugin->channel = NULL; | 93 | plugin->channel = NULL; |
92 | plugin->round_finished = 1; | 94 | plugin->round_finished = 1; |
@@ -110,6 +112,7 @@ send_discard_message (struct EXTRACTOR_PluginList *plugin) | |||
110 | &disc_msg, | 112 | &disc_msg, |
111 | sizeof (disc_msg)) ) | 113 | sizeof (disc_msg)) ) |
112 | { | 114 | { |
115 | LOG ("Failed to send DISCARD_STATE message to plugin\n"); | ||
113 | EXTRACTOR_IPC_channel_destroy_ (plugin->channel); | 116 | EXTRACTOR_IPC_channel_destroy_ (plugin->channel); |
114 | plugin->channel = NULL; | 117 | plugin->channel = NULL; |
115 | plugin->round_finished = 1; | 118 | plugin->round_finished = 1; |
@@ -182,6 +185,7 @@ process_plugin_reply (void *cls, | |||
182 | &cont_msg, | 185 | &cont_msg, |
183 | sizeof (cont_msg)) ) | 186 | sizeof (cont_msg)) ) |
184 | { | 187 | { |
188 | LOG ("Failed to send CONTINUE_EXTRACTING message to plugin\n"); | ||
185 | EXTRACTOR_IPC_channel_destroy_ (plugin->channel); | 189 | EXTRACTOR_IPC_channel_destroy_ (plugin->channel); |
186 | plugin->channel = NULL; | 190 | plugin->channel = NULL; |
187 | plugin->round_finished = 1; | 191 | plugin->round_finished = 1; |
@@ -240,6 +244,7 @@ do_extract (struct EXTRACTOR_PluginList *plugins, | |||
240 | &start, | 244 | &start, |
241 | sizeof (start)) ) ) | 245 | sizeof (start)) ) ) |
242 | { | 246 | { |
247 | LOG ("Failed to send EXTRACT_START message to plugin\n"); | ||
243 | EXTRACTOR_IPC_channel_destroy_ (pos->channel); | 248 | EXTRACTOR_IPC_channel_destroy_ (pos->channel); |
244 | pos->channel = NULL; | 249 | pos->channel = NULL; |
245 | } | 250 | } |
@@ -265,6 +270,7 @@ do_extract (struct EXTRACTOR_PluginList *plugins, | |||
265 | &prp)) | 270 | &prp)) |
266 | { | 271 | { |
267 | /* serious problem in IPC; reset *all* channels */ | 272 | /* serious problem in IPC; reset *all* channels */ |
273 | LOG ("Failed to receive message from channels; full reset\n"); | ||
268 | abort_all_channels (plugins); | 274 | abort_all_channels (plugins); |
269 | break; | 275 | break; |
270 | } | 276 | } |
@@ -298,6 +304,7 @@ do_extract (struct EXTRACTOR_PluginList *plugins, | |||
298 | min_seek, | 304 | min_seek, |
299 | DEFAULT_SHM_SIZE))) | 305 | DEFAULT_SHM_SIZE))) |
300 | { | 306 | { |
307 | LOG ("Failed to seek; full reset\n"); | ||
301 | abort_all_channels (plugins); | 308 | abort_all_channels (plugins); |
302 | break; | 309 | break; |
303 | } | 310 | } |
@@ -334,6 +341,7 @@ do_extract (struct EXTRACTOR_PluginList *plugins, | |||
334 | { | 341 | { |
335 | if (EXTRACTOR_OPTION_IN_PROCESS != pos->flags) | 342 | if (EXTRACTOR_OPTION_IN_PROCESS != pos->flags) |
336 | continue; | 343 | continue; |
344 | LOG ("In-process plugins not implemented\n"); | ||
337 | // FIXME: initialize read/seek context... | 345 | // FIXME: initialize read/seek context... |
338 | // pos->extract_method (FIXME); | 346 | // pos->extract_method (FIXME); |
339 | } | 347 | } |
diff --git a/src/main/extractor_common.c b/src/main/extractor_common.c index 3b7f1d7..08a32e4 100644 --- a/src/main/extractor_common.c +++ b/src/main/extractor_common.c | |||
@@ -17,9 +17,14 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | /** | |
21 | * @file main/extractor_common.c | ||
22 | * @brief commonly used functions within the library | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
21 | #include "platform.h" | 25 | #include "platform.h" |
22 | #include "extractor_common.h" | 26 | #include "extractor_common.h" |
27 | #include "extractor_logging.h" | ||
23 | #include "extractor.h" | 28 | #include "extractor.h" |
24 | #include <sys/types.h> | 29 | #include <sys/types.h> |
25 | #include <signal.h> | 30 | #include <signal.h> |
@@ -48,7 +53,11 @@ EXTRACTOR_write_all_ (int fd, | |||
48 | { | 53 | { |
49 | ret = write (fd, &data[off], size - off); | 54 | ret = write (fd, &data[off], size - off); |
50 | if (ret <= 0) | 55 | if (ret <= 0) |
51 | return -1; | 56 | { |
57 | if (-1 == ret) | ||
58 | LOG_STRERROR ("write"); | ||
59 | return -1; | ||
60 | } | ||
52 | off += ret; | 61 | off += ret; |
53 | } | 62 | } |
54 | return size; | 63 | return size; |
@@ -76,7 +85,11 @@ EXTRACTOR_read_all_ (int fd, | |||
76 | { | 85 | { |
77 | ret = read (fd, &data[off], size - off); | 86 | ret = read (fd, &data[off], size - off); |
78 | if (ret <= 0) | 87 | if (ret <= 0) |
79 | return -1; | 88 | { |
89 | if (-1 == ret) | ||
90 | LOG_STRERROR ("write"); | ||
91 | return -1; | ||
92 | } | ||
80 | off += ret; | 93 | off += ret; |
81 | } | 94 | } |
82 | return size; | 95 | return size; |
diff --git a/src/main/extractor_common.h b/src/main/extractor_common.h index 1fb90d4..1354e8e 100644 --- a/src/main/extractor_common.h +++ b/src/main/extractor_common.h | |||
@@ -17,7 +17,11 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | /** | |
21 | * @file main/extractor_common.h | ||
22 | * @brief commonly used functions within the library | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
21 | 25 | ||
22 | #ifndef EXTRACTOR_COMMON_H | 26 | #ifndef EXTRACTOR_COMMON_H |
23 | #define EXTRACTOR_COMMON_H | 27 | #define EXTRACTOR_COMMON_H |
diff --git a/src/main/extractor_datasource.c b/src/main/extractor_datasource.c index 2338a1e..77702d2 100644 --- a/src/main/extractor_datasource.c +++ b/src/main/extractor_datasource.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "extractor_logging.h" | ||
26 | #include "extractor_datasource.h" | 27 | #include "extractor_datasource.h" |
27 | 28 | ||
28 | #if HAVE_LIBBZ2 | 29 | #if HAVE_LIBBZ2 |
@@ -218,7 +219,10 @@ bfds_pick_next_buffer_at (struct BufferedFileDataSource *bfds, | |||
218 | ssize_t rd; | 219 | ssize_t rd; |
219 | 220 | ||
220 | if (pos > bfds->fsize) | 221 | if (pos > bfds->fsize) |
221 | return -1; /* invalid */ | 222 | { |
223 | LOG ("Invalid seek operation\n"); | ||
224 | return -1; /* invalid */ | ||
225 | } | ||
222 | if (NULL == bfds->buffer) | 226 | if (NULL == bfds->buffer) |
223 | { | 227 | { |
224 | bfds->buffer_pos = pos; | 228 | bfds->buffer_pos = pos; |
@@ -231,7 +235,10 @@ bfds_pick_next_buffer_at (struct BufferedFileDataSource *bfds, | |||
231 | bfds->buffer_pos = 0; | 235 | bfds->buffer_pos = 0; |
232 | rd = read (bfds->fd, bfds->buffer, bfds->buffer_size); | 236 | rd = read (bfds->fd, bfds->buffer, bfds->buffer_size); |
233 | if (rd < 0) | 237 | if (rd < 0) |
234 | return -1; | 238 | { |
239 | LOG_STRERROR ("read"); | ||
240 | return -1; | ||
241 | } | ||
235 | bfds->buffer_bytes = rd; | 242 | bfds->buffer_bytes = rd; |
236 | return 0; | 243 | return 0; |
237 | } | 244 | } |
@@ -258,13 +265,19 @@ bfds_new (const void *data, | |||
258 | else | 265 | else |
259 | xtra = (size_t) fsize; | 266 | xtra = (size_t) fsize; |
260 | if ( (-1 == fd) && (NULL == data) ) | 267 | if ( (-1 == fd) && (NULL == data) ) |
261 | return NULL; | 268 | { |
269 | LOG ("Invalid arguments\n"); | ||
270 | return NULL; | ||
271 | } | ||
262 | if ( (-1 != fd) && (NULL != data) ) | 272 | if ( (-1 != fd) && (NULL != data) ) |
263 | fd = -1; /* don't need fd */ | 273 | fd = -1; /* don't need fd */ |
264 | if (NULL != data) | 274 | if (NULL != data) |
265 | xtra = 0; | 275 | xtra = 0; |
266 | if (NULL == (result = malloc (sizeof (struct BufferedFileDataSource) + xtra))) | 276 | if (NULL == (result = malloc (sizeof (struct BufferedFileDataSource) + xtra))) |
267 | return NULL; | 277 | { |
278 | LOG_STRERROR ("malloc"); | ||
279 | return NULL; | ||
280 | } | ||
268 | memset (result, 0, sizeof (struct BufferedFileDataSource)); | 281 | memset (result, 0, sizeof (struct BufferedFileDataSource)); |
269 | result->data = (NULL != data) ? data : &result[1]; | 282 | result->data = (NULL != data) ? data : &result[1]; |
270 | result->buffer = (NULL != data) ? NULL : &result[1]; | 283 | result->buffer = (NULL != data) ? NULL : &result[1]; |
@@ -308,9 +321,15 @@ bfds_seek (struct BufferedFileDataSource *bfds, | |||
308 | { | 321 | { |
309 | case SEEK_CUR: | 322 | case SEEK_CUR: |
310 | if (bfds->fpos + bfds->buffer_pos + pos < 0) | 323 | if (bfds->fpos + bfds->buffer_pos + pos < 0) |
311 | return -1; | 324 | { |
325 | LOG ("Invalid seek operation\n"); | ||
326 | return -1; | ||
327 | } | ||
312 | if (bfds->fpos + bfds->buffer_pos + pos > bfds->fsize) | 328 | if (bfds->fpos + bfds->buffer_pos + pos > bfds->fsize) |
313 | return -1; | 329 | { |
330 | LOG ("Invalid seek operation\n"); | ||
331 | return -1; | ||
332 | } | ||
314 | if ( (NULL == bfds->buffer) || | 333 | if ( (NULL == bfds->buffer) || |
315 | ( (bfds->buffer_pos + pos < bfds->buffer_bytes) && | 334 | ( (bfds->buffer_pos + pos < bfds->buffer_bytes) && |
316 | (bfds->buffer_pos + pos >= 0) ) ) | 335 | (bfds->buffer_pos + pos >= 0) ) ) |
@@ -320,20 +339,35 @@ bfds_seek (struct BufferedFileDataSource *bfds, | |||
320 | } | 339 | } |
321 | if (0 != bfds_pick_next_buffer_at (bfds, | 340 | if (0 != bfds_pick_next_buffer_at (bfds, |
322 | bfds->fpos + bfds->buffer_pos + pos)) | 341 | bfds->fpos + bfds->buffer_pos + pos)) |
323 | return -1; | 342 | { |
343 | LOG ("seek operation failed\n"); | ||
344 | return -1; | ||
345 | } | ||
324 | return bfds->fpos; | 346 | return bfds->fpos; |
325 | case SEEK_END: | 347 | case SEEK_END: |
326 | if (pos > 0) | 348 | if (pos > 0) |
327 | return -1; | 349 | { |
350 | LOG ("Invalid seek operation\n"); | ||
351 | return -1; | ||
352 | } | ||
328 | if (bfds->fsize < - pos) | 353 | if (bfds->fsize < - pos) |
329 | return -1; | 354 | { |
355 | LOG ("Invalid seek operation\n"); | ||
356 | return -1; | ||
357 | } | ||
330 | pos = bfds->fsize + pos; | 358 | pos = bfds->fsize + pos; |
331 | /* fall-through! */ | 359 | /* fall-through! */ |
332 | case SEEK_SET: | 360 | case SEEK_SET: |
333 | if (pos < 0) | 361 | if (pos < 0) |
334 | return -1; | 362 | { |
363 | LOG ("Invalid seek operation\n"); | ||
364 | return -1; | ||
365 | } | ||
335 | if (pos > bfds->fsize) | 366 | if (pos > bfds->fsize) |
336 | return -1; | 367 | { |
368 | LOG ("Invalid seek operation\n"); | ||
369 | return -1; | ||
370 | } | ||
337 | if ( (NULL == bfds->buffer) || | 371 | if ( (NULL == bfds->buffer) || |
338 | ( (bfds->buffer_pos <= pos) && | 372 | ( (bfds->buffer_pos <= pos) && |
339 | (bfds->buffer_pos + bfds->buffer_bytes > pos) ) ) | 373 | (bfds->buffer_pos + bfds->buffer_bytes > pos) ) ) |
@@ -342,7 +376,10 @@ bfds_seek (struct BufferedFileDataSource *bfds, | |||
342 | return bfds->buffer_pos; | 376 | return bfds->buffer_pos; |
343 | } | 377 | } |
344 | if (0 != bfds_pick_next_buffer_at (bfds, pos)) | 378 | if (0 != bfds_pick_next_buffer_at (bfds, pos)) |
345 | return -1; | 379 | { |
380 | LOG ("seek operation failed\n"); | ||
381 | return -1; | ||
382 | } | ||
346 | return bfds->fpos; | 383 | return bfds->fpos; |
347 | } | 384 | } |
348 | return -1; | 385 | return -1; |
@@ -383,13 +420,13 @@ bfds_read (struct BufferedFileDataSource *bfds, | |||
383 | bfds->fpos = old_off; | 420 | bfds->fpos = old_off; |
384 | bfds->buffer_bytes = 0; | 421 | bfds->buffer_bytes = 0; |
385 | bfds->buffer_pos = 0; | 422 | bfds->buffer_pos = 0; |
423 | LOG ("read operation failed\n"); | ||
386 | return -1; /* getting more failed */ | 424 | return -1; /* getting more failed */ |
387 | } | 425 | } |
388 | avail = bfds->buffer_bytes - bfds->buffer_pos; | 426 | avail = bfds->buffer_bytes - bfds->buffer_pos; |
389 | if (avail > count) | 427 | if (avail > count) |
390 | avail = count; | 428 | avail = count; |
391 | if (0 == avail) | 429 | ASSERT (0 != avail); |
392 | abort (); /* must not happen */ | ||
393 | memcpy (&cbuf[ret], bfds->data + bfds->buffer_pos, avail); | 430 | memcpy (&cbuf[ret], bfds->data + bfds->buffer_pos, avail); |
394 | bfds->buffer_pos += avail; | 431 | bfds->buffer_pos += avail; |
395 | count -= avail; | 432 | count -= avail; |
@@ -433,6 +470,7 @@ cfs_reset_stream_zlib (struct CompressedFileSource *cfs) | |||
433 | #endif | 470 | #endif |
434 | )) | 471 | )) |
435 | { | 472 | { |
473 | LOG ("Failed to initialize zlib decompression\n"); | ||
436 | return -1; | 474 | return -1; |
437 | } | 475 | } |
438 | cfs->fpos = 0; | 476 | cfs->fpos = 0; |
@@ -450,6 +488,7 @@ static int | |||
450 | cfs_reset_stream_bz2 (struct CompressedFileSource *cfs) | 488 | cfs_reset_stream_bz2 (struct CompressedFileSource *cfs) |
451 | { | 489 | { |
452 | /* not implemented */ | 490 | /* not implemented */ |
491 | LOG ("bz2 decompression not implemented\n"); | ||
453 | return -1; | 492 | return -1; |
454 | } | 493 | } |
455 | 494 | ||
@@ -473,6 +512,7 @@ cfs_reset_stream (struct CompressedFileSource *cfs) | |||
473 | case COMP_TYPE_BZ2: | 512 | case COMP_TYPE_BZ2: |
474 | return cfs_reset_stream_bz2 (cfs); | 513 | return cfs_reset_stream_bz2 (cfs); |
475 | default: | 514 | default: |
515 | LOG ("invalid compression type selected\n"); | ||
476 | return -1; | 516 | return -1; |
477 | } | 517 | } |
478 | } | 518 | } |
@@ -575,6 +615,7 @@ static int | |||
575 | cfs_init_decompressor_bz2 (struct CompressedFileSource *cfs, | 615 | cfs_init_decompressor_bz2 (struct CompressedFileSource *cfs, |
576 | EXTRACTOR_MetaDataProcessor proc, void *proc_cls) | 616 | EXTRACTOR_MetaDataProcessor proc, void *proc_cls) |
577 | { | 617 | { |
618 | LOG ("bz2 decompression not implemented\n"); | ||
578 | return -1; | 619 | return -1; |
579 | } | 620 | } |
580 | 621 | ||
@@ -599,6 +640,7 @@ cfs_init_decompressor (struct CompressedFileSource *cfs, | |||
599 | case COMP_TYPE_BZ2: | 640 | case COMP_TYPE_BZ2: |
600 | return cfs_init_decompressor_bz2 (cfs, proc, proc_cls); | 641 | return cfs_init_decompressor_bz2 (cfs, proc, proc_cls); |
601 | default: | 642 | default: |
643 | LOG ("invalid compression type selected\n"); | ||
602 | return -1; | 644 | return -1; |
603 | } | 645 | } |
604 | } | 646 | } |
@@ -627,6 +669,7 @@ cfs_deinit_decompressor_zlib (struct CompressedFileSource *cfs) | |||
627 | static int | 669 | static int |
628 | cfs_deinit_decompressor_bz2 (struct CompressedFileSource *cfs) | 670 | cfs_deinit_decompressor_bz2 (struct CompressedFileSource *cfs) |
629 | { | 671 | { |
672 | LOG ("bz2 decompression not implemented\n"); | ||
630 | return -1; | 673 | return -1; |
631 | } | 674 | } |
632 | 675 | ||
@@ -647,6 +690,7 @@ cfs_deinit_decompressor (struct CompressedFileSource *cfs) | |||
647 | case COMP_TYPE_BZ2: | 690 | case COMP_TYPE_BZ2: |
648 | return cfs_deinit_decompressor_bz2 (cfs); | 691 | return cfs_deinit_decompressor_bz2 (cfs); |
649 | default: | 692 | default: |
693 | LOG ("invalid compression type selected\n"); | ||
650 | return -1; | 694 | return -1; |
651 | } | 695 | } |
652 | } | 696 | } |
@@ -684,7 +728,10 @@ cfs_new (struct BufferedFileDataSource *bfds, | |||
684 | struct CompressedFileSource *cfs; | 728 | struct CompressedFileSource *cfs; |
685 | 729 | ||
686 | if (NULL == (cfs = malloc (sizeof (struct CompressedFileSource)))) | 730 | if (NULL == (cfs = malloc (sizeof (struct CompressedFileSource)))) |
687 | return NULL; | 731 | { |
732 | LOG_STRERROR ("malloc"); | ||
733 | return NULL; | ||
734 | } | ||
688 | memset (cfs, 0, sizeof (struct CompressedFileSource)); | 735 | memset (cfs, 0, sizeof (struct CompressedFileSource)); |
689 | cfs->compression_type = compression_type; | 736 | cfs->compression_type = compression_type; |
690 | cfs->bfds = bfds; | 737 | cfs->bfds = bfds; |
@@ -784,6 +831,7 @@ cfs_read_bz2 (struct CompressedFileSource *cfs, | |||
784 | void *data, | 831 | void *data, |
785 | size_t size) | 832 | size_t size) |
786 | { | 833 | { |
834 | LOG ("bz2 decompression not implemented\n"); | ||
787 | return -1; | 835 | return -1; |
788 | } | 836 | } |
789 | 837 | ||
@@ -810,6 +858,7 @@ cfs_read (struct CompressedFileSource *cfs, | |||
810 | case COMP_TYPE_BZ2: | 858 | case COMP_TYPE_BZ2: |
811 | return cfs_read_bz2 (cfs, data, size); | 859 | return cfs_read_bz2 (cfs, data, size); |
812 | default: | 860 | default: |
861 | LOG ("invalid compression type selected\n"); | ||
813 | return -1; | 862 | return -1; |
814 | } | 863 | } |
815 | } | 864 | } |
@@ -837,33 +886,53 @@ cfs_seek (struct CompressedFileSource *cfs, | |||
837 | { | 886 | { |
838 | case SEEK_CUR: | 887 | case SEEK_CUR: |
839 | if (cfs->fpos + position < 0) | 888 | if (cfs->fpos + position < 0) |
840 | return -1; | 889 | { |
890 | LOG ("Invalid seek operation\n"); | ||
891 | return -1; | ||
892 | } | ||
841 | if ( (-1 != cfs->uncompressed_size) && | 893 | if ( (-1 != cfs->uncompressed_size) && |
842 | (cfs->fpos + position > cfs->uncompressed_size) ) | 894 | (cfs->fpos + position > cfs->uncompressed_size) ) |
843 | return -1; | 895 | { |
896 | LOG ("Invalid seek operation\n"); | ||
897 | return -1; | ||
898 | } | ||
844 | nposition = cfs->fpos + position; | 899 | nposition = cfs->fpos + position; |
845 | break; | 900 | break; |
846 | case SEEK_END: | 901 | case SEEK_END: |
847 | if (-1 == cfs->uncompressed_size) | 902 | if (-1 == cfs->uncompressed_size) |
848 | { | 903 | { |
849 | /* yuck, need to first find end of file! */ | 904 | /* yuck, need to first find end of file! */ |
905 | LOG ("Seeking from end-of-file in compressed files not implemented\n"); | ||
850 | return -1; // FIXME: not implemented | 906 | return -1; // FIXME: not implemented |
851 | } | 907 | } |
852 | if (position > 0) | 908 | if (position > 0) |
853 | return -1; | 909 | { |
910 | LOG ("Invalid seek operation\n"); | ||
911 | return -1; | ||
912 | } | ||
854 | if (cfs->uncompressed_size < - position) | 913 | if (cfs->uncompressed_size < - position) |
855 | return -1; | 914 | { |
915 | LOG ("Invalid seek operation\n"); | ||
916 | return -1; | ||
917 | } | ||
856 | nposition = cfs->uncompressed_size + position; | 918 | nposition = cfs->uncompressed_size + position; |
857 | break; | 919 | break; |
858 | case SEEK_SET: | 920 | case SEEK_SET: |
859 | if (position < 0) | 921 | if (position < 0) |
860 | return -1; | 922 | { |
923 | LOG ("Invalid seek operation\n"); | ||
924 | return -1; | ||
925 | } | ||
861 | if ( (-1 != cfs->uncompressed_size) && | 926 | if ( (-1 != cfs->uncompressed_size) && |
862 | (cfs->uncompressed_size < position ) ) | 927 | (cfs->uncompressed_size < position ) ) |
863 | return -1; | 928 | { |
929 | LOG ("Invalid seek operation\n"); | ||
930 | return -1; | ||
931 | } | ||
864 | nposition = (uint64_t) position; | 932 | nposition = (uint64_t) position; |
865 | break; | 933 | break; |
866 | default: | 934 | default: |
935 | LOG ("Invalid seek operation\n"); | ||
867 | return -1; | 936 | return -1; |
868 | } | 937 | } |
869 | 938 | ||
@@ -878,7 +947,10 @@ cfs_seek (struct CompressedFileSource *cfs, | |||
878 | else | 947 | else |
879 | { | 948 | { |
880 | if (-1 == cfs_reset_stream (cfs)) | 949 | if (-1 == cfs_reset_stream (cfs)) |
881 | return -1; | 950 | { |
951 | LOG ("Failed to restart compressed stream for seek operation\n"); | ||
952 | return -1; | ||
953 | } | ||
882 | delta = nposition; | 954 | delta = nposition; |
883 | } | 955 | } |
884 | } | 956 | } |
@@ -891,7 +963,10 @@ cfs_seek (struct CompressedFileSource *cfs, | |||
891 | max = (sizeof (buf) > delta) ? delta : sizeof (buf); | 963 | max = (sizeof (buf) > delta) ? delta : sizeof (buf); |
892 | ret = cfs_read (cfs, buf, max); | 964 | ret = cfs_read (cfs, buf, max); |
893 | if (-1 == ret) | 965 | if (-1 == ret) |
894 | return -1; | 966 | { |
967 | LOG ("Failed to read decompressed stream for seek operation\n"); | ||
968 | return -1; | ||
969 | } | ||
895 | delta -= ret; | 970 | delta -= ret; |
896 | } | 971 | } |
897 | return cfs->fpos; | 972 | return cfs->fpos; |
@@ -979,10 +1054,14 @@ EXTRACTOR_datasource_create_from_file_ (const char *filename, | |||
979 | int64_t fsize; | 1054 | int64_t fsize; |
980 | 1055 | ||
981 | if (-1 == (fd = open (filename, O_RDONLY | O_LARGEFILE))) | 1056 | if (-1 == (fd = open (filename, O_RDONLY | O_LARGEFILE))) |
982 | return NULL; | 1057 | { |
1058 | LOG_STRERROR_FILE ("open", filename); | ||
1059 | return NULL; | ||
1060 | } | ||
983 | if ( (0 != fstat (fd, &sb)) || | 1061 | if ( (0 != fstat (fd, &sb)) || |
984 | (S_ISDIR (sb.st_mode)) ) | 1062 | (S_ISDIR (sb.st_mode)) ) |
985 | { | 1063 | { |
1064 | LOG_STRERROR_FILE ("fstat", filename); | ||
986 | (void) close (fd); | 1065 | (void) close (fd); |
987 | return NULL; | 1066 | return NULL; |
988 | } | 1067 | } |
@@ -1000,21 +1079,26 @@ EXTRACTOR_datasource_create_from_file_ (const char *filename, | |||
1000 | } | 1079 | } |
1001 | if (NULL == (ds = malloc (sizeof (struct EXTRACTOR_Datasource)))) | 1080 | if (NULL == (ds = malloc (sizeof (struct EXTRACTOR_Datasource)))) |
1002 | { | 1081 | { |
1082 | LOG_STRERROR ("malloc"); | ||
1003 | bfds_delete (bfds); | 1083 | bfds_delete (bfds); |
1004 | return NULL; | 1084 | return NULL; |
1005 | } | 1085 | } |
1006 | ds->bfds = bfds; | 1086 | ds->bfds = bfds; |
1007 | ds->fd = fd; | 1087 | ds->fd = fd; |
1088 | ds->cfs = NULL; | ||
1008 | ct = get_compression_type (bfds); | 1089 | ct = get_compression_type (bfds); |
1009 | if ( (COMP_TYPE_ZLIB == ct) || | 1090 | if ( (COMP_TYPE_ZLIB == ct) || |
1010 | (COMP_TYPE_BZ2 == ct) ) | 1091 | (COMP_TYPE_BZ2 == ct) ) |
1011 | ds->cfs = cfs_new (bfds, fsize, ct, proc, proc_cls); | ||
1012 | if (NULL == ds->cfs) | ||
1013 | { | 1092 | { |
1014 | bfds_delete (bfds); | 1093 | ds->cfs = cfs_new (bfds, fsize, ct, proc, proc_cls); |
1015 | free (ds); | 1094 | if (NULL == ds->cfs) |
1016 | (void) close (fd); | 1095 | { |
1017 | return NULL; | 1096 | LOG ("Failed to initialize decompressor\n"); |
1097 | bfds_delete (bfds); | ||
1098 | free (ds); | ||
1099 | (void) close (fd); | ||
1100 | return NULL; | ||
1101 | } | ||
1018 | } | 1102 | } |
1019 | return ds; | 1103 | return ds; |
1020 | } | 1104 | } |
@@ -1041,9 +1125,13 @@ EXTRACTOR_datasource_create_from_buffer_ (const char *buf, | |||
1041 | if (0 == size) | 1125 | if (0 == size) |
1042 | return NULL; | 1126 | return NULL; |
1043 | if (NULL == (bfds = bfds_new (buf, -1, size))) | 1127 | if (NULL == (bfds = bfds_new (buf, -1, size))) |
1044 | return NULL; | 1128 | { |
1129 | LOG ("Failed to initialize buffer data source\n"); | ||
1130 | return NULL; | ||
1131 | } | ||
1045 | if (NULL == (ds = malloc (sizeof (struct EXTRACTOR_Datasource)))) | 1132 | if (NULL == (ds = malloc (sizeof (struct EXTRACTOR_Datasource)))) |
1046 | { | 1133 | { |
1134 | LOG_STRERROR ("malloc"); | ||
1047 | bfds_delete (bfds); | 1135 | bfds_delete (bfds); |
1048 | return NULL; | 1136 | return NULL; |
1049 | } | 1137 | } |
@@ -1052,12 +1140,15 @@ EXTRACTOR_datasource_create_from_buffer_ (const char *buf, | |||
1052 | ct = get_compression_type (bfds); | 1140 | ct = get_compression_type (bfds); |
1053 | if ( (COMP_TYPE_ZLIB == ct) || | 1141 | if ( (COMP_TYPE_ZLIB == ct) || |
1054 | (COMP_TYPE_BZ2 == ct) ) | 1142 | (COMP_TYPE_BZ2 == ct) ) |
1055 | ds->cfs = cfs_new (bfds, size, ct, proc, proc_cls); | ||
1056 | if (NULL == ds->cfs) | ||
1057 | { | 1143 | { |
1058 | bfds_delete (bfds); | 1144 | ds->cfs = cfs_new (bfds, size, ct, proc, proc_cls); |
1059 | free (ds); | 1145 | if (NULL == ds->cfs) |
1060 | return NULL; | 1146 | { |
1147 | LOG ("Failed to initialize decompressor\n"); | ||
1148 | bfds_delete (bfds); | ||
1149 | free (ds); | ||
1150 | return NULL; | ||
1151 | } | ||
1061 | } | 1152 | } |
1062 | return ds; | 1153 | return ds; |
1063 | } | 1154 | } |
diff --git a/src/main/extractor_ipc.c b/src/main/extractor_ipc.c index 4c8a14d..2d935df 100644 --- a/src/main/extractor_ipc.c +++ b/src/main/extractor_ipc.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "extractor_logging.h" | ||
26 | #include "extractor_ipc.h" | 27 | #include "extractor_ipc.h" |
27 | #include "extractor_plugins.h" | 28 | #include "extractor_plugins.h" |
28 | 29 | ||
@@ -78,7 +79,10 @@ EXTRACTOR_IPC_process_reply_ (struct EXTRACTOR_PluginList *plugin, | |||
78 | memcpy (&meta, cdata, sizeof (meta)); | 79 | memcpy (&meta, cdata, sizeof (meta)); |
79 | /* check hdr for sanity */ | 80 | /* check hdr for sanity */ |
80 | if (meta.value_size > MAX_META_DATA) | 81 | if (meta.value_size > MAX_META_DATA) |
81 | return -1; /* not allowing more than MAX_META_DATA meta data */ | 82 | { |
83 | LOG ("Meta data exceeds size limit\n"); | ||
84 | return -1; /* not allowing more than MAX_META_DATA meta data */ | ||
85 | } | ||
82 | if (size < sizeof (meta) + meta.mime_length + meta.value_size) | 86 | if (size < sizeof (meta) + meta.mime_length + meta.value_size) |
83 | { | 87 | { |
84 | plugin->seek_request = -1; | 88 | plugin->seek_request = -1; |
@@ -92,7 +96,10 @@ EXTRACTOR_IPC_process_reply_ (struct EXTRACTOR_PluginList *plugin, | |||
92 | { | 96 | { |
93 | mime_type = &cdata[sizeof (struct MetaMessage)]; | 97 | mime_type = &cdata[sizeof (struct MetaMessage)]; |
94 | if ('\0' != mime_type[meta.mime_length - 1]) | 98 | if ('\0' != mime_type[meta.mime_length - 1]) |
95 | return -1; | 99 | { |
100 | LOG ("Mime type not 0-terminated\n"); | ||
101 | return -1; | ||
102 | } | ||
96 | } | 103 | } |
97 | if (0 == meta.value_size) | 104 | if (0 == meta.value_size) |
98 | value = NULL; | 105 | value = NULL; |
@@ -106,6 +113,7 @@ EXTRACTOR_IPC_process_reply_ (struct EXTRACTOR_PluginList *plugin, | |||
106 | mime_type, value); | 113 | mime_type, value); |
107 | return sizeof (struct MetaMessage) + meta.mime_length + meta.value_size; | 114 | return sizeof (struct MetaMessage) + meta.mime_length + meta.value_size; |
108 | default: | 115 | default: |
116 | LOG ("Invalid message type %d\n", (int) code); | ||
109 | return -1; | 117 | return -1; |
110 | } | 118 | } |
111 | } | 119 | } |
diff --git a/src/main/extractor_ipc_gnu.c b/src/main/extractor_ipc_gnu.c index 68b6162..7dce32b 100644 --- a/src/main/extractor_ipc_gnu.c +++ b/src/main/extractor_ipc_gnu.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "plibc.h" | 26 | #include "plibc.h" |
27 | #include "extractor.h" | 27 | #include "extractor.h" |
28 | #include "extractor_datasource.h" | 28 | #include "extractor_datasource.h" |
29 | #include "extractor_logging.h" | ||
29 | #include "extractor_plugin_main.h" | 30 | #include "extractor_plugin_main.h" |
30 | #include "extractor_ipc.h" | 31 | #include "extractor_ipc.h" |
31 | #include <dirent.h> | 32 | #include <dirent.h> |
@@ -136,7 +137,10 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size) | |||
136 | const char *tpath; | 137 | const char *tpath; |
137 | 138 | ||
138 | if (NULL == (shm = malloc (sizeof (struct EXTRACTOR_SharedMemory)))) | 139 | if (NULL == (shm = malloc (sizeof (struct EXTRACTOR_SharedMemory)))) |
139 | return NULL; | 140 | { |
141 | LOG_STRERROR ("malloc"); | ||
142 | return NULL; | ||
143 | } | ||
140 | #if SOMEBSD | 144 | #if SOMEBSD |
141 | /* this works on FreeBSD, not sure about others... */ | 145 | /* this works on FreeBSD, not sure about others... */ |
142 | tpath = getenv ("TMPDIR"); | 146 | tpath = getenv ("TMPDIR"); |
@@ -153,6 +157,7 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size) | |||
153 | if (-1 == (shm->shm_id = shm_open (shm->shm_name, | 157 | if (-1 == (shm->shm_id = shm_open (shm->shm_name, |
154 | O_RDWR | O_CREAT, S_IRUSR | S_IWUSR))) | 158 | O_RDWR | O_CREAT, S_IRUSR | S_IWUSR))) |
155 | { | 159 | { |
160 | LOG_STRERROR_FILE ("shm_open", shm->shm_name); | ||
156 | free (shm); | 161 | free (shm); |
157 | return NULL; | 162 | return NULL; |
158 | } | 163 | } |
@@ -162,6 +167,7 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size) | |||
162 | shm->shm_id, 0))) || | 167 | shm->shm_id, 0))) || |
163 | (((void*) -1) == shm->shm_ptr) ) | 168 | (((void*) -1) == shm->shm_ptr) ) |
164 | { | 169 | { |
170 | LOG_STRERROR ("ftruncate/mmap"); | ||
165 | (void) close (shm->shm_id); | 171 | (void) close (shm->shm_id); |
166 | (void) shm_unlink (shm->shm_name); | 172 | (void) shm_unlink (shm->shm_name); |
167 | free (shm); | 173 | free (shm); |
@@ -251,16 +257,21 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin, | |||
251 | size_t slen; | 257 | size_t slen; |
252 | 258 | ||
253 | if (NULL == (channel = malloc (sizeof (struct EXTRACTOR_Channel)))) | 259 | if (NULL == (channel = malloc (sizeof (struct EXTRACTOR_Channel)))) |
254 | return NULL; | 260 | { |
261 | LOG_STRERROR ("malloc"); | ||
262 | return NULL; | ||
263 | } | ||
255 | channel->shm = shm; | 264 | channel->shm = shm; |
256 | channel->plugin = plugin; | 265 | channel->plugin = plugin; |
257 | if (0 != pipe (p1)) | 266 | if (0 != pipe (p1)) |
258 | { | 267 | { |
268 | LOG_STRERROR ("pipe"); | ||
259 | free (channel); | 269 | free (channel); |
260 | return NULL; | 270 | return NULL; |
261 | } | 271 | } |
262 | if (0 != pipe (p2)) | 272 | if (0 != pipe (p2)) |
263 | { | 273 | { |
274 | LOG_STRERROR ("pipe"); | ||
264 | (void) close (p1[0]); | 275 | (void) close (p1[0]); |
265 | (void) close (p1[1]); | 276 | (void) close (p1[1]); |
266 | free (channel); | 277 | free (channel); |
@@ -269,6 +280,7 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin, | |||
269 | pid = fork (); | 280 | pid = fork (); |
270 | if (pid == -1) | 281 | if (pid == -1) |
271 | { | 282 | { |
283 | LOG_STRERROR ("fork"); | ||
272 | (void) close (p1[0]); | 284 | (void) close (p1[0]); |
273 | (void) close (p1[1]); | 285 | (void) close (p1[1]); |
274 | (void) close (p2[0]); | 286 | (void) close (p2[0]); |
@@ -291,6 +303,7 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin, | |||
291 | slen = strlen (shm->shm_name) + 1; | 303 | slen = strlen (shm->shm_name) + 1; |
292 | if (NULL == (init = malloc (sizeof (struct InitMessage) + slen))) | 304 | if (NULL == (init = malloc (sizeof (struct InitMessage) + slen))) |
293 | { | 305 | { |
306 | LOG_STRERROR ("malloc"); | ||
294 | EXTRACTOR_IPC_channel_destroy_ (channel); | 307 | EXTRACTOR_IPC_channel_destroy_ (channel); |
295 | return NULL; | 308 | return NULL; |
296 | } | 309 | } |
@@ -304,6 +317,7 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin, | |||
304 | init, | 317 | init, |
305 | sizeof (init) + slen) ) | 318 | sizeof (init) + slen) ) |
306 | { | 319 | { |
320 | LOG ("Failed to send INIT_STATE message to plugin\n"); | ||
307 | EXTRACTOR_IPC_channel_destroy_ (channel); | 321 | EXTRACTOR_IPC_channel_destroy_ (channel); |
308 | return NULL; | 322 | return NULL; |
309 | } | 323 | } |
@@ -322,10 +336,14 @@ EXTRACTOR_IPC_channel_destroy_ (struct EXTRACTOR_Channel *channel) | |||
322 | { | 336 | { |
323 | int status; | 337 | int status; |
324 | 338 | ||
325 | (void) kill (channel->cpid, SIGKILL); | 339 | if (0 != kill (channel->cpid, SIGKILL)) |
326 | (void) waitpid (channel->cpid, &status, 0); | 340 | LOG_STRERROR ("kill"); |
327 | (void) close (channel->cpipe_out); | 341 | if (-1 == waitpid (channel->cpid, &status, 0)) |
328 | (void) close (channel->cpipe_in); | 342 | LOG_STRERROR ("waitpid"); |
343 | if (0 != close (channel->cpipe_out)) | ||
344 | LOG_STRERROR ("close"); | ||
345 | if (0 != close (channel->cpipe_in)) | ||
346 | LOG_STRERROR ("close"); | ||
329 | free (channel); | 347 | free (channel); |
330 | } | 348 | } |
331 | 349 | ||
@@ -352,7 +370,11 @@ EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel, | |||
352 | { | 370 | { |
353 | ret = write (channel->cpipe_in, &cdata[off], size - off); | 371 | ret = write (channel->cpipe_in, &cdata[off], size - off); |
354 | if (ret <= 0) | 372 | if (ret <= 0) |
355 | return -1; | 373 | { |
374 | if (-1 == ret) | ||
375 | LOG_STRERROR ("write"); | ||
376 | return -1; | ||
377 | } | ||
356 | off += ret; | 378 | off += ret; |
357 | } | 379 | } |
358 | return size; | 380 | return size; |
@@ -404,6 +426,8 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, | |||
404 | if (-1 == select (max + 1, &to_check, NULL, NULL, &tv)) | 426 | if (-1 == select (max + 1, &to_check, NULL, NULL, &tv)) |
405 | { | 427 | { |
406 | /* an error or timeout -> something's wrong or all plugins hung up */ | 428 | /* an error or timeout -> something's wrong or all plugins hung up */ |
429 | if (EINTR != errno) | ||
430 | LOG_STRERROR ("select"); | ||
407 | return -1; | 431 | return -1; |
408 | } | 432 | } |
409 | for (i=0;i<num_channels;i++) | 433 | for (i=0;i<num_channels;i++) |
@@ -421,6 +445,8 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, | |||
421 | channel->size + iret, | 445 | channel->size + iret, |
422 | proc, proc_cls)) ) | 446 | proc, proc_cls)) ) |
423 | { | 447 | { |
448 | if (-1 == iret) | ||
449 | LOG_STRERROR ("read"); | ||
424 | EXTRACTOR_IPC_channel_destroy_ (channel); | 450 | EXTRACTOR_IPC_channel_destroy_ (channel); |
425 | channels[i] = NULL; | 451 | channels[i] = NULL; |
426 | } | 452 | } |
diff --git a/src/main/extractor_logging.h b/src/main/extractor_logging.h index d8c7a54..54a6564 100644 --- a/src/main/extractor_logging.h +++ b/src/main/extractor_logging.h | |||
@@ -42,12 +42,19 @@ EXTRACTOR_log_ (const char *file, int line, const char *format, ...); | |||
42 | /** | 42 | /** |
43 | * Log a message. | 43 | * Log a message. |
44 | * | 44 | * |
45 | * @param fmt format string | 45 | * @param ... format string and arguments for fmt (printf-style) |
46 | * @param ... arguments for fmt (printf-style) | ||
47 | */ | 46 | */ |
48 | #define LOG(fmt, ...) EXTRACTOR_log_ (__FILE__, __LINE__, fmt, __VA_ARGS__) | 47 | #define LOG(...) EXTRACTOR_log_(__FILE__, __LINE__, __VA_ARGS__) |
48 | |||
49 | #else | 49 | #else |
50 | |||
51 | /** | ||
52 | * Log a message. | ||
53 | * | ||
54 | * @param ... format string and arguments for fmt (printf-style) | ||
55 | */ | ||
50 | #define LOG(...) | 56 | #define LOG(...) |
57 | |||
51 | #endif | 58 | #endif |
52 | 59 | ||
53 | 60 | ||
diff --git a/src/main/extractor_plugin_main.c b/src/main/extractor_plugin_main.c index 26701f7..650a55f 100644 --- a/src/main/extractor_plugin_main.c +++ b/src/main/extractor_plugin_main.c | |||
@@ -22,7 +22,6 @@ | |||
22 | * @brief main loop for an out-of-process plugin | 22 | * @brief main loop for an out-of-process plugin |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | */ | 24 | */ |
25 | |||
26 | #include "platform.h" | 25 | #include "platform.h" |
27 | #include "plibc.h" | 26 | #include "plibc.h" |
28 | #include "extractor.h" | 27 | #include "extractor.h" |
@@ -30,6 +29,7 @@ | |||
30 | #include "extractor_datasource.h" | 29 | #include "extractor_datasource.h" |
31 | #include "extractor_plugins.h" | 30 | #include "extractor_plugins.h" |
32 | #include "extractor_ipc.h" | 31 | #include "extractor_ipc.h" |
32 | #include "extractor_logging.h" | ||
33 | #include "extractor_plugin_main.h" | 33 | #include "extractor_plugin_main.h" |
34 | #include <dirent.h> | 34 | #include <dirent.h> |
35 | #include <sys/types.h> | 35 | #include <sys/types.h> |
@@ -120,24 +120,37 @@ plugin_env_seek (void *cls, | |||
120 | { | 120 | { |
121 | case SEEK_CUR: | 121 | case SEEK_CUR: |
122 | if ( (pos < 0) && (pc->read_position < - pos) ) | 122 | if ( (pos < 0) && (pc->read_position < - pos) ) |
123 | return -1; | 123 | { |
124 | LOG ("Invalid seek operation\n"); | ||
125 | return -1; | ||
126 | } | ||
124 | if ( (pos > 0) && | 127 | if ( (pos > 0) && |
125 | ( (pc->read_position + pos < pc->read_position) || | 128 | ( (pc->read_position + pos < pc->read_position) || |
126 | (pc->read_position + pos > pc->file_size) ) ) | 129 | (pc->read_position + pos > pc->file_size) ) ) |
127 | return -1; | 130 | { |
131 | LOG ("Invalid seek operation\n"); | ||
132 | return -1; | ||
133 | } | ||
128 | npos = (uint64_t) (pc->read_position + pos); | 134 | npos = (uint64_t) (pc->read_position + pos); |
129 | break; | 135 | break; |
130 | case SEEK_END: | 136 | case SEEK_END: |
131 | if (pos > 0) | 137 | if (pos > 0) |
132 | return -1; | 138 | { |
139 | LOG ("Invalid seek operation\n"); | ||
140 | return -1; | ||
141 | } | ||
133 | pos = (int64_t) (pc->file_size + pos); | 142 | pos = (int64_t) (pc->file_size + pos); |
134 | /* fall-through! */ | 143 | /* fall-through! */ |
135 | case SEEK_SET: | 144 | case SEEK_SET: |
136 | if ( (pos < 0) || (pc->file_size < pos) ) | 145 | if ( (pos < 0) || (pc->file_size < pos) ) |
137 | return -1; | 146 | { |
147 | LOG ("Invalid seek operation\n"); | ||
148 | return -1; | ||
149 | } | ||
138 | npos = (uint64_t) pos; | 150 | npos = (uint64_t) pos; |
139 | break; | 151 | break; |
140 | default: | 152 | default: |
153 | LOG ("Invalid seek operation\n"); | ||
141 | return -1; | 154 | return -1; |
142 | } | 155 | } |
143 | if ( (pc->shm_off <= npos) && | 156 | if ( (pc->shm_off <= npos) && |
@@ -155,15 +168,24 @@ plugin_env_seek (void *cls, | |||
155 | srm.requested_bytes = pc->file_size - npos; | 168 | srm.requested_bytes = pc->file_size - npos; |
156 | srm.file_offset = npos; | 169 | srm.file_offset = npos; |
157 | if (-1 == EXTRACTOR_write_all_ (pc->out, &srm, sizeof (srm))) | 170 | if (-1 == EXTRACTOR_write_all_ (pc->out, &srm, sizeof (srm))) |
158 | return -1; | 171 | { |
172 | LOG ("Failed to send MESSAGE_SEEK\n"); | ||
173 | return -1; | ||
174 | } | ||
159 | if (-1 == | 175 | if (-1 == |
160 | EXTRACTOR_read_all_ (pc->in, | 176 | EXTRACTOR_read_all_ (pc->in, |
161 | &reply, sizeof (reply))) | 177 | &reply, sizeof (reply))) |
162 | return -1; | 178 | { |
163 | if (MESSAGE_SEEK != reply) | 179 | LOG ("Failed to read response to MESSAGE_SEEK\n"); |
180 | return -1; | ||
181 | } | ||
182 | if (MESSAGE_SEEK != reply) | ||
164 | return -1; /* was likely a MESSAGE_DISCARD_STATE */ | 183 | return -1; /* was likely a MESSAGE_DISCARD_STATE */ |
165 | if (-1 == EXTRACTOR_read_all_ (pc->in, &um.reserved, sizeof (um) - 1)) | 184 | if (-1 == EXTRACTOR_read_all_ (pc->in, &um.reserved, sizeof (um) - 1)) |
166 | return -1; | 185 | { |
186 | LOG ("Failed to read UPDATE_MESSAGE\n"); | ||
187 | return -1; | ||
188 | } | ||
167 | pc->shm_off = um.shm_off; | 189 | pc->shm_off = um.shm_off; |
168 | pc->shm_ready_bytes = um.shm_ready_bytes; | 190 | pc->shm_ready_bytes = um.shm_ready_bytes; |
169 | if ( (pc->shm_off <= npos) && | 191 | if ( (pc->shm_off <= npos) && |
@@ -174,6 +196,7 @@ plugin_env_seek (void *cls, | |||
174 | } | 196 | } |
175 | /* oops, serious missunderstanding, we asked to seek | 197 | /* oops, serious missunderstanding, we asked to seek |
176 | and then were notified about a different position!? */ | 198 | and then were notified about a different position!? */ |
199 | LOG ("Got invalid UPDATE_MESSAGE in response to my seek\n"); | ||
177 | return -1; | 200 | return -1; |
178 | } | 201 | } |
179 | 202 | ||
@@ -200,7 +223,10 @@ plugin_env_read (void *cls, | |||
200 | if ( ( (pc->read_position >= pc->shm_off + pc->shm_ready_bytes) || | 223 | if ( ( (pc->read_position >= pc->shm_off + pc->shm_ready_bytes) || |
201 | (pc->read_position < pc->shm_off) ) && | 224 | (pc->read_position < pc->shm_off) ) && |
202 | (-1 == plugin_env_seek (pc, pc->read_position, SEEK_SET)) ) | 225 | (-1 == plugin_env_seek (pc, pc->read_position, SEEK_SET)) ) |
203 | return -1; | 226 | { |
227 | LOG ("Failed to seek to satisfy read\n"); | ||
228 | return -1; | ||
229 | } | ||
204 | if (pc->read_position + count > pc->shm_off + pc->shm_ready_bytes) | 230 | if (pc->read_position + count > pc->shm_off + pc->shm_ready_bytes) |
205 | count = pc->shm_off + pc->shm_ready_bytes - pc->read_position; | 231 | count = pc->shm_off + pc->shm_ready_bytes - pc->read_position; |
206 | dp = pc->shm; | 232 | dp = pc->shm; |
@@ -220,6 +246,7 @@ static uint64_t | |||
220 | plugin_env_get_size (void *cls) | 246 | plugin_env_get_size (void *cls) |
221 | { | 247 | { |
222 | struct ProcessingContext *pc = cls; | 248 | struct ProcessingContext *pc = cls; |
249 | |||
223 | return pc->file_size; | 250 | return pc->file_size; |
224 | } | 251 | } |
225 | 252 | ||
@@ -275,11 +302,17 @@ plugin_env_send_proc (void *cls, | |||
275 | (data_len != | 302 | (data_len != |
276 | EXTRACTOR_write_all_ (pc->out, | 303 | EXTRACTOR_write_all_ (pc->out, |
277 | data, data_len)) ) | 304 | data, data_len)) ) |
278 | return 1; | 305 | { |
306 | LOG ("Failed to send meta message\n"); | ||
307 | return 1; | ||
308 | } | ||
279 | if (-1 == | 309 | if (-1 == |
280 | EXTRACTOR_read_all_ (pc->in, | 310 | EXTRACTOR_read_all_ (pc->in, |
281 | &reply, sizeof (reply))) | 311 | &reply, sizeof (reply))) |
282 | return 1; | 312 | { |
313 | LOG ("Failed to read response to meta message\n"); | ||
314 | return 1; | ||
315 | } | ||
283 | if (MESSAGE_CONTINUE_EXTRACTING != reply) | 316 | if (MESSAGE_CONTINUE_EXTRACTING != reply) |
284 | return 1; | 317 | return 1; |
285 | return 0; | 318 | return 0; |
@@ -298,14 +331,23 @@ handle_init_message (struct ProcessingContext *pc) | |||
298 | struct InitMessage init; | 331 | struct InitMessage init; |
299 | 332 | ||
300 | if (NULL != pc->shm) | 333 | if (NULL != pc->shm) |
301 | return -1; | 334 | { |
335 | LOG ("Cannot handle 'init' message, have already been initialized\n"); | ||
336 | return -1; | ||
337 | } | ||
302 | if (sizeof (struct InitMessage) - 1 | 338 | if (sizeof (struct InitMessage) - 1 |
303 | != EXTRACTOR_read_all_ (pc->in, | 339 | != EXTRACTOR_read_all_ (pc->in, |
304 | &init.reserved, | 340 | &init.reserved, |
305 | sizeof (struct InitMessage) - 1)) | 341 | sizeof (struct InitMessage) - 1)) |
306 | return -1; | 342 | { |
343 | LOG ("Failed to read 'init' message\n"); | ||
344 | return -1; | ||
345 | } | ||
307 | if (init.shm_name_length > MAX_SHM_NAME) | 346 | if (init.shm_name_length > MAX_SHM_NAME) |
308 | return -1; | 347 | { |
348 | LOG ("Invalid 'init' message\n"); | ||
349 | return -1; | ||
350 | } | ||
309 | { | 351 | { |
310 | char shm_name[init.shm_name_length + 1]; | 352 | char shm_name[init.shm_name_length + 1]; |
311 | 353 | ||
@@ -313,7 +355,10 @@ handle_init_message (struct ProcessingContext *pc) | |||
313 | != EXTRACTOR_read_all_ (pc->in, | 355 | != EXTRACTOR_read_all_ (pc->in, |
314 | shm_name, | 356 | shm_name, |
315 | init.shm_name_length)) | 357 | init.shm_name_length)) |
316 | return -1; | 358 | { |
359 | LOG ("Failed to read 'init' message\n"); | ||
360 | return -1; | ||
361 | } | ||
317 | shm_name[init.shm_name_length] = '\0'; | 362 | shm_name[init.shm_name_length] = '\0'; |
318 | 363 | ||
319 | pc->shm_map_size = init.shm_map_size; | 364 | pc->shm_map_size = init.shm_map_size; |
@@ -324,14 +369,20 @@ handle_init_message (struct ProcessingContext *pc) | |||
324 | #else | 369 | #else |
325 | pc->shm_id = open (shm_name, O_RDONLY, 0); | 370 | pc->shm_id = open (shm_name, O_RDONLY, 0); |
326 | if (-1 == pc->shm_id) | 371 | if (-1 == pc->shm_id) |
327 | return -1; | 372 | { |
373 | LOG_STRERROR_FILE ("open", shm_name); | ||
374 | return -1; | ||
375 | } | ||
328 | pc->shm = mmap (NULL, | 376 | pc->shm = mmap (NULL, |
329 | pc->shm_map_size, | 377 | pc->shm_map_size, |
330 | PROT_READ, | 378 | PROT_READ, |
331 | MAP_SHARED, | 379 | MAP_SHARED, |
332 | pc->shm_id, 0); | 380 | pc->shm_id, 0); |
333 | if ( ((void*) -1) == pc->shm) | 381 | if ( ((void*) -1) == pc->shm) |
334 | return -1; | 382 | { |
383 | LOG_STRERROR_FILE ("mmap", shm_name); | ||
384 | return -1; | ||
385 | } | ||
335 | #endif | 386 | #endif |
336 | } | 387 | } |
337 | return 0; | 388 | return 0; |
@@ -355,7 +406,10 @@ handle_start_message (struct ProcessingContext *pc) | |||
355 | != EXTRACTOR_read_all_ (pc->in, | 406 | != EXTRACTOR_read_all_ (pc->in, |
356 | &start.reserved, | 407 | &start.reserved, |
357 | sizeof (struct StartMessage) - 1)) | 408 | sizeof (struct StartMessage) - 1)) |
358 | return -1; | 409 | { |
410 | LOG ("Failed to read 'start' message\n"); | ||
411 | return -1; | ||
412 | } | ||
359 | pc->shm_ready_bytes = start.shm_ready_bytes; | 413 | pc->shm_ready_bytes = start.shm_ready_bytes; |
360 | pc->file_size = start.file_size; | 414 | pc->file_size = start.file_size; |
361 | pc->read_position = 0; | 415 | pc->read_position = 0; |
@@ -369,7 +423,10 @@ handle_start_message (struct ProcessingContext *pc) | |||
369 | pc->plugin->extract_method (&ec); | 423 | pc->plugin->extract_method (&ec); |
370 | done = MESSAGE_DONE; | 424 | done = MESSAGE_DONE; |
371 | if (-1 == EXTRACTOR_write_all_ (pc->out, &done, sizeof (done))) | 425 | if (-1 == EXTRACTOR_write_all_ (pc->out, &done, sizeof (done))) |
372 | return -1; | 426 | { |
427 | LOG ("Failed to write 'done' message\n"); | ||
428 | return -1; | ||
429 | } | ||
373 | if ( (NULL != pc->plugin->specials) && | 430 | if ( (NULL != pc->plugin->specials) && |
374 | (NULL != strstr (pc->plugin->specials, "force-kill")) ) | 431 | (NULL != strstr (pc->plugin->specials, "force-kill")) ) |
375 | { | 432 | { |
@@ -400,7 +457,10 @@ process_requests (struct ProcessingContext *pc) | |||
400 | unsigned char code; | 457 | unsigned char code; |
401 | 458 | ||
402 | if (1 != EXTRACTOR_read_all_ (pc->in, &code, 1)) | 459 | if (1 != EXTRACTOR_read_all_ (pc->in, &code, 1)) |
403 | break; | 460 | { |
461 | LOG ("Failed to read next request\n"); | ||
462 | break; | ||
463 | } | ||
404 | switch (code) | 464 | switch (code) |
405 | { | 465 | { |
406 | case MESSAGE_INIT_STATE: | 466 | case MESSAGE_INIT_STATE: |
@@ -417,6 +477,7 @@ process_requests (struct ProcessingContext *pc) | |||
417 | /* odd, we're already in the start state... */ | 477 | /* odd, we're already in the start state... */ |
418 | continue; | 478 | continue; |
419 | default: | 479 | default: |
480 | LOG ("Received invalid messag %d\n", (int) code); | ||
420 | /* error, unexpected message */ | 481 | /* error, unexpected message */ |
421 | return; | 482 | return; |
422 | } | 483 | } |
@@ -440,16 +501,21 @@ open_dev_null (int target_fd, | |||
440 | 501 | ||
441 | fd = open ("/dev/null", flags); | 502 | fd = open ("/dev/null", flags); |
442 | if (-1 == fd) | 503 | if (-1 == fd) |
443 | return; /* good luck */ | 504 | { |
505 | LOG_STRERROR_FILE ("open", "/dev/null"); | ||
506 | return; /* good luck */ | ||
507 | } | ||
444 | if (fd == target_fd) | 508 | if (fd == target_fd) |
445 | return; /* already done */ | 509 | return; /* already done */ |
446 | if (-1 == dup2 (fd, target_fd)) | 510 | if (-1 == dup2 (fd, target_fd)) |
447 | { | 511 | { |
512 | LOG_STRERROR ("dup2"); | ||
448 | (void) close (fd); | 513 | (void) close (fd); |
449 | return; /* good luck */ | 514 | return; /* good luck */ |
450 | } | 515 | } |
451 | /* close original result from 'open' */ | 516 | /* close original result from 'open' */ |
452 | (void) close (fd); | 517 | if (0 != close (fd)) |
518 | LOG_STRERROR ("close"); | ||
453 | } | 519 | } |
454 | #endif | 520 | #endif |
455 | 521 | ||
@@ -479,7 +545,8 @@ EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin, | |||
479 | if ( (NULL != plugin->specials) && | 545 | if ( (NULL != plugin->specials) && |
480 | (NULL != strstr (plugin->specials, "close-stderr"))) | 546 | (NULL != strstr (plugin->specials, "close-stderr"))) |
481 | { | 547 | { |
482 | (void) close (2); | 548 | if (0 != close (2)) |
549 | LOG_STRERROR ("close"); | ||
483 | #ifndef WINDOWS | 550 | #ifndef WINDOWS |
484 | open_dev_null (2, O_WRONLY); | 551 | open_dev_null (2, O_WRONLY); |
485 | #endif | 552 | #endif |
@@ -487,7 +554,8 @@ EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin, | |||
487 | if ( (NULL != plugin->specials) && | 554 | if ( (NULL != plugin->specials) && |
488 | (NULL != strstr (plugin->specials, "close-stdout"))) | 555 | (NULL != strstr (plugin->specials, "close-stdout"))) |
489 | { | 556 | { |
490 | (void) close (1); | 557 | if (0 != close (1)) |
558 | LOG_STRERROR ("close"); | ||
491 | #ifndef WINDOWS | 559 | #ifndef WINDOWS |
492 | open_dev_null (1, O_WRONLY); | 560 | open_dev_null (1, O_WRONLY); |
493 | #endif | 561 | #endif |
@@ -507,7 +575,10 @@ EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin, | |||
507 | (((void*) 1) != pc.shm) ) | 575 | (((void*) 1) != pc.shm) ) |
508 | munmap (pc.shm, pc.shm_map_size); | 576 | munmap (pc.shm, pc.shm_map_size); |
509 | if (-1 != pc.shm_id) | 577 | if (-1 != pc.shm_id) |
510 | (void) close (pc.shm_id); | 578 | { |
579 | if (0 != close (pc.shm_id)) | ||
580 | LOG_STRERROR ("close"); | ||
581 | } | ||
511 | #endif | 582 | #endif |
512 | } | 583 | } |
513 | 584 | ||
@@ -529,7 +600,10 @@ read_plugin_data (int fd) | |||
529 | 600 | ||
530 | // FIXME: check for errors from 'EXTRACTOR_read_all_'! | 601 | // FIXME: check for errors from 'EXTRACTOR_read_all_'! |
531 | if (NULL == (ret = malloc (sizeof (struct EXTRACTOR_PluginList)))) | 602 | if (NULL == (ret = malloc (sizeof (struct EXTRACTOR_PluginList)))) |
532 | return NULL; | 603 | { |
604 | LOG_STRERROR ("malloc"); | ||
605 | return NULL; | ||
606 | } | ||
533 | GetSystemInfo (&si); | 607 | GetSystemInfo (&si); |
534 | ret->allocation_granularity = si.dwAllocationGranularity; | 608 | ret->allocation_granularity = si.dwAllocationGranularity; |
535 | EXTRACTOR_read_all_ (fd, &i, sizeof (size_t)); | 609 | EXTRACTOR_read_all_ (fd, &i, sizeof (size_t)); |
diff --git a/src/main/extractor_plugins.c b/src/main/extractor_plugins.c index 5b0f20d..c8b21cd 100644 --- a/src/main/extractor_plugins.c +++ b/src/main/extractor_plugins.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "extractor_plugins.h" | 25 | #include "extractor_plugins.h" |
26 | #include "extractor_plugpath.h" | 26 | #include "extractor_plugpath.h" |
27 | #include "extractor_ipc.h" | 27 | #include "extractor_ipc.h" |
28 | #include "extractor_logging.h" | ||
28 | 29 | ||
29 | 30 | ||
30 | /** | 31 | /** |
@@ -55,9 +56,11 @@ get_symbol_with_prefix (void *lib_handle, | |||
55 | return NULL; | 56 | return NULL; |
56 | sym_name++; | 57 | sym_name++; |
57 | if (NULL == (sym = strdup (sym_name))) | 58 | if (NULL == (sym = strdup (sym_name))) |
58 | return NULL; | 59 | { |
59 | dot = strchr (sym, '.'); | 60 | LOG_STRERROR ("strdup"); |
60 | if (NULL != dot) | 61 | return NULL; |
62 | } | ||
63 | if (NULL != (dot = strchr (sym, '.'))) | ||
61 | *dot = '\0'; | 64 | *dot = '\0'; |
62 | if (NULL == (name = malloc(strlen(sym) + strlen(template) + 1))) | 65 | if (NULL == (name = malloc(strlen(sym) + strlen(template) + 1))) |
63 | { | 66 | { |
@@ -72,34 +75,29 @@ get_symbol_with_prefix (void *lib_handle, | |||
72 | if (NULL == symbol) | 75 | if (NULL == symbol) |
73 | { | 76 | { |
74 | /* now try with the '_' */ | 77 | /* now try with the '_' */ |
75 | #if DEBUG | ||
76 | char *first_error = strdup (lt_dlerror ()); | 78 | char *first_error = strdup (lt_dlerror ()); |
77 | #endif | ||
78 | symbol = lt_dlsym (lib_handle, name); | 79 | symbol = lt_dlsym (lib_handle, name); |
79 | #if DEBUG | ||
80 | if (NULL == symbol) | 80 | if (NULL == symbol) |
81 | { | 81 | { |
82 | fprintf (stderr, | 82 | LOG ("Resolving symbol `%s' failed, " |
83 | "Resolving symbol `%s' failed, " | 83 | "so I tried `%s', but that failed also. Errors are: " |
84 | "so I tried `%s', but that failed also. Errors are: " | 84 | "`%s' and `%s'.\n", |
85 | "`%s' and `%s'.\n", | 85 | name+1, |
86 | name+1, | 86 | name, |
87 | name, | 87 | first_error == NULL ? "out of memory" : first_error, |
88 | first_error == NULL ? "out of memory" : first_error, | 88 | lt_dlerror ()); |
89 | lt_dlerror()); | ||
90 | } | 89 | } |
91 | if (NULL != first_error) | 90 | if (NULL != first_error) |
92 | free (first_error); | 91 | free (first_error); |
93 | #endif | ||
94 | } | 92 | } |
95 | 93 | ||
96 | if ( (NULL != symbol) && | 94 | if ( (NULL != symbol) && |
97 | (NULL != options) ) | 95 | (NULL != options) ) |
98 | { | 96 | { |
99 | /* get special options */ | 97 | /* get special options */ |
100 | sprintf(name, | 98 | sprintf (name, |
101 | "_EXTRACTOR_%s_options", | 99 | "_EXTRACTOR_%s_options", |
102 | sym); | 100 | sym); |
103 | /* try without '_' first */ | 101 | /* try without '_' first */ |
104 | opt_fun = lt_dlsym (lib_handle, name + 1); | 102 | opt_fun = lt_dlsym (lib_handle, name + 1); |
105 | if (NULL == opt_fun) | 103 | if (NULL == opt_fun) |
@@ -134,11 +132,8 @@ EXTRACTOR_plugin_load_ (struct EXTRACTOR_PluginList *plugin) | |||
134 | plugin->libname = EXTRACTOR_find_plugin_ (plugin->short_libname); | 132 | plugin->libname = EXTRACTOR_find_plugin_ (plugin->short_libname); |
135 | if (NULL == plugin->libname) | 133 | if (NULL == plugin->libname) |
136 | { | 134 | { |
137 | #if DEBUG | 135 | LOG ("Failed to find plugin `%s'\n", |
138 | fprintf (stderr, | 136 | plugin->short_libname); |
139 | "Failed to find plugin `%s'\n", | ||
140 | plugin->short_libname); | ||
141 | #endif | ||
142 | plugin->flags = EXTRACTOR_OPTION_DISABLED; | 137 | plugin->flags = EXTRACTOR_OPTION_DISABLED; |
143 | return -1; | 138 | return -1; |
144 | } | 139 | } |
@@ -153,12 +148,9 @@ EXTRACTOR_plugin_load_ (struct EXTRACTOR_PluginList *plugin) | |||
153 | (WideCharToMultiByte (CP_ACP, 0, wlibname, -1, | 148 | (WideCharToMultiByte (CP_ACP, 0, wlibname, -1, |
154 | llibname, sizeof (llibname), NULL, NULL) < 0) ) | 149 | llibname, sizeof (llibname), NULL, NULL) < 0) ) |
155 | { | 150 | { |
156 | #if DEBUG | 151 | LOG ("Loading `%s' plugin failed: %s\n", |
157 | fprintf (stderr, | 152 | plugin->short_libname, |
158 | "Loading `%s' plugin failed: %s\n", | 153 | "can't convert plugin name to local encoding"); |
159 | plugin->short_libname, | ||
160 | "can't convert plugin name to local encoding"); | ||
161 | #endif | ||
162 | free (plugin->libname); | 154 | free (plugin->libname); |
163 | plugin->libname = NULL; | 155 | plugin->libname = NULL; |
164 | plugin->flags = EXTRACTOR_OPTION_DISABLED; | 156 | plugin->flags = EXTRACTOR_OPTION_DISABLED; |
@@ -173,12 +165,9 @@ EXTRACTOR_plugin_load_ (struct EXTRACTOR_PluginList *plugin) | |||
173 | lt_dladvise_destroy (&advise); | 165 | lt_dladvise_destroy (&advise); |
174 | if (NULL == plugin->libraryHandle) | 166 | if (NULL == plugin->libraryHandle) |
175 | { | 167 | { |
176 | #if DEBUG | 168 | LOG ("Loading `%s' plugin failed: %s\n", |
177 | fprintf (stderr, | 169 | plugin->short_libname, |
178 | "Loading `%s' plugin failed: %s\n", | 170 | lt_dlerror ()); |
179 | plugin->short_libname, | ||
180 | lt_dlerror ()); | ||
181 | #endif | ||
182 | free (plugin->libname); | 171 | free (plugin->libname); |
183 | plugin->libname = NULL; | 172 | plugin->libname = NULL; |
184 | plugin->flags = EXTRACTOR_OPTION_DISABLED; | 173 | plugin->flags = EXTRACTOR_OPTION_DISABLED; |
@@ -190,12 +179,9 @@ EXTRACTOR_plugin_load_ (struct EXTRACTOR_PluginList *plugin) | |||
190 | &plugin->specials); | 179 | &plugin->specials); |
191 | if (NULL == plugin->extract_method) | 180 | if (NULL == plugin->extract_method) |
192 | { | 181 | { |
193 | #if DEBUG | 182 | LOG ("Resolving `extract' method of plugin `%s' failed: %s\n", |
194 | fprintf (stderr, | 183 | plugin->short_libname, |
195 | "Resolving `extract' method of plugin `%s' failed: %s\n", | 184 | lt_dlerror ()); |
196 | plugin->short_libname, | ||
197 | lt_dlerror ()); | ||
198 | #endif | ||
199 | lt_dlclose (plugin->libraryHandle); | 185 | lt_dlclose (plugin->libraryHandle); |
200 | free (plugin->libname); | 186 | free (plugin->libname); |
201 | plugin->libname = NULL; | 187 | plugin->libname = NULL; |
@@ -230,9 +216,8 @@ EXTRACTOR_plugin_add (struct EXTRACTOR_PluginList *prev, | |||
230 | return prev; /* no change, library already loaded */ | 216 | return prev; /* no change, library already loaded */ |
231 | if (NULL == (libname = EXTRACTOR_find_plugin_ (library))) | 217 | if (NULL == (libname = EXTRACTOR_find_plugin_ (library))) |
232 | { | 218 | { |
233 | fprintf (stderr, | 219 | LOG ("Could not load plugin `%s'\n", |
234 | "Could not load `%s'\n", | 220 | library); |
235 | library); | ||
236 | return prev; | 221 | return prev; |
237 | } | 222 | } |
238 | if (NULL == (result = malloc (sizeof (struct EXTRACTOR_PluginList)))) | 223 | if (NULL == (result = malloc (sizeof (struct EXTRACTOR_PluginList)))) |
@@ -367,11 +352,8 @@ EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList *prev, | |||
367 | } | 352 | } |
368 | if (NULL == pos) | 353 | if (NULL == pos) |
369 | { | 354 | { |
370 | #if DEBUG | 355 | LOG ("Unloading plugin `%s' failed!\n", |
371 | fprintf(stderr, | 356 | library); |
372 | "Unloading plugin `%s' failed!\n", | ||
373 | library); | ||
374 | #endif | ||
375 | return first; | 357 | return first; |
376 | } | 358 | } |
377 | /* found, close library */ | 359 | /* found, close library */ |
diff --git a/src/main/extractor_plugpath.c b/src/main/extractor_plugpath.c index af3c94a..d45622e 100644 --- a/src/main/extractor_plugpath.c +++ b/src/main/extractor_plugpath.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include <ltdl.h> | 32 | #include <ltdl.h> |
33 | 33 | ||
34 | #include "extractor_plugpath.h" | 34 | #include "extractor_plugpath.h" |
35 | 35 | #include "extractor_logging.h" | |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Function to call on paths. | 38 | * Function to call on paths. |
@@ -78,6 +78,7 @@ cut_bin (char * in) | |||
78 | return in; | 78 | return in; |
79 | } | 79 | } |
80 | 80 | ||
81 | |||
81 | #if LINUX | 82 | #if LINUX |
82 | /** | 83 | /** |
83 | * Try to determine path by reading /proc/PID/exe or | 84 | * Try to determine path by reading /proc/PID/exe or |
@@ -146,6 +147,7 @@ get_path_from_proc_exe () | |||
146 | lnk = cut_bin (lnk); | 147 | lnk = cut_bin (lnk); |
147 | if (NULL == (ret = realloc (lnk, strlen(lnk) + 6))) | 148 | if (NULL == (ret = realloc (lnk, strlen(lnk) + 6))) |
148 | { | 149 | { |
150 | LOG_STRERROR ("realloc"); | ||
149 | free (lnk); | 151 | free (lnk); |
150 | return NULL; | 152 | return NULL; |
151 | } | 153 | } |
@@ -178,6 +180,7 @@ get_path_from_module_filename () | |||
178 | path = cut_bin (path); | 180 | path = cut_bin (path); |
179 | if (NULL == (ret = realloc (path, strlen(path) + 6))) | 181 | if (NULL == (ret = realloc (path, strlen(path) + 6))) |
180 | { | 182 | { |
183 | LOG_STRERROR ("realloc"); | ||
181 | free (path); | 184 | free (path); |
182 | return NULL; | 185 | return NULL; |
183 | } | 186 | } |
@@ -223,7 +226,11 @@ get_path_from_NSGetExecutablePath () | |||
223 | (void) func (path, &len); | 226 | (void) func (path, &len); |
224 | if (0 == len) | 227 | if (0 == len) |
225 | return NULL; | 228 | return NULL; |
226 | path = GNUNET_malloc (len); | 229 | if (NULL == (path = malloc (len))) |
230 | { | ||
231 | LOG_STRERROR ("malloc"); | ||
232 | return NULL; | ||
233 | } | ||
227 | if (0 != func (path, &len)) | 234 | if (0 != func (path, &len)) |
228 | { | 235 | { |
229 | GNUNET_free (path); | 236 | GNUNET_free (path); |
@@ -259,7 +266,10 @@ get_path_from_dyld_image () | |||
259 | if ( (NULL == path) || (0 == strlen (path)) ) | 266 | if ( (NULL == path) || (0 == strlen (path)) ) |
260 | continue; | 267 | continue; |
261 | if (NULL == (p = strdup (path))) | 268 | if (NULL == (p = strdup (path))) |
262 | return NULL; | 269 | { |
270 | LOG_STRERROR ("strdup"); | ||
271 | return NULL; | ||
272 | } | ||
263 | s = p + strlen (p); | 273 | s = p + strlen (p); |
264 | while ( (s > p) && ('/' != *s) ) | 274 | while ( (s > p) && ('/' != *s) ) |
265 | s--; | 275 | s--; |
@@ -291,9 +301,13 @@ get_path_from_PATH() { | |||
291 | if (NULL == (p = getenv ("PATH"))) | 301 | if (NULL == (p = getenv ("PATH"))) |
292 | return NULL; | 302 | return NULL; |
293 | if (NULL == (path = strdup (p))) /* because we write on it */ | 303 | if (NULL == (path = strdup (p))) /* because we write on it */ |
294 | return NULL; | 304 | { |
305 | LOG_STRERROR ("strdup"); | ||
306 | return NULL; | ||
307 | } | ||
295 | if (NULL == (buf = malloc (strlen(path) + 20))) | 308 | if (NULL == (buf = malloc (strlen(path) + 20))) |
296 | { | 309 | { |
310 | LOG_STRERROR ("malloc"); | ||
297 | free (path); | 311 | free (path); |
298 | return NULL; | 312 | return NULL; |
299 | } | 313 | } |
@@ -304,14 +318,17 @@ get_path_from_PATH() { | |||
304 | sprintf(buf, "%s/%s", pos, "extract"); | 318 | sprintf(buf, "%s/%s", pos, "extract"); |
305 | if (0 == stat(buf, &sbuf)) | 319 | if (0 == stat(buf, &sbuf)) |
306 | { | 320 | { |
307 | pos = strdup(pos); | ||
308 | free (buf); | 321 | free (buf); |
309 | free (path); | 322 | free (path); |
310 | if (NULL == pos) | 323 | if (NULL == (pos = strdup(pos))) |
311 | return NULL; | 324 | { |
325 | LOG_STRERROR ("strdup"); | ||
326 | return NULL; | ||
327 | } | ||
312 | pos = cut_bin (pos); | 328 | pos = cut_bin (pos); |
313 | if (NULL == (ret = realloc (pos, strlen(pos) + 5))) | 329 | if (NULL == (ret = realloc (pos, strlen(pos) + 5))) |
314 | { | 330 | { |
331 | LOG_STRERROR ("realloc"); | ||
315 | free (pos); | 332 | free (pos); |
316 | return NULL; | 333 | return NULL; |
317 | } | 334 | } |
@@ -329,9 +346,9 @@ get_path_from_PATH() { | |||
329 | if (NULL == pos) | 346 | if (NULL == pos) |
330 | return NULL; | 347 | return NULL; |
331 | pos = cut_bin (pos); | 348 | pos = cut_bin (pos); |
332 | ret = realloc (pos, strlen(pos) + 5); | 349 | if (NULL == (ret = realloc (pos, strlen(pos) + 5))) |
333 | if (NULL == ret) | ||
334 | { | 350 | { |
351 | LOG_STRERROR ("realloc"); | ||
335 | free (pos); | 352 | free (pos); |
336 | return NULL; | 353 | return NULL; |
337 | } | 354 | } |
@@ -412,7 +429,10 @@ get_installation_paths (EXTRACTOR_PathProcessor pp, | |||
412 | if (NULL != (p = getenv ("LIBEXTRACTOR_PREFIX"))) | 429 | if (NULL != (p = getenv ("LIBEXTRACTOR_PREFIX"))) |
413 | { | 430 | { |
414 | if (NULL == (d = strdup (p))) | 431 | if (NULL == (d = strdup (p))) |
415 | return; | 432 | { |
433 | LOG_STRERROR ("strdup"); | ||
434 | return; | ||
435 | } | ||
416 | for (prefix = strtok (d, PATH_SEPARATOR_STR); | 436 | for (prefix = strtok (d, PATH_SEPARATOR_STR); |
417 | NULL != prefix; | 437 | NULL != prefix; |
418 | prefix = strtok (NULL, PATH_SEPARATOR_STR)) | 438 | prefix = strtok (NULL, PATH_SEPARATOR_STR)) |
@@ -500,9 +520,9 @@ find_plugin_in_path (void *cls, | |||
500 | if (NULL == (sym_name = strrchr (ent->d_name, '_'))) | 520 | if (NULL == (sym_name = strrchr (ent->d_name, '_'))) |
501 | continue; | 521 | continue; |
502 | sym_name++; | 522 | sym_name++; |
503 | sym = strdup (sym_name); | 523 | if (NULL == (sym = strdup (sym_name))) |
504 | if (NULL == sym) | ||
505 | { | 524 | { |
525 | LOG_STRERROR ("strdup"); | ||
506 | CLOSEDIR (dir); | 526 | CLOSEDIR (dir); |
507 | return; | 527 | return; |
508 | } | 528 | } |
@@ -573,8 +593,7 @@ load_plugins_from_dir (void *cls, | |||
573 | char *sym; | 593 | char *sym; |
574 | char *dot; | 594 | char *dot; |
575 | 595 | ||
576 | dir = opendir (path); | 596 | if (NULL == (dir = opendir (path))) |
577 | if (NULL == dir) | ||
578 | return; | 597 | return; |
579 | while (NULL != (ent = readdir (dir))) | 598 | while (NULL != (ent = readdir (dir))) |
580 | { | 599 | { |
@@ -586,18 +605,16 @@ load_plugins_from_dir (void *cls, | |||
586 | (la[2] == '\0')) ) | 605 | (la[2] == '\0')) ) |
587 | continue; /* only load '.so' and '.dll' */ | 606 | continue; /* only load '.so' and '.dll' */ |
588 | 607 | ||
589 | sym_name = strrchr (ent->d_name, '_'); | 608 | if (NULL == (sym_name = strrchr (ent->d_name, '_'))) |
590 | if (sym_name == NULL) | ||
591 | continue; | 609 | continue; |
592 | sym_name++; | 610 | sym_name++; |
593 | sym = strdup (sym_name); | 611 | if (NULL == (sym = strdup (sym_name))) |
594 | if (NULL == sym) | ||
595 | { | 612 | { |
613 | LOG_STRERROR ("strdup"); | ||
596 | closedir (dir); | 614 | closedir (dir); |
597 | return; | 615 | return; |
598 | } | 616 | } |
599 | dot = strchr (sym, '.'); | 617 | if (NULL != (dot = strchr (sym, '.'))) |
600 | if (dot != NULL) | ||
601 | *dot = '\0'; | 618 | *dot = '\0'; |
602 | #if DEBUG > 1 | 619 | #if DEBUG > 1 |
603 | fprintf (stderr, | 620 | fprintf (stderr, |
diff --git a/src/main/extractor_print.c b/src/main/extractor_print.c index 6ea8f19..21b444a 100644 --- a/src/main/extractor_print.c +++ b/src/main/extractor_print.c | |||
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | #include "platform.h" | 21 | #include "platform.h" |
22 | #include "extractor.h" | 22 | #include "extractor.h" |
23 | 23 | #include "extractor_logging.h" | |
24 | #include "iconv.c" | 24 | #include "iconv.c" |
25 | 25 | ||
26 | /** | 26 | /** |
@@ -58,10 +58,14 @@ EXTRACTOR_meta_data_print (void *handle, | |||
58 | cd = iconv_open (nl_langinfo(CODESET), | 58 | cd = iconv_open (nl_langinfo(CODESET), |
59 | "UTF-8"); | 59 | "UTF-8"); |
60 | if (((iconv_t) -1) == cd) | 60 | if (((iconv_t) -1) == cd) |
61 | return 1; | 61 | { |
62 | buf = iconv_helper(cd, data); | 62 | LOG_STRERROR ("iconv_open"); |
63 | return 1; | ||
64 | } | ||
65 | buf = iconv_helper (cd, data); | ||
63 | if (NULL == buf) | 66 | if (NULL == buf) |
64 | { | 67 | { |
68 | LOG_STRERROR ("iconv_helper"); | ||
65 | ret = -1; | 69 | ret = -1; |
66 | } | 70 | } |
67 | else | 71 | else |