]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Fix problem with logging of current working directory
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 17 Jul 2014 14:08:29 +0000 (16:08 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 17 Jul 2014 14:10:19 +0000 (16:10 +0200)
ccache.c

index a6bca4a34ede7e28014a0191cb073a69190e969d..8bdc8bdc397defa9956c21229f698638290894a9 100644 (file)
--- 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);