diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2003-02-21 03:11:18 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2003-02-21 03:11:18 +0800 |
commit | 12f146c032eb21c73f9a941ce812876a23e625f0 (patch) | |
tree | ffff3558f1021dd4674bd38bdf2b2bf54531da21 /camel | |
parent | 99a343eb815c833f54866d88bb222fa79947232c (diff) | |
download | gsoc2013-evolution-12f146c032eb21c73f9a941ce812876a23e625f0.tar.gz gsoc2013-evolution-12f146c032eb21c73f9a941ce812876a23e625f0.tar.zst gsoc2013-evolution-12f146c032eb21c73f9a941ce812876a23e625f0.zip |
Redirect program's stdout and stderr to /dev/null
2003-02-20 Jeffrey Stedfast <fejj@ximian.com>
* camel-filter-search.c (run_command): Redirect program's stdout
and stderr to /dev/null
* camel-filter-driver.c (pipe_to_system): Redirect the program's
stderr to /dev/null
(pipe_to_system): Write the pipe to a mem stream and use the mem
stream in the parser. Also, when setting an exception get the
errno from the parser so we can give more info about the error to
the user.
svn path=/trunk/; revision=19974
Diffstat (limited to 'camel')
-rw-r--r-- | camel/ChangeLog | 7 | ||||
-rw-r--r-- | camel/camel-filter-driver.c | 23 | ||||
-rw-r--r-- | camel/camel-filter-search.c | 14 |
3 files changed, 32 insertions, 12 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index a5730b0f11..54763b7388 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,7 +1,14 @@ 2003-02-20 Jeffrey Stedfast <fejj@ximian.com> + * camel-filter-search.c (run_command): Redirect program's stdout + and stderr to /dev/null + * camel-filter-driver.c (pipe_to_system): Redirect the program's stderr to /dev/null + (pipe_to_system): Write the pipe to a mem stream and use the mem + stream in the parser. Also, when setting an exception get the + errno from the parser so we can give more info about the error to + the user. 2003-02-19 Jeffrey Stedfast <fejj@ximian.com> diff --git a/camel/camel-filter-driver.c b/camel/camel-filter-driver.c index c6004a38df..a9a7bb004a 100644 --- a/camel/camel-filter-driver.c +++ b/camel/camel-filter-driver.c @@ -42,6 +42,7 @@ #include "camel-service.h" #include "camel-stream-fs.h" +#include "camel-stream-mem.h" #include "camel-mime-message.h" #include "e-util/e-sexp.h" @@ -645,7 +646,7 @@ pipe_to_system (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFil int result, status, fds[4], i; CamelMimeMessage *message; CamelMimeParser *parser; - CamelStream *stream; + CamelStream *stream, *mem; pid_t pid; if (argc < 1 || argv[0]->value.string[0] == '\0') @@ -692,9 +693,9 @@ pipe_to_system (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFil maxfd = sysconf (_SC_OPEN_MAX); if (maxfd > 0) { - for (i = 0; i < maxfd; i++) { - if (i != STDIN_FILENO && i != STDOUT_FILENO && i != STDERR_FILENO) - close (i); + for (fd = 0; fd < maxfd; fd++) { + if (fd != STDIN_FILENO && fd != STDOUT_FILENO && fd != STDERR_FILENO) + close (fd); } } @@ -726,15 +727,23 @@ pipe_to_system (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFil camel_stream_flush (stream); camel_object_unref (stream); + stream = camel_stream_fs_new_with_fd (fds[2]); + mem = camel_stream_mem_new (); + camel_stream_write_to_stream (stream, mem); + camel_object_unref (stream); + camel_stream_reset (mem); + parser = camel_mime_parser_new (); - camel_mime_parser_init_with_fd (parser, fds[2]); + camel_mime_parser_init_with_stream (parser, mem); camel_mime_parser_scan_from (parser, FALSE); + camel_object_unref (mem); message = camel_mime_message_new (); if (camel_mime_part_construct_from_parser ((CamelMimePart *) message, parser) == -1) { camel_exception_setv (p->ex, CAMEL_EXCEPTION_SYSTEM, - _("Invalid message stream received from %s"), - argv[0]->value.string); + _("Invalid message stream received from %s: %s"), + argv[0]->value.string, + g_strerror (camel_mime_parser_errno (parser))); camel_object_unref (message); message = NULL; } else { diff --git a/camel/camel-filter-search.c b/camel/camel-filter-search.c index 9a42b5e002..e0e385346b 100644 --- a/camel/camel-filter-search.c +++ b/camel/camel-filter-search.c @@ -519,18 +519,22 @@ run_command (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessa if (!(pid = fork ())) { /* child process */ GPtrArray *args; - int maxfd, i; + int maxfd, fd, i; - if (dup2 (in_fds[0], STDIN_FILENO) < 0) + fd = open ("/dev/null", O_WRONLY); + + if (dup2 (in_fds[0], STDIN_FILENO) < 0 || + dup2 (fd, STDOUT_FILENO) < 0 || + dup2 (fd, STDERR_FILENO) < 0) _exit (255); setsid (); maxfd = sysconf (_SC_OPEN_MAX); if (maxfd > 0) { - for (i = 0; i < maxfd; i++) { - if (i != STDIN_FILENO && i != STDOUT_FILENO && i != STDERR_FILENO) - close (i); + for (fd = 0; fd < maxfd; fd++) { + if (fd != STDIN_FILENO && fd != STDOUT_FILENO && fd != STDERR_FILENO) + close (fd); } } |