Skip to content

Commit dde74d7

Browse files
dschogitster
authored andcommitted
run-command: use BUG() to report bugs, not die()
The slightly misleading name die_bug() of the function intended to report a bug is actually called always, and only reports a bug if the passed-in parameter `err` is non-zero. It uses die_errno() to report the bug, to helpfully include the error message corresponding to `err`. However, as these messages indicate bugs, we really should use BUG(). And as BUG() is a macro to be able to report the exact file and line number, we need to convert die_bug() to a macro instead of only replacing the die_errno() by a call to BUG(). While at it, use a name more indicative of the purpose: CHECK_BUG(). Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a86303c commit dde74d7

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

run-command.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,12 @@ struct atfork_state {
471471
sigset_t old;
472472
};
473473

474-
#ifndef NO_PTHREADS
475-
static void bug_die(int err, const char *msg)
476-
{
477-
if (err) {
478-
errno = err;
479-
die_errno("BUG: %s", msg);
480-
}
481-
}
482-
#endif
474+
#define CHECK_BUG(err, msg) \
475+
do { \
476+
int e = (err); \
477+
if (e) \
478+
BUG("%s: %s", msg, strerror(e)); \
479+
} while(0)
483480

484481
static void atfork_prepare(struct atfork_state *as)
485482
{
@@ -491,9 +488,9 @@ static void atfork_prepare(struct atfork_state *as)
491488
if (sigprocmask(SIG_SETMASK, &all, &as->old))
492489
die_errno("sigprocmask");
493490
#else
494-
bug_die(pthread_sigmask(SIG_SETMASK, &all, &as->old),
491+
CHECK_BUG(pthread_sigmask(SIG_SETMASK, &all, &as->old),
495492
"blocking all signals");
496-
bug_die(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &as->cs),
493+
CHECK_BUG(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &as->cs),
497494
"disabling cancellation");
498495
#endif
499496
}
@@ -504,9 +501,9 @@ static void atfork_parent(struct atfork_state *as)
504501
if (sigprocmask(SIG_SETMASK, &as->old, NULL))
505502
die_errno("sigprocmask");
506503
#else
507-
bug_die(pthread_setcancelstate(as->cs, NULL),
504+
CHECK_BUG(pthread_setcancelstate(as->cs, NULL),
508505
"re-enabling cancellation");
509-
bug_die(pthread_sigmask(SIG_SETMASK, &as->old, NULL),
506+
CHECK_BUG(pthread_sigmask(SIG_SETMASK, &as->old, NULL),
510507
"restoring signal mask");
511508
#endif
512509
}

0 commit comments

Comments
 (0)