diff options
-rw-r--r-- | pseudo_wrappers.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pseudo_wrappers.c b/pseudo_wrappers.c index 2ea4a04..041a2f5 100644 --- a/pseudo_wrappers.c +++ b/pseudo_wrappers.c @@ -121,6 +121,7 @@ pseudo_populate_wrappers(void) { char *debug; static int done = 0; char *pseudo_path = 0; + int fd; if (done) return done; @@ -149,6 +150,29 @@ pseudo_populate_wrappers(void) { pseudo_debug_verbose(); } } + if (getenv("PSEUDO_DEBUG_FILE")) { + char filebuf[pseudo_path_max()], *fmt = getenv("PSEUDO_DEBUG_FILE"); + char *name, *pid; + name = strstr(fmt, "%s"); + pid = strstr(fmt, "%d"); + if (name && pid) { + if (name > pid) { + snprintf(filebuf, pseudo_path_max(), fmt, getpid(), program_invocation_short_name); + } else { + snprintf(filebuf, pseudo_path_max(), fmt, program_invocation_short_name, getpid()); + } + } else if (name) { + snprintf(filebuf, pseudo_path_max(), fmt, program_invocation_short_name); + } else if (pid) { + snprintf(filebuf, pseudo_path_max(), fmt, getpid()); + } else { + snprintf(filebuf, pseudo_path_max(), "%s", fmt); + } + fd = open(filebuf, O_WRONLY | O_APPEND | O_CREAT, 0644); + if (fd >= 0) { + pseudo_util_debug_fd = fd; + } + } /* must happen after wrappers are set up, because it can call * getcwd(), which needs wrappers, but must happen here so that * any attempt to use a path in a wrapper function will have a |