author | Olivier Brunel
<jjk@jjacky.com> 2015-02-21 13:41:08 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2015-04-04 12:47:34 UTC |
parent | 6ad7ca187d4031a4b61dd1d0e6ca848b5f166f3d |
doc/aa-pivot.pod | +35 | -0 |
package/modes | +1 | -0 |
package/targets.mak | +3 | -1 |
src/utils/aa-pivot.c | +59 | -0 |
src/utils/deps-exe/aa-pivot | +2 | -0 |
diff --git a/doc/aa-pivot.pod b/doc/aa-pivot.pod new file mode 100644 index 0000000..84706b0 --- /dev/null +++ b/doc/aa-pivot.pod @@ -0,0 +1,35 @@ +=head1 NAME + +aa-pivot - Pivot root directory + +=head1 SYNOPSIS + +B<aa-pivot> I<NEWROOT> I<OLDROOT> + +=head1 OPTIONS + +=over + +=item B<-h, --help> + +Show help screen and exit. + +=item B<-V, --version> + +Show version information and exit. + +=back + +=head1 DESCRIPTION + +B<aa-pivot>(1) moves the root filesystem of the current process to I<OLDROOT> +and makes I<NEWROOT> the new root filesystem. Since it simply calls +B<pivot_root>(2), refer to that man page for further details. + +Note that B<aa-pivot>(1) doesn't change directory nor chroots, so for proper +use, you should first chdir into I<NEWROOT>, call B<aa-pivot>(1) and then chroot +into the current directory, e.g. using B<aa-chroot>(1). For example: + + cd NEWROOT + aa-pivot . OLDROOT + aa-chroot . COMMAND diff --git a/package/modes b/package/modes index fe462f7..6e4ace5 100644 --- a/package/modes +++ b/package/modes @@ -3,3 +3,4 @@ aa-stop 0755 aa-enable 0755 aa-echo 0755 aa-kill 0755 +aa-pivot 0755 diff --git a/package/targets.mak b/package/targets.mak index a4036b1..266e6f8 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -5,12 +5,14 @@ aa-stop LIBEXEC_TARGETS := \ aa-echo \ -aa-kill +aa-kill \ +aa-pivot DOC_TARGETS := \ anopa.1 \ aa-echo.1 \ aa-enable.1 \ +aa-pivot.1 \ aa-start.1 \ aa-stop.1 \ aa-kill.1 \ diff --git a/src/utils/aa-pivot.c b/src/utils/aa-pivot.c new file mode 100644 index 0000000..64ea60f --- /dev/null +++ b/src/utils/aa-pivot.c @@ -0,0 +1,59 @@ + +#include <getopt.h> +#include <skalibs/strerr2.h> +#include <anopa/common.h> + +#ifndef NULL +#define NULL (void *) 0 +#endif + +extern int pivot_root (char const *new_root, char const *old_root); + +static void +dieusage (int rc) +{ + aa_die_usage (rc, "NEWROOT OLDROOT", + " -h, --help Show this help screen and exit\n" + " -V, --version Show version information and exit\n" + ); +} + +int +main (int argc, char * const argv[]) +{ + PROG = "aa-pivot"; + + for (;;) + { + struct option longopts[] = { + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'V' }, + { NULL, 0, 0, 0 } + }; + int c; + + c = getopt_long (argc, argv, "hV", longopts, NULL); + if (c == -1) + break; + switch (c) + { + case 'h': + dieusage (0); + + case 'V': + aa_die_version (); + + default: + dieusage (1); + } + } + argc -= optind; + argv += optind; + + if (argc < 2) + dieusage (1); + + if (pivot_root (argv[0], argv[1]) < 0) + strerr_diefu2sys (2, "pivot into ", argv[0]); + return 0; +} diff --git a/src/utils/deps-exe/aa-pivot b/src/utils/deps-exe/aa-pivot new file mode 100644 index 0000000..30987b4 --- /dev/null +++ b/src/utils/deps-exe/aa-pivot @@ -0,0 +1,2 @@ +${LIBANOPA} +-lskarnet