From: Enrico Scholz Date: Tue, 2 Dec 2003 02:17:17 +0000 (+0000) Subject: getRecentName(): return basename of directory but not this of the link anymore X-Git-Tag: VERSION_0_10~1046 X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00c7a18632f3701dedf54f03ddec5ce76aa59aae;p=util-vserver.git getRecentName(): return basename of directory but not this of the link anymore git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@459 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- diff --git a/util-vserver/lib/getvservername.c b/util-vserver/lib/getvservername.c index 0482537..046f828 100644 --- a/util-vserver/lib/getvservername.c +++ b/util-vserver/lib/getvservername.c @@ -28,12 +28,14 @@ #include #include #include +#include static char * getRecentName(char *start, char *end) { char *res = 0; int fd; + char buf[PATH_MAX]; strcpy(end, "/name"); fd = open(start, O_RDONLY); @@ -59,8 +61,21 @@ getRecentName(char *start, char *end) } if (res==0) { + int old_fd = open(".", O_RDONLY); + *end = '\0'; - res = basename(start); + + if (old_fd!=-1 && + chdir(start)!=-1 && + getcwd(buf, sizeof buf)==buf) + start = buf; + + res = basename(start); + + if (old_fd!=-1) { + fchdir(old_fd); + close(old_fd); + } } return strdup(res);