getRecentName(): use realpath(3) instead of errorprone 'chdir()' calls
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Sat, 8 May 2004 01:27:25 +0000 (01:27 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Sat, 8 May 2004 01:27:25 +0000 (01:27 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1543 94cd875c-1c1d-0410-91d2-eb244daf1a30

util-vserver/lib/getvservername.c

index 046f828..212c9df 100644 (file)
@@ -61,21 +61,12 @@ getRecentName(char *start, char *end)
   }
 
   if (res==0) {
-    int                old_fd = open(".", O_RDONLY);
-
     *end = '\0';
-    
-    if (old_fd!=-1 &&
-       chdir(start)!=-1 &&
-       getcwd(buf, sizeof buf)==buf)
-      start = buf;
-
-    res = basename(start);
+    res  = realpath(start, buf);
+    //printf("start='%s', res='%s'\n", start,res);
+    if (res==0) res = start;
 
-    if (old_fd!=-1) {
-      fchdir(old_fd);
-      close(old_fd);
-    }
+    res = basename(res);
   }
 
   return strdup(res);