diff options
Diffstat (limited to 'src/main/extractor_ipc_gnu.c')
-rw-r--r-- | src/main/extractor_ipc_gnu.c | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/main/extractor_ipc_gnu.c b/src/main/extractor_ipc_gnu.c index 7e7a086..6c80188 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_plugin_main.h" | ||
29 | #include "extractor_ipc.h" | 30 | #include "extractor_ipc.h" |
30 | #include <dirent.h> | 31 | #include <dirent.h> |
31 | #include <sys/types.h> | 32 | #include <sys/types.h> |
@@ -33,12 +34,12 @@ | |||
33 | #include <sys/shm.h> | 34 | #include <sys/shm.h> |
34 | #include <signal.h> | 35 | #include <signal.h> |
35 | 36 | ||
37 | |||
36 | /** | 38 | /** |
37 | * Size of the channel buffer; determines largest IPC message that | 39 | * Maximum length of a shared memory object name |
38 | * is going to be allowed. FIXME: we might want to grow this | ||
39 | * buffer dynamically instead... | ||
40 | */ | 40 | */ |
41 | #define CHANNEL_BUFFER_SIZE (1024 * 256) | 41 | #define MAX_SHM_NAME 255 |
42 | |||
42 | 43 | ||
43 | /** | 44 | /** |
44 | * A shared memory resource (often shared with several | 45 | * A shared memory resource (often shared with several |
@@ -64,7 +65,7 @@ struct EXTRACTOR_SharedMemory | |||
64 | /** | 65 | /** |
65 | * POSIX id of the shm into which data is uncompressed | 66 | * POSIX id of the shm into which data is uncompressed |
66 | */ | 67 | */ |
67 | int shm; | 68 | int shm_id; |
68 | 69 | ||
69 | /** | 70 | /** |
70 | * Name of the shm | 71 | * Name of the shm |
@@ -83,8 +84,10 @@ struct EXTRACTOR_Channel | |||
83 | 84 | ||
84 | /** | 85 | /** |
85 | * Buffer for reading data from the plugin. | 86 | * Buffer for reading data from the plugin. |
87 | * FIXME: we might want to grow this | ||
88 | * buffer dynamically instead of always using 32 MB! | ||
86 | */ | 89 | */ |
87 | char data[CHANNEL_BUFFER_SIZE]; | 90 | char data[MAX_META_DATA]; |
88 | 91 | ||
89 | /** | 92 | /** |
90 | * Memory segment shared with this process. | 93 | * Memory segment shared with this process. |
@@ -92,9 +95,9 @@ struct EXTRACTOR_Channel | |||
92 | struct EXTRACTOR_SharedMemory *shm; | 95 | struct EXTRACTOR_SharedMemory *shm; |
93 | 96 | ||
94 | /** | 97 | /** |
95 | * Name of the plugin to use for this channel. | 98 | * The plugin this channel is to communicate with. |
96 | */ | 99 | */ |
97 | const char *short_libname; | 100 | struct EXTRACTOR_PluginList *plugin; |
98 | 101 | ||
99 | /** | 102 | /** |
100 | * Pipe used to communicate information to the plugin child process. | 103 | * Pipe used to communicate information to the plugin child process. |
@@ -179,8 +182,8 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size) | |||
179 | void | 182 | void |
180 | EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm) | 183 | EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm) |
181 | { | 184 | { |
182 | munmap (shm->shm_ptr, shm->map_size); | 185 | munmap (shm->shm_ptr, shm->shm_size); |
183 | (void) close (plugin->shm_id); | 186 | (void) close (shm->shm_id); |
184 | (void) shm_unlink (shm->shm_name); | 187 | (void) shm_unlink (shm->shm_name); |
185 | free (shm); | 188 | free (shm); |
186 | } | 189 | } |
@@ -204,8 +207,8 @@ EXTRACTOR_IPC_shared_memory_set_ (struct EXTRACTOR_SharedMemory *shm, | |||
204 | if (-1 == | 207 | if (-1 == |
205 | EXTRACTOR_datasource_seek_ (ds, off, SEEK_SET)) | 208 | EXTRACTOR_datasource_seek_ (ds, off, SEEK_SET)) |
206 | return -1; | 209 | return -1; |
207 | if (size > shm->map_size) | 210 | if (size > shm->shm_size) |
208 | size = shm->map_size; | 211 | size = shm->shm_size; |
209 | return EXTRACTOR_datasource_read_ (ds, | 212 | return EXTRACTOR_datasource_read_ (ds, |
210 | shm->shm_ptr, | 213 | shm->shm_ptr, |
211 | size); | 214 | size); |
@@ -216,24 +219,23 @@ EXTRACTOR_IPC_shared_memory_set_ (struct EXTRACTOR_SharedMemory *shm, | |||
216 | * Create a channel to communicate with a process wrapping | 219 | * Create a channel to communicate with a process wrapping |
217 | * the plugin of the given name. Starts the process as well. | 220 | * the plugin of the given name. Starts the process as well. |
218 | * | 221 | * |
219 | * @param short_libname name of the plugin | 222 | * @param plugin the plugin |
220 | * @param shm memory to share with the process | 223 | * @param shm memory to share with the process |
221 | * @return NULL on error, otherwise IPC channel | 224 | * @return NULL on error, otherwise IPC channel |
222 | */ | 225 | */ |
223 | struct EXTRACTOR_Channel * | 226 | struct EXTRACTOR_Channel * |
224 | EXTRACTOR_IPC_channel_create_ (const char *short_libname, | 227 | EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin, |
225 | struct EXTRACTOR_SharedMemory *shm) | 228 | struct EXTRACTOR_SharedMemory *shm) |
226 | { | 229 | { |
227 | struct EXTRACTOR_Channel *channel; | 230 | struct EXTRACTOR_Channel *channel; |
228 | int p1[2]; | 231 | int p1[2]; |
229 | int p2[2]; | 232 | int p2[2]; |
230 | pid_t pid; | 233 | pid_t pid; |
231 | int status; | ||
232 | 234 | ||
233 | if (NULL == (channel = malloc (sizeof (struct EXTRACTOR_Channel)))) | 235 | if (NULL == (channel = malloc (sizeof (struct EXTRACTOR_Channel)))) |
234 | return NULL; | 236 | return NULL; |
235 | channel->shm = shm; | 237 | channel->shm = shm; |
236 | channel->short_libname = short_libname; | 238 | channel->plugin = plugin; |
237 | if (0 != pipe (p1)) | 239 | if (0 != pipe (p1)) |
238 | { | 240 | { |
239 | free (channel); | 241 | free (channel); |
@@ -244,7 +246,7 @@ EXTRACTOR_IPC_channel_create_ (const char *short_libname, | |||
244 | (void) close (p1[0]); | 246 | (void) close (p1[0]); |
245 | (void) close (p1[1]); | 247 | (void) close (p1[1]); |
246 | free (channel); | 248 | free (channel); |
247 | return; | 249 | return NULL; |
248 | } | 250 | } |
249 | pid = fork (); | 251 | pid = fork (); |
250 | if (pid == -1) | 252 | if (pid == -1) |
@@ -260,7 +262,7 @@ EXTRACTOR_IPC_channel_create_ (const char *short_libname, | |||
260 | { | 262 | { |
261 | (void) close (p1[1]); | 263 | (void) close (p1[1]); |
262 | (void) close (p2[0]); | 264 | (void) close (p2[0]); |
263 | EXTRACTOR_plugin_main_ (short_libname, p1[0], p2[1]); | 265 | EXTRACTOR_plugin_main_ (plugin, p1[0], p2[1]); |
264 | _exit (0); | 266 | _exit (0); |
265 | } | 267 | } |
266 | (void) close (p1[0]); | 268 | (void) close (p1[0]); |
@@ -376,12 +378,13 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, | |||
376 | continue; | 378 | continue; |
377 | if ( (-1 == (iret = read (channel->cpipe_out, | 379 | if ( (-1 == (iret = read (channel->cpipe_out, |
378 | &channel->data[channel->size], | 380 | &channel->data[channel->size], |
379 | CHANNEL_BUFFER_SIZE - channel->size)) ) || | 381 | MAX_META_DATA - channel->size)) ) || |
380 | (ret = EXTRACTOR_IPC_process_reply_ (channel->data, | 382 | (ret = EXTRACTOR_IPC_process_reply_ (channel->plugin, |
383 | channel->data, | ||
381 | channel->size + iret, | 384 | channel->size + iret, |
382 | proc, proc_cls)) ) | 385 | proc, proc_cls)) ) |
383 | { | 386 | { |
384 | EXTRACTOR_IPC_channel_destroy (channel); | 387 | EXTRACTOR_IPC_channel_destroy_ (channel); |
385 | channels[i] = NULL; | 388 | channels[i] = NULL; |
386 | } | 389 | } |
387 | else | 390 | else |