[parted-devel] [PATCH] Diagnose invalid command arguments.

Otavio Salvador otavio at debian.org
Fri May 25 21:49:28 UTC 2007


Jim Meyering <jim at meyering.net> writes:

> This started because I objected to parted failing with no diagnostic
> when given an invalid file system type:
>
>     $ /sbin/parted -s $dev mklabel loop mkpartfs hfsplus 0 1.4
>     WARNING: You are not superuser.  Watch out for permissions.
>     [Exit 1]
>
> With the changes below, it does this:
>
>     $ ./parted -s $dev mklabel loop mkpartfs hfsplus 0 1.4
>     ./parted: invalid token: hfsplus
>     [Exit 1]
>
> The following may look like a simple change, but looks are deceptive...
> For example, if you try to diagnose via ped_exception_throw instead
> of "error", you'll find that the mere fact of diagnosing the problem
> introduces new ones because of how the exception handler manipulates the
> global command line buffer containing the token we're complaining about.
>
> But this isn't library code, so using error() is fine.
>
> 	Diagnose invalid command arguments.
> 	When a command argument doesn't match the expected candidate values,
> 	parted would silently exit (in script mode) or simply act as if that
> 	value and any following ones had not been specified (in interactive
> 	mode).  With this change, it complains about the "invalid token",
> 	and in script mode (where there hasn't been a prompt to give context)
> 	sometimes tells what type of token it was expecting.
> 	* parted/ui.c: Include "error.h".
> 	(command_line_get_word): If the user's "token" wasn't a good enough
> 	match, give a diagnostic.  In script mode, return NULL so that the
> 	callers can give additional information.
> 	* tests/t2000-mkfs.sh: New test for the above.
> 	* tests/t0000-basic.sh: Expect the new diagnostic when "msdos" is
> 	treated as an unrecognized first token after "mklabel".  This happens
> 	when trying to label a disk that already has a label.
> 	* tests/t1100-busy-label.sh: Likewise.

Fully ack! :-)

-- 
        O T A V I O    S A L V A D O R
---------------------------------------------
 E-mail: otavio at debian.org      UIN: 5906116
 GNU/Linux User: 239058     GPG ID: 49A5F855
 Home Page: http://otavio.ossystems.com.br
---------------------------------------------
"Microsoft sells you Windows ... Linux gives
 you the whole house."



More information about the parted-devel mailing list