commit 0bec44ecb9c75f2d9cb4e009317a629d99c7296c
parent f8f83e3394f120df1f211505eb8bd122c29edb22
Author: Gerrit Pape <pape@smarden.org>
Date:   Tue, 23 Sep 2003 08:01:17 +0000
  * fmt_ptime.c: calculate UTC localtime correctly.
  * runsv.c: support ./supervise as symbolic link, on dangling symlink create
    link target.
Diffstat:
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/fmt_ptime.c b/src/fmt_ptime.c
@@ -3,8 +3,11 @@
 
 unsigned int fmt_ptime(char *s, struct taia *ta) {
   struct tm *t;
+  unsigned long u;
 
-  if (! (t =localtime((time_t*)&ta->sec.x))) return(0);
+  if (ta->sec.x < 4611686018427387914ULL) return(0); /* impossible? */
+  u =ta->sec.x -4611686018427387914ULL;
+  if (! (t =localtime((time_t*)&u))) return(0);
   fmt_ulong(s, 1900 +t->tm_year);
   s[4] ='-'; fmt_uint0(&s[5], t->tm_mon +1, 2);
   s[7] ='-'; fmt_uint0(&s[8], t->tm_mday, 2);
diff --git a/src/runsv.c b/src/runsv.c
@@ -318,6 +318,7 @@ int ctrl(struct svdir *s, char c) {
 int main(int argc, char **argv) {
   struct stat s;
   int fd;
+  char buf[256];
 
   progname =argv[0];
   if (! argv[1] || argv[2]) usage();
@@ -367,7 +368,21 @@ int main(int argc, char **argv) {
     }
   }
 
-  mkdir("supervise", 0700);
+  if (mkdir("supervise", 0700) == -1) {
+    if ((fd =readlink("supervise", buf, 256)) != -1) {
+      if (fd == 256) {
+	errno =EOVERFLOW;
+	fatal("unable to readlink ./supervise");
+      }
+      buf[fd] =0;
+      mkdir(buf, 0700);
+    }
+    else {
+      if ((errno != ENOENT) && (errno != EINVAL))
+	fatal("unable to readlink ./supervise");
+    }
+  }
+  
   if ((svd[0].fdlock =open_append("supervise/lock")) == -1)
     fatal("unable to open lock");
   if (lock_exnb(svd[0].fdlock) == -1) fatal("unable to lock");