chiark / gitweb /
WIP jpctb wrapper
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 1 Nov 2009 20:16:47 +0000 (20:16 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 1 Nov 2009 20:16:47 +0000 (20:16 +0000)
Makefile
jpctb [new file with mode: 0755]
jwrap-script-jpctb [moved from jwrap-script with 100% similarity]
libjava-wrap [deleted file]
libjava-wrap.c [deleted file]
pctb-preload-wrap.c [deleted file]

index cce8b953575d11202965eaec933808958a644c6a..0b52505272e716a689b53b60c25d51bfc2a760ca 100644 (file)
--- 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 (executable)
index 0000000..b2aa721
--- /dev/null
+++ b/jpctb
@@ -0,0 +1,18 @@
+#!/bin/bash -e
+usage () { cat <<END
+usage: .../jpctb /path/to/dir/with/PCTB*.jar /path/to/yohoho/yohoho [...]
+END
+}
+
+jpctb_base="$0"
+jpctb_base="${jpctb_base%/*}"
+
+if [ $* -lt 2 ]; then usage >&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 "$@"
similarity index 100%
rename from jwrap-script
rename to jwrap-script-jpctb
diff --git a/libjava-wrap b/libjava-wrap
deleted file mode 100644 (file)
index 9b904ed..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/**/
-
-#define _GNU_SOURCE
-#include <dlfcn.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#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 (file)
index 4bafa41..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/**/
-
-#define _GNU_SOURCE
-#include <dlfcn.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#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 (file)
index a547c01..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/**/
-
-#define _GNU_SOURCE
-#include <dlfcn.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#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
-}