poser
A C framework for POsix SERvices
Loading...
Searching...
No Matches
process.h
Go to the documentation of this file.
1#ifndef POSER_CORE_PROCESS_H
2#define POSER_CORE_PROCESS_H
3
8#include <poser/decl.h>
9#include <sys/types.h>
10
12#define PSC_ERR_EXEC 127
13
15typedef enum PSC_StreamType
16{
21
23typedef enum PSC_StreamAction
24{
30
43C_CLASS_DECL(PSC_Process);
44
48C_CLASS_DECL(PSC_ProcessOpts);
49
53C_CLASS_DECL(PSC_EAProcessDone);
54
55C_CLASS_DECL(PSC_Connection);
56C_CLASS_DECL(PSC_Event);
57
66typedef void (*PSC_StreamCallback)(void *obj,
67 PSC_StreamType type, PSC_Connection *conn);
68
76typedef int (*PSC_ProcessMain)(int argc, char **argv);
77
83DECLEXPORT PSC_ProcessOpts *
85 ATTR_RETNONNULL;
86
96DECLEXPORT void
98 CMETHOD ATTR_NONNULL((2));
99
106DECLEXPORT void
108 CMETHOD ATTR_NONNULL((2));
109
117DECLEXPORT int
119 PSC_StreamAction action)
120 CMETHOD;
121
132DECLEXPORT int
134 CMETHOD;
135
140DECLEXPORT void
142
149DECLEXPORT PSC_Process *
151 ATTR_RETNONNULL;
152
165DECLEXPORT int
167 const char *path)
168 CMETHOD ATTR_NONNULL((3));
169
182DECLEXPORT int
184 PSC_ProcessMain main)
185 CMETHOD ATTR_NONNULL((3));
186
197DECLEXPORT int
198PSC_Process_stop(PSC_Process *self, unsigned forceMs)
199 CMETHOD;
200
210DECLEXPORT PSC_Event *
212 CMETHOD ATTR_RETNONNULL;
213
220DECLEXPORT pid_t
222 CMETHOD;
223
230DECLEXPORT int
232 CMETHOD;
233
240DECLEXPORT int
242 CMETHOD;
243
244#endif
A socket connection.
Event arguments for a finished child process.
int PSC_EAProcessDone_signal(const PSC_EAProcessDone *self)
The signal that terminated the child process.
int PSC_EAProcessDone_status(const PSC_EAProcessDone *self)
The exit status of the child process.
A simple event class.
A child process.
PSC_Process * PSC_Process_create(const PSC_ProcessOpts *opts)
PSC_Process default constructor.
int PSC_Process_stop(PSC_Process *self, unsigned forceMs)
Send signals to stop the child process.
int PSC_Process_exec(PSC_Process *self, void *obj, PSC_StreamCallback cb, const char *path)
Execute an external program in the child process.
int PSC_Process_run(PSC_Process *self, void *obj, PSC_StreamCallback cb, PSC_ProcessMain main)
Execute a given function in the child process.
PSC_Event * PSC_Process_done(PSC_Process *self)
The child process finished.
pid_t PSC_Process_pid(const PSC_Process *self)
The process id of the child process.
Creation options for a child process.
int PSC_ProcessOpts_setExecError(PSC_ProcessOpts *self, int execError)
Configure which exit status to use to indicate exec() errors.
int PSC_ProcessOpts_streamAction(PSC_ProcessOpts *self, PSC_StreamType stream, PSC_StreamAction action)
Configure an action for a standard I/O stream of the child process.
void PSC_ProcessOpts_addArg(PSC_ProcessOpts *self, const char *arg)
Add a command-line argument.
PSC_ProcessOpts * PSC_ProcessOpts_create(void)
PSC_ProcessOpts default constructor.
void PSC_ProcessOpts_destroy(PSC_ProcessOpts *self)
PSC_ProcessOpts destructor.
void PSC_ProcessOpts_setName(PSC_ProcessOpts *self, const char *name)
Set the name of the child process.
int(* PSC_ProcessMain)(int argc, char **argv)
A main function for a child process.
Definition: process.h:76
void(* PSC_StreamCallback)(void *obj, PSC_StreamType type, PSC_Connection *conn)
A callback to receive a PSC_Connection for a standard I/O stream.
Definition: process.h:66
PSC_StreamType
Standard I/O streams of the child process.
Definition: process.h:16
@ PSC_ST_STDOUT
standard output
Definition: process.h:18
@ PSC_ST_STDIN
standard input
Definition: process.h:17
@ PSC_ST_STDERR
standard error
Definition: process.h:19
PSC_StreamAction
What to do with a standard I/O stream in a child process.
Definition: process.h:24
@ PSC_SA_CLOSE
close it, so the child can't use it
Definition: process.h:26
@ PSC_SA_NULL
redirect it to /dev/null (silence)
Definition: process.h:27
@ PSC_SA_LEAVE
leave it alone (inherit from parent)
Definition: process.h:25
@ PSC_SA_PIPE
redirect it to a pipe
Definition: process.h:28