i18n: simplify numeric error reporting
[gitweb.git] / trace.c
diff --git a/trace.c b/trace.c
index 6a77e4df037cfe48694d5b686bcc291243cb8dd3..7508aea028bb642140cabcd02c37cdaf3a21234c 100644 (file)
--- a/trace.c
+++ b/trace.c
@@ -61,21 +61,19 @@ static int get_trace_fd(struct trace_key *key)
        else if (is_absolute_path(trace)) {
                int fd = open(trace, O_WRONLY | O_APPEND | O_CREAT, 0666);
                if (fd == -1) {
-                       warning("Could not open '%s' for tracing: %s\n"
-                               "Defaulting to tracing on stderr...",
+                       warning("could not open '%s' for tracing: %s",
                                trace, strerror(errno));
-                       key->fd = STDERR_FILENO;
+                       trace_disable(key);
                } else {
                        key->fd = fd;
                        key->need_close = 1;
                }
        } else {
-               warning("What does '%s' for %s mean?\n"
-                       "If you want to trace into a file, then please set "
-                       "%s to an absolute pathname (starting with /).\n"
-                       "Defaulting to tracing on stderr...",
-                       trace, key->key, key->key);
-               key->fd = STDERR_FILENO;
+               warning("unknown trace value for '%s': %s\n"
+                       "         If you want to trace into a file, then please set %s\n"
+                       "         to an absolute pathname (starting with /)",
+                       key->key, trace, key->key);
+               trace_disable(key);
        }
 
        key->initialized = 1;
@@ -93,9 +91,6 @@ void trace_disable(struct trace_key *key)
        key->need_close = 0;
 }
 
-static const char err_msg[] = "Could not trace into fd given by "
-       "GIT_TRACE environment variable";
-
 static int prepare_trace_line(const char *file, int line,
                              struct trace_key *key, struct strbuf *buf)
 {
@@ -133,8 +128,12 @@ static int prepare_trace_line(const char *file, int line,
 
 static void trace_write(struct trace_key *key, const void *buf, unsigned len)
 {
-       if (write_in_full(get_trace_fd(key), buf, len) < 0)
-               warning("%s: write error (%s)", err_msg, strerror(errno));
+       if (write_in_full(get_trace_fd(key), buf, len) < 0) {
+               normalize_trace_key(&key);
+               warning("unable to write trace for %s: %s",
+                       key->key, strerror(errno));
+               trace_disable(key);
+       }
 }
 
 void trace_verbatim(struct trace_key *key, const void *buf, unsigned len)