From 207f554b11455f2b82f0562e65ad968087e427eb Mon Sep 17 00:00:00 2001 From: Daniel Roskams Date: Wed, 12 Oct 2016 20:05:40 +0800 Subject: [PATCH] Document chroot(8). --- utils/Makefile | 1 + utils/chroot.8 | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ utils/chroot.c | 28 +++++-------------------- 3 files changed, 61 insertions(+), 23 deletions(-) create mode 100644 utils/chroot.8 diff --git a/utils/Makefile b/utils/Makefile index 3a5477bd..fb58a6e8 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -84,6 +84,7 @@ chroot \ unmount \ MANPAGES8=\ +chroot.8 \ unmount.8 \ all: $(BINARIES) $(SBINS) diff --git a/utils/chroot.8 b/utils/chroot.8 new file mode 100644 index 00000000..851efe15 --- /dev/null +++ b/utils/chroot.8 @@ -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 diff --git a/utils/chroot.c b/utils/chroot.c index f30e61b4..09d57077 100644 --- a/utils/chroot.c +++ b/utils/chroot.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -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);