Index: usr.sbin/chroot/chroot.8 =================================================================== --- usr.sbin/chroot/chroot.8 +++ usr.sbin/chroot/chroot.8 @@ -28,7 +28,7 @@ .\" @(#)chroot.8 8.1 (Berkeley) 6/9/93 .\" $FreeBSD$ .\" -.Dd March 14, 2019 +.Dd October 8, 2019 .Dt CHROOT 8 .Os .Sh NAME @@ -62,6 +62,18 @@ Run the command as the .Ar user . .El +.Pp +If the +.Fl u , +.Fl g +or +.Fl G +options are given, +the user, +group and group list of the process are set to +these values after the +.Nm +has taken place. .Sh ENVIRONMENT The following environment variable is referenced by .Nm : Index: usr.sbin/chroot/chroot.c =================================================================== --- usr.sbin/chroot/chroot.c +++ usr.sbin/chroot/chroot.c @@ -101,6 +101,9 @@ if (argc < 1) usage(); + if (chdir(argv[0]) == -1 || chroot(".") == -1) + err(1, "%s", argv[0]); + if (group != NULL) { if (isdigit((unsigned char)*group)) { gid = (gid_t)strtoul(group, &endp, 0); @@ -153,9 +156,6 @@ } } - if (chdir(argv[0]) == -1 || chroot(".") == -1) - err(1, "%s", argv[0]); - if (gids && setgroups(gids, gidlist) == -1) err(1, "setgroups"); if (group && setgid(gid) == -1)