diff options
author | midipix <writeonce@midipix.org> | 2015-12-23 22:12:14 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2016-11-11 00:22:31 -0500 |
commit | db486471613b80f756a26578f6015a690dc8212f (patch) | |
tree | 1a505b16bd2365db102ad1220c2661888e2a7afd /src/driver | |
parent | cfa298f7f4637201610624b86d03dd209de0034a (diff) | |
download | mdso-db486471613b80f756a26578f6015a690dc8212f.tar.bz2 mdso-db486471613b80f756a26578f6015a690dc8212f.tar.xz |
driver: added driver-level handling of stdin.
Diffstat (limited to 'src/driver')
-rw-r--r-- | src/driver/mdso_driver_ctx.c | 4 | ||||
-rw-r--r-- | src/driver/mdso_unit_ctx.c | 23 |
2 files changed, 25 insertions, 2 deletions
diff --git a/src/driver/mdso_driver_ctx.c b/src/driver/mdso_driver_ctx.c index 1538d95..14f1e75 100644 --- a/src/driver/mdso_driver_ctx.c +++ b/src/driver/mdso_driver_ctx.c @@ -86,6 +86,7 @@ static struct mdso_driver_ctx_impl * mdso_driver_ctx_alloc( *units++ = entry->arg; ictx->meta = meta; + ictx->ctx.fdtmpin = -1; ictx->ctx.ctx.units = ictx->units; return &ictx->ctx; } @@ -267,6 +268,9 @@ static void mdso_free_driver_ctx_impl(struct mdso_driver_ctx_alloc * ictx) if (ictx->ctx.fddst >= 0) close(ictx->ctx.fddst); + if (ictx->ctx.fdtmpin >= 0) + close(ictx->ctx.fdtmpin); + if (ictx->ctx.asmbase) free(ictx->ctx.asmbase); diff --git a/src/driver/mdso_unit_ctx.c b/src/driver/mdso_unit_ctx.c index d46820b..14fbe27 100644 --- a/src/driver/mdso_unit_ctx.c +++ b/src/driver/mdso_unit_ctx.c @@ -31,16 +31,35 @@ static int mdso_free_unit_ctx_impl(struct mdso_unit_ctx_impl * ctx, int status) return status; } -static FILE * mdso_stdin_to_tmp(void) +static FILE * mdso_stdin_to_tmp(const struct mdso_driver_ctx * dctx) { + struct mdso_driver_ctx_impl * ictx; + uintptr_t addr; + int fdtmp; + FILE * ftmp; char buf[4096]; ssize_t nread; int ret; + addr = (uintptr_t)dctx - offsetof(struct mdso_driver_ctx_impl,ctx); + ictx = (struct mdso_driver_ctx_impl *)addr; + + if (ictx->fdtmpin >= 0) { + if ((fdtmp = dup(ictx->fdtmpin)) < 0) + return 0; + + return fdopen(fdtmp,"r"); + } + if (!(ftmp = tmpfile())) return 0; + if ((ictx->fdtmpin = dup(fileno(ftmp))) < 0) { + fclose(ftmp); + return 0; + } + nread = read(0,buf,sizeof(buf)-1); while (nread) { @@ -152,7 +171,7 @@ int mdso_get_unit_ctx( if (strcmp(path,"-")) fd = -1; - else if (!(ftmp = mdso_stdin_to_tmp())) + else if (!(ftmp = mdso_stdin_to_tmp(dctx))) return mdso_free_unit_ctx_impl(ctx,-1); else if ((fd = dup(fileno(ftmp))) < 0) return mdso_free_unit_ctx_impl(ctx,-1); |