2 * SPDX-License-Identifier: GPL-2.0-or-later
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.
9 * Copyright (C) 2000 Werner Almesberger
16 #include <sys/syscall.h>
21 #include "closestream.h"
23 #define pivot_root(new_root,put_old) syscall(SYS_pivot_root,new_root,put_old)
25 static void __attribute__((__noreturn__
)) usage(void)
28 fputs(USAGE_HEADER
, out
);
29 fprintf(out
, _(" %s [options] new_root put_old\n"),
30 program_invocation_short_name
);
32 fputs(USAGE_SEPARATOR
, out
);
33 fputs(_("Change the root filesystem.\n"), out
);
35 fputs(USAGE_OPTIONS
, out
);
36 fprintf(out
, USAGE_HELP_OPTIONS(16));
37 fprintf(out
, USAGE_MAN_TAIL("pivot_root(8)"));
41 int main(int argc
, char **argv
)
44 static const struct option longopts
[] = {
45 {"version", no_argument
, NULL
, 'V'},
46 {"help", no_argument
, NULL
, 'h'},
50 setlocale(LC_ALL
, "");
51 bindtextdomain(PACKAGE
, LOCALEDIR
);
53 close_stdout_atexit();
55 while ((ch
= getopt_long(argc
, argv
, "Vh", longopts
, NULL
)) != -1)
58 print_version(EXIT_SUCCESS
);
62 errtryhelp(EXIT_FAILURE
);
66 warnx(_("bad usage"));
67 errtryhelp(EXIT_FAILURE
);
69 if (pivot_root(argv
[1], argv
[2]) < 0)
70 err(EXIT_FAILURE
, _("failed to change root from `%s' to `%s'"),