summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys-utils/pivot_root.81
-rw-r--r--sys-utils/pivot_root.c60
2 files changed, 51 insertions, 10 deletions
diff --git a/sys-utils/pivot_root.8 b/sys-utils/pivot_root.8
index 2260957e9..cf1eda640 100644
--- a/sys-utils/pivot_root.8
+++ b/sys-utils/pivot_root.8
@@ -61,6 +61,7 @@ exec chroot . sh -c 'umount /old_root; exec /sbin/init' \\
.BR chroot (1),
.BR mount (8),
.BR pivot_root (2),
+.BR switch_root (8),
.BR umount (8)
.SH AVAILABILITY
The pivot_root command is part of the util-linux package and is available from
diff --git a/sys-utils/pivot_root.c b/sys-utils/pivot_root.c
index f2a6f4834..8669748a1 100644
--- a/sys-utils/pivot_root.c
+++ b/sys-utils/pivot_root.c
@@ -13,21 +13,61 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
+#include <err.h>
+#include <errno.h>
+#include <getopt.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>
+#include "c.h"
+#include "nls.h"
+
#define pivot_root(new_root,put_old) syscall(SYS_pivot_root,new_root,put_old)
-int main(int argc, const char **argv)
+static void __attribute__ ((__noreturn__)) usage(FILE * out)
{
- if (argc != 3) {
- fprintf(stderr, "usage: %s new_root put_old\n", argv[0]);
- return 1;
- }
- if (pivot_root(argv[1], argv[2]) < 0) {
- perror("pivot_root");
- return 1;
- }
- return 0;
+ fprintf(out, USAGE_HEADER);
+ fprintf(out, _(" %s [options] new_root put_old\n"),
+ program_invocation_short_name);
+ fprintf(out, USAGE_HELP);
+ fprintf(out, USAGE_VERSION);
+ fprintf(out, USAGE_BEGIN_TAIL);
+ fprintf(out, USAGE_MAN_TAIL, "pivot_root(8)");
+ exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+int main(int argc, char **argv)
+{
+ int ch;
+ static const struct option longopts[] = {
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+ };
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+
+ while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
+ switch (ch) {
+ case 'V':
+ printf(UTIL_LINUX_VERSION);
+ return EXIT_SUCCESS;
+ case 'h':
+ usage(stdout);
+ default:
+ usage(stderr);
+ }
+
+ if (argc != 3)
+ usage(stderr);
+
+ if (pivot_root(argv[1], argv[2]) < 0)
+ err(EXIT_FAILURE, _("failed to change root from `%s' to `%s'"),
+ argv[1], argv[2]);
+
+ return EXIT_SUCCESS;
}