]>
Commit | Line | Data |
---|---|---|
1dabcd24 KZ |
1 | /* |
2 | * pivot_root.c - Change the root file system | |
3 | * | |
4 | * Copyright (C) 2000 Werner Almesberger | |
5 | * | |
6 | * This file is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This file is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | */ | |
922eafb2 SK |
16 | #include <err.h> |
17 | #include <errno.h> | |
18 | #include <getopt.h> | |
22853e4a | 19 | #include <stdio.h> |
922eafb2 | 20 | #include <stdlib.h> |
d03dd608 KZ |
21 | #include <sys/syscall.h> |
22 | #include <unistd.h> | |
612721db | 23 | |
922eafb2 SK |
24 | #include "c.h" |
25 | #include "nls.h" | |
efb8854f | 26 | #include "closestream.h" |
922eafb2 | 27 | |
d03dd608 | 28 | #define pivot_root(new_root,put_old) syscall(SYS_pivot_root,new_root,put_old) |
22853e4a | 29 | |
6e1eda6f | 30 | static void __attribute__((__noreturn__)) usage(void) |
22853e4a | 31 | { |
6e1eda6f RM |
32 | FILE *out = stdout; |
33 | fputs(USAGE_HEADER, out); | |
922eafb2 SK |
34 | fprintf(out, _(" %s [options] new_root put_old\n"), |
35 | program_invocation_short_name); | |
451dbcfa BS |
36 | |
37 | fputs(USAGE_SEPARATOR, out); | |
38 | fputs(_("Change the root filesystem.\n"), out); | |
39 | ||
6e1eda6f | 40 | fputs(USAGE_OPTIONS, out); |
f45f3ec3 RM |
41 | printf(USAGE_HELP_OPTIONS(16)); |
42 | printf(USAGE_MAN_TAIL("pivot_root(8)")); | |
6e1eda6f | 43 | exit(EXIT_SUCCESS); |
922eafb2 SK |
44 | } |
45 | ||
46 | int main(int argc, char **argv) | |
47 | { | |
48 | int ch; | |
49 | static const struct option longopts[] = { | |
50 | {"version", no_argument, NULL, 'V'}, | |
51 | {"help", no_argument, NULL, 'h'}, | |
52 | {NULL, 0, NULL, 0} | |
53 | }; | |
54 | ||
55 | setlocale(LC_ALL, ""); | |
56 | bindtextdomain(PACKAGE, LOCALEDIR); | |
57 | textdomain(PACKAGE); | |
2c308875 | 58 | close_stdout_atexit(); |
922eafb2 SK |
59 | |
60 | while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) | |
61 | switch (ch) { | |
62 | case 'V': | |
2c308875 | 63 | print_version(EXIT_SUCCESS); |
922eafb2 | 64 | case 'h': |
6e1eda6f | 65 | usage(); |
922eafb2 | 66 | default: |
677ec86c | 67 | errtryhelp(EXIT_FAILURE); |
922eafb2 SK |
68 | } |
69 | ||
6e1eda6f RM |
70 | if (argc != 3) { |
71 | warnx(_("bad usage")); | |
72 | errtryhelp(EXIT_FAILURE); | |
73 | } | |
922eafb2 SK |
74 | if (pivot_root(argv[1], argv[2]) < 0) |
75 | err(EXIT_FAILURE, _("failed to change root from `%s' to `%s'"), | |
76 | argv[1], argv[2]); | |
77 | ||
78 | return EXIT_SUCCESS; | |
22853e4a | 79 | } |