#include "pfopen.h"
#include "dnxDebug.h"
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/wait.h>
#include <assert.h>
Go to the source code of this file.
Defines | |
#define | elemcount(x) (sizeof(x)/sizeof(*(x))) |
Functions | |
PFILE * | pfopen (const char *cmdstring, const char *type) |
Open a child process whose STDIO is redirected to the parent. | |
int | pfclose (PFILE *pfile) |
Close an existing PFILE object. | |
int | pfkill (PFILE *pfile, int sig) |
Kill a set of processes associated with an existing PFILE object. |
Definition in file pfopen.c.
int pfclose | ( | PFILE * | pfile | ) |
Close an existing PFILE object.
Closes all open pipe handles, and then waits for the associated child process to die, returning the status value of the child process.
[in] | pfile | - the process pipe to be closed. |
Definition at line 212 of file pfopen.c.
References _pfile_::fp, _pfile_::pid, and xfree.
Referenced by dnxPluginExternal().
int pfkill | ( | PFILE * | pfile, | |
int | sig | |||
) |
Kill a set of processes associated with an existing PFILE object.
[in] | pfile | - the pipe representing the process to be killed. |
[in] | sig | - the signal to send the process. |
Definition at line 247 of file pfopen.c.
References _pfile_::pid.
Referenced by dnxPluginExternal().
PFILE* pfopen | ( | const char * | cmdstring, | |
const char * | type | |||
) |
Open a child process whose STDIO is redirected to the parent.
The STDOUT, STDERR, and (optionally) STDIN file handles for the child process are available to the parent (the calling process) to be used in any appropriate manner.
The only allowable modes for the pipe are 'read' and 'write' as specified by the type
parameter in the form of a single 'r' or 'w' character string. A 'r' channel is read-only and can only be used to gather data from the child process. A 'w' channel can also be used to send data to the child process.
We use (up to) three pipes for communication. According to POSIX.1g it's not specified whether you can write to the read end of a pipe, or vice-versa; pipes are defined as half-duplex. Thus, we need to open a separate pipe (pair of file descriptors) for each channel. While full- duplex pipes are probably available everywhere, it's not in the spec, so it's not portable.
[in] | cmdstring | - the command string executed as a child process. |
[in] | type | - the file type string used when opening the I/O channel to the child process. |
Definition at line 93 of file pfopen.c.
References elemcount, _pfile_::fp, _pfile_::pid, xcalloc, and xfree.
Referenced by dnxPluginExternal().