From 69df4eebe2095c20a1fa6298cfe5e20ea60af033 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 1 Nov 2009 20:16:47 +0000 Subject: [PATCH] WIP jpctb wrapper --- Makefile | 3 + jpctb | 18 +++++ jwrap-script => jwrap-script-jpctb | 0 libjava-wrap | 119 ----------------------------- libjava-wrap.c | 118 ---------------------------- pctb-preload-wrap.c | 107 -------------------------- 6 files changed, 21 insertions(+), 344 deletions(-) create mode 100755 jpctb rename jwrap-script => jwrap-script-jpctb (100%) delete mode 100644 libjava-wrap delete mode 100644 libjava-wrap.c delete mode 100644 pctb-preload-wrap.c diff --git a/Makefile b/Makefile index cce8b95..0b52505 100644 --- a/Makefile +++ b/Makefile @@ -21,3 +21,6 @@ $(LIBTARGET): libjwrap.o libjwrap.o: libjwrap.c $(CC) -D_REENTRANT $(CFLAGS) $(CPPFLAGS) -c -o $@ -fPIC $< + +clean: + rm -f *.o $(TARGETS) *~ diff --git a/jpctb b/jpctb new file mode 100755 index 0000000..b2aa721 --- /dev/null +++ b/jpctb @@ -0,0 +1,18 @@ +#!/bin/bash -e +usage () { cat <&2; exit 127; if + +export JWRAP_EXTDIR="$1"; shift +export JWRAP_SCRIPT="$jpctb_base/jwrap-script-pctb" + +if [ x"$LD_PRELOAD" != x ]; then LD_PRELOAD="$LD_PRELOAD:"; fi +export LD_PRELOAD="${LD_PRELOAD}$jpctb_base/libjwrap.so.1.0" + +exec "$@" diff --git a/jwrap-script b/jwrap-script-jpctb similarity index 100% rename from jwrap-script rename to jwrap-script-jpctb diff --git a/libjava-wrap b/libjava-wrap deleted file mode 100644 index 9b904ed..0000000 --- a/libjava-wrap +++ /dev/null @@ -1,119 +0,0 @@ -/**/ - -#define _GNU_SOURCE -#include -#include -#include - -#define STDERRSTR_CONST(m) write(2,m,sizeof(m)-1) -#define STDERRSTR_STRING(m) write(2,m,strlen(m)) - -static anyfn_type *find_any(const char *name) { - static const char *dlerr; - anyfn_type *kv; - - kv= dlsym(RTLD_NEXT,name); if (kv) return kv; - dlerr= dlerror(); if (!dlerr) dlerr= "dlsym() failed for no reason"; - STDERRSTR_CONST("pctb-preload-wrap: error finding original version of "); - STDERRSTR_STRING(name); - STDERRSTR_CONST(": "); - STDERRSTR_STRING(dlerr); - STDERRSTR_STRING("\n"); - errno= ENOSYS; - return 0; -} - -typedef int -execvefn_type(const char *path, char *const argv[], char *const envp[]); - -static execvefn_type find_execve, *old_execve= find_execve; - -static int find_execve(const char *path, - char *const argv[], char *const envp[]) { - anyfn_type *anyfn; - anyfn= find_any("execve"); if (!anyfn) return -1; - old_execve= (execvefn_type*)anyfn; - return old_execve(path, argv, envp); -} - -static const char javatail[]= "/bin/java"; - -int execve(const char *path, char *const argv[], char *const envp[]) { - int pathlen= strlen(path); - if (pathlen < (sizeof(path2extdir_rm)-1) || - strcmp(javatail, path + pathlen-(sizeof(path2extdir_rm)-1))) - old_execve(opath, oargv, oenvp); - - - - - int oargc; - - - - xassert(opathlen >= - - - for (oargc=0; oargv[oargc]; oargc++); - xassert(oargc); - if (strcmp(oargv[oargc-1], "com.threerings.yohoho.client.YoApp")) - - /* Remove ourselves from LD_PRELOAD */ - int ipreloadenv=-1; - const char ldpreload[]= "LD_PRELOAD="; - for (oenvc=0; oenvp[oenvc]; oenvc++) { - if (memcmp(oenvp[oenvc], ldpreload, sizeof(ldpreload)-1)) continue; - xassert(ipreloadenv==-1); - ipreloadenv= oenvc; - } - xassert(ipreloadenv>=0); - xassert(!strchr(':',oenvp[ipreloadenv])); - - - int nargc= oargc+2; - char **nargv= xmalloc(sizeof(*nargv) * (nargc+1)); - - /* Add argument for accessibility assistive tech. */ - int iargc= oargc-1; - memcpy(nargv, oargv, iargc); - nargv[iargc++]= "-Djavax.accessibility.assistive_technologies=" - "com.tedpearson.ypp.market.MarketUploader"; - - /* Calculate and add argument for ext dirs containing our jars */ - const char *nextdir; - xassert((nextdir= getenv("JPCTB_EXTDIR"))); - int nextdirlen= strlen(nextdir); - - int njvmextdirbaselen= opathlen-sizeof(path2extdir_rm)-1); - xassert(!strcmp(path2extdir_rm, opath+njvmextdirbaselen); - - const char path2extdir_pfx[]= "-Djava.ext.dirs="; - const char path2extdir_sfx[]= "/lib/ext"; - -#define STRS(STR,DL) \ - STR( path2extdir_pfx, sizeof(path2extdir_pfx)-1 ) DL \ - STR( nextdir, nextdirlen ) DL \ - STR( ":", 1 ) DL \ - STR( opath, njvmextdirbaselen ) DL \ - STR( path2extdir_sfx, sizeof(path2extdir_sfx)-1 ) DL \ - STR( "", 1 ) - -#define STR_LEN(str,len) (len) - char *nextdirarg= xmalloc(STRS(STR_LEN, +)); - char *p= nextdirarg; - -#define STR_ADD(str,len) \ - memcpy(p,(str),(len)); p += (len); - STRS(STR_ADD, ;); - - nargv[iargc++]= nextdirarg; - - /* Remaining argument: the class */ - nargv[iargc++]= oargv[oargc-1]; - - - - - - if (arg -} diff --git a/libjava-wrap.c b/libjava-wrap.c deleted file mode 100644 index 4bafa41..0000000 --- a/libjava-wrap.c +++ /dev/null @@ -1,118 +0,0 @@ -/**/ - -#define _GNU_SOURCE -#include -#include -#include - -#define STDERRSTR_CONST(m) write(2,m,sizeof(m)-1) -#define STDERRSTR_STRING(m) write(2,m,strlen(m)) - -static anyfn_type *find_any(const char *name) { - static const char *dlerr; - anyfn_type *kv; - - kv= dlsym(RTLD_NEXT,name); if (kv) return kv; - dlerr= dlerror(); if (!dlerr) dlerr= "dlsym() failed for no reason"; - STDERRSTR_CONST("pctb-preload-wrap: error finding original version of "); - STDERRSTR_STRING(name); - STDERRSTR_CONST(": "); - STDERRSTR_STRING(dlerr); - STDERRSTR_STRING("\n"); - errno= ENOSYS; - return 0; -} - -typedef int -execvefn_type(const char *path, char *const argv[], char *const envp[]); - -static execvefn_type find_execve, *old_execve= find_execve; - -static int find_execve(const char *path, - char *const argv[], char *const envp[]) { - anyfn_type *anyfn; - anyfn= find_any("execve"); if (!anyfn) return -1; - old_execve= (execvefn_type*)anyfn; - return old_execve(path, argv, envp); -} - -static const char javatail[]= "/bin/java"; - -int execve(const char *path, char *const argv[], char *const envp[]) { - int pathlen= strlen(path); - if (pathlen < (sizeof(path2extdir_rm)-1) || - strcmp(javatail, path + pathlen-(sizeof(path2extdir_rm)-1))) - old_execve(opath, oargv, oenvp); - - - - - int oargc; - - - - xassert(opathlen >= - - - for (oargc=0; oargv[oargc]; oargc++); - xassert(oargc); - if (strcmp(oargv[oargc-1], "com.threerings.yohoho.client.YoApp")) - - /* Remove ourselves from LD_PRELOAD */ - int ipreloadenv=-1; - const char ldpreload[]= "LD_PRELOAD="; - for (oenvc=0; oenvp[oenvc]; oenvc++) { - if (memcmp(oenvp[oenvc], ldpreload, sizeof(ldpreload)-1)) continue; - xassert(ipreloadenv==-1); - ipreloadenv= oenvc; - } - xassert(ipreloadenv>=0); - xassert(!strchr(':',oenvp[ipreloadenv])); - - - int nargc= oargc+2; - char **nargv= xmalloc(sizeof(*nargv) * (nargc+1)); - - /* Add argument for accessibility assistive tech. */ - int iargc= oargc-1; - memcpy(nargv, oargv, iargc); - nargv[iargc++]= " - ""; - - /* Calculate and add argument for ext dirs containing our jars */ - const char *nextdir; - xassert((nextdir= getenv("JPCTB_EXTDIR"))); - int nextdirlen= strlen(nextdir); - - int njvmextdirbaselen= opathlen-sizeof(path2extdir_rm)-1); - xassert(!strcmp(path2extdir_rm, opath+njvmextdirbaselen); - - const char path2extdir_pfx[]= " - -#define STRS(STR,DL) \ - STR( path2extdir_pfx, sizeof(path2extdir_pfx)-1 ) DL \ - STR( nextdir, nextdirlen ) DL \ - STR( ":", 1 ) DL \ - STR( opath, njvmextdirbaselen ) DL \ - STR( path2extdir_sfx, sizeof(path2extdir_sfx)-1 ) DL \ - STR( "", 1 ) - -#define STR_LEN(str,len) (len) - char *nextdirarg= xmalloc(STRS(STR_LEN, +)); - char *p= nextdirarg; - -#define STR_ADD(str,len) \ - memcpy(p,(str),(len)); p += (len); - STRS(STR_ADD, ;); - - nargv[iargc++]= nextdirarg; - - /* Remaining argument: the class */ - nargv[iargc++]= oargv[oargc-1]; - - - - - - if (arg -} diff --git a/pctb-preload-wrap.c b/pctb-preload-wrap.c deleted file mode 100644 index a547c01..0000000 --- a/pctb-preload-wrap.c +++ /dev/null @@ -1,107 +0,0 @@ -/**/ - -#define _GNU_SOURCE -#include -#include -#include - -#define STDERRSTR_CONST(m) write(2,m,sizeof(m)-1) -#define STDERRSTR_STRING(m) write(2,m,strlen(m)) - -static anyfn_type *find_any(const char *name) { - static const char *dlerr; - anyfn_type *kv; - - kv= dlsym(RTLD_NEXT,name); if (kv) return kv; - dlerr= dlerror(); if (!dlerr) dlerr= "dlsym() failed for no reason"; - STDERRSTR_CONST("pctb-preload-wrap: error finding original version of "); - STDERRSTR_STRING(name); - STDERRSTR_CONST(": "); - STDERRSTR_STRING(dlerr); - STDERRSTR_STRING("\n"); - errno= ENOSYS; - return 0; -} - -typedef int -execvefn_type(const char *path, char *const argv[], char *const envp[]); - -static execvefn_type find_execve, *old_execve= find_execve; - -static int find_execve(const char *path, - char *const argv[], char *const envp[]) { - anyfn_type *anyfn; - anyfn= find_any("execve"); if (!anyfn) return -1; - old_execve= (execvefn_type*)anyfn; - return old_execve(path, argv, envp); -} - -int execve(const char *opath, char *const oargv[], char *const oenvp[]) { - int oargc; - for (oargc=0; oargv[oargc]; oargc++); - xassert(oargc); - if (strcmp(oargv[oargc-1], "com.threerings.yohoho.client.YoApp")) - old_execve(opath, oargv, oenvp); - - /* Remove ourselves from LD_PRELOAD */ - int ipreloadenv=-1; - const char ldpreload[]= "LD_PRELOAD="; - for (oenvc=0; oenvp[oenvc]; oenvc++) { - if (memcmp(oenvp[oenvc], ldpreload, sizeof(ldpreload)-1)) continue; - xassert(ipreloadenv==-1); - ipreloadenv= oenvc; - } - xassert(ipreloadenv>=0); - xassert(!strchr(':',oenvp[ipreloadenv])); - - - int nargc= oargc+2; - char **nargv= xmalloc(sizeof(*nargv) * (nargc+1)); - - /* Add argument for accessibility assistive tech. */ - int iargc= oargc-1; - memcpy(nargv, oargv, iargc); - nargv[iargc++]= "-Djavax.accessibility.assistive_technologies=" - "com.tedpearson.ypp.market.MarketUploader"; - - /* Calculate and add argument for ext dirs containing our jars */ - const char *nextdir; - xassert((nextdir= getenv("JPCTB_EXTDIR"))); - int nextdirlen= strlen(nextdir); - - const char path2extdir_rm[]= "/bin/java"; - int opathlen= strlen(opath); - int njvmextdirbaselen= opathlen-sizeof(path2extdir_rm)-1); - xassert(opathlen >= sizeof(path2extdir_rm)); - xassert(!strcmp(path2extdir_rm, opath+njvmextdirbaselen); - - const char path2extdir_pfx[]= "-Djava.ext.dirs="; - const char path2extdir_sfx[]= "/lib/ext"; - -#define STRS(STR,DL) \ - STR( path2extdir_pfx, sizeof(path2extdir_pfx)-1 ) DL \ - STR( nextdir, nextdirlen ) DL \ - STR( ":", 1 ) DL \ - STR( opath, njvmextdirbaselen ) DL \ - STR( path2extdir_sfx, sizeof(path2extdir_sfx)-1 ) DL \ - STR( "", 1 ) - -#define STR_LEN(str,len) (len) - char *nextdirarg= xmalloc(STRS(STR_LEN, +)); - char *p= nextdirarg; - -#define STR_ADD(str,len) \ - memcpy(p,(str),(len)); p += (len); - STRS(STR_ADD, ;); - - nargv[iargc++]= nextdirarg; - - /* Remaining argument: the class */ - nargv[iargc++]= oargv[oargc-1]; - - - - - - if (arg -} -- 2.30.2