[klibc] [PATCH 4/8] switch_root: add + enhance -h help invocation
maximilian attems
max at stro.at
Wed Jul 13 06:48:29 PDT 2011
Enhance help message by shortening it to explicit variables.
The help invocation goes to stdout, the rest to stderr.
Signed-off-by: maximilian attems <max at stro.at>
---
usr/kinit/switch_root/switch_root.c | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/usr/kinit/switch_root/switch_root.c b/usr/kinit/switch_root/switch_root.c
index f717637..68ef62d 100644
--- a/usr/kinit/switch_root/switch_root.c
+++ b/usr/kinit/switch_root/switch_root.c
@@ -47,12 +47,12 @@
static const char *program;
-static void __attribute__ ((noreturn)) usage(void)
+static void __attribute__ ((noreturn)) usage(FILE *output)
{
- fprintf(stderr,
- "Usage: exec %s [-c consoledev] /real-root /sbin/init [args]\n",
+ fprintf(output,
+ "Usage: exec %s [-c consoledev] <newroot> <init> [args]\n",
program);
- exit(1);
+ exit(output == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
int main(int argc, char *argv[])
@@ -70,22 +70,24 @@ int main(int argc, char *argv[])
/* Parse the command line */
program = argv[0];
- while ((o = getopt(argc, argv, "c:")) != -1) {
+ while ((o = getopt(argc, argv, "c:h")) != -1) {
if (o == 'c')
console = optarg;
+ else if (o == 'h')
+ usage(stdout);
else
- usage();
+ usage(stderr);
}
if (argc - optind < 2)
- usage();
+ usage(stderr);
realroot = argv[optind];
init = argv[optind + 1];
initargs = argv + optind + 1;
if (!*realroot || !*init)
- usage();
+ usage(stderr);
error = switch_root(realroot, console, init, initargs);
--
1.7.5.4
More information about the klibc
mailing list