From 1379f79d286988f2582ff8efb1af736bf4229a3f Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 24 Oct 2016 12:34:04 -0400 Subject: driver: removed unit context and related interfaces (not needed by slibtool). --- include/slibtool/slibtool.h | 15 --------- project/common.mk | 2 -- src/driver/slbt_amain.c | 14 --------- src/driver/slbt_driver_ctx.c | 23 +++----------- src/driver/slbt_unit_ctx.c | 62 ------------------------------------- src/internal/slibtool_driver_impl.h | 7 ----- src/logic/slbt_map_input.c | 51 ------------------------------ 7 files changed, 5 insertions(+), 169 deletions(-) delete mode 100644 src/driver/slbt_unit_ctx.c delete mode 100644 src/logic/slbt_map_input.c diff --git a/include/slibtool/slibtool.h b/include/slibtool/slibtool.h index 3ea06a9..1a4b9fe 100644 --- a/include/slibtool/slibtool.h +++ b/include/slibtool/slibtool.h @@ -221,7 +221,6 @@ struct slbt_common_ctx { }; struct slbt_driver_ctx { - const char ** units; const char * program; const char * module; const struct slbt_common_ctx * cctx; @@ -229,15 +228,6 @@ struct slbt_driver_ctx { void * any; }; -struct slbt_unit_ctx { - const char * const * path; - const struct slbt_input * map; - const struct slbt_common_ctx * cctx; - void * any; - int status; - int nerrors; -}; - /* package info */ slbt_api const struct slbt_source_version * slbt_source_version(void); @@ -246,9 +236,6 @@ slbt_api int slbt_get_driver_ctx (char ** argv, char ** envp, uint32_t flags, s slbt_api int slbt_create_driver_ctx (const struct slbt_common_ctx *, struct slbt_driver_ctx **); slbt_api void slbt_free_driver_ctx (struct slbt_driver_ctx *); -slbt_api int slbt_get_unit_ctx (const struct slbt_driver_ctx *, const char * path, struct slbt_unit_ctx **); -slbt_api void slbt_free_unit_ctx (struct slbt_unit_ctx *); - /* execution context api */ slbt_api int slbt_get_exec_ctx (const struct slbt_driver_ctx *, struct slbt_exec_ctx **); slbt_api void slbt_free_exec_ctx (struct slbt_exec_ctx *); @@ -267,8 +254,6 @@ slbt_api int slbt_set_alternate_host (const struct slbt_driver_ctx *, const cha slbt_api void slbt_reset_alternate_host (const struct slbt_driver_ctx *); /* helper api */ -slbt_api int slbt_map_input (int fd, const char * path, int prot, struct slbt_input *); -slbt_api int slbt_unmap_input (struct slbt_input *); slbt_api int slbt_archive_import (const struct slbt_driver_ctx *, struct slbt_exec_ctx *, char * dstarchive, char * srcarchive); slbt_api int slbt_copy_file (const struct slbt_driver_ctx *, struct slbt_exec_ctx *, diff --git a/project/common.mk b/project/common.mk index 47c5d74..240ec7d 100644 --- a/project/common.mk +++ b/project/common.mk @@ -5,7 +5,6 @@ COMMON_SRCS = \ src/internal/slibtool_symlink_impl.c \ src/driver/slbt_amain.c \ src/driver/slbt_driver_ctx.c \ - src/driver/slbt_unit_ctx.c \ src/helper/slbt_archive_import.c \ src/helper/slbt_copy_file.c \ src/helper/slbt_dump_machine.c \ @@ -15,7 +14,6 @@ COMMON_SRCS = \ src/logic/slbt_exec_install.c \ src/logic/slbt_exec_link.c \ src/logic/slbt_exec_uninstall.c \ - src/logic/slbt_map_input.c \ src/output/slbt_output_config.c \ src/output/slbt_output_error.c \ src/output/slbt_output_exec.c \ diff --git a/src/driver/slbt_amain.c b/src/driver/slbt_amain.c index 25a1159..5d1417e 100644 --- a/src/driver/slbt_amain.c +++ b/src/driver/slbt_amain.c @@ -72,11 +72,6 @@ static void slbt_perform_driver_actions(struct slbt_driver_ctx * dctx) slbt_exec_uninstall(dctx,0); } -static void slbt_perform_unit_actions(struct slbt_unit_ctx * uctx) -{ - (void)uctx; -} - static int slbt_exit(struct slbt_driver_ctx * dctx, int ret) { slbt_output_error_vector(dctx); @@ -89,8 +84,6 @@ int slbt_main(int argc, char ** argv, char ** envp) int ret; uint64_t flags; struct slbt_driver_ctx * dctx; - struct slbt_unit_ctx * uctx; - const char ** unit; char * program; char * dash; char * sargv[5]; @@ -161,12 +154,5 @@ int slbt_main(int argc, char ** argv, char ** envp) slbt_perform_driver_actions(dctx); - for (unit=dctx->units; *unit; unit++) { - if (!(slbt_get_unit_ctx(dctx,*unit,&uctx))) { - slbt_perform_unit_actions(uctx); - slbt_free_unit_ctx(uctx); - } - } - return slbt_exit(dctx,dctx->errv[0] ? 2 : 0); } diff --git a/src/driver/slbt_driver_ctx.c b/src/driver/slbt_driver_ctx.c index ac41ed3..088f431 100644 --- a/src/driver/slbt_driver_ctx.c +++ b/src/driver/slbt_driver_ctx.c @@ -73,7 +73,6 @@ struct slbt_driver_ctx_alloc { struct argv_meta * meta; struct slbt_driver_ctx_impl ctx; uint64_t guard; - const char * units[]; }; static void slbt_output_raw_vector(char ** argv, char ** envp) @@ -146,17 +145,13 @@ static int slbt_driver_usage( static struct slbt_driver_ctx_impl * slbt_driver_ctx_alloc( struct argv_meta * meta, - const struct slbt_common_ctx * cctx, - size_t nunits) + const struct slbt_common_ctx * cctx) { struct slbt_driver_ctx_alloc * ictx; size_t size; - struct argv_entry * entry; - const char ** units; int elements; size = sizeof(struct slbt_driver_ctx_alloc); - size += (nunits+1)*sizeof(const char *); if (!(ictx = calloc(1,size))) return 0; @@ -164,17 +159,12 @@ static struct slbt_driver_ctx_impl * slbt_driver_ctx_alloc( if (cctx) memcpy(&ictx->ctx.cctx,cctx,sizeof(*cctx)); - for (entry=meta->entries,units=ictx->units; entry->fopt || entry->arg; entry++) - if (!entry->fopt) - *units++ = entry->arg; - elements = sizeof(ictx->ctx.erribuf) / sizeof(*ictx->ctx.erribuf); ictx->ctx.errinfp = &ictx->ctx.erriptr[0]; ictx->ctx.erricap = &ictx->ctx.erriptr[--elements]; ictx->meta = meta; - ictx->ctx.ctx.units = ictx->units; ictx->ctx.ctx.errv = ictx->ctx.errinfp; return &ictx->ctx; } @@ -810,7 +800,6 @@ int slbt_get_driver_ctx( const struct argv_option * options; struct argv_meta * meta; struct argv_entry * entry; - size_t nunits; const char * program; options = slbt_default_options; @@ -821,7 +810,6 @@ int slbt_get_driver_ctx( if (!(meta = argv_get(sargv.targv,options,slbt_argv_flags(flags)))) return -1; - nunits = 0; program = argv_program_name(argv[0]); memset(&cctx,0,sizeof(cctx)); @@ -831,7 +819,7 @@ int slbt_get_driver_ctx( /* full annotation when annotation is on; */ cctx.drvflags |= SLBT_DRIVER_ANNOTATE_FULL; - /* get options, count units */ + /* get options */ for (entry=meta->entries; entry->fopt || entry->arg; entry++) { if (entry->fopt) { switch (entry->tag) { @@ -1057,8 +1045,7 @@ int slbt_get_driver_ctx( cctx.drvflags &= ~(uint64_t)SLBT_DRIVER_SHARED; break; } - } else - nunits++; + } } /* debug: raw argument vector */ @@ -1072,7 +1059,7 @@ int slbt_get_driver_ctx( } /* driver context */ - if (!(ctx = slbt_driver_ctx_alloc(meta,&cctx,nunits))) + if (!(ctx = slbt_driver_ctx_alloc(meta,&cctx))) return slbt_get_driver_ctx_fail(meta); ctx->ctx.program = program; @@ -1134,7 +1121,7 @@ int slbt_create_driver_ctx( if (!(meta = argv_get(argv,slbt_default_options,0))) return -1; - if (!(ctx = slbt_driver_ctx_alloc(meta,cctx,0))) + if (!(ctx = slbt_driver_ctx_alloc(meta,cctx))) return slbt_get_driver_ctx_fail(0); ctx->ctx.cctx = &ctx->cctx; diff --git a/src/driver/slbt_unit_ctx.c b/src/driver/slbt_unit_ctx.c deleted file mode 100644 index 3fab392..0000000 --- a/src/driver/slbt_unit_ctx.c +++ /dev/null @@ -1,62 +0,0 @@ -/*******************************************************************/ -/* slibtool: a skinny libtool implementation, written in C */ -/* Copyright (C) 2016 Z. Gilboa */ -/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */ -/*******************************************************************/ - -#include -#include -#include -#include -#include - -#include -#include "slibtool_driver_impl.h" - -static int slbt_free_unit_ctx_impl(struct slbt_unit_ctx_impl * ctx, int status) -{ - if (ctx) { - slbt_unmap_input(&ctx->map); - free(ctx); - } - - return status; -} - -int slbt_get_unit_ctx( - const struct slbt_driver_ctx * dctx, - const char * path, - struct slbt_unit_ctx ** pctx) -{ - struct slbt_unit_ctx_impl * ctx; - - if (!dctx || !(ctx = calloc(1,sizeof(*ctx)))) - return -1; - - if (slbt_map_input(-1,path,PROT_READ,&ctx->map)) - return slbt_free_unit_ctx_impl(ctx,-1); - - memcpy(&ctx->cctx,dctx->cctx, - sizeof(ctx->cctx)); - - ctx->path = path; - - ctx->uctx.path = &ctx->path; - ctx->uctx.map = &ctx->map; - ctx->uctx.cctx = &ctx->cctx; - - *pctx = &ctx->uctx; - return 0; -} - -void slbt_free_unit_ctx(struct slbt_unit_ctx * ctx) -{ - struct slbt_unit_ctx_impl * ictx; - uintptr_t addr; - - if (ctx) { - addr = (uintptr_t)ctx - offsetof(struct slbt_unit_ctx_impl,uctx); - ictx = (struct slbt_unit_ctx_impl *)addr; - slbt_free_unit_ctx_impl(ictx,0); - } -} diff --git a/src/internal/slibtool_driver_impl.h b/src/internal/slibtool_driver_impl.h index a6b69a6..72f86b0 100644 --- a/src/internal/slibtool_driver_impl.h +++ b/src/internal/slibtool_driver_impl.h @@ -83,13 +83,6 @@ struct slbt_driver_ctx_impl { struct slbt_error_info erribuf[64]; }; -struct slbt_unit_ctx_impl { - const char * path; - struct slbt_input map; - struct slbt_common_ctx cctx; - struct slbt_unit_ctx uctx; -}; - static inline struct slbt_driver_ctx_impl * slbt_get_driver_ictx(const struct slbt_driver_ctx * dctx) { uintptr_t addr; diff --git a/src/logic/slbt_map_input.c b/src/logic/slbt_map_input.c deleted file mode 100644 index 2da2429..0000000 --- a/src/logic/slbt_map_input.c +++ /dev/null @@ -1,51 +0,0 @@ -/*******************************************************************/ -/* slibtool: a skinny libtool implementation, written in C */ -/* Copyright (C) 2016 Z. Gilboa */ -/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */ -/*******************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -#include - -int slbt_map_input( - int fd, - const char * path, - int prot, - struct slbt_input * map) -{ - struct stat st; - bool fnew; - int ret; - - if ((fnew = (fd < 0))) - fd = open(path,O_RDONLY | O_CLOEXEC); - - if (fd < 0) - return -1; - - if ((ret = fstat(fd,&st) < 0) && fnew) - close(fd); - - if (ret < 0) - return -1; - - map->size = st.st_size; - map->addr = mmap(0,map->size,prot,MAP_PRIVATE,fd,0); - - if (fnew) - close(fd); - - return (map->addr == MAP_FAILED) ? -1 : 0; -} - -int slbt_unmap_input(struct slbt_input * map) -{ - return munmap(map->addr,map->size); -} -- cgit v1.2.3