diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2020-01-30 14:08:23 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2020-01-30 14:08:23 +0200 |
commit | 3bc027ef68aa1f876bfc3b7d1e60ea5d478ddade (patch) | |
tree | bc328f31a472eb5cb7dee6f7d7afbea79d129288 /runcap.h | |
parent | 99f77c702c0213b9c22c21f4e9568e509d332903 (diff) | |
download | runcap-3bc027ef68aa1f876bfc3b7d1e60ea5d478ddade.tar.gz runcap-3bc027ef68aa1f876bfc3b7d1e60ea5d478ddade.tar.bz2 |
Optionally store the captured stream in a file.v1.3
* runcap.3: Document the sc_storfd member and the RCF_STDOUT_STORFD
and RCF_STDERR_STORFD flags.
* runcap.c (stream_capture_init): Rewrite.
(stream_capture_reset): Don't close sc_storfd if RCF_SC_STORFD flag
is set.
(runcap_start): Redirect output to the corresponding sc_storfd
descriptor if so requested.
* runcap.h (stream_capture): Replace sc_nocap with sc_flags.
(RCF_SC_SIZE,RCF_SC_LINEMON)
(RCF_SC_NOCAP,RCF_SC_STORFD): New stream-specific constants.
(RCF_SC_TO_FLAG,RCF_FLAG_TO_SC): New macros.
Rewrite existing RCF_STDOUT_* and RCF_STDERR_* flags using RCF_SC_TO_FLAG.
(RCF_STDOUT_STORFD,RCF_STDERR_STORFD): New flags.
* t/redirect.at: New test case.
* t/Makefile.am: Add new test.
* t/testsuite.at: Likewise.
* t/rt.c: New option -o: send output to a file.
Diffstat (limited to 'runcap.h')
-rw-r--r-- | runcap.h | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -31,7 +31,7 @@ struct stream_capture void (*sc_linemon)(const char *, size_t, void *); /* Line monitor function */ void *sc_monarg; /* Line monitor argument */ - int sc_nocap; /* If 1, capturing is disabled */ + int sc_flags; /* Stream flags */ }; #define STRCAP_BUFSIZE 4096 @@ -58,12 +58,24 @@ struct runcap #define RCF_PROGRAM 0x0001 /* rc_program is set */ #define RCF_TIMEOUT 0x0002 /* rc_timeout is set */ #define RCF_STDIN 0x0004 /* rc_cap[RUNCAP_STDIN] is set */ -#define RCF_STDOUT_SIZE 0x0008 /* rc_cap[RUNCAP_STDOUT].sc_size is set */ -#define RCF_STDOUT_LINEMON 0x0010 /* rc_cap[RUNCAP_STDOUT].sc_linemon is set */ -#define RCF_STDERR_SIZE 0x0020 /* rc_cap[RUNCAP_STDERR].sc_size is set */ -#define RCF_STDERR_LINEMON 0x0040 /* rc_cap[RUNCAP_STDERR].sc_linemon is set */ -#define RCF_STDOUT_NOCAP 0x0080 /* disable stdout capturing */ -#define RCF_STDERR_NOCAP 0x0100 /* disable stderr capturing */ + +#define RCF_SC_SIZE 0x1 /* sc_size is set */ +#define RCF_SC_LINEMON 0x2 /* sc_linemon is set*/ +#define RCF_SC_NOCAP 0x4 /* capturing is disabled */ +#define RCF_SC_STORFD 0x8 /* sc_storfd is set */ + +#define RCF_SC_TO_FLAG(f,s) ((f) << (4*(s))) +#define RCF_FLAG_TO_SC(f,s) (((f) >> (4*(s))) & 0xf) + +#define RCF_STDOUT_SIZE RCF_SC_TO_FLAG(RCF_SC_SIZE, RUNCAP_STDOUT) +#define RCF_STDOUT_LINEMON RCF_SC_TO_FLAG(RCF_SC_LINEMON, RUNCAP_STDOUT) +#define RCF_STDOUT_NOCAP RCF_SC_TO_FLAG(RCF_SC_NOCAP, RUNCAP_STDOUT) +#define RCF_STDOUT_STORFD RCF_SC_TO_FLAG(RCF_SC_STORFD, RUNCAP_STDOUT) + +#define RCF_STDERR_SIZE RCF_SC_TO_FLAG(RCF_SC_SIZE, RUNCAP_STDERR) +#define RCF_STDERR_LINEMON RCF_SC_TO_FLAG(RCF_SC_LINEMON, RUNCAP_STDERR) +#define RCF_STDERR_NOCAP RCF_SC_TO_FLAG(RCF_SC_NOCAP, RUNCAP_STDERR) +#define RCF_STDERR_STORFD RCF_SC_TO_FLAG(RCF_SC_STORFD, RUNCAP_STDERR) int runcap(struct runcap *rc, int flags); void runcap_free(struct runcap *rc); @@ -80,7 +92,7 @@ runcap_get_capture(struct runcap *rc, int stream) fp = &rc->rc_cap[stream]; - if (!fp->sc_base || fp->sc_size == 0 || fp->sc_nocap) { + if (!fp->sc_base || fp->sc_size == 0 || (fp->sc_flags & RCF_SC_NOCAP)) { errno = EINVAL; return NULL; } |