git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@459
94cd875c-1c1d-0410-91d2-
eb244daf1a30
#include <errno.h>
#include <libgen.h>
#include <unistd.h>
+#include <limits.h>
static char *
getRecentName(char *start, char *end)
{
char *res = 0;
int fd;
+ char buf[PATH_MAX];
strcpy(end, "/name");
fd = open(start, O_RDONLY);
}
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);