1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

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 \ unmount \
MANPAGES8=\ MANPAGES8=\
chroot.8 \
unmount.8 \ unmount.8 \
all: $(BINARIES) $(SBINS) 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/stat.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <err.h>
#include <errno.h> #include <errno.h>
#include <error.h> #include <error.h>
#include <fcntl.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 char* mount_point_dev;
static void unmount_handler(int signum) static void unmount_handler(int signum)
@ -71,7 +62,6 @@ static void unmount_handler(int signum)
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
bool devices = false; bool devices = false;
const char* argv0 = argv[0];
for ( int i = 1; i < argc; i++ ) for ( int i = 1; i < argc; i++ )
{ {
const char* arg = argv[i]; const char* arg = argv[i];
@ -87,21 +77,13 @@ int main(int argc, char* argv[])
{ {
case 'd': devices = true; break; case 'd': devices = true; break;
default: default:
fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c); errx(1, "unknown option -- '%c'", c);
help(stderr, argv0);
exit(1);
} }
} }
else if ( !strcmp(arg, "--help") ) else if ( !strcmp(arg, "--devices") )
help(stdout, argv0), exit(0); devices = true;
else if ( !strcmp(arg, "--version") )
version(stdout, argv0), exit(0);
else else
{ errx(1, "unknown option: %s", arg);
fprintf(stderr, "%s: unknown option: %s\n", argv0, arg);
help(stderr, argv0);
exit(1);
}
} }
compact_arguments(&argc, &argv); compact_arguments(&argc, &argv);