Document chroot(8).

This commit is contained in:
Daniel Roskams 2016-10-12 20:05:40 +08:00
parent 27677f2f9a
commit 207f554b11
3 changed files with 61 additions and 23 deletions

View File

@ -84,6 +84,7 @@ chroot \
unmount \
MANPAGES8=\
chroot.8 \
unmount.8 \
all: $(BINARIES) $(SBINS)

55
utils/chroot.8 Normal file
View File

@ -0,0 +1,55 @@
.Dd September 29, 2016
.Dt CHROOT 8
.Os
.Sh NAME
.Nm chroot
.Nd run command with changed root directory
.Sh SYNOPSIS
.Nm
.Op Fl d
.Ar newroot
.Oo
.Ar command
.Oo
.Ar arguments ...
.Oc
.Oc
.Sh DESCRIPTION
.Nm
changes the root directory to
.Ar newroot
and runs
.Ar command
with the given
.Ar arguments .
.Ar command
defaults to
.Xr sh 1 .
The working directory for
.Ar command
is changed to
.Pa / .
.Pp
The options are as follows:
.Bl -tag -width "12345678"
.It Fl d, Fl \-devices
Mount
.Pa /dev
from the host system into the
.Pa /dev
inside
.Ar newroot .
The mountpoint is removed when
.Ar command
completes. This option is useful for running installations.
.El
.Sh ENVIRONMENT
The environment is preserved.
.Ev PATH
is used to search for
.Ar command .
.Sh EXIT STATUS
.Nm
will exit 0 on success and non-zero otherwise.
.Sh SEE ALSO
.Xr chroot 2

View File

@ -21,6 +21,7 @@
#include <sys/stat.h>
#include <sys/wait.h>
#include <err.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
@ -45,16 +46,6 @@ static void compact_arguments(int* argc, char*** argv)
}
}
static void help(FILE* fp, const char* argv0)
{
fprintf(fp, "Usage: %s [OPTION]... ROOT [CMD] [ARGUMENT...]\n", argv0);
}
static void version(FILE* fp, const char* argv0)
{
fprintf(fp, "%s (Sortix) %s\n", argv0, VERSIONSTR);
}
static char* mount_point_dev;
static void unmount_handler(int signum)
@ -71,7 +62,6 @@ static void unmount_handler(int signum)
int main(int argc, char* argv[])
{
bool devices = false;
const char* argv0 = argv[0];
for ( int i = 1; i < argc; i++ )
{
const char* arg = argv[i];
@ -87,21 +77,13 @@ int main(int argc, char* argv[])
{
case 'd': devices = true; break;
default:
fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c);
help(stderr, argv0);
exit(1);
errx(1, "unknown option -- '%c'", c);
}
}
else if ( !strcmp(arg, "--help") )
help(stdout, argv0), exit(0);
else if ( !strcmp(arg, "--version") )
version(stdout, argv0), exit(0);
else if ( !strcmp(arg, "--devices") )
devices = true;
else
{
fprintf(stderr, "%s: unknown option: %s\n", argv0, arg);
help(stderr, argv0);
exit(1);
}
errx(1, "unknown option: %s", arg);
}
compact_arguments(&argc, &argv);