aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-11-03 16:50:15 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2012-11-03 16:50:15 +0200
commit0273a63f52377b3fb613ed9692c697cbe83cd54d (patch)
treee81775d393e39f5c101d26a78a04d39284242993 /src
parentc8fddb5d928a222adc96f8ad751000f8503ffa97 (diff)
downloadmailfromd-0273a63f52377b3fb613ed9692c697cbe83cd54d.tar.gz
mailfromd-0273a63f52377b3fb613ed9692c697cbe83cd54d.tar.bz2
Fix communication with a program invoked via open().
* src/builtin/io.bi (REDIRECT_STDOUT_P): Fix. (open_program_stream): Remove improper calls to close(). (open): Implement the |< prefix to open read-only communication with the invoked program. * doc/functions.texi: Document the |< prefix. * NEWS: Update. * THANKS: Mention Mehmet Tolga Avcioglu.
Diffstat (limited to 'src')
-rw-r--r--src/builtin/io.bi15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/builtin/io.bi b/src/builtin/io.bi
index fdcd928a..2ced45f9 100644
--- a/src/builtin/io.bi
+++ b/src/builtin/io.bi
@@ -114,7 +114,7 @@ read_stream_delim(struct io_stream *str, char *delim)
}
#define REDIRECT_STDIN_P(f) ((f) & (O_WRONLY|O_RDWR))
-#define REDIRECT_STDOUT_P(f) ((f) & (O_RDONLY|O_RDWR))
+#define REDIRECT_STDOUT_P(f) (!((f) & O_WRONLY))
#define STDERR_SHUT 0
#define STDERR_NULL 1
@@ -321,20 +321,14 @@ open_program_stream(eval_environ_t env,
/* Right-end */
if (REDIRECT_STDOUT_P(flags)) {
- if (rightp[1] != 1) {
- close(1);
+ if (rightp[1] != 1)
dup2(rightp[1], 1);
- }
- close(rightp[0]);
}
/* Left-end */
if (REDIRECT_STDIN_P(flags)) {
- if (leftp[0] != 0) {
- close(0);
+ if (leftp[0] != 0)
dup2(leftp[0], 0);
- }
- close(leftp[1]);
}
stderr_handler(err, arg, cmdline);
@@ -707,6 +701,9 @@ MF_DEFUN(open, NUMBER, STRING name)
if (*name == '&') {
flags = O_RDWR;
name++;
+ } else if (*name == '<') {
+ flags = O_RDONLY;
+ name++;
}
} else if (*name == '@') {
name++;

Return to:

Send suggestions and report system problems to the System administrator.