diff options
-rw-r--r-- | runcap.c | 45 | ||||
-rw-r--r-- | t/pipe.at | 2 | ||||
-rw-r--r-- | t/stdin.at | 2 |
3 files changed, 19 insertions, 30 deletions
@@ -26,9 +26,14 @@ #include "runcap.h" -static int -stream_capture_alloc(struct stream_capture *cap, size_t size) +int +stream_capture_init(struct stream_capture *cap, size_t size) { + if (!cap) { + errno = EINVAL; + return -1; + } + if (size) { cap->sc_base = malloc(size); if (!cap->sc_base) @@ -45,20 +50,6 @@ stream_capture_alloc(struct stream_capture *cap, size_t size) return 0; } -int -stream_capture_init(struct stream_capture *cap, size_t size) -{ - if (!cap) { - errno = EINVAL; - return -1; - } - - if (stream_capture_alloc(cap, size)) - return -1; - - return 0; -} - static void stream_capture_reset(struct stream_capture *cap) { @@ -434,6 +425,7 @@ runcap_init(struct runcap *rc, int flags) rc->rc_program = NULL; if (!(flags & RCF_TIMEOUT)) rc->rc_timeout = 0; + if (flags & RCF_STDIN) { if (rc->rc_cap[RUNCAP_STDIN].sc_size > 0 && rc->rc_cap[RUNCAP_STDIN].sc_fd != -1) { @@ -443,15 +435,14 @@ runcap_init(struct runcap *rc, int flags) rc->rc_cap[RUNCAP_STDIN].sc_level = rc->rc_cap[RUNCAP_STDIN].sc_size; rc->rc_cap[RUNCAP_STDIN].sc_cur = 0; + rc->rc_cap[RUNCAP_STDIN].sc_storfd = -1; } else if (stream_capture_init(&rc->rc_cap[RUNCAP_STDIN], 0)) return -1; - if (flags & RCF_STDOUT_SIZE) - res = stream_capture_alloc(&rc->rc_cap[RUNCAP_STDOUT], - rc->rc_cap[RUNCAP_STDOUT].sc_size); - else - res = stream_capture_init(&rc->rc_cap[RUNCAP_STDOUT], - STRCAP_BUFSIZE); + res = stream_capture_init(&rc->rc_cap[RUNCAP_STDOUT], + (flags & RCF_STDOUT_SIZE) + ? rc->rc_cap[RUNCAP_STDOUT].sc_size + : STRCAP_BUFSIZE); if (res) return res; @@ -460,12 +451,10 @@ runcap_init(struct runcap *rc, int flags) rc->rc_cap[RUNCAP_STDOUT].sc_monarg = NULL; } - if (flags & RCF_STDERR_SIZE) - res = stream_capture_alloc(&rc->rc_cap[RUNCAP_STDERR], - rc->rc_cap[RUNCAP_STDERR].sc_size); - else - res = stream_capture_init(&rc->rc_cap[RUNCAP_STDERR], - STRCAP_BUFSIZE); + res = stream_capture_init(&rc->rc_cap[RUNCAP_STDERR], + (flags & RCF_STDERR_SIZE) + ? rc->rc_cap[RUNCAP_STDERR].sc_size + : STRCAP_BUFSIZE); if (res) return res; @@ -16,7 +16,7 @@ AT_SETUP([pipe stdin]) AT_KEYWORDS([pipe]) -AT_CHECK([rt -n all -i -f $INPUT -- genout -l 337 -o - -s 628 -l 734 -e $INPUT +AT_CHECK([rt -n all -t 5 -i -f $INPUT -- genout -l 337 -o - -s 628 -l 734 -e $INPUT ], [0], [res=0 @@ -16,7 +16,7 @@ AT_SETUP([supply stdin]) AT_KEYWORDS([stdin]) -AT_CHECK([rt -n all -f $INPUT -- genout -l 337 -o - -s 628 -l 734 -e $INPUT +AT_CHECK([rt -n all -t 5 -f $INPUT -- genout -l 337 -o - -s 628 -l 734 -e $INPUT ], [0], [res=0 |