Re: [PATCH] mkswap: renovation to error printing, usage and option handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 21, 2011 at 12:00:25AM +0100, Sami Kerola wrote:
> All fprintf(stderr, ...) are converted to use err(), errx(),
> warn() or warnx() functions. A bit rough option handling is
> converted replaced with getopt_long(), and help output and man
> contents are modifed accordingly. Numeric inputs from user are
> scrutinize by strtol() instead of letting atoi() do something
> silly. New function strtoll_or_err() is added to strutils.h.
> Finally few compiler type mismatch warnings where removed by
> using correct data types.

 It would be better to split this patch to three small patches:

    1. err/warn() stuff
    2. getopt_long() implementation
    3. strtol()


> -static void
> -die(const char *str) {
> -	fprintf(stderr, "%s: %s\n", program_name, str);
> -	exit(1);
> +		_("Usage: %s [options] device [size]\n\n"),
> +		program_invocation_short_name);
> +
> +	puts(_(	"  -c, --check         check bad blocks before creating the swap area\n"
> +		"  -f, --force         force; will allow larger swap than device\n"
> +		"  -p, --pagesize      specify page size\n"
> +		"  -L, --label         specify label\n"
> +		"  -v, --swapversion   specify swap-space version\n"
> +		"  -U, --uuid          specify the uuid to use\n"
> +		"  -V, --version       print version and exit\n"));

 Maybe you can add --help, -h too.

> +	warnx(_("%s: warning: don't erase bootbits sectors"), devname);
> +	if (type) {
> +		fprintf(stderr,
> +			_("        (%s partition table detected). "),
> +			type);
> +	} else if (whole) {
> +		fprintf(stderr,
> +			_("        on whole disk. "));
> +	} else {
> +		fprintf(stderr,
> +			_("        (compiled without libblkid). "));
> +	}

 Please, don't use unnecessary braces.

> +		case 'U':
>  #ifdef HAVE_LIBUUID
> -					opt_uuid = argv[i]+2;
> -					if (!*opt_uuid && i+1 < argc)
> -						opt_uuid = argv[++i];
> +			opt_uuid = optarg;
>  #else
> -					fprintf(stderr, _("%1$s: warning: ignore -U (UUIDs are unsupported by %1$s)\n"),
> -						program_name);
> +			errx(_("UUIDs are unsupported"));

 Unacceptable, see the original code, we cannot call exit(). Use:

            warnx()

    Karel


-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
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


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux