Skip to content

Commit 0359381

Browse files
authored
[2.55.0] fixup! gvfs: add global command pre and post hook procs (#956)
Users were noticing some cases of infinite loops with the error message: ``` fatal: recursion detected in die handler ``` It's only happening for repos with a post-command hook, but it's not deterministic. I'm not sure what is triggering the problem, but the post-command hook is definitely able to recurse with its existing logic around the `run_post_hook` variable. Move this earlier to avoid a potential double-call. It's a fixup to the introduction of the method, which may cause conflicts with later adjustments to this method still in the branch thicket (but maybe those should be squashed, too). See #955 for the version on 2.54.0.
2 parents f5917cf + c694a5b commit 0359381

2 files changed

Lines changed: 37 additions & 17 deletions

File tree

git.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,12 @@ static int run_post_command_hook(struct repository *r)
528528

529529
/*
530530
* Only run post_command if pre_command succeeded in this process
531+
* and we haven't attempted post_command yet.
531532
*/
532533
if (!run_post_hook)
533534
return 0;
535+
run_post_hook = 0;
536+
534537
lock = getenv("COMMAND_HOOK_LOCK");
535538
if (!lock || strcmp(lock, "true"))
536539
return 0;
@@ -539,8 +542,6 @@ static int run_post_command_hook(struct repository *r)
539542
strvec_pushf(&opt.args, "--exit_code=%u", exit_code);
540543
ret = run_hooks_opt(r, "post-command", &opt);
541544

542-
run_post_hook = 0;
543-
544545
errno = saved_errno;
545546
strvec_clear(&sargv);
546547
strvec_clear(&opt.args);

trace2/tr2_tbuf.c

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,64 @@
33

44
void tr2_tbuf_local_time(struct tr2_tbuf *tb)
55
{
6-
struct timeval tv;
7-
struct tm tm;
6+
struct timeval tv = { 0 };
7+
struct tm tm = { 0 };
88
time_t secs;
9+
int len;
910

1011
gettimeofday(&tv, NULL);
1112
secs = tv.tv_sec;
1213
localtime_r(&secs, &tm);
1314

14-
xsnprintf(tb->buf, sizeof(tb->buf), "%02d:%02d:%02d.%06ld", tm.tm_hour,
15-
tm.tm_min, tm.tm_sec, (long)tv.tv_usec);
15+
len = snprintf(tb->buf, sizeof(tb->buf), "%02d:%02d:%02d.%06ld",
16+
tm.tm_hour, tm.tm_min, tm.tm_sec, (long)tv.tv_usec);
17+
18+
if (len < 0 || (size_t)len >= sizeof(tb->buf)) {
19+
const char *blank = "00:00:00.000000";
20+
strlcpy(tb->buf, blank, sizeof(tb->buf));
21+
}
1622
}
1723

1824
void tr2_tbuf_utc_datetime_extended(struct tr2_tbuf *tb)
1925
{
20-
struct timeval tv;
21-
struct tm tm;
26+
struct timeval tv = { 0 };
27+
struct tm tm = { 0 };
2228
time_t secs;
29+
int len;
2330

2431
gettimeofday(&tv, NULL);
2532
secs = tv.tv_sec;
2633
gmtime_r(&secs, &tm);
2734

28-
xsnprintf(tb->buf, sizeof(tb->buf),
29-
"%4d-%02d-%02dT%02d:%02d:%02d.%06ldZ", tm.tm_year + 1900,
30-
tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
31-
(long)tv.tv_usec);
35+
len = snprintf(tb->buf, sizeof(tb->buf),
36+
"%4d-%02d-%02dT%02d:%02d:%02d.%06ldZ",
37+
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
38+
tm.tm_hour, tm.tm_min, tm.tm_sec, (long)tv.tv_usec);
39+
40+
if (len < 0 || (size_t)len >= sizeof(tb->buf)) {
41+
const char *blank = "1900-00-00T00:00:00.000000Z";
42+
strlcpy(tb->buf, blank, sizeof(tb->buf));
43+
}
3244
}
3345

3446
void tr2_tbuf_utc_datetime(struct tr2_tbuf *tb)
3547
{
36-
struct timeval tv;
37-
struct tm tm;
48+
struct timeval tv = { 0 };
49+
struct tm tm = { 0 };
3850
time_t secs;
51+
int len;
3952

4053
gettimeofday(&tv, NULL);
4154
secs = tv.tv_sec;
4255
gmtime_r(&secs, &tm);
4356

44-
xsnprintf(tb->buf, sizeof(tb->buf), "%4d%02d%02dT%02d%02d%02d.%06ldZ",
45-
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
46-
tm.tm_min, tm.tm_sec, (long)tv.tv_usec);
57+
len = snprintf(tb->buf, sizeof(tb->buf),
58+
"%4d%02d%02dT%02d%02d%02d.%06ldZ",
59+
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
60+
tm.tm_hour, tm.tm_min, tm.tm_sec, (long)tv.tv_usec);
61+
62+
if (len < 0 || (size_t)len >= sizeof(tb->buf)) {
63+
const char *blank = "19000000T000000.000000Z";
64+
strlcpy(tb->buf, blank, sizeof(tb->buf));
65+
}
4766
}

0 commit comments

Comments
 (0)