From: Joel Rosdahl Date: Thu, 17 Jul 2014 14:08:29 +0000 (+0200) Subject: Fix problem with logging of current working directory X-Git-Tag: v3.1.10~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22a3299a200bcb660abb9d92ace6b88fcea43495;p=thirdparty%2Fccache.git Fix problem with logging of current working directory --- diff --git a/ccache.c b/ccache.c index a6bca4a34..8bdc8bdc3 100644 --- a/ccache.c +++ b/ccache.c @@ -304,6 +304,24 @@ clean_up_internal_tempdir(void) closedir(dir); } +static char * +get_current_working_dir(void) +{ + if (!current_working_dir) { + char *cwd = get_cwd(); + if (cwd) { + current_working_dir = x_realpath(cwd); + free(cwd); + } + if (!current_working_dir) { + cc_log("Unable to determine current working directory: %s", + strerror(errno)); + failed(); + } + } + return current_working_dir; +} + /* * Transform a name to a full path into the cache directory, creating needed * sublevels if needed. Caller frees. @@ -448,20 +466,6 @@ make_relative_path(char *path) return path; } - /* Look up CWD and cache it in the global current_working_dir variable. */ - if (!current_working_dir) { - char *cwd = get_cwd(); - if (cwd) { - current_working_dir = x_realpath(cwd); - free(cwd); - } - if (!current_working_dir) { - cc_log("Unable to determine current working directory: %s", - strerror(errno)); - failed(); - } - } - /* x_realpath only works for existing paths, so if path doesn't exist, try * dirname(path) and assemble the path afterwards. We only bother to try * canonicalizing one of these two paths since a compiler path argument @@ -484,7 +488,7 @@ make_relative_path(char *path) canon_path = x_realpath(path); if (canon_path) { free(path); - relpath = get_relative_path(current_working_dir, canon_path); + relpath = get_relative_path(get_current_working_dir(), canon_path); free(canon_path); if (path_suffix) { path = format("%s/%s", relpath, path_suffix); @@ -2055,7 +2059,7 @@ ccache(char *argv[]) cc_log_argv("Command line: ", argv); cc_log("Hostname: %s", get_hostname()); - cc_log("Working directory: %s", current_working_dir); + cc_log("Working directory: %s", get_current_working_dir()); if (base_dir) { cc_log("Base directory: %s", base_dir);