aboutsummaryrefslogtreecommitdiffstats
path: root/makewrappers
diff options
context:
space:
mode:
authorPeter Seebach <seebs@eee12.(none)>2010-04-03 15:54:54 -0500
committerPeter Seebach <seebs@eee12.(none)>2010-04-05 14:33:58 -0500
commitee4f4a62e8ac20ef1a231e1a8f774b08c3ceb275 (patch)
tree5653c705829f5715de30cc02bb7118801c249a00 /makewrappers
parent44ad2586a20bc4c5fe07ec99f6b0181668063599 (diff)
downloadpseudo-ee4f4a62e8ac20ef1a231e1a8f774b08c3ceb275.tar.gz
pseudo-ee4f4a62e8ac20ef1a231e1a8f774b08c3ceb275.tar.bz2
pseudo-ee4f4a62e8ac20ef1a231e1a8f774b08c3ceb275.zip
Shuffle some code around.
Migrate the stable part of the wrapper code (not machine-generated) out of makewrappers, to make it easier to maintain.
Diffstat (limited to 'makewrappers')
-rwxr-xr-xmakewrappers159
1 files changed, 6 insertions, 153 deletions
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