From: Joel Rosdahl Date: Sun, 3 Apr 2011 11:22:57 +0000 (+0200) Subject: Include strerror(errno) in error messages when system calls fail X-Git-Tag: v3.1.5~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08526533e128f152698642fe29d26c484dd0b89d;p=thirdparty%2Fccache.git Include strerror(errno) in error messages when system calls fail --- diff --git a/ccache.c b/ccache.c index 5e36706af..eabed134c 100644 --- a/ccache.c +++ b/ccache.c @@ -267,7 +267,7 @@ get_path_in_cache(const char *name, const char *suffix) free(path); path = p; if (create_dir(path) != 0) { - cc_log("Failed to create %s", path); + cc_log("Failed to create %s: %s", path, strerror(errno)); failed(); } } @@ -307,7 +307,7 @@ remember_include_file(char *path, size_t path_len, struct mdfour *cpp_hash) } if (stat(path, &st) != 0) { - cc_log("Failed to stat include file %s", path); + cc_log("Failed to stat include file %s: %s", path, strerror(errno)); goto failure; } if (S_ISDIR(st.st_mode)) { @@ -552,22 +552,23 @@ to_cache(struct args *args) tmp_stderr2 = format("%s.tmp.stderr2.%s", cached_obj, tmp_string()); if (x_rename(tmp_stderr, tmp_stderr2)) { - cc_log("Failed to rename %s to %s", tmp_stderr, tmp_stderr2); + cc_log("Failed to rename %s to %s: %s", tmp_stderr, tmp_stderr2, + strerror(errno)); failed(); } fd_cpp_stderr = open(cpp_stderr, O_RDONLY | O_BINARY); if (fd_cpp_stderr == -1) { - cc_log("Failed opening %s", cpp_stderr); + cc_log("Failed opening %s: %s", cpp_stderr, strerror(errno)); failed(); } fd_real_stderr = open(tmp_stderr2, O_RDONLY | O_BINARY); if (fd_real_stderr == -1) { - cc_log("Failed opening %s", tmp_stderr2); + cc_log("Failed opening %s: %s", tmp_stderr2, strerror(errno)); failed(); } fd_result = open(tmp_stderr, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); if (fd_result == -1) { - cc_log("Failed opening %s", tmp_stderr); + cc_log("Failed opening %s: %s", tmp_stderr, strerror(errno)); failed(); } copy_fd(fd_cpp_stderr, fd_result); @@ -615,14 +616,15 @@ to_cache(struct args *args) } if (stat(tmp_stderr, &st) != 0) { - cc_log("Failed to stat %s", tmp_stderr); + cc_log("Failed to stat %s: %s", tmp_stderr, strerror(errno)); stats_update(STATS_ERROR); failed(); } if (st.st_size > 0) { if (move_uncompressed_file(tmp_stderr, cached_stderr, enable_compression) != 0) { - cc_log("Failed to move %s to %s", tmp_stderr, cached_stderr); + cc_log("Failed to move %s to %s: %s", tmp_stderr, cached_stderr, + strerror(errno)); stats_update(STATS_ERROR); failed(); } @@ -636,7 +638,7 @@ to_cache(struct args *args) tmp_unlink(tmp_stderr); } if (move_uncompressed_file(tmp_obj, cached_obj, enable_compression) != 0) { - cc_log("Failed to move %s to %s", tmp_obj, cached_obj); + cc_log("Failed to move %s to %s: %s", tmp_obj, cached_obj, strerror(errno)); stats_update(STATS_ERROR); failed(); } else { @@ -651,7 +653,7 @@ to_cache(struct args *args) * size statistics. */ if (stat(cached_obj, &st) != 0) { - cc_log("Failed to stat %s", strerror(errno)); + cc_log("Failed to stat %s: %s", cached_obj, strerror(errno)); stats_update(STATS_ERROR); failed(); } @@ -708,8 +710,8 @@ get_object_name_from_cpp(struct args *args, struct mdfour *hash) correct i_tmpfile */ path_stdout = input_file; if (create_empty_file(path_stderr) != 0) { + cc_log("Failed to create %s: %s", path_stderr, strerror(errno)); stats_update(STATS_ERROR); - cc_log("Failed to create %s", path_stderr); failed(); } status = 0; @@ -751,7 +753,7 @@ get_object_name_from_cpp(struct args *args, struct mdfour *hash) hash_delimiter(hash, "cppstderr"); if (!hash_file(hash, path_stderr)) { - fatal("Failed to open %s", path_stderr); + fatal("Failed to open %s: %s", path_stderr, strerror(errno)); } i_tmpfile = path_stdout; @@ -809,7 +811,7 @@ calculate_common_hash(struct args *args, struct mdfour *hash) hash_string(hash, i_extension); if (stat(args->argv[0], &st) != 0) { - cc_log("Couldn't stat the compiler (%s)", args->argv[0]); + cc_log("Couldn't stat compiler %s: %s", args->argv[0], strerror(errno)); stats_update(STATS_COMPILER); failed(); } @@ -1022,7 +1024,7 @@ from_cache(enum fromcache_call_mode mode, bool put_object_in_manifest) cc_log("Object file %s just disappeared from cache", cached_obj); stats_update(STATS_MISSING); } else { - cc_log("Failed to copy/link %s to %s (%s)", + cc_log("Failed to copy/link %s to %s: %s", cached_obj, output_obj, strerror(errno)); stats_update(STATS_ERROR); failed(); @@ -1053,9 +1055,8 @@ from_cache(enum fromcache_call_mode mode, bool put_object_in_manifest) cc_log("Dependency file %s just disappeared from cache", output_obj); stats_update(STATS_MISSING); } else { - cc_log("Failed to copy/link %s to %s (%s)", - cached_dep, output_dep, - strerror(errno)); + cc_log("Failed to copy/link %s to %s: %s", + cached_dep, output_dep, strerror(errno)); stats_update(STATS_ERROR); failed(); } @@ -1082,7 +1083,8 @@ from_cache(enum fromcache_call_mode mode, bool put_object_in_manifest) /* Store the dependency file in the cache. */ ret = copy_file(output_dep, cached_dep, enable_compression); if (ret == -1) { - cc_log("Failed to copy %s to %s", output_dep, cached_dep); + cc_log("Failed to copy %s to %s: %s", output_dep, cached_dep, + strerror(errno)); /* Continue despite the error. */ } else { cc_log("Stored in cache: %s", cached_dep); @@ -2041,7 +2043,7 @@ setup_uncached_err(void) uncached_fd = dup(2); if (uncached_fd == -1) { - cc_log("dup(2) failed"); + cc_log("dup(2) failed: %s", strerror(errno)); failed(); } @@ -2049,7 +2051,7 @@ setup_uncached_err(void) buf = format("UNCACHED_ERR_FD=%d", uncached_fd); if (putenv(buf) == -1) { - cc_log("putenv failed"); + cc_log("putenv failed: %s", strerror(errno)); failed(); } } diff --git a/execute.c b/execute.c index d68ad58f4..6e4d002e7 100644 --- a/execute.c +++ b/execute.c @@ -170,7 +170,7 @@ execute(char **argv, const char *path_stdout, const char *path_stderr) cc_log_argv("Executing ", argv); pid = fork(); - if (pid == -1) fatal("Failed to fork"); + if (pid == -1) fatal("Failed to fork: %s", strerror(errno)); if (pid == 0) { int fd; @@ -195,7 +195,7 @@ execute(char **argv, const char *path_stdout, const char *path_stderr) } if (waitpid(pid, &status, 0) != pid) { - fatal("waitpid failed"); + fatal("waitpid failed: %s", strerror(errno)); } if (WEXITSTATUS(status) == 0 && WIFSIGNALED(status)) {