[Toybox] [CLEANUP] groupdel
Rob Landley
rob at landley.net
Sun Jul 6 21:55:41 PDT 2014
Haven't checked this in yet because it needs more testing, but patch is
attached:
GROUP is always toys.optargs[toys.optc-1] so let's move the getgrnam()
before the two if/else cases so it's not duplicated. (Speaking of which,
in the original code getgrnam() with the corresponding error message
gets called twice in a row?)
First question: are we ok hardwiring in the colon-separated /etc/groups
file? (Because I thought android had some magic database instead?) I'm
going to assume that's ok for now...
I got confused by the man page for getgrnam pointing me to man 5 group,
the second of which said that gr_mem is a comma separated list. But in
the first it's a char *array[] which I _assume_ has a null terminator at
the end, but it never SAYS so. (That's what the man page in Ubuntu 12.04
says, anyway. Maybe it's stale?) That tangent got me to write a
comma_find() function that should at least be useful elsewhere.
The found == -1 part is using xprintf() instead of error_exit() because
it wants to exit with status 0? And to print to stdout instead of
stderr? And while we're at it, removing a user from a group that has no
users in it doesn't produce this message either?
Why do we call getpwnam() at all? Just to confirm it's an actual user?
(Not being there is an error, can it be there and _not_ be a valid user?)
Ooh, _subtle_: due to xexec() not necessarily doing an actual exec()
each time, we should call setpwent() before our first getpwent() because
it's yet more process state that doesn't necessarily get reset between
calls. (Possibly endpwent() should be part of the toy_init() stuff?) Or
maybe endpwent() is better?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: groupdel.patch
Type: text/x-diff
Size: 3541 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20140706/bd4d843f/attachment.patch>
More information about the Toybox
mailing list