diff options
author | midipix <writeonce@midipix.org> | 2021-04-20 22:15:00 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2021-04-20 19:27:28 +0000 |
commit | 00bc9c19cdd57be69d8ab8ac9d0459efc25aab6a (patch) | |
tree | 5119dc7a1bbaded22aebdffc79c9af493e095206 | |
parent | 25a377af92d753ba157274e2b8ee630372c0619d (diff) | |
download | tpax-00bc9c19cdd57be69d8ab8ac9d0459efc25aab6a.tar.bz2 tpax-00bc9c19cdd57be69d8ab8ac9d0459efc25aab6a.tar.xz |
driver: tpax_get_unit_ctx(): support paths relative to an arbitrary location.
-rw-r--r-- | include/tpax/tpax.h | 2 | ||||
-rw-r--r-- | src/driver/tpax_amain.c | 5 | ||||
-rw-r--r-- | src/driver/tpax_unit_ctx.c | 8 |
3 files changed, 9 insertions, 6 deletions
diff --git a/include/tpax/tpax.h b/include/tpax/tpax.h index 8897818..17fe7d8 100644 --- a/include/tpax/tpax.h +++ b/include/tpax/tpax.h @@ -141,7 +141,7 @@ tpax_api int tpax_get_driver_ctx (char ** argv, char ** envp, uint32_t fl tpax_api void tpax_free_driver_ctx (struct tpax_driver_ctx *); -tpax_api int tpax_get_unit_ctx (const struct tpax_driver_ctx *, const char * path, +tpax_api int tpax_get_unit_ctx (const struct tpax_driver_ctx *, int, const char * path, struct tpax_unit_ctx **); tpax_api void tpax_free_unit_ctx (struct tpax_unit_ctx *); diff --git a/src/driver/tpax_amain.c b/src/driver/tpax_amain.c index d94eaf0..9d87e18 100644 --- a/src/driver/tpax_amain.c +++ b/src/driver/tpax_amain.c @@ -4,6 +4,7 @@ /* Released under GPLv2 and GPLv3; see COPYING.TPAX. */ /******************************************************/ +#include <fcntl.h> #include <stdio.h> #include <unistd.h> #include <tpax/tpax.h> @@ -67,6 +68,7 @@ int tpax_main(char ** argv, char ** envp, const struct tpax_fd_ctx * fdctx) { int ret; int fdout; + int fdcwd; uint64_t flags; struct tpax_driver_ctx * dctx; struct tpax_unit_ctx * uctx; @@ -74,6 +76,7 @@ int tpax_main(char ** argv, char ** envp, const struct tpax_fd_ctx * fdctx) flags = TPAX_DRIVER_FLAGS; fdout = fdctx ? fdctx->fdout : STDOUT_FILENO; + fdcwd = fdctx ? fdctx->fdcwd : AT_FDCWD; if ((ret = tpax_get_driver_ctx(argv,envp,flags,fdctx,&dctx))) return (ret == TPAX_USAGE) @@ -85,7 +88,7 @@ int tpax_main(char ** argv, char ** envp, const struct tpax_fd_ctx * fdctx) return tpax_exit(dctx,TPAX_ERROR); for (unit=dctx->units; *unit; unit++) { - if (!(tpax_get_unit_ctx(dctx,*unit,&uctx))) { + if (!(tpax_get_unit_ctx(dctx,fdcwd,*unit,&uctx))) { tpax_perform_unit_actions(dctx,uctx); tpax_free_unit_ctx(uctx); } diff --git a/src/driver/tpax_unit_ctx.c b/src/driver/tpax_unit_ctx.c index 0f0bd98..f034b17 100644 --- a/src/driver/tpax_unit_ctx.c +++ b/src/driver/tpax_unit_ctx.c @@ -27,6 +27,7 @@ static int tpax_free_unit_ctx_impl(struct tpax_unit_ctx_impl * ctx, int ret) int tpax_get_unit_ctx( const struct tpax_driver_ctx * dctx, + int fdat, const char * path, struct tpax_unit_ctx ** pctx) { @@ -45,8 +46,8 @@ int tpax_get_unit_ctx( if (dctx->cctx->drvflags & TPAX_DRIVER_EXEC_MODE_WRITE_COPY) { ret = fstatat( - tpax_driver_fdcwd(dctx),path, - &ctx->st,AT_SYMLINK_NOFOLLOW); + fdat,path,&ctx->st, + AT_SYMLINK_NOFOLLOW); if (ret < 0) { free(ctx); @@ -56,8 +57,7 @@ int tpax_get_unit_ctx( if (S_ISLNK(ctx->st.st_mode)) { if (tpax_readlinkat( - tpax_driver_fdcwd(dctx), - path,ctx->linkbuf, + fdat,path,ctx->linkbuf, sizeof(ctx->linkbuf)) < 0) { free(ctx); return TPAX_SYSTEM_ERROR(dctx); |