8 #define STDERRSTR_CONST(m) write(2,m,sizeof(m)-1)
9 #define STDERRSTR_STRING(m) write(2,m,strlen(m))
11 static anyfn_type *find_any(const char *name) {
12 static const char *dlerr;
15 kv= dlsym(RTLD_NEXT,name); if (kv) return kv;
16 dlerr= dlerror(); if (!dlerr) dlerr= "dlsym() failed for no reason";
17 STDERRSTR_CONST("pctb-preload-wrap: error finding original version of ");
18 STDERRSTR_STRING(name);
19 STDERRSTR_CONST(": ");
20 STDERRSTR_STRING(dlerr);
21 STDERRSTR_STRING("\n");
27 execvefn_type(const char *path, char *const argv[], char *const envp[]);
29 static execvefn_type find_execve, *old_execve= find_execve;
31 static int find_execve(const char *path,
32 char *const argv[], char *const envp[]) {
34 anyfn= find_any("execve"); if (!anyfn) return -1;
35 old_execve= (execvefn_type*)anyfn;
36 return old_execve(path, argv, envp);
39 int execve(const char *opath, char *const oargv[], char *const oenvp[]) {
41 for (oargc=0; oargv[oargc]; oargc++);
43 if (strcmp(oargv[oargc-1], "com.threerings.yohoho.client.YoApp"))
44 old_execve(opath, oargv, oenvp);
46 /* Remove ourselves from LD_PRELOAD */
48 const char ldpreload[]= "LD_PRELOAD=";
49 for (oenvc=0; oenvp[oenvc]; oenvc++) {
50 if (memcmp(oenvp[oenvc], ldpreload, sizeof(ldpreload)-1)) continue;
51 xassert(ipreloadenv==-1);
54 xassert(ipreloadenv>=0);
55 xassert(!strchr(':',oenvp[ipreloadenv]));
59 char **nargv= xmalloc(sizeof(*nargv) * (nargc+1));
61 /* Add argument for accessibility assistive tech. */
63 memcpy(nargv, oargv, iargc);
64 nargv[iargc++]= "-Djavax.accessibility.assistive_technologies="
65 "com.tedpearson.ypp.market.MarketUploader";
67 /* Calculate and add argument for ext dirs containing our jars */
69 xassert((nextdir= getenv("JPCTB_EXTDIR")));
70 int nextdirlen= strlen(nextdir);
72 const char path2extdir_rm[]= "/bin/java";
73 int opathlen= strlen(opath);
74 int njvmextdirbaselen= opathlen-sizeof(path2extdir_rm)-1);
75 xassert(opathlen >= sizeof(path2extdir_rm));
76 xassert(!strcmp(path2extdir_rm, opath+njvmextdirbaselen);
78 const char path2extdir_pfx[]= "-Djava.ext.dirs=";
79 const char path2extdir_sfx[]= "/lib/ext";
81 #define STRS(STR,DL) \
82 STR( path2extdir_pfx, sizeof(path2extdir_pfx)-1 ) DL \
83 STR( nextdir, nextdirlen ) DL \
85 STR( opath, njvmextdirbaselen ) DL \
86 STR( path2extdir_sfx, sizeof(path2extdir_sfx)-1 ) DL \
89 #define STR_LEN(str,len) (len)
90 char *nextdirarg= xmalloc(STRS(STR_LEN, +));
93 #define STR_ADD(str,len) \
94 memcpy(p,(str),(len)); p += (len);
97 nargv[iargc++]= nextdirarg;
99 /* Remaining argument: the class */
100 nargv[iargc++]= oargv[oargc-1];