runcmd.h File Reference
runcmd library function declarations
More...
#include <signal.h>
Go to the source code of this file.
Detailed Description
runcmd library function declarations
- Note:
- This is inherited from the nagiosplugins project, although I (AE) wrote the original code, and it might need refactoring for performance later.
Define Documentation
#define RUNCMD_HAS_REDIR (1 << 0) |
Function Documentation
int int runcmd_close |
( |
int |
fd |
) |
|
Close a command and return its exit status.
- Note:
- Don't use this. It's a retarded way to reap children suitable only for launching a one-shot program.
- Parameters:
-
[in] | fd | The child's stdout filedescriptor |
- Returns:
- exit-status of the child, or -1 in case of errors
int runcmd_cmd2strv |
( |
const char * |
str, |
|
|
int * |
out_argc, |
|
|
char ** |
out_argv | |
|
) |
| | |
Convert a string to a vector of arguments like a shell would.
- Note:
- This might have bugs and is only tested to behave similar to how /bin/sh does things. For csh or other non bash-ish shells there are no guarantees.
-
The out_argv array has to be large enough to hold all strings found in the command.
- Parameters:
-
[in] | str | The string to convert to an argument vector |
[out] | out_argc | The number of arguments found |
[out] | out_argv | The argument vector |
- Returns:
- 0 on (great) success, or a bitmask of failure-codes representing f.e. unclosed quotes, job control or output redirection. See the RUNCMD_HAS_* and their ilk to find out about the flag.
void runcmd_init |
( |
void |
|
) |
|
Initialize the runcmd library.
Only multi-threaded programs that might launch the first external program from multiple threads simultaneously need to bother with this.
int runcmd_open |
( |
const char * |
cmd, |
|
|
int * |
pfd, |
|
|
int * |
pfderr, |
|
|
char ** |
env, |
|
|
void(*)(int, int, void *) |
iobreg, |
|
|
void * |
iobregarg | |
|
) |
| | |
Start a command from a command string.
- Parameters:
-
[in] | cmdstring | The command to launch |
[out] | pfd | Child's stdout filedescriptor |
[out] | pfderr | Child's stderr filedescriptor |
[in] | env | Currently ignored for portability |
[in] | iobreg | The callback function to register the iobrokers for the read ends of the pipe |
[in] | iobregarg | The "arg" value to pass to iobroker_register() |
pid_t runcmd_pid |
( |
int |
fd |
) |
|
Return pid of a command with a specific file descriptor.
- Parameters:
-
[in] | fd | stdout filedescriptor of the child to get pid from |
- Returns:
- pid of the child, or 0 on errors
const char* runcmd_strerror |
( |
int |
code |
) |
|
Return explanation of which system call or operation failed.
- Parameters:
-
| code | Error code returned by a library function |
- Returns:
- A non-free()'able string explaining where the error occurred