зеркало из https://github.com/github/putty.git
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:
Родитель
eef8cac28e
Коммит
6b8cd49aa7
|
@ -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(); // <bundle>/Contents/MacOS/<filename>
|
||||
char *macos = dirname_wrapper(prog_path); // <bundle>/Contents/MacOS
|
||||
char *contents = dirname_wrapper(macos); // <bundle>/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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче