> Many thanks. The resolver and OS-specific include
> ones will go in immediately. The environment one,
> I'm wary about the dropping of other bits of environment
> that may be relevant to the code being wrapped in
> the to-zulu-time. Locale comes specifically to mind.
You may be right on that one and there is no need to take that risk.
> The lack of setenv was raised for older Solaris
> environments, in https://bugs.exim.org/show_bug.cgi?id=1578
> I wrote a patch then but was unable to test it
> due to lack of such a system. Could you have a
> play with the patch attached there and see if it
> works for you?
>From looking at the code, I doubt it will. Reading up on putenv,
it may remove the variable if no value is given, but that cannot be
taken for granted.
I suggest something along these lines:
--- src/tls.c.orig 2015-12-20 22:57:25.000000000 +0100
+++ src/tls.c 2015-12-20 23:44:02.000000000 +0100
@@ -84,19 +84,55 @@
* Timezone environment flipping *
*************************************************/
+#ifndef HAVE_UNSETENV
+int unsetenv(const char *name)
+{
+extern char **environ;
+
+size_t len;
+const char *end;
+char **e;
+
+if (!name)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+for (end = name; *end && *end != '='; ++end);
+len = end - name;
+
+for (e = environ; *e; ++e)
+ {
+ if (strncmp(*e, name, len) == 0 && (*e)[len] == '=')
+ {
+ /* Move remaining environment variables down */
+ while (*e)
+ {
+ *e = *(e + 1);
+ ++e;
+ }
+ break;
+ }
+ }
+
+return 0;
+}
+#endif
+
static uschar *
to_tz(uschar * tz)
{
uschar * old = US getenv("TZ");
- setenv("TZ", CS tz, 1);
+ putenv("TZ=GMT0");
tzset();
- return old;
+ return old ? old-3 : NULL; /* include `TZ=' in returned string */
}
static void
restore_tz(uschar * tz)
{
if (tz)
- setenv("TZ", CS tz, 1);
+ putenv(tz);
else
unsetenv("TZ");
tzset();
I did not refactor to_tz to to_tz_gmt0. Returning the previous variable
instead of just its value and putting it back in the environment avoids
the possible memory leak of the current code, as does having the static
entry TZ=GMT0.
Michael