[monit-dev] [monit] r337 committed - reuse the TZ

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[monit-dev] [monit] r337 committed - reuse the TZ

monit-2
Revision: 337
Author: [hidden email]
Date: Tue Mar  8 01:32:09 2011
Log: reuse the TZ
http://code.google.com/p/monit/source/detail?r=337

Modified:
  /trunk/env.c

=======================================
--- /trunk/env.c Tue Mar  1 11:39:55 2011
+++ /trunk/env.c Tue Mar  8 01:32:09 2011
@@ -150,29 +150,25 @@
   */
  static void set_sandbox(void) {

-  int    i;
+  int    i = 0;
    struct stat st;
    extern char **environ;
    char   *path = "PATH=/bin:/usr/bin:/sbin:/usr/sbin";
-  char   buf[STRLEN];
+  char   *tz;

    /*
-   * Keep the TZ variable, the time.h family depends on it at least on AIX
+   * Purge the environment, but keep the TZ variable as the time.h family  
depends on it at least on AIX
     */
-  snprintf(buf, sizeof(buf), "TZ=%s", getenv("TZ") ? getenv("TZ") : "");
-
-  /*
-   * Purge the environment. Then make sure PATH is set; some shells default
-   * to a path with '.' first. You may have to putenv() other stuff, too,
-   * but be careful with importing too much.
-   */
-  environ[0] = 0;
-
-  if (putenv(xstrdup(buf))) {
-    LogError("%s: cannot set the TZ variable -- %s\n", prog, STRERROR);
-    exit(1);
-  }
-
+  for (tz = environ[0]; tz; tz = environ[++i]) {
+    if (! strncasecmp(tz, "TZ=", 3)) {
+      environ[0] = tz;
+      environ[1] = 0;
+      break;
+    }
+  }
+  if (! tz)
+    environ[0] = 0;
+
    if (putenv(path)) {
      LogError("%s: cannot set the PATH variable -- %s\n", prog, STRERROR);
      exit(1);

_______________________________________________
monit-dev mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/monit-dev