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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 /* Invokes a command 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;
48 if (pipe (pout) == -1)
62 if (pipe (perr) == -1)
78 mutt_block_signals_system ();
80 if ((thepid = fork ()) == 0)
82 mutt_unblock_signals_system (0);
102 else if (fdout != -1)
114 else if (fderr != -1)
120 execl (EXECSHELL, "sh", "-c", cmd, NULL);
123 else if (thepid == -1)
125 mutt_unblock_signals_system (1);
151 *out = fdopen (pout[0], "r");
157 *in = fdopen (pin[1], "w");
163 *err = fdopen (perr[0], "r");
169 pid_t mutt_create_filter (const char *s, FILE **in, FILE **out, FILE **err)
171 return (mutt_create_filter_fd (s, in, out, err, -1, -1, -1));
174 int mutt_wait_filter (pid_t pid)
178 waitpid (pid, &rc, 0);
179 mutt_unblock_signals_system (1);
180 rc = WIFEXITED (rc) ? WEXITSTATUS (rc) : -1;