aboutsummaryrefslogtreecommitdiff
path: root/src/main/extractor_plugin_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/extractor_plugin_main.c')
-rw-r--r--src/main/extractor_plugin_main.c48
1 files changed, 45 insertions, 3 deletions
diff --git a/src/main/extractor_plugin_main.c b/src/main/extractor_plugin_main.c
index 03269fb..9cf7624 100644
--- a/src/main/extractor_plugin_main.c
+++ b/src/main/extractor_plugin_main.c
@@ -27,6 +27,7 @@
27#include "plibc.h" 27#include "plibc.h"
28#include "extractor.h" 28#include "extractor.h"
29#include "extractor_datasource.h" 29#include "extractor_datasource.h"
30#include "extractor_ipc.h"
30#include "extractor_plugin_main.h" 31#include "extractor_plugin_main.h"
31#include <dirent.h> 32#include <dirent.h>
32#include <sys/types.h> 33#include <sys/types.h>
@@ -493,6 +494,36 @@ process_requests (struct EXTRACTOR_PluginList *plugin,
493} 494}
494 495
495 496
497#ifndef WINDOWS
498/**
499 * Open '/dev/null' and make the result the given
500 * file descriptor.
501 *
502 * @param target_fd desired FD to point to /dev/null
503 * @param flags open flags (O_RDONLY, O_WRONLY)
504 */
505static void
506open_dev_null (int target_fd,
507 int flags)
508{
509 int fd;
510
511 fd = open ("/dev/null", flags);
512 if (-1 == fd)
513 return; /* good luck */
514 if (fd == target_fd)
515 return; /* already done */
516 if (-1 == dup2 (fd, target_fd))
517 {
518 (void) close (fd);
519 return; /* good luck */
520 }
521 /* close original result from 'open' */
522 (void) close (fd);
523}
524#endif
525
526
496/** 527/**
497 * 'main' function of the child process. Loads the plugin, 528 * 'main' function of the child process. Loads the plugin,
498 * sets up its in and out pipes, then runs the request serving function. 529 * sets up its in and out pipes, then runs the request serving function.
@@ -508,16 +539,27 @@ EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin,
508 if (0 != EXTRACTOR_plugin_load_ (plugin)) 539 if (0 != EXTRACTOR_plugin_load_ (plugin))
509 { 540 {
510#if DEBUG 541#if DEBUG
511 fprintf (stderr, "Plugin `%s' failed to load!\n", plugin->short_libname); 542 fprintf (stderr, "Plugin `%s' failed to load!\n",
543 plugin->short_libname);
512#endif 544#endif
513 return; 545 return;
514 } 546 }
515 if ( (NULL != plugin->specials) && 547 if ( (NULL != plugin->specials) &&
516 (NULL != strstr (plugin->specials, "close-stderr"))) 548 (NULL != strstr (plugin->specials, "close-stderr")))
517 close (2); 549 {
550 (void) close (2);
551#ifndef WINDOWS
552 open_dev_null (2, O_WRONLY);
553#endif
554 }
518 if ( (NULL != plugin->specials) && 555 if ( (NULL != plugin->specials) &&
519 (NULL != strstr (plugin->specials, "close-stdout"))) 556 (NULL != strstr (plugin->specials, "close-stdout")))
520 close (1); 557 {
558 (void) close (1);
559#ifndef WINDOWS
560 open_dev_null (1, O_WRONLY);
561#endif
562 }
521 process_requests (plugin, in, out); 563 process_requests (plugin, in, out);
522} 564}
523 565