if (validate_buffers(&enabled_buffers) < 0)
return 1;
+ /** Optimisation for short-lived (i.e. dumping) instances.
+
+ We can assume that such instances will not see a timezone
+ change happen during their lifetime, and even if they do,
+ it is probably best if they ignore it (a dump would ideally
+ behave as if it was atomic). This means we can optimize the
+ behaviour where printing the timestamp requires us to check
+ whether the timezone changed, which involves calling stat()
+ on /etc/localtime, which is not cheap on its own and made
+ even worse when it has to go through multiple symlinks.
+
+ glibc has a feature where setting the TZ environmental var
+ will cache the timezone, achieving precisely what we want.
+ */
+ if (logs.dump != DUMP_CONTINUOUS && !getenv("TZ"))
+ putenv("TZ=:/etc/localtime");
+
const char *const backend = log_config_get(&conf, "backend");
if (!backend) {
ERR("Error: backend not defined\n");