2 * Copyright (C) 1996-2000 Michael R. Elkins.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
29 /* Invokes a commmand on a pipe and optionally connects its stdin and stdout
30 * to the specified handles.
33 mutt_create_filter_fd (const char *cmd, FILE ** in, FILE ** out, FILE ** err,
34 int fdin, int fdout, int fderr)
36 int pin[2], pout[2], perr[2], thepid;
46 if (pipe (pout) == -1) {
57 if (pipe (perr) == -1) {
70 mutt_block_signals_system ();
72 if ((thepid = fork ()) == 0) {
73 mutt_unblock_signals_system (0);
80 else if (fdin != -1) {
90 else if (fdout != -1) {
100 else if (fderr != -1) {
105 execl (EXECSHELL, "sh", "-c", cmd, NULL);
108 else if (thepid == -1) {
109 mutt_unblock_signals_system (1);
131 *out = fdopen (pout[0], "r");
136 *in = fdopen (pin[1], "w");
141 *err = fdopen (perr[0], "r");
147 pid_t mutt_create_filter (const char *s, FILE ** in, FILE ** out, FILE ** err)
149 return (mutt_create_filter_fd (s, in, out, err, -1, -1, -1));
152 int mutt_wait_filter (pid_t pid)
156 waitpid (pid, &rc, 0);
157 mutt_unblock_signals_system (1);
158 rc = WIFEXITED (rc) ? WEXITSTATUS (rc) : -1;