summaryrefslogtreecommitdiffstats
path: root/sys-utils/pivot_root.c
diff options
context:
space:
mode:
authorSami Kerola2011-08-31 20:33:27 +0200
committerSami Kerola2011-09-17 14:25:20 +0200
commit922eafb28ab4331e7183901a1eb2e5e2269629db (patch)
tree8ad1d24124ab6412088aac49df24f0e973f56ba4 /sys-utils/pivot_root.c
parentipcs: comment & white space clean up (diff)
downloadkernel-qcow2-util-linux-922eafb28ab4331e7183901a1eb2e5e2269629db.tar.gz
kernel-qcow2-util-linux-922eafb28ab4331e7183901a1eb2e5e2269629db.tar.xz
kernel-qcow2-util-linux-922eafb28ab4331e7183901a1eb2e5e2269629db.zip
pivot_root: add version & help option
Including other necessary changes to usage(). Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/pivot_root.c')
-rw-r--r--sys-utils/pivot_root.c60
1 files changed, 50 insertions, 10 deletions
diff --git a/sys-utils/pivot_root.c b/sys-utils/pivot_root.c
index f2a6f4834..8669748a1 100644
--- a/sys-utils/pivot_root.c
+++ b/sys-utils/pivot_root.c
@@ -13,21 +13,61 @@
* 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;
}