aboutsummaryrefslogtreecommitdiff
path: root/src/main/extractor_ipc_w32.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/extractor_ipc_w32.c')
-rw-r--r--src/main/extractor_ipc_w32.c223
1 files changed, 118 insertions, 105 deletions
diff --git a/src/main/extractor_ipc_w32.c b/src/main/extractor_ipc_w32.c
index c4fbf1b..b53bc3c 100644
--- a/src/main/extractor_ipc_w32.c
+++ b/src/main/extractor_ipc_w32.c
@@ -34,32 +34,32 @@ struct EXTRACTOR_SharedMemory
34 34
35 /** 35 /**
36 * W32 handle of the shm into which data is uncompressed 36 * W32 handle of the shm into which data is uncompressed
37 */ 37 */
38 HANDLE map; 38 HANDLE map;
39 39
40 /** 40 /**
41 * Name of the shm 41 * Name of the shm
42 */ 42 */
43 char shm_name[MAX_SHM_NAME + 1]; 43 char shm_name[MAX_SHM_NAME + 1];
44 44
45 /** 45 /**
46 * Pointer to the mapped region of the shm (covers the whole shm) 46 * Pointer to the mapped region of the shm (covers the whole shm)
47 */ 47 */
48 void *ptr; 48 void *ptr;
49 49
50 /** 50 /**
51 * Position within shm 51 * Position within shm
52 */ 52 */
53 int64_t pos; 53 int64_t pos;
54 54
55 /** 55 /**
56 * Allocated size of the shm 56 * Allocated size of the shm
57 */ 57 */
58 int64_t shm_size; 58 int64_t shm_size;
59 59
60 /** 60 /**
61 * Number of bytes in shm (<= shm_size) 61 * Number of bytes in shm (<= shm_size)
62 */ 62 */
63 size_t shm_buf_size; 63 size_t shm_buf_size;
64 64
65 size_t shm_map_size; 65 size_t shm_map_size;
@@ -132,11 +132,11 @@ struct EXTRACTOR_Channel
132 */ 132 */
133 char *mdata; 133 char *mdata;
134 134
135 /** 135 /**
136 * Size of the 'mdata' buffer. 136 * Size of the 'mdata' buffer.
137 */ 137 */
138 size_t mdata_size; 138 size_t mdata_size;
139 139
140 /** 140 /**
141 * Number of valid bytes in the channel's buffer. 141 * Number of valid bytes in the channel's buffer.
142 */ 142 */
@@ -159,11 +159,12 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size)
159 if (NULL == (shm = malloc (sizeof (struct EXTRACTOR_SharedMemory)))) 159 if (NULL == (shm = malloc (sizeof (struct EXTRACTOR_SharedMemory))))
160 return NULL; 160 return NULL;
161 161
162 snprintf (shm->shm_name, MAX_SHM_NAME, 162 snprintf (shm->shm_name, MAX_SHM_NAME,
163 "%slibextractor-shm-%u-%u", 163 "%slibextractor-shm-%u-%u",
164 tpath, getpid(), 164 tpath, getpid (),
165 (unsigned int) RANDOM()); 165 (unsigned int) RANDOM ());
166 shm->map = CreateFileMapping (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, shm->shm_name); 166 shm->map = CreateFileMapping (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
167 size, shm->shm_name);
167 shm->ptr = MapViewOfFile (shm->map, FILE_MAP_WRITE, 0, 0, size); 168 shm->ptr = MapViewOfFile (shm->map, FILE_MAP_WRITE, 0, 0, size);
168 if (shm->ptr == NULL) 169 if (shm->ptr == NULL)
169 { 170 {
@@ -176,6 +177,7 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size)
176 return shm; 177 return shm;
177} 178}
178 179
180
179/** 181/**
180 * Change the reference counter for this shm instance. 182 * Change the reference counter for this shm instance.
181 * 183 *
@@ -185,7 +187,7 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size)
185 */ 187 */
186unsigned int 188unsigned int
187EXTRACTOR_IPC_shared_memory_change_rc_ (struct EXTRACTOR_SharedMemory *shm, 189EXTRACTOR_IPC_shared_memory_change_rc_ (struct EXTRACTOR_SharedMemory *shm,
188 int delta) 190 int delta)
189{ 191{
190 shm->rc += delta; 192 shm->rc += delta;
191 return shm->rc; 193 return shm->rc;
@@ -200,7 +202,7 @@ EXTRACTOR_IPC_shared_memory_change_rc_ (struct EXTRACTOR_SharedMemory *shm,
200 */ 202 */
201void 203void
202EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm) 204EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm)
203{ 205{
204 if (shm->ptr != NULL) 206 if (shm->ptr != NULL)
205 UnmapViewOfFile (shm->ptr); 207 UnmapViewOfFile (shm->ptr);
206 if (shm->map != 0) 208 if (shm->map != 0)
@@ -208,6 +210,7 @@ EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm)
208 free (shm); 210 free (shm);
209} 211}
210 212
213
211/** 214/**
212 * Initialize shared memory area from data source. 215 * Initialize shared memory area from data source.
213 * 216 *
@@ -219,21 +222,21 @@ EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm)
219 */ 222 */
220ssize_t 223ssize_t
221EXTRACTOR_IPC_shared_memory_set_ (struct EXTRACTOR_SharedMemory *shm, 224EXTRACTOR_IPC_shared_memory_set_ (struct EXTRACTOR_SharedMemory *shm,
222 struct EXTRACTOR_Datasource *ds, 225 struct EXTRACTOR_Datasource *ds,
223 uint64_t off, 226 uint64_t off,
224 size_t size) 227 size_t size)
225{ 228{
226 if (-1 == 229 if (-1 ==
227 EXTRACTOR_datasource_seek_ (ds, off, SEEK_SET)) 230 EXTRACTOR_datasource_seek_ (ds, off, SEEK_SET))
228 { 231 {
229 LOG ("Failed to set IPC memory due to seek error\n"); 232 LOG ("Failed to set IPC memory due to seek error\n");
230 return -1; 233 return -1;
231 } 234 }
232 if (size > shm->shm_size) 235 if (size > shm->shm_size)
233 size = shm->shm_size; 236 size = shm->shm_size;
234 return EXTRACTOR_datasource_read_ (ds, 237 return EXTRACTOR_datasource_read_ (ds,
235 shm->ptr, 238 shm->ptr,
236 size); 239 size);
237} 240}
238 241
239 242
@@ -291,7 +294,7 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
291 static volatile LONG pipe_unique_id; 294 static volatile LONG pipe_unique_id;
292 295
293 snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld", 296 snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld",
294 getpid (), InterlockedIncrement ((LONG *) & pipe_unique_id)); 297 getpid (), InterlockedIncrement ((LONG *) &pipe_unique_id));
295 /* Use CreateNamedPipe instead of CreatePipe, because the latter 298 /* Use CreateNamedPipe instead of CreatePipe, because the latter
296 * returns a write handle that does not permit FILE_READ_ATTRIBUTES 299 * returns a write handle that does not permit FILE_READ_ATTRIBUTES
297 * access, on versions of win32 earlier than WinXP SP2. 300 * access, on versions of win32 earlier than WinXP SP2.
@@ -300,8 +303,8 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
300 * It's important to only allow a single instance, to ensure that 303 * It's important to only allow a single instance, to ensure that
301 * the pipe was not created earlier by some other process, even if 304 * the pipe was not created earlier by some other process, even if
302 * the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE 305 * the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE
303 * because that is only available for Win2k SP2 and WinXP. */ 306 * because that is only available for Win2k SP2 and WinXP. */read_pipe = CreateNamedPipeA (pipename, PIPE_ACCESS_INBOUND | dwReadMode,
304 read_pipe = CreateNamedPipeA (pipename, PIPE_ACCESS_INBOUND | dwReadMode, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, /* max instances */ 307 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, /* max instances */
305 psize, /* output buffer size */ 308 psize, /* output buffer size */
306 psize, /* input buffer size */ 309 psize, /* input buffer size */
307 NMPWAIT_USE_DEFAULT_WAIT, sa_ptr); 310 NMPWAIT_USE_DEFAULT_WAIT, sa_ptr);
@@ -359,6 +362,7 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
359 return 0; 362 return 0;
360} 363}
361 364
365
362/** 366/**
363 * Communicates plugin data (library name, options) to the plugin 367 * Communicates plugin data (library name, options) to the plugin
364 * process. This is only necessary on W32, where this information 368 * process. This is only necessary on W32, where this information
@@ -367,10 +371,10 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
367 * @param plugin plugin context 371 * @param plugin plugin context
368 * 372 *
369 * @return 0 on success, -1 on failure 373 * @return 0 on success, -1 on failure
370 */ 374 */
371static int 375static int
372write_plugin_data (struct EXTRACTOR_PluginList *plugin, 376write_plugin_data (struct EXTRACTOR_PluginList *plugin,
373 struct EXTRACTOR_Channel *channel) 377 struct EXTRACTOR_Channel *channel)
374{ 378{
375 size_t libname_len, shortname_len, opts_len; 379 size_t libname_len, shortname_len, opts_len;
376 DWORD len; 380 DWORD len;
@@ -418,6 +422,7 @@ write_plugin_data (struct EXTRACTOR_PluginList *plugin,
418 return total_len == write_result; 422 return total_len == write_result;
419} 423}
420 424
425
421/** 426/**
422 * Create a channel to communicate with a process wrapping 427 * Create a channel to communicate with a process wrapping
423 * the plugin of the given name. Starts the process as well. 428 * the plugin of the given name. Starts the process as well.
@@ -425,10 +430,10 @@ write_plugin_data (struct EXTRACTOR_PluginList *plugin,
425 * @param plugin the plugin 430 * @param plugin the plugin
426 * @param shm memory to share with the process 431 * @param shm memory to share with the process
427 * @return NULL on error, otherwise IPC channel 432 * @return NULL on error, otherwise IPC channel
428 */ 433 */
429struct EXTRACTOR_Channel * 434struct EXTRACTOR_Channel *
430EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin, 435EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
431 struct EXTRACTOR_SharedMemory *shm) 436 struct EXTRACTOR_SharedMemory *shm)
432{ 437{
433 struct EXTRACTOR_Channel *channel; 438 struct EXTRACTOR_Channel *channel;
434 HANDLE p1[2]; 439 HANDLE p1[2];
@@ -445,18 +450,19 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
445 SECURITY_ATTRIBUTES sa; 450 SECURITY_ATTRIBUTES sa;
446 451
447 if (NULL == (channel = malloc (sizeof (struct EXTRACTOR_Channel)))) 452 if (NULL == (channel = malloc (sizeof (struct EXTRACTOR_Channel))))
448 { 453 {
449 LOG_STRERROR ("malloc"); 454 LOG_STRERROR ("malloc");
450 return NULL; 455 return NULL;
451 } 456 }
452 memset (channel, 0, sizeof (struct EXTRACTOR_Channel)); 457 memset (channel, 0, sizeof (struct EXTRACTOR_Channel));
453 channel->mdata_size = 1024; 458 channel->mdata_size = 1024;
454 if (NULL == (channel->mdata = malloc (channel->mdata_size))) 459 if (NULL == (channel->mdata = malloc (channel->mdata_size)))
455 { 460 {
456 LOG_STRERROR ("malloc"); 461 LOG_STRERROR ("malloc");
457 free (channel); 462 free (channel);
458 return NULL; 463 return NULL;
459 } channel->shm = shm; 464 }
465 channel->shm = shm;
460 channel->plugin = plugin; 466 channel->plugin = plugin;
461 channel->size = 0; 467 channel->size = 0;
462 468
@@ -464,13 +470,15 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
464 sa.lpSecurityDescriptor = NULL; 470 sa.lpSecurityDescriptor = NULL;
465 sa.bInheritHandle = FALSE; 471 sa.bInheritHandle = FALSE;
466 472
467 if (0 != create_selectable_pipe (&p1[0], &p1[1], &sa, 1024, FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED)) 473 if (0 != create_selectable_pipe (&p1[0], &p1[1], &sa, 1024,
474 FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED))
468 { 475 {
469 LOG_STRERROR ("pipe"); 476 LOG_STRERROR ("pipe");
470 free (channel); 477 free (channel);
471 return NULL; 478 return NULL;
472 } 479 }
473 if (0 != create_selectable_pipe (&p2[0], &p2[1], &sa, 1024, FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED)) 480 if (0 != create_selectable_pipe (&p2[0], &p2[1], &sa, 1024,
481 FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED))
474 { 482 {
475 LOG_STRERROR ("pipe"); 483 LOG_STRERROR ("pipe");
476 CloseHandle (p1[0]); 484 CloseHandle (p1[0]);
@@ -479,10 +487,10 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
479 return NULL; 487 return NULL;
480 } 488 }
481 489
482 if (!DuplicateHandle (GetCurrentProcess (), p1[0], GetCurrentProcess (), 490 if (! DuplicateHandle (GetCurrentProcess (), p1[0], GetCurrentProcess (),
483 &p10_os_inh, 0, TRUE, DUPLICATE_SAME_ACCESS) 491 &p10_os_inh, 0, TRUE, DUPLICATE_SAME_ACCESS)
484 || !DuplicateHandle (GetCurrentProcess (), p2[1], GetCurrentProcess (), 492 || ! DuplicateHandle (GetCurrentProcess (), p2[1], GetCurrentProcess (),
485 &p21_os_inh, 0, TRUE, DUPLICATE_SAME_ACCESS)) 493 &p21_os_inh, 0, TRUE, DUPLICATE_SAME_ACCESS))
486 { 494 {
487 LOG_STRERROR ("DuplicateHandle"); 495 LOG_STRERROR ("DuplicateHandle");
488 if (p10_os_inh != INVALID_HANDLE_VALUE) 496 if (p10_os_inh != INVALID_HANDLE_VALUE)
@@ -506,13 +514,13 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
506 * Also, users might freak out seeing over 9000 rundll32 processes (seeing over 9000 processes named 514 * Also, users might freak out seeing over 9000 rundll32 processes (seeing over 9000 processes named
507 * "libextractor_plugin_helper" is probably less confusing). 515 * "libextractor_plugin_helper" is probably less confusing).
508 */ 516 */
509 snprintf(cmd, MAX_PATH, 517 snprintf (cmd, MAX_PATH,
510 "rundll32.exe libextractor-3.dll,RundllEntryPoint@16 %lu %lu", 518 "rundll32.exe libextractor-3.dll,RundllEntryPoint@16 %lu %lu",
511 p10_os_inh, p21_os_inh); 519 p10_os_inh, p21_os_inh);
512 cmd[MAX_PATH] = '\0'; 520 cmd[MAX_PATH] = '\0';
513 startup.cb = sizeof (STARTUPINFOA); 521 startup.cb = sizeof (STARTUPINFOA);
514 if (CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, 522 if (CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL,
515 &startup, &proc)) 523 &startup, &proc))
516 { 524 {
517 channel->hProcess = proc.hProcess; 525 channel->hProcess = proc.hProcess;
518 ResumeThread (proc.hThread); 526 ResumeThread (proc.hThread);
@@ -544,7 +552,7 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
544 channel->ov_write.hEvent = CreateEvent (NULL, TRUE, TRUE, NULL); 552 channel->ov_write.hEvent = CreateEvent (NULL, TRUE, TRUE, NULL);
545 channel->ov_read.hEvent = CreateEvent (NULL, TRUE, TRUE, NULL); 553 channel->ov_read.hEvent = CreateEvent (NULL, TRUE, TRUE, NULL);
546 554
547 if (!write_plugin_data (plugin, channel)) 555 if (! write_plugin_data (plugin, channel))
548 { 556 {
549 LOG_STRERROR ("write_plugin_data"); 557 LOG_STRERROR ("write_plugin_data");
550 EXTRACTOR_IPC_channel_destroy_ (channel); 558 EXTRACTOR_IPC_channel_destroy_ (channel);
@@ -553,11 +561,11 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
553 561
554 slen = strlen (shm->shm_name) + 1; 562 slen = strlen (shm->shm_name) + 1;
555 if (NULL == (init = malloc (sizeof (struct InitMessage) + slen))) 563 if (NULL == (init = malloc (sizeof (struct InitMessage) + slen)))
556 { 564 {
557 LOG_STRERROR ("malloc"); 565 LOG_STRERROR ("malloc");
558 EXTRACTOR_IPC_channel_destroy_ (channel); 566 EXTRACTOR_IPC_channel_destroy_ (channel);
559 return NULL; 567 return NULL;
560 } 568 }
561 init->opcode = MESSAGE_INIT_STATE; 569 init->opcode = MESSAGE_INIT_STATE;
562 init->reserved = 0; 570 init->reserved = 0;
563 init->reserved2 = 0; 571 init->reserved2 = 0;
@@ -566,17 +574,18 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
566 memcpy (&init[1], shm->shm_name, slen); 574 memcpy (&init[1], shm->shm_name, slen);
567 if (sizeof (struct InitMessage) + slen != 575 if (sizeof (struct InitMessage) + slen !=
568 EXTRACTOR_IPC_channel_send_ (channel, init, 576 EXTRACTOR_IPC_channel_send_ (channel, init,
569 sizeof (struct InitMessage) + slen)) 577 sizeof (struct InitMessage) + slen))
570 { 578 {
571 LOG ("Failed to send INIT_STATE message to plugin\n"); 579 LOG ("Failed to send INIT_STATE message to plugin\n");
572 EXTRACTOR_IPC_channel_destroy_ (channel); 580 EXTRACTOR_IPC_channel_destroy_ (channel);
573 free (init); 581 free (init);
574 return NULL; 582 return NULL;
575 } 583 }
576 free (init); 584 free (init);
577 return channel; 585 return channel;
578} 586}
579 587
588
580/** 589/**
581 * Destroy communication channel with a plugin/process. Also 590 * Destroy communication channel with a plugin/process. Also
582 * destroys the process. 591 * destroys the process.
@@ -606,6 +615,7 @@ EXTRACTOR_IPC_channel_destroy_ (struct EXTRACTOR_Channel *channel)
606 free (channel); 615 free (channel);
607} 616}
608 617
618
609/** 619/**
610 * Send data via the given IPC channel (blocking). 620 * Send data via the given IPC channel (blocking).
611 * 621 *
@@ -617,8 +627,8 @@ EXTRACTOR_IPC_channel_destroy_ (struct EXTRACTOR_Channel *channel)
617 */ 627 */
618ssize_t 628ssize_t
619EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel, 629EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel,
620 const void *data, 630 const void *data,
621 size_t size) 631 size_t size)
622{ 632{
623 DWORD written; 633 DWORD written;
624 DWORD err; 634 DWORD err;
@@ -644,7 +654,8 @@ EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel,
644 channel->ov_write.Pointer = 0; 654 channel->ov_write.Pointer = 0;
645 channel->ov_write.Internal = 0; 655 channel->ov_write.Internal = 0;
646 channel->ov_write.InternalHigh = 0; 656 channel->ov_write.InternalHigh = 0;
647 bresult = WriteFile (channel->cpipe_in, channel->old_buf, size, &written, &channel->ov_write); 657 bresult = WriteFile (channel->cpipe_in, channel->old_buf, size, &written,
658 &channel->ov_write);
648 659
649 if (bresult == TRUE) 660 if (bresult == TRUE)
650 { 661 {
@@ -682,9 +693,9 @@ EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel,
682 */ 693 */
683int 694int
684EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, 695EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels,
685 unsigned int num_channels, 696 unsigned int num_channels,
686 EXTRACTOR_ChannelMessageProcessor proc, 697 EXTRACTOR_ChannelMessageProcessor proc,
687 void *proc_cls) 698 void *proc_cls)
688{ 699{
689 DWORD ms; 700 DWORD ms;
690 DWORD first_ready; 701 DWORD first_ready;
@@ -707,7 +718,8 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels,
707 if (WaitForSingleObject (channels[i]->ov_read.hEvent, 0) == WAIT_OBJECT_0) 718 if (WaitForSingleObject (channels[i]->ov_read.hEvent, 0) == WAIT_OBJECT_0)
708 { 719 {
709 ResetEvent (channels[i]->ov_read.hEvent); 720 ResetEvent (channels[i]->ov_read.hEvent);
710 bresult = ReadFile (channels[i]->cpipe_out, &i, 0, &bytes_read, &channels[i]->ov_read); 721 bresult = ReadFile (channels[i]->cpipe_out, &i, 0, &bytes_read,
722 &channels[i]->ov_read);
711 if (bresult == TRUE) 723 if (bresult == TRUE)
712 { 724 {
713 SetEvent (channels[i]->ov_read.hEvent); 725 SetEvent (channels[i]->ov_read.hEvent);
@@ -728,7 +740,7 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels,
728 740
729 ms = 500; 741 ms = 500;
730 first_ready = WaitForMultipleObjects (c, events, FALSE, ms); 742 first_ready = WaitForMultipleObjects (c, events, FALSE, ms);
731 if (first_ready == WAIT_TIMEOUT || first_ready == WAIT_FAILED) 743 if ((first_ready == WAIT_TIMEOUT) || (first_ready == WAIT_FAILED))
732 { 744 {
733 /* an error or timeout -> something's wrong or all plugins hung up */ 745 /* an error or timeout -> something's wrong or all plugins hung up */
734 closed_channel = 0; 746 closed_channel = 0;
@@ -765,37 +777,40 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels,
765 { 777 {
766 int ret; 778 int ret;
767 if (channels[i]->mdata_size == channels[i]->size) 779 if (channels[i]->mdata_size == channels[i]->size)
768 { 780 {
769 /* not enough space, need to grow allocation (if allowed) */ 781 /* not enough space, need to grow allocation (if allowed) */
770 if (MAX_META_DATA == channels[i]->mdata_size) 782 if (MAX_META_DATA == channels[i]->mdata_size)
771 { 783 {
772 LOG ("Inbound message from channel too large, aborting\n"); 784 LOG ("Inbound message from channel too large, aborting\n");
773 EXTRACTOR_IPC_channel_destroy_ (channels[i]); 785 EXTRACTOR_IPC_channel_destroy_ (channels[i]);
774 channels[i] = NULL; 786 channels[i] = NULL;
775 } 787 }
776 channels[i]->mdata_size *= 2; 788 channels[i]->mdata_size *= 2;
777 if (channels[i]->mdata_size > MAX_META_DATA) 789 if (channels[i]->mdata_size > MAX_META_DATA)
778 channels[i]->mdata_size = MAX_META_DATA; 790 channels[i]->mdata_size = MAX_META_DATA;
779 if (NULL == (ndata = realloc (channels[i]->mdata, 791 if (NULL == (ndata = realloc (channels[i]->mdata,
780 channels[i]->mdata_size))) 792 channels[i]->mdata_size)))
781 { 793 {
782 LOG_STRERROR ("realloc"); 794 LOG_STRERROR ("realloc");
783 EXTRACTOR_IPC_channel_destroy_ (channels[i]); 795 EXTRACTOR_IPC_channel_destroy_ (channels[i]);
784 channels[i] = NULL; 796 channels[i] = NULL;
785 } 797 }
786 channels[i]->mdata = ndata; 798 channels[i]->mdata = ndata;
787 } 799 }
788 bresult = ReadFile (channels[i]->cpipe_out, 800 bresult = ReadFile (channels[i]->cpipe_out,
789 &channels[i]->mdata[channels[i]->size], 801 &channels[i]->mdata[channels[i]->size],
790 channels[i]->mdata_size - channels[i]->size, &bytes_read, NULL); 802 channels[i]->mdata_size - channels[i]->size,
803 &bytes_read, NULL);
791 if (bresult) 804 if (bresult)
792 ret = EXTRACTOR_IPC_process_reply_ (channels[i]->plugin, 805 ret = EXTRACTOR_IPC_process_reply_ (channels[i]->plugin,
793 channels[i]->mdata, channels[i]->size + bytes_read, proc, proc_cls); 806 channels[i]->mdata,
794 if (!bresult || -1 == ret) 807 channels[i]->size + bytes_read,
808 proc, proc_cls);
809 if (! bresult || (-1 == ret))
795 { 810 {
796 DWORD error = GetLastError (); 811 DWORD error = GetLastError ();
797 SetErrnoFromWinError (error); 812 SetErrnoFromWinError (error);
798 if (!bresult) 813 if (! bresult)
799 LOG_STRERROR ("ReadFile"); 814 LOG_STRERROR ("ReadFile");
800 EXTRACTOR_IPC_channel_destroy_ (channels[i]); 815 EXTRACTOR_IPC_channel_destroy_ (channels[i]);
801 channels[i] = NULL; 816 channels[i] = NULL;
@@ -803,12 +818,10 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels,
803 else 818 else
804 { 819 {
805 memmove (channels[i]->mdata, &channels[i]->mdata[ret], 820 memmove (channels[i]->mdata, &channels[i]->mdata[ret],
806 channels[i]->size + bytes_read - ret); 821 channels[i]->size + bytes_read - ret);
807 channels[i]->size = channels[i]->size + bytes_read- ret; 822 channels[i]->size = channels[i]->size + bytes_read - ret;
808 } 823 }
809 } 824 }
810 } 825 }
811 return 1; 826 return 1;
812} 827}
813
814