diff --git a/src/afsd/afsd.c b/src/afsd/afsd.c index 147865105f..dd63963c5c 100644 --- a/src/afsd/afsd.c +++ b/src/afsd/afsd.c @@ -1684,8 +1684,16 @@ rmtsysd_thread(void *rock) } #endif /* !UKERNEL */ -int -mainproc(struct cmd_syndesc *as, void *arock) +/** + * Check the command line and cacheinfo options. + * + * @param[in] as parsed command line arguments + * + * @note Invokes the shutdown syscall and exits with 0 when + * -shutdown is given. + */ +static int +CheckOptions(struct cmd_syndesc *as) { afs_int32 code; /*Result of fork() */ #ifdef AFS_SUN5_ENV @@ -2520,7 +2528,7 @@ afsd_init(void) { struct cmd_syndesc *ts; - ts = cmd_CreateSyntax(NULL, mainproc, NULL, 0, "start AFS"); + ts = cmd_CreateSyntax(NULL, NULL, NULL, 0, "start AFS"); /* 0 - 10 */ cmd_AddParmAtOffset(ts, OPT_blocks, "-blocks", CMD_SINGLE, @@ -2618,10 +2626,24 @@ afsd_init(void) "Set inode number calculation method"); } +/** + * Parse and check the command line options. + * + * @note The -shutdown command is handled in CheckOptions(). + */ int afsd_parse(int argc, char **argv) { - return cmd_Dispatch(argc, argv); + struct cmd_syndesc *ts = NULL; + int code; + + code = cmd_Parse(argc, argv, &ts); + if (code) { + return code; + } + code = CheckOptions(ts); + cmd_FreeOptions(&ts); + return code; } /** diff --git a/src/afsd/afsd_fuse.c b/src/afsd/afsd_fuse.c index 7b3968b79d..6c03476e7c 100644 --- a/src/afsd/afsd_fuse.c +++ b/src/afsd/afsd_fuse.c @@ -608,7 +608,18 @@ main(int argc, char **argv) split_args(&args); - uafs_ParseArgs(afsd_args.argc, afsd_args.argv); + code = uafs_ParseArgs(afsd_args.argc, afsd_args.argv); + if (code != 0) { + /* + * split_args() failed to populate afds_args correctly. + * We do not not bother to check for CMD_HELP here, since + * split_args() exits when -help is given. + */ + fprintf(stderr, + "afsd.fuse: Could not parse command line options; code %d\n", + code); + return 1; + } /* pass "-- /mount/dir" to fuse to specify dir to mount; "--" is * just to make sure fuse doesn't interpret the mount dir as a flag diff --git a/src/afsd/afsd_kernel.c b/src/afsd/afsd_kernel.c index f3cfab6c10..5799f3dd0f 100644 --- a/src/afsd/afsd_kernel.c +++ b/src/afsd/afsd_kernel.c @@ -570,7 +570,10 @@ main(int argc, char **argv) afsd_init(); code = afsd_parse(argc, argv); - if (code) { + if (code == CMD_HELP) { + return 0; /* Displaying help is not an error. */ + } + if (code != 0) { return -1; }