1From 7ee585cab1d5b68f804a5601a66ae87799c8a7c3 Mon Sep 17 00:00:00 2001 2From: Gerrit Pape <pape@smarden.org> 3Date: Sun, 24 Feb 2008 10:54:26 +0000 4Subject: [PATCH] supervise.c: ./supervise may be a symlink, if it's dangling, create link target 5 6--- 7 daemontools-0.76/src/supervise.c | 17 ++++++++++++++++- 8 1 files changed, 16 insertions(+), 1 deletions(-) 9 10diff --git daemontools-0.76.orig/src/supervise.c daemontools-0.76/src/supervise.c 11index 2482ad2..f43cabf 100644 12--- daemontools-0.76.orig/src/supervise.c 13+++ daemontools-0.76/src/supervise.c 14@@ -208,6 +208,8 @@ void doit(void) 15 int main(int argc,char **argv) 16 { 17 struct stat st; 18+ int r; 19+ char buf[256]; 20 21 dir = argv[1]; 22 if (!dir || argv[2]) 23@@ -232,7 +234,20 @@ int main(int argc,char **argv) 24 if (errno != error_noent) 25 strerr_die4sys(111,FATAL,"unable to stat ",dir,"/down: "); 26 27- mkdir("supervise",0700); 28+ if (mkdir("supervise",0700) == -1) { 29+ if ((r = readlink("supervise", buf, 256)) != -1) { 30+ if (r == 256) { 31+ errno = EOVERFLOW; 32+ strerr_die1sys(111,"unable to readlink ./supervise: "); 33+ } 34+ buf[r] = 0; 35+ mkdir(buf, 0700); 36+ } 37+ else { 38+ if ((errno != ENOENT) && (errno != EINVAL)) 39+ strerr_die1sys(111, "unable to readlink ./supervise: "); 40+ } 41+ } 42 fdlock = open_append("supervise/lock"); 43 if ((fdlock == -1) || (lock_exnb(fdlock) == -1)) 44 strerr_die4sys(111,FATAL,"unable to acquire ",dir,"/supervise/lock: "); 45-- 461.5.4.2 47 48