aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/env_universal_common.h
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-11-08 23:48:32 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-11-08 23:48:32 -0800
commit45dfa2d8640ab94c86ba97d5dc15db87badc67fb (patch)
treeb7b6a4a88c105b7f34c19bdda03fb0a1200f96d6 /src/env_universal_common.h
parentc2024a6a948f3669f611d9830c1559fb2979c3ea (diff)
Attempt to fix the sporadic uvar test failures on Linux
We identify when the universal variable file has changed out from under us by comparing a bunch of fields from its stat: inode, device, size, high-precision timestamp, generation. Linux aggressively reuses inodes, and the size may be the same by coincidence (which is the case in the tests). Also, Linux officially has nanosecond precision, but in practice it seems to only uses millisecond precision for storing mtimes. Thus if there are three or more updates within a millisecond, every field we check may be the same, and we are vulnerable to the ABA problem. I believe this explains the occasional test failures. The solution is to manually set the nanosecond field of the mtime timestamp to something unlikely to be duplicated, like a random number, or better yet, the current time (with nanosecond precision). This is more in the spirit of the timestamp, and it means we're around a million times less likely to collide. This seems to fix the tests.
Diffstat (limited to 'src/env_universal_common.h')
-rw-r--r--src/env_universal_common.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/env_universal_common.h b/src/env_universal_common.h
index 203f952b..3428c693 100644
--- a/src/env_universal_common.h
+++ b/src/env_universal_common.h
@@ -168,7 +168,7 @@ public:
};
bool universal_log_enabled();
-#define UNIVERSAL_LOG(x) if (universal_log_enabled()) fprintf(stderr, "UNIVERSAL LOG: %s\n", x)
+#define UNIVERSAL_LOG(x) do { if (universal_log_enabled()) fprintf(stderr, "UNIVERSAL LOG: %s\n", x); } while (0)
/* Environment variable for requesting a particular universal notifier. See fetch_default_strategy_from_environment for names. */
#define UNIVERSAL_NOTIFIER_ENV_NAME "fish_universal_notifier"