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.
18 #include <lib-sys/mutt_signal.h>
22 /* Invokes a commmand on a pipe and optionally connects its stdin and stdout
23 * to the specified handles.
26 mutt_create_filter_fd (const char *cmd, FILE ** in, FILE ** out, FILE ** err,
27 int fdin, int fdout, int fderr)
29 int pin[2], pout[2], perr[2], thepid;
39 if (pipe (pout) == -1) {
50 if (pipe (perr) == -1) {
63 mutt_block_signals_system ();
65 if ((thepid = fork ()) == 0) {
66 mutt_unblock_signals_system (0);
73 else if (fdin != -1) {
83 else if (fdout != -1) {
93 else if (fderr != -1) {
98 execl ("/bin/sh", "sh", "-c", cmd, NULL);
101 else if (thepid == -1) {
102 mutt_unblock_signals_system (1);
124 *out = fdopen (pout[0], "r");
129 *in = fdopen (pin[1], "w");
134 *err = fdopen (perr[0], "r");
140 pid_t mutt_create_filter (const char *s, FILE ** in, FILE ** out, FILE ** err)
142 return (mutt_create_filter_fd (s, in, out, err, -1, -1, -1));
145 int mutt_wait_filter (pid_t pid)
149 waitpid (pid, &rc, 0);
150 mutt_unblock_signals_system (1);
151 rc = WIFEXITED (rc) ? WEXITSTATUS (rc) : -1;