diff --git a/unix/osxlaunch.c b/unix/osxlaunch.c index 3d10c7d8..6ad43a51 100644 --- a/unix/osxlaunch.c +++ b/unix/osxlaunch.c @@ -352,19 +352,35 @@ char *alloc_cat(const char *str1, const char *str2) * Overwrite an environment variable, preserving the old one for the * real app to restore. */ +void setenv_wrap(const char *name, const char *value) +{ +#ifdef DEBUG_OSXLAUNCH + printf("setenv(\"%s\",\"%s\")\n", name, value); +#endif + setenv(name, value, 1); +} + +void unsetenv_wrap(const char *name) +{ +#ifdef DEBUG_OSXLAUNCH + printf("unsetenv(\"%s\")\n", name); +#endif + unsetenv(name); +} + char *prefix, *prefixset, *prefixunset; void overwrite_env(const char *name, const char *value) { const char *oldvalue = getenv(name); if (oldvalue) { - setenv(alloc_cat(prefixset, name), oldvalue, 1); + setenv_wrap(alloc_cat(prefixset, name), oldvalue); } else { - setenv(alloc_cat(prefixunset, name), "", 1); + setenv_wrap(alloc_cat(prefixunset, name), ""); } if (value) - setenv(name, value, 1); + setenv_wrap(name, value); else - unsetenv(name); + unsetenv_wrap(name); } /* ---------------------------------------------------------------------- @@ -377,6 +393,11 @@ int main(int argc, char **argv) prefixset = alloc_cat(prefix, "s"); prefixunset = alloc_cat(prefix, "u"); +#ifdef DEBUG_OSXLAUNCH + printf("Environment prefixes: main=\"%s\", set=\"%s\", unset=\"%s\"\n", + prefix, prefixset, prefixunset); +#endif + char *prog_path = get_program_path(); // /Contents/MacOS/ char *macos = dirname_wrapper(prog_path); // /Contents/MacOS char *contents = dirname_wrapper(macos); // /Contents @@ -412,17 +433,30 @@ int main(int argc, char **argv) } int j = 0; new_argv[j++] = realbin; +#ifdef DEBUG_OSXLAUNCH + printf("argv[%d] = \"%s\"\n", j-1, new_argv[j-1]); +#endif { int i = 1; if (i < argc && !strncmp(argv[i], "-psn_", 5)) i++; - for (; i < argc; i++) + for (; i < argc; i++) { new_argv[j++] = argv[i]; +#ifdef DEBUG_OSXLAUNCH + printf("argv[%d] = \"%s\"\n", j-1, new_argv[j-1]); +#endif + } } new_argv[j++] = prefix; +#ifdef DEBUG_OSXLAUNCH + printf("argv[%d] = \"%s\"\n", j-1, new_argv[j-1]); +#endif new_argv[j++] = NULL; +#ifdef DEBUG_OSXLAUNCH + printf("executing \"%s\"\n", realbin); +#endif execv(realbin, new_argv); perror("execv"); free(new_argv);