]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
pivot_root: add version & help option
authorSami Kerola <kerolasa@iki.fi>
Wed, 31 Aug 2011 18:33:27 +0000 (20:33 +0200)
committerSami Kerola <kerolasa@iki.fi>
Sat, 17 Sep 2011 12:25:20 +0000 (14:25 +0200)
Including other necessary changes to usage().

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/pivot_root.8
sys-utils/pivot_root.c

index 2260957e9aa7ec53d615d1577fc6e188d30c16bd..cf1eda64065520dbcd784aa38ea151e11416e6e1 100644 (file)
@@ -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
index f2a6f4834798d9d5a6ad339da67dd9328cb3360f..8669748a1adbb78b36b69ea10fa3dcacfac02887 100644 (file)
  * 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;
 }