Signed-off-by: Sami Kerola <kerolasa@xxxxxx> --- sys-utils/switch_root.c | 24 ++++++++++++++++++------ 1 file 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); -- 2.12.2 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html