2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins.
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
20 /* Invokes a commmand on a pipe and optionally connects its stdin and stdout
21 * to the specified handles.
24 mutt_create_filter_fd (const char *cmd, FILE ** in, FILE ** out, FILE ** err,
25 int fdin, int fdout, int fderr)
27 int pin[2], pout[2], perr[2], thepid;
37 if (pipe (pout) == -1) {
48 if (pipe (perr) == -1) {
61 mutt_block_signals_system ();
63 if ((thepid = fork ()) == 0) {
64 mutt_unblock_signals_system (0);
71 else if (fdin != -1) {
81 else if (fdout != -1) {
91 else if (fderr != -1) {
96 execl ("/bin/sh", "sh", "-c", cmd, NULL);
99 else if (thepid == -1) {
100 mutt_unblock_signals_system (1);
122 *out = fdopen (pout[0], "r");
127 *in = fdopen (pin[1], "w");
132 *err = fdopen (perr[0], "r");
138 pid_t mutt_create_filter (const char *s, FILE ** in, FILE ** out, FILE ** err)
140 return (mutt_create_filter_fd (s, in, out, err, -1, -1, -1));
143 int mutt_wait_filter (pid_t pid)
147 waitpid (pid, &rc, 0);
148 mutt_unblock_signals_system (1);
149 rc = WIFEXITED (rc) ? WEXITSTATUS (rc) : -1;