libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 14f8181fe2edef2dbfa6606ec55718f00b79f660
parent fdc5ca9b7e4037c1db48e85e0d5c97a39aaa8db6
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat,  4 Aug 2012 01:01:10 +0000

-bugfixes

Diffstat:
Msrc/main/TODO | 3+++
Msrc/main/extractor.c | 36+++++++++++++++++++++++-------------
Msrc/main/extractor_ipc_gnu.c | 7++++++-
Msrc/main/extractor_plugin_main.c | 23+++++++++++++++++++----
Msrc/main/extractor_plugins.c | 23++++++++++++-----------
5 files changed, 63 insertions(+), 29 deletions(-)

diff --git a/src/main/TODO b/src/main/TODO @@ -3,3 +3,5 @@ * testcases for extract-from-file, extract-from-gz-file, extract-from-bz2-file * testcases for running multiple files in one run (known to fail!) +* MAX_META_DATA buffer of 32 MB is a bit big as a non-growing default size; + also, valgrind reports it is leaked even though printf-debugging shows it is not (!?) +\ No newline at end of file diff --git a/src/main/extractor.c b/src/main/extractor.c @@ -414,15 +414,21 @@ do_extract (struct EXTRACTOR_PluginList *plugins, while (! done) { struct EXTRACTOR_Channel *channels[plugin_count]; - + /* calculate current 'channels' array */ plugin_count = 0; for (pos = plugins; NULL != pos; pos = pos->next) { - if (-1 != pos->seek_request) - channels[plugin_count] = pos->channel; + if (-1 == pos->seek_request) + { + /* channel is not seeking, must be running or done */ + channels[plugin_count] = pos->channel; + } else - channels[plugin_count] = NULL; /* not running this round, seeking! */ + { + /* not running this round, seeking! */ + channels[plugin_count] = NULL; + } plugin_count++; } @@ -438,6 +444,7 @@ do_extract (struct EXTRACTOR_PluginList *plugins, abort_all_channels (plugins); break; } + /* calculate minimum seek request (or set done=0 to continue here) */ done = 1; min_seek = -1; @@ -482,24 +489,26 @@ do_extract (struct EXTRACTOR_PluginList *plugins, { if (NULL == (channel = pos->channel)) continue; + if ( (-1 != pos->seek_request) && + (1 == prp.file_finished) ) + { + send_discard_message (pos); + pos->round_finished = 1; + pos->seek_request = -1; + } if ( (-1 != pos->seek_request) && ((last_position > pos->seek_request) || (last_position + data_available <= pos->seek_request)) && (min_seek <= pos->seek_request) && ((min_seek + data_available > pos->seek_request) || (min_seek == EXTRACTOR_datasource_get_size_ (ds))) ) { + LOG ("Sending update message\n"); send_update_message (pos, min_seek, data_available, ds); - /*pos->seek_request = -1;*/ + pos->seek_request = -1; } - if ( (-1 != pos->seek_request) && - (1 == prp.file_finished) ) - { - send_discard_message (pos); - pos->round_finished = 1; - } if (0 == pos->round_finished) done = 0; /* can't be done, plugin still active */ } @@ -576,10 +585,11 @@ EXTRACTOR_extract (struct EXTRACTOR_PluginList *plugins, have_oop = 0; for (pos = plugins; NULL != pos; pos = pos->next) { - if (NULL != (shm = pos->shm)) - break; + if (NULL == shm) + shm = pos->shm; if (EXTRACTOR_OPTION_IN_PROCESS != pos->flags) have_oop = 1; + pos->round_finished = 0; } if ( (NULL == shm) && (1 == have_oop) ) diff --git a/src/main/extractor_ipc_gnu.c b/src/main/extractor_ipc_gnu.c @@ -236,6 +236,7 @@ EXTRACTOR_IPC_shared_memory_set_ (struct EXTRACTOR_SharedMemory *shm, size); } + /** * Query datasource for current position * @@ -251,6 +252,7 @@ EXTRACTOR_datasource_get_pos_ (struct EXTRACTOR_Datasource *ds) return pos; } + /** * Create a channel to communicate with a process wrapping * the plugin of the given name. Starts the process as well. @@ -440,7 +442,10 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, max = channel->cpipe_out; } if (-1 == max) - return 1; /* nothing left to do! */ + { + LOG ("No channels to select on...\n"); + return 1; /* nothing left to do! */ + } tv.tv_sec = 10; tv.tv_usec = 0; if (-1 == select (max + 1, &to_check, NULL, NULL, &tv)) diff --git a/src/main/extractor_plugin_main.c b/src/main/extractor_plugin_main.c @@ -318,8 +318,13 @@ plugin_env_send_proc (void *cls, LOG ("Failed to read response to meta message\n"); return 1; } - if (MESSAGE_CONTINUE_EXTRACTING != reply) + if (MESSAGE_DISCARD_STATE == reply) return 1; + if (MESSAGE_CONTINUE_EXTRACTING != reply) + { + LOG ("Received unexpected reply to meta data: %d\n", reply); + return 1; + } return 0; } @@ -467,7 +472,7 @@ process_requests (struct ProcessingContext *pc) while (1) { unsigned char code; - + if (1 != EXTRACTOR_read_all_ (pc->in, &code, 1)) { LOG ("Failed to read next request\n"); @@ -477,12 +482,20 @@ process_requests (struct ProcessingContext *pc) { case MESSAGE_INIT_STATE: if (0 != handle_init_message (pc)) - return; + { + LOG ("Failure to handle INIT\n"); + return; + } break; case MESSAGE_EXTRACT_START: if (0 != handle_start_message (pc)) - return; + { + LOG ("Failure to handle START\n"); + return; + } + break; case MESSAGE_UPDATED_SHM: + LOG ("Illegal message\n"); /* not allowed here, we're not waiting for SHM to move! */ return; case MESSAGE_DISCARD_STATE: @@ -579,6 +592,8 @@ EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin, pc.shm = NULL; pc.shm_map_size = 0; process_requests (&pc); + LOG ("IPC error; plugin `%s' terminates!\n", + plugin->short_libname); #if WINDOWS if (NULL != pc.shm) UnmapViewOfFile (pc.shm); diff --git a/src/main/extractor_plugins.c b/src/main/extractor_plugins.c @@ -208,7 +208,7 @@ EXTRACTOR_plugin_add (struct EXTRACTOR_PluginList *prev, const char *options, enum EXTRACTOR_Options flags) { - struct EXTRACTOR_PluginList *result; + struct EXTRACTOR_PluginList *plugin; struct EXTRACTOR_PluginList *pos; char *libname; @@ -221,22 +221,23 @@ EXTRACTOR_plugin_add (struct EXTRACTOR_PluginList *prev, library); return prev; } - if (NULL == (result = malloc (sizeof (struct EXTRACTOR_PluginList)))) + if (NULL == (plugin = malloc (sizeof (struct EXTRACTOR_PluginList)))) return prev; - memset (result, 0, sizeof (struct EXTRACTOR_PluginList)); - result->next = prev; - if (NULL == (result->short_libname = strdup (library))) + memset (plugin, 0, sizeof (struct EXTRACTOR_PluginList)); + plugin->next = prev; + if (NULL == (plugin->short_libname = strdup (library))) { - free (result); + free (plugin); return NULL; } - result->libname = libname; - result->flags = flags; + plugin->libname = libname; + plugin->flags = flags; if (NULL != options) - result->plugin_options = strdup (options); + plugin->plugin_options = strdup (options); else - result->plugin_options = NULL; - return result; + plugin->plugin_options = NULL; + plugin->seek_request = -1; + return plugin; }