MCPcopy Create free account
hub / github.com/git/git / get_trace_fd

Function get_trace_fd

trace.c:38–75  ·  view source on GitHub ↗

Get a trace file descriptor from "key" env variable. */

Source from the content-addressed store, hash-verified

36
37/* Get a trace file descriptor from "key" env variable. */
38static int get_trace_fd(struct trace_key *key, const char *override_envvar)
39{
40 const char *trace;
41
42 /* don't open twice */
43 if (key->initialized)
44 return key->fd;
45
46 trace = override_envvar ? override_envvar : getenv(key->key);
47
48 if (!trace || !strcmp(trace, "") ||
49 !strcmp(trace, "0") || !strcasecmp(trace, "false"))
50 key->fd = 0;
51 else if (!strcmp(trace, "1") || !strcasecmp(trace, "true"))
52 key->fd = STDERR_FILENO;
53 else if (strlen(trace) == 1 && isdigit(*trace))
54 key->fd = atoi(trace);
55 else if (is_absolute_path(trace)) {
56 int fd = open(trace, O_WRONLY | O_APPEND | O_CREAT, 0666);
57 if (fd == -1) {
58 warning("could not open '%s' for tracing: %s",
59 trace, strerror(errno));
60 trace_disable(key);
61 } else {
62 key->fd = fd;
63 key->need_close = 1;
64 }
65 } else {
66 warning("unknown trace value for '%s': %s\n"
67 " If you want to trace into a file, then please set %s\n"
68 " to an absolute pathname (starting with /)",
69 key->key, trace, key->key);
70 trace_disable(key);
71 }
72
73 key->initialized = 1;
74 return key->fd;
75}
76
77void trace_override_envvar(struct trace_key *key, const char *value)
78{

Callers 3

trace_override_envvarFunction · 0.85
trace_writeFunction · 0.85
trace_wantFunction · 0.85

Calls 3

is_absolute_pathFunction · 0.85
warningFunction · 0.85
trace_disableFunction · 0.85

Tested by

no test coverage detected