On 06/09/2009 04:48 PM, Karel Zak wrote: > --- > sys-utils/switch_root.c | 43 ++++++++++++++++++++----------------------- > 1 files changed, 20 insertions(+), 23 deletions(-) > [...] > -static void usage(FILE *output) > +static void usage() > { > - fprintf(output, "usage: %s <newrootdir> <init> <args to init>\n", > + fprintf(stderr, "usage: %s <newrootdir> <init> <args to init>\n", > program_invocation_short_name); > - if (output == stderr) > - exit(EXIT_FAILURE); > - exit(EXIT_SUCCESS); > + exit(EXIT_FAILURE); > } I think it'd be better to leave this as the old way and add --help parsing in main. > > int main(int argc, char *argv[]) > { > - char *newroot = argv[1]; > - char *init = argv[2]; > - char **initargs = &argv[2]; > + char *newroot, *init, **initargs; > > - if (newroot == NULL || newroot[0] == '\0' || > - init == NULL || init[0] == '\0' ) { > - usage(stderr); > - } > + if (argc < 3) > + usage(); > + > + newroot = argv[1]; > + init = argv[2]; > + initargs = &argv[2]; > + > + if (!*newroot || !*init) > + usage(); > > if (switchroot(newroot)) > errx(EXIT_FAILURE, "failed. Sorry."); > > - if (access(initargs[0], X_OK)) > - warn("cannot access %s", initargs[0]); > + if (access(init, X_OK)) > + warn("cannot access %s", init); > > /* get session leader */ > setsid(); > + > /* set controlling terminal */ > - ioctl (0, TIOCSCTTY, 1); > + if (ioctl (0, TIOCSCTTY, 1)) > + warn("failed to TIOCSCTTY"); > > - execv(initargs[0], initargs); > - err(EXIT_FAILURE, "failed to execute %s", initargs[0]); > + execv(init, initargs); > + err(EXIT_FAILURE, "failed to execute %s", init); > } This all looks fine (though one could argue all but the ioctl() bit is unnecessary...) -- Peter I hope you know that this will go down on your permanent record. -- To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html