summaryrefslogtreecommitdiffstats
path: root/sys-utils/switch_root.c
diff options
context:
space:
mode:
authorSami Kerola2017-05-09 20:10:51 +0200
committerKarel Zak2017-05-10 10:53:28 +0200
commit105bb8572f5eddd3e196363ee18a0d210990905f (patch)
treea3927e21aade6e9c91cceacb0657405e2b22c5bf /sys-utils/switch_root.c
parentvipw: use getopt_long() to parse options (diff)
downloadkernel-qcow2-util-linux-105bb8572f5eddd3e196363ee18a0d210990905f.tar.gz
kernel-qcow2-util-linux-105bb8572f5eddd3e196363ee18a0d210990905f.tar.xz
kernel-qcow2-util-linux-105bb8572f5eddd3e196363ee18a0d210990905f.zip
switch_root: use getopt_long() to parse options
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/switch_root.c')
-rw-r--r--sys-utils/switch_root.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/sys-utils/switch_root.c b/sys-utils/switch_root.c
index 2b42ddf85..7bd07783e 100644
--- a/sys-utils/switch_root.c
+++ b/sys-utils/switch_root.c
@@ -33,6 +33,7 @@
#include <errno.h>
#include <ctype.h>
#include <dirent.h>
+#include <getopt.h>
#include "c.h"
#include "nls.h"
@@ -217,14 +218,25 @@ static void __attribute__((__noreturn__)) usage(FILE *output)
int main(int argc, char *argv[])
{
char *newroot, *init, **initargs;
+ int c;
+ static const struct option longopts[] = {
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+ };
+
atexit(close_stdout);
- if (argv[1] && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")))
- usage(stdout);
- if (argv[1] && (!strcmp(argv[1], "--version") || !strcmp(argv[1], "-V"))) {
- printf(UTIL_LINUX_VERSION);
- return EXIT_SUCCESS;
- }
+ while ((c = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
+ switch (c) {
+ case 'V':
+ printf(UTIL_LINUX_VERSION);
+ return EXIT_SUCCESS;
+ case 'h':
+ usage(stdout);
+ default:
+ errtryhelp(EXIT_FAILURE);
+ }
if (argc < 3)
usage(stderr);