1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

osxlaunch: add diagnostics under an #ifdef.

Now I can compile with -DDEBUG_OSXLAUNCH and see exactly what the
program is doing, if I suspect it of misbehaviour.
This commit is contained in:
Simon Tatham 2017-12-20 09:54:40 +00:00
parent eef8cac28e
commit 6b8cd49aa7

View File

@ -352,19 +352,35 @@ char *alloc_cat(const char *str1, const char *str2)
* Overwrite an environment variable, preserving the old one for the * Overwrite an environment variable, preserving the old one for the
* real app to restore. * 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; char *prefix, *prefixset, *prefixunset;
void overwrite_env(const char *name, const char *value) void overwrite_env(const char *name, const char *value)
{ {
const char *oldvalue = getenv(name); const char *oldvalue = getenv(name);
if (oldvalue) { if (oldvalue) {
setenv(alloc_cat(prefixset, name), oldvalue, 1); setenv_wrap(alloc_cat(prefixset, name), oldvalue);
} else { } else {
setenv(alloc_cat(prefixunset, name), "", 1); setenv_wrap(alloc_cat(prefixunset, name), "");
} }
if (value) if (value)
setenv(name, value, 1); setenv_wrap(name, value);
else else
unsetenv(name); unsetenv_wrap(name);
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -377,6 +393,11 @@ int main(int argc, char **argv)
prefixset = alloc_cat(prefix, "s"); prefixset = alloc_cat(prefix, "s");
prefixunset = alloc_cat(prefix, "u"); 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(); // <bundle>/Contents/MacOS/<filename> char *prog_path = get_program_path(); // <bundle>/Contents/MacOS/<filename>
char *macos = dirname_wrapper(prog_path); // <bundle>/Contents/MacOS char *macos = dirname_wrapper(prog_path); // <bundle>/Contents/MacOS
char *contents = dirname_wrapper(macos); // <bundle>/Contents char *contents = dirname_wrapper(macos); // <bundle>/Contents
@ -412,17 +433,30 @@ int main(int argc, char **argv)
} }
int j = 0; int j = 0;
new_argv[j++] = realbin; new_argv[j++] = realbin;
#ifdef DEBUG_OSXLAUNCH
printf("argv[%d] = \"%s\"\n", j-1, new_argv[j-1]);
#endif
{ {
int i = 1; int i = 1;
if (i < argc && !strncmp(argv[i], "-psn_", 5)) if (i < argc && !strncmp(argv[i], "-psn_", 5))
i++; i++;
for (; i < argc; i++) for (; i < argc; i++) {
new_argv[j++] = argv[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; new_argv[j++] = prefix;
#ifdef DEBUG_OSXLAUNCH
printf("argv[%d] = \"%s\"\n", j-1, new_argv[j-1]);
#endif
new_argv[j++] = NULL; new_argv[j++] = NULL;
#ifdef DEBUG_OSXLAUNCH
printf("executing \"%s\"\n", realbin);
#endif
execv(realbin, new_argv); execv(realbin, new_argv);
perror("execv"); perror("execv");
free(new_argv); free(new_argv);