Index: realpath.1 =================================================================== RCS file: /usr/repo/src/bin/realpath/realpath.1,v retrieving revision 1.10 diff -u -p -r1.10 realpath.1 --- realpath.1 16 Jan 2005 16:41:58 -0000 1.10 +++ realpath.1 13 Jan 2007 10:06:33 -0000 @@ -33,7 +33,7 @@ .\" From: src/bin/pwd/pwd.1,v 1.11 2000/11/20 11:39:39 ru Exp .\" $FreeBSD: src/bin/realpath/realpath.1,v 1.10 2005/01/16 16:41:58 ru Exp $ .\" -.Dd November 24, 2000 +.Dd January 11, 2006 .Dt REALPATH 1 .Os .Sh NAME @@ -41,6 +41,7 @@ .Nd return resolved physical path .Sh SYNOPSIS .Nm +.Op Fl c chpath .Ar path .Sh DESCRIPTION The @@ -55,9 +56,21 @@ and .Pa /../ in .Ar path . +If the +.Fl c +option is given, the +.Nm +utility will +.Xr chroot 2 +to the +.Ar chpath +directory before resolving +.Ar path . .Sh EXIT STATUS .Ex -std .Sh SEE ALSO +.Xr chroot 1 , +.Xr chroot 2 , .Xr realpath 3 .Sh HISTORY The Index: realpath.c =================================================================== RCS file: /usr/repo/src/bin/realpath/realpath.c,v retrieving revision 1.6 diff -u -p -r1.6 realpath.c --- realpath.c 6 Apr 2004 20:06:50 -0000 1.6 +++ realpath.c 11 Jan 2007 19:37:29 -0000 @@ -43,13 +43,30 @@ int main(int argc, char *argv[]) { char buf[PATH_MAX]; - char *p; + char *p, *chpath; + int ch; - if (argc == 2) { - if ((p = realpath(argv[1], buf)) == NULL) - err(1, "%s", buf); - } else + chpath = NULL; + while ((ch = getopt(argc, argv, "c:")) != -1) { + switch ((char)ch) { + case 'c': + chpath = optarg; + break; + case '?': + default: + usage(); + } + } + argc -= optind; + argv += optind; + + if (argc != 1) usage(); + + if (chpath != NULL && chroot(chpath) == -1) + err(1, "chroot(%s)", chpath); + if ((p = realpath(argv[0], buf)) == NULL) + err(1, "%s", buf); (void)printf("%s\n", p); exit(0); }