1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include "process.ih"
int p_parent(Process *pp, int *readPipe, int *writePipe)
{
int status;
size_t input_length;
close(readPipe[WRITE]); /* Close unused pipe-ends */
close(writePipe[READ]);
if ((input_length = strlen(pp->d_input)))
{
if
(
(size_t)write(writePipe[WRITE], pp->d_input, input_length)
!=
input_length
)
{
char *input = new_str(string_short(pp->d_input));
if (kill(pp->d_pid, SIGTERM))
kill(pp->d_pid, SIGKILL);
if (message_show(MSG_CRIT))
message("%s: Can't pipe `%s' to `%s'",
pp->d_fname, input, string_short(pp->d_cmd));
free(input);
}
}
close(writePipe[WRITE]);
p_fill_output(pp, readPipe[READ]);
waitpid(pp->d_pid, &status, 0);
return status;
}
|