diff options
-rw-r--r-- | Makefile.in | 11 | ||||
-rwxr-xr-x | makewrappers | 159 | ||||
-rw-r--r-- | pseudo_client.c | 2 | ||||
-rw-r--r-- | pseudo_wrappers.c | 150 |
4 files changed, 163 insertions, 159 deletions
diff --git a/Makefile.in b/Makefile.in index b4b1f8c..079ee90 100644 --- a/Makefile.in +++ b/Makefile.in @@ -97,10 +97,10 @@ wrappers: wrapfuncs.in $(USE_64) makewrappers .SECONDARY: wrappers -pseudo_wrappers.c: wrappers +pseudo_wrapfuncs.c: wrappers # no-strict-aliasing is needed for the function pointer trickery. -pseudo_wrappers.o: $(GUTS) pseudo_wrappers.c +pseudo_wrappers.o: $(GUTS) pseudo_wrappers.c pseudo_wrapfuncs.c pseudo_wrapfuncs.h $(CC) -fno-strict-aliasing $(CFLAGS) -D_GNU_SOURCE -c -o pseudo_wrappers.o pseudo_wrappers.c offsets32: @@ -111,9 +111,10 @@ offsets64: clean: rm -f *.o *.so pseudo pseudodb pseudolog \ - pseudo_wrappers.h pseudo_wrappers.c \ - pseudo_wrapper_table.c pseudo_wrappers.c.old \ - pseudo_wrappers.h.old offsets32 offsets64 + pseudo_wrapfuncs.h pseudo_wrapfuncs.c \ + pseudo_wrapper_table.c \ + pseudo_wrapfuncs.c.old pseudo_wrapfuncs.h.old \ + offsets32 offsets64 distclean: clean rm -f Makefile diff --git a/makewrappers b/makewrappers index 4700bfd..cd6a675 100755 --- a/makewrappers +++ b/makewrappers @@ -25,17 +25,17 @@ case $# in esac # save old versions -test -f "pseudo_wrappers.c" && mv pseudo_wrappers.c pseudo_wrappers.c.old -test -f "pseudo_wrappers.h" && mv pseudo_wrappers.h pseudo_wrappers.h.old +test -f "pseudo_wrapfuncs.c" && mv pseudo_wrapfuncs.c pseudo_wrapfuncs.c.old +test -f "pseudo_wrapfuncs.h" && mv pseudo_wrapfuncs.h pseudo_wrapfuncs.h.old # create files -exec 5>pseudo_wrappers.c -exec 6>pseudo_wrappers.h +exec 5>pseudo_wrapfuncs.c +exec 6>pseudo_wrapfuncs.h exec 7>pseudo_wrapper_table.c # "cat >&N <<EOF" populates the file on &N with the here-document. -# pseudo_wrappers.c has to have all the hunks used by the wrapper functions, +# pseudo_wrapfuncs.c has to have all the hunks used by the wrapper functions, # including guts/*.c. cat >&5 <<EOF `cat guts/COPYRIGHT` @@ -43,77 +43,6 @@ cat >&5 <<EOF /* This file is generated and should not be modified. See the makewrappers * script if you want to modify this. */ - -#include <stdlib.h> -#include <limits.h> -#include <stdarg.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <pthread.h> - -#include <sys/types.h> -#include <unistd.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <dlfcn.h> - -/* used for various specific function arguments */ -#include <dirent.h> -#include <fts.h> -#include <ftw.h> -#include <glob.h> -#include <grp.h> -#include <pwd.h> -#include <utime.h> - -#include "pseudo.h" -#include "pseudo_wrappers.h" -#include "pseudo_ipc.h" -#include "pseudo_client.h" - -static void pseudo_enosys(const char *); -static int pseudo_populate_wrappers(void); -static volatile int antimagic = 0; -static pthread_mutex_t pseudo_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_t pseudo_mutex_holder; -static int pseudo_mutex_recursion = 0; - -int -pseudo_getlock() { - if (pthread_equal(pseudo_mutex_holder, pthread_self())) { - ++pseudo_mutex_recursion; - return 0; - } else { - if (pthread_mutex_lock(&pseudo_mutex) == 0) { - pseudo_mutex_recursion = 1; - pseudo_mutex_holder = pthread_self(); - return 0; - } else { - return -1; - } - } -} - -void -pseudo_droplock() { - if (--pseudo_mutex_recursion == 0) { - pseudo_mutex_holder = 0; - pthread_mutex_unlock(&pseudo_mutex); - } -} - -void -pseudo_antimagic() { - ++antimagic; -} - -void -pseudo_magic() { - if (antimagic > 0) - --antimagic; -} - EOF cat >&6 <<EOF @@ -451,7 +380,7 @@ EOF EOF fi fi - # prototypes for pseudo_wrappers.h + # prototypes for pseudo_wrapfuncs.h cat >&6 <<EOF /* $type $name($args); */ static $type dummy_$name($args); @@ -478,79 +407,3 @@ cat >&7 <<EOF { NULL, NULL, NULL, NULL }, }; EOF - -# and now the actual populate_wrappers function. -cat >&5 <<EOF -#include "pseudo_wrapper_table.c" - -extern char *program_invocation_short_name; - -static void -pseudo_enosys(const char *func) { - pseudo_diag("pseudo: ENOSYS for '%s'.\n", func ? func : "<nil>"); - if (getenv("PSEUDO_ENOSYS_ABORT")) - abort(); -} - -static int -pseudo_populate_wrappers(void) { - int i; - char *debug; - static int done = 0; - char *pseudo_path = 0; - - if (done) - return done; - pseudo_getlock(); - pseudo_antimagic(); - for (i = 0; pseudo_functions[i].name; ++i) { - if (*pseudo_functions[i].real == pseudo_functions[i].dummy) { - int (*f)(void); - char *e; - dlerror(); - f = dlsym(RTLD_NEXT, pseudo_functions[i].name); - if ((e = dlerror()) != NULL) { - /* leave it pointed to dummy */ - pseudo_diag("No wrapper for %s: %s\n", pseudo_functions[i].name, e); - } else { - if (f) - *pseudo_functions[i].real = f; - } - } - } - done = 1; - debug = getenv("PSEUDO_DEBUG"); - if (debug) { - int level = atoi(debug); - for (i = 0; i < level; ++i) { - pseudo_debug_verbose(); - } - } - /* must happen after wrappers are set up, because it can call - * getcwd(), which needs wrappers, but must happen here so that - * any attempt to use a path in a wrapper function will have a - * value for cwd. - */ - pseudo_client_reset(); - pseudo_path = pseudo_prefix_path(NULL); - if (pseudo_dir_fd == -1) { - if (pseudo_path) { - pseudo_dir_fd = open(pseudo_path, O_RDONLY); - pseudo_dir_fd = pseudo_fd(pseudo_dir_fd, MOVE_FD); - free(pseudo_path); - } else { - pseudo_diag("No prefix available to to find server.\n"); - exit(1); - } - if (pseudo_dir_fd == -1) { - pseudo_diag("Can't open prefix path (%s) for server.\n", - strerror(errno)); - exit(1); - } - } - pseudo_debug(2, "(%s) set up wrappers\n", program_invocation_short_name); - pseudo_magic(); - pseudo_droplock(); - return done; -} -EOF diff --git a/pseudo_client.c b/pseudo_client.c index ffa6092..f009d8b 100644 --- a/pseudo_client.c +++ b/pseudo_client.c @@ -890,7 +890,7 @@ pseudo_client_op(op_id_t op, int access, int fd, int dirfd, const char *path, co /* since we have a FILE * on it, we close that... */ fclose(pseudo_grp); /* and open a new one on the copy */ - pseudo_grp = fdopen(pseudo_grp, "r"); + pseudo_grp = fdopen(pseudo_grp_fd, "r"); } } pseudo_client_close(fd); diff --git a/pseudo_wrappers.c b/pseudo_wrappers.c new file mode 100644 index 0000000..84bdce7 --- /dev/null +++ b/pseudo_wrappers.c @@ -0,0 +1,150 @@ +/* wrapper code -- this is the shared code used around the pseduo + * wrapper functions, which are in pseudo_wrapfuncs.c. + */ +#include <stdlib.h> +#include <limits.h> +#include <stdarg.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <pthread.h> + +#include <sys/types.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <dlfcn.h> + +/* used for various specific function arguments */ +#include <dirent.h> +#include <fts.h> +#include <ftw.h> +#include <glob.h> +#include <grp.h> +#include <pwd.h> +#include <utime.h> + +#include "pseudo.h" +#include "pseudo_wrapfuncs.h" +#include "pseudo_ipc.h" +#include "pseudo_client.h" + +static void pseudo_enosys(const char *); +static int pseudo_populate_wrappers(void); +static volatile int antimagic = 0; +static pthread_mutex_t pseudo_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_t pseudo_mutex_holder; +static int pseudo_mutex_recursion = 0; +static int pseudo_getlock(void); +static void pseudo_droplock(void); + +extern char *program_invocation_short_name; + +/* the generated code goes here */ +#include "pseudo_wrapper_table.c" +#include "pseudo_wrapfuncs.c" + +static int +pseudo_getlock(void) { + if (pthread_equal(pseudo_mutex_holder, pthread_self())) { + ++pseudo_mutex_recursion; + return 0; + } else { + if (pthread_mutex_lock(&pseudo_mutex) == 0) { + pseudo_mutex_recursion = 1; + pseudo_mutex_holder = pthread_self(); + return 0; + } else { + return -1; + } + } +} + +static void +pseudo_droplock(void) { + if (--pseudo_mutex_recursion == 0) { + pseudo_mutex_holder = 0; + pthread_mutex_unlock(&pseudo_mutex); + } +} + +void +pseudo_antimagic() { + ++antimagic; +} + +void +pseudo_magic() { + if (antimagic > 0) + --antimagic; +} + +static void +pseudo_enosys(const char *func) { + pseudo_diag("pseudo: ENOSYS for '%s'.\n", func ? func : "<nil>"); + if (getenv("PSEUDO_ENOSYS_ABORT")) + abort(); +} + +static int +pseudo_populate_wrappers(void) { + int i; + char *debug; + static int done = 0; + char *pseudo_path = 0; + + if (done) + return done; + pseudo_getlock(); + pseudo_antimagic(); + for (i = 0; pseudo_functions[i].name; ++i) { + if (*pseudo_functions[i].real == pseudo_functions[i].dummy) { + int (*f)(void); + char *e; + dlerror(); + f = dlsym(RTLD_NEXT, pseudo_functions[i].name); + if ((e = dlerror()) != NULL) { + /* leave it pointed to dummy */ + pseudo_diag("No wrapper for %s: %s\n", pseudo_functions[i].name, e); + } else { + if (f) + *pseudo_functions[i].real = f; + } + } + } + done = 1; + debug = getenv("PSEUDO_DEBUG"); + if (debug) { + int level = atoi(debug); + for (i = 0; i < level; ++i) { + pseudo_debug_verbose(); + } + } + /* must happen after wrappers are set up, because it can call + * getcwd(), which needs wrappers, but must happen here so that + * any attempt to use a path in a wrapper function will have a + * value for cwd. + */ + pseudo_client_reset(); + pseudo_path = pseudo_prefix_path(NULL); + if (pseudo_dir_fd == -1) { + if (pseudo_path) { + pseudo_dir_fd = open(pseudo_path, O_RDONLY); + pseudo_dir_fd = pseudo_fd(pseudo_dir_fd, MOVE_FD); + free(pseudo_path); + } else { + pseudo_diag("No prefix available to to find server.\n"); + exit(1); + } + if (pseudo_dir_fd == -1) { + pseudo_diag("Can't open prefix path (%s) for server.\n", + strerror(errno)); + exit(1); + } + } + pseudo_debug(2, "(%s) set up wrappers\n", program_invocation_short_name); + pseudo_magic(); + pseudo_droplock(); + return done; +} + |