File: pparent.c

package info (click to toggle)
yodl 4.05.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,724 kB
  • sloc: ansic: 7,803; perl: 683; cpp: 570; sh: 411; xml: 190; makefile: 163
file content (36 lines) | stat: -rw-r--r-- 922 bytes parent folder | download | duplicates (10)
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;
}