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.
24 #include "mutt_curses.h"
33 /* Invokes a command on a pipe and optionally connects its stdin and stdout
34 * to the specified handles.
37 mutt_create_filter_fd (const char *cmd, FILE **in, FILE **out, FILE **err,
38 int fdin, int fdout, int fderr)
40 int pin[2], pout[2], perr[2], thepid;
53 if (pipe (pout) == -1)
67 if (pipe (perr) == -1)
83 mutt_block_signals_system ();
85 if ((thepid = fork ()) == 0)
87 mutt_unblock_signals_system (0);
107 else if (fdout != -1)
119 else if (fderr != -1)
125 if (MuttIndexWindow && (MuttIndexWindow->cols > 0))
127 snprintf (columns, sizeof (columns), "%d", MuttIndexWindow->cols);
128 mutt_envlist_set ("COLUMNS", columns, 1);
131 execle (EXECSHELL, "sh", "-c", cmd, NULL, mutt_envlist ());
134 else if (thepid == -1)
136 mutt_unblock_signals_system (1);
162 *out = fdopen (pout[0], "r");
168 *in = fdopen (pin[1], "w");
174 *err = fdopen (perr[0], "r");
180 pid_t mutt_create_filter (const char *s, FILE **in, FILE **out, FILE **err)
182 return (mutt_create_filter_fd (s, in, out, err, -1, -1, -1));
185 int mutt_wait_filter (pid_t pid)
189 waitpid (pid, &rc, 0);
190 mutt_unblock_signals_system (1);
191 rc = WIFEXITED (rc) ? WEXITSTATUS (rc) : -1;
197 * This is used for filters that are actually interactive commands
198 * with input piped in: e.g. in mutt_view_attachment(), a mailcap
199 * entry without copiousoutput _and_ without a %s.
201 * For those cases, we treat it like a blocking system command, and
202 * poll IMAP to keep connections open.
204 int mutt_wait_interactive_filter (pid_t pid)
209 waitpid (pid, &rc, 0);
211 rc = imap_wait_keepalive (pid);
213 mutt_unblock_signals_system (1);
214 rc = WIFEXITED (rc) ? WEXITSTATUS (rc) : -1;