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