From: Daniel Hokka Zakrisson Date: Wed, 28 Sep 2011 20:33:34 +0000 (+0200) Subject: Dereference the potential symlinks X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?p=util-vserver.git;a=commitdiff_plain;h=710b574e268ecfa9705ac7c73332362da9563fbd Dereference the potential symlinks --- diff --git a/scripts/vserver.functions b/scripts/vserver.functions index ee1751e..afc337a 100644 --- a/scripts/vserver.functions +++ b/scripts/vserver.functions @@ -843,8 +843,11 @@ function prepareInit pushd "$1/vdir" >/dev/null case "$INITSTYLE" in sysv) - { $_FIND var/run ! -type d -print0; \ - $_FIND var/lock ! -type d -print0; } | xargs -0r $_CHROOT_SH rm + local -a dirs=( $($_CHROOT_SH realpath /var/run /var/lock || :) ) + local dir + for dir in dirs; do + $_FIND $dir ! -type d -print0 | xargs -0r $_CHROOT_SH rm + done ;; plain) $_CHROOT_SH rm .autofsck forcefsck 2>/dev/null || : diff --git a/src/chroot-sh.c b/src/chroot-sh.c index 123ba87..d6a710a 100644 --- a/src/chroot-sh.c +++ b/src/chroot-sh.c @@ -228,6 +228,33 @@ execMv(int argc, char *argv[]) return res; } +static int +execRealpath(int argc, char *argv[]) +{ + int res = EXIT_SUCCESS, + i; + + if (argc < 2) { + WRITE_MSG(2, "Need some files to work on for 'realpath' operation; try '--help' for more information\n"); + return wrapper_exit_code; + } + + for (i = 1; i< argc; i++) { + char buf[4096]; + + if (realpath(argv[i], buf) == NULL) { + PERROR_Q(ENSC_WRAPPERS_PREFIX "realpath", argv[i]); + res = EXIT_FAILURE; + } + else { + WRITE_STR(1, buf); + WRITE_MSG(1, "\n"); + } + } + + return res; +} + static struct Command { char const *cmd; int (*handler)(int argc, char *argv[]); @@ -241,6 +268,7 @@ static struct Command { { "chmod", execChmod }, { "link", execLink }, { "mv", execMv }, + { "realpath", execRealpath }, { 0,0 } }; @@ -265,6 +293,7 @@ showHelp() " ... change access permissions of files\n" " link ... create a symbolic link from to \n" " mv ... rename to \n" + " realpath + ... output real path of each \n" "\nPlease report bugs to " PACKAGE_BUGREPORT "\n"); exit(0); }