libcortex
Event loop library following a "batteries included" approach
Loading...
Searching...
No Matches
popen.h
1#ifndef _CRTX_POPEN_H
2#define _CRTX_POPEN_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8/*
9 * Mario Kicherer (dev@kicherer.org) 2019
10 *
11 */
12
13#include "core.h"
14#include "fork.h"
15#include "pipe.h"
16#include "writequeue.h"
17
19 struct crtx_listener_base base;
20
21 struct crtx_fork_listener fork_lstnr;
22
23 struct crtx_writequeue_listener stdin_wq_lstnr;
24 struct crtx_pipe_listener stdin_lstnr;
25 struct crtx_pipe_listener stdout_lstnr;
26 struct crtx_pipe_listener stderr_lstnr;
27
28 int fstdin; // override stdin for the new process (optional)
29 int fstdout; // override stdout for the new process (optional)
30 int fstderr; // override stderr for the new process (optional)
31
32 int rc; // return code of the child process
33
34 void (*stdout_cb)(int fd, void *userdata); // if set, will be called if child process writes to stdout
35 void (*stderr_cb)(int fd, void *userdata); // if set, will be called if child process writes to stderr
36
37 void *stdout_cb_data; // user data that will be passed to the respective callback above
38 void *stderr_cb_data; // user data that will be passed to the respective callback above
39
40 const char *filepath; // execute the executable with this file path
41 const char *filename; // execute an executable with this filename (e.g., in $PATH)
42 char **argv; // start executable with parameters (must include executable itself)
43 char **envp; // start executable with a custom environment (optional)
44 const char *chdir; // change current directory before starting child process (optional)
45
46 // execute callback just before execv'ing the given command
47 void (*pre_exec)(struct crtx_popen_listener *plstnr, void *pre_exec_userdata);
48 void *pre_exec_userdata;
49};
50
51struct crtx_listener_base *crtx_setup_popen_listener(void *options);
52void crtx_popen_clear_lstnr(struct crtx_popen_listener *lstnr);
53void crtx_popen_close_stdin(struct crtx_popen_listener *lstnr);
54CRTX_DECLARE_ALLOC_FUNCTION(popen)
55
56void crtx_popen_init();
57void crtx_popen_finish();
58
59#ifdef __cplusplus
60}
61#endif
62
63#endif
The core definitions of libcortex.
Definition fork.h:23
base structure of a listener
Definition core.h:186
Definition pipe.h:16
Definition popen.h:18
Definition writequeue.h:16