But gcc gives a warning for it, anyway. And "x == 7" is much more readable
than "7 == x".
At least, for English speakers it is. I don't know; maybe there are languages
in which saying "if x is equal to y" implies that x is the constant and y
is the variable.
I've found the following phrases in Wiktionary:
http://en.wiktionary.org/wiki/equal
"Two plus two equals four."
"A and B are equal"
"A is equal to B"
"A is equal with B"
In Hungarian, forms 1 and 3 don't exist, but forms 2 and 4 are used with
the exact same structure. And yet I don't have any difficulty writing
7 == x
and thinking, "7 is equal with x". Equality is symmetric. It took some
self-education (let's not be inquisitive about the why), but it was so
effective that now I frown on
x == 7
.... I updated the function below to its current form two days ago;
you'll love to hate it:
static void
bailout(void)
{
sigset_t tmp_set;
if (pthread_equal(pthread_self(), main_thread)) {
if (0 != opathn) {
(void)unlink(opathn);
}
if (0 == sigemptyset(&tmp_set) && 0 == sigaddset(&tmp_set, SIGPIPE)
&& 0 == sigaddset(&tmp_set, SIGXFSZ)) {
(void)pthread_sigmask(SIG_UNBLOCK, &tmp_set, 0);
}
}
else {
if (0 == sigemptyset(&tmp_set) && 0 == sigpending(&tmp_set)) {
int chk;
chk = sigismember(&tmp_set, SIGPIPE);
if (0 == chk || (1 == chk && 0 == kill(pid, SIGPIPE))) {
chk = sigismember(&tmp_set, SIGXFSZ);
if ((0 == chk || (1 == chk && 0 == kill(pid, SIGXFSZ)))
&& 0 == kill(pid, SIGUSR1)) {
pthread_exit(0);
}
}
}
}
_exit(EX_FAIL);
}
(If called from the main thread, it removes the output file, if any.
Then it tries to unblock any pending SIGPIPE or SIGXFSZ. If it succeeds
(it should) and there is in fact any such signal pending for the whole
process or specifically for the main thread, such that its action is not
SIG_IGN (but SIG_DFL), then the process dies with one of those signals.
If unblocking fails (for whatever reason -- it shouldn't), or no such
signal was pending, or all relevant actions were SIG_IGN (yes, a signal
may remain pending even though its action is SIG_IGN), then the process
exits with status 1. (Unless a sub-thread encounters an EPIPE/EFBIG and
raises a SIGPIPE or SIGXFSZ, see below, to the process level, just
between unblocking and exiting, which is fine.)
If called from any sub-thread, if any of the following fails, the entire
process is terminated with exit status 1 as a last resort. Each
sub-thread has SIGPIPE and SIGXFSZ blocked. If any such signal is
pending on the thread, the thread forwards it to the process level, so
that it will become deliverable to the main thread. If any such signal
is already pending on the whole process, then the thread regenerates it
for the whole process -- an idempotent operation. Then the thread wakes
the main thread -- which is waiting for asynchronously generated signals
anyway like SIGINT and SIGTERM -- with a SIGUSR1 error notification, and
finally, the sub-thread terminates.
sigismember() can theoretically return -1, that's why 1 == chk is
checked after 0 == chk proves false.
tmp_set must be emptied before it can be passed to sigpending().)
Cheers,
lacos