From 93ba78d6f4632ef1c5228965e3edc8c0faf88c1e Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 26 May 2020 00:06:52 +0100 Subject: revert(3p/git): Revert merge of git upstream at v2.26.2 This causes cgit to serve error pages, which is undesirable. This reverts commit 5229c9b232de5bfa959ad6ebbb4c8192ac513352, reversing changes made to f2b211131f2347342dde63975b09cf603149f1a3. --- third_party/git/trace2/tr2_dst.c | 120 +++++--------------------------- third_party/git/trace2/tr2_dst.h | 1 - third_party/git/trace2/tr2_sid.c | 2 +- third_party/git/trace2/tr2_sysenv.c | 3 - third_party/git/trace2/tr2_sysenv.h | 2 - third_party/git/trace2/tr2_tgt_event.c | 36 ++++------ third_party/git/trace2/tr2_tgt_normal.c | 37 +++++----- third_party/git/trace2/tr2_tgt_perf.c | 108 ++++++++++++---------------- 8 files changed, 95 insertions(+), 214 deletions(-) (limited to 'third_party/git/trace2') diff --git a/third_party/git/trace2/tr2_dst.c b/third_party/git/trace2/tr2_dst.c index ae052a07fe2e..5dda0ca1cdb5 100644 --- a/third_party/git/trace2/tr2_dst.c +++ b/third_party/git/trace2/tr2_dst.c @@ -8,19 +8,6 @@ */ #define MAX_AUTO_ATTEMPTS 10 -/* - * Sentinel file used to detect when we should discard new traces to avoid - * writing too many trace files to a directory. - */ -#define DISCARD_SENTINEL_NAME "git-trace2-discard" - -/* - * When set to zero, disables directory file count checks. Otherwise, controls - * how many files we can write to a directory before entering discard mode. - * This can be overridden via the TR2_SYSENV_MAX_FILES setting. - */ -static int tr2env_max_files = 0; - static int tr2_dst_want_warning(void) { static int tr2env_dst_debug = -1; @@ -45,75 +32,9 @@ void tr2_dst_trace_disable(struct tr2_dst *dst) dst->need_close = 0; } -/* - * Check to make sure we're not overloading the target directory with too many - * files. First get the threshold (if present) from the config or envvar. If - * it's zero or unset, disable this check. Next check for the presence of a - * sentinel file, then check file count. - * - * Returns 0 if tracing should proceed as normal. Returns 1 if the sentinel file - * already exists, which means tracing should be disabled. Returns -1 if there - * are too many files but there was no sentinel file, which means we have - * created and should write traces to the sentinel file. - * - * We expect that some trace processing system is gradually collecting files - * from the target directory; after it removes the sentinel file we'll start - * writing traces again. - */ -static int tr2_dst_too_many_files(struct tr2_dst *dst, const char *tgt_prefix) -{ - int file_count = 0, max_files = 0, ret = 0; - const char *max_files_var; - DIR *dirp; - struct strbuf path = STRBUF_INIT, sentinel_path = STRBUF_INIT; - struct stat statbuf; - - /* Get the config or envvar and decide if we should continue this check */ - max_files_var = tr2_sysenv_get(TR2_SYSENV_MAX_FILES); - if (max_files_var && *max_files_var && ((max_files = atoi(max_files_var)) >= 0)) - tr2env_max_files = max_files; - - if (!tr2env_max_files) { - ret = 0; - goto cleanup; - } - - strbuf_addstr(&path, tgt_prefix); - if (!is_dir_sep(path.buf[path.len - 1])) { - strbuf_addch(&path, '/'); - } - - /* check sentinel */ - strbuf_addbuf(&sentinel_path, &path); - strbuf_addstr(&sentinel_path, DISCARD_SENTINEL_NAME); - if (!stat(sentinel_path.buf, &statbuf)) { - ret = 1; - goto cleanup; - } - - /* check file count */ - dirp = opendir(path.buf); - while (file_count < tr2env_max_files && dirp && readdir(dirp)) - file_count++; - if (dirp) - closedir(dirp); - - if (file_count >= tr2env_max_files) { - dst->too_many_files = 1; - dst->fd = open(sentinel_path.buf, O_WRONLY | O_CREAT | O_EXCL, 0666); - ret = -1; - goto cleanup; - } - -cleanup: - strbuf_release(&path); - strbuf_release(&sentinel_path); - return ret; -} - static int tr2_dst_try_auto_path(struct tr2_dst *dst, const char *tgt_prefix) { - int too_many_files; + int fd; const char *last_slash, *sid = tr2_sid_get(); struct strbuf path = STRBUF_INIT; size_t base_path_len; @@ -129,29 +50,18 @@ static int tr2_dst_try_auto_path(struct tr2_dst *dst, const char *tgt_prefix) strbuf_addstr(&path, sid); base_path_len = path.len; - too_many_files = tr2_dst_too_many_files(dst, tgt_prefix); - if (!too_many_files) { - for (attempt_count = 0; attempt_count < MAX_AUTO_ATTEMPTS; attempt_count++) { - if (attempt_count > 0) { - strbuf_setlen(&path, base_path_len); - strbuf_addf(&path, ".%d", attempt_count); - } - - dst->fd = open(path.buf, O_WRONLY | O_CREAT | O_EXCL, 0666); - if (dst->fd != -1) - break; + for (attempt_count = 0; attempt_count < MAX_AUTO_ATTEMPTS; attempt_count++) { + if (attempt_count > 0) { + strbuf_setlen(&path, base_path_len); + strbuf_addf(&path, ".%d", attempt_count); } - } else if (too_many_files == 1) { - strbuf_release(&path); - if (tr2_dst_want_warning()) - warning("trace2: not opening %s trace file due to too " - "many files in target directory %s", - tr2_sysenv_display_name(dst->sysenv_var), - tgt_prefix); - return 0; + + fd = open(path.buf, O_WRONLY | O_CREAT | O_EXCL, 0666); + if (fd != -1) + break; } - if (dst->fd == -1) { + if (fd == -1) { if (tr2_dst_want_warning()) warning("trace2: could not open '%.*s' for '%s' tracing: %s", (int) base_path_len, path.buf, @@ -165,6 +75,7 @@ static int tr2_dst_try_auto_path(struct tr2_dst *dst, const char *tgt_prefix) strbuf_release(&path); + dst->fd = fd; dst->need_close = 1; dst->initialized = 1; @@ -304,8 +215,13 @@ connected: static void tr2_dst_malformed_warning(struct tr2_dst *dst, const char *tgt_value) { - warning("trace2: unknown value for '%s': '%s'", - tr2_sysenv_display_name(dst->sysenv_var), tgt_value); + struct strbuf buf = STRBUF_INIT; + + strbuf_addf(&buf, "trace2: unknown value for '%s': '%s'", + tr2_sysenv_display_name(dst->sysenv_var), tgt_value); + warning("%s", buf.buf); + + strbuf_release(&buf); } int tr2_dst_get_trace_fd(struct tr2_dst *dst) diff --git a/third_party/git/trace2/tr2_dst.h b/third_party/git/trace2/tr2_dst.h index b1a8c144e073..3adf3bac139b 100644 --- a/third_party/git/trace2/tr2_dst.h +++ b/third_party/git/trace2/tr2_dst.h @@ -9,7 +9,6 @@ struct tr2_dst { int fd; unsigned int initialized : 1; unsigned int need_close : 1; - unsigned int too_many_files : 1; }; /* diff --git a/third_party/git/trace2/tr2_sid.c b/third_party/git/trace2/tr2_sid.c index dc6e75ef1315..6948fd41086f 100644 --- a/third_party/git/trace2/tr2_sid.c +++ b/third_party/git/trace2/tr2_sid.c @@ -19,7 +19,7 @@ static int tr2sid_nr_git_parents; * "H" * "Localhost" when no hostname. * - * where is a 9 character string containing the least significant + * where is a 9 character string containing the least signifcant * 32 bits in the process-id. * "P" * (This is an abribrary choice. On most systems pid_t is a 32 bit value, diff --git a/third_party/git/trace2/tr2_sysenv.c b/third_party/git/trace2/tr2_sysenv.c index 3c3792eca2e2..5958cfc424b5 100644 --- a/third_party/git/trace2/tr2_sysenv.c +++ b/third_party/git/trace2/tr2_sysenv.c @@ -49,9 +49,6 @@ static struct tr2_sysenv_entry tr2_sysenv_settings[] = { "trace2.perftarget" }, [TR2_SYSENV_PERF_BRIEF] = { "GIT_TRACE2_PERF_BRIEF", "trace2.perfbrief" }, - - [TR2_SYSENV_MAX_FILES] = { "GIT_TRACE2_MAX_FILES", - "trace2.maxfiles" }, }; /* clang-format on */ diff --git a/third_party/git/trace2/tr2_sysenv.h b/third_party/git/trace2/tr2_sysenv.h index d4364a7b85a5..8dd82a7a56bb 100644 --- a/third_party/git/trace2/tr2_sysenv.h +++ b/third_party/git/trace2/tr2_sysenv.h @@ -24,8 +24,6 @@ enum tr2_sysenv_variable { TR2_SYSENV_PERF, TR2_SYSENV_PERF_BRIEF, - TR2_SYSENV_MAX_FILES, - TR2_SYSENV_MUST_BE_LAST }; diff --git a/third_party/git/trace2/tr2_tgt_event.c b/third_party/git/trace2/tr2_tgt_event.c index 6353e8ad9156..c2852d1bd2bd 100644 --- a/third_party/git/trace2/tr2_tgt_event.c +++ b/third_party/git/trace2/tr2_tgt_event.c @@ -10,17 +10,16 @@ #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_event = { TR2_SYSENV_EVENT, 0, 0, 0, 0 }; +static struct tr2_dst tr2dst_event = { TR2_SYSENV_EVENT, 0, 0, 0 }; /* - * The version number of the JSON data generated by the EVENT target in this - * source file. The version should be incremented if new event types are added, - * if existing fields are removed, or if there are significant changes in - * interpretation of existing events or fields. Smaller changes, such as adding - * a new field to an existing event, do not require an increment to the EVENT - * format version. + * The version number of the JSON data generated by the EVENT target + * in this source file. Update this if you make a significant change + * to the JSON fields or message structure. You probably do not need + * to update this if you just add another call to one of the existing + * TRACE2 API methods. */ -#define TR2_EVENT_VERSION "2" +#define TR2_EVENT_VERSION "1" /* * Region nesting limit for messages written to the event target. @@ -108,19 +107,6 @@ static void event_fmt_prepare(const char *event_name, const char *file, jw_object_intmax(jw, "repo", repo->trace2_repo_id); } -static void fn_too_many_files_fl(const char *file, int line) -{ - const char *event_name = "too_many_files"; - struct json_writer jw = JSON_WRITER_INIT; - - jw_object_begin(&jw, 0); - event_fmt_prepare(event_name, file, line, NULL, &jw); - jw_end(&jw); - - tr2_dst_write_line(&tr2dst_event, &jw.json); - jw_release(&jw); -} - static void fn_version_fl(const char *file, int line) { const char *event_name = "version"; @@ -134,9 +120,6 @@ static void fn_version_fl(const char *file, int line) tr2_dst_write_line(&tr2dst_event, &jw.json); jw_release(&jw); - - if (tr2dst_event.too_many_files) - fn_too_many_files_fl(file, line); } static void fn_start_fl(const char *file, int line, @@ -222,6 +205,11 @@ static void maybe_add_string_va(struct json_writer *jw, const char *field_name, strbuf_release(&buf); return; } + + if (fmt && *fmt) { + jw_object_string(jw, field_name, fmt); + return; + } } static void fn_error_va_fl(const char *file, int line, const char *fmt, diff --git a/third_party/git/trace2/tr2_tgt_normal.c b/third_party/git/trace2/tr2_tgt_normal.c index 31b602c171fc..00b116d797c8 100644 --- a/third_party/git/trace2/tr2_tgt_normal.c +++ b/third_party/git/trace2/tr2_tgt_normal.c @@ -9,7 +9,7 @@ #include "trace2/tr2_tgt.h" #include "trace2/tr2_tls.h" -static struct tr2_dst tr2dst_normal = { TR2_SYSENV_NORMAL, 0, 0, 0, 0 }; +static struct tr2_dst tr2dst_normal = { TR2_SYSENV_NORMAL, 0, 0, 0 }; /* * Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the "