[PATCH] addgroup code cleanup, size reduction and feature enhancement

Tito farmatito at tiscali.it
Tue Mar 27 20:44:04 UTC 2007


Hi to all,

this patch cleans up addgroup, reduces the size, removes a crippled feature,
and re-adds it as optional fully functional feature.

1) code cleanup and size reduction (with make defconfig; make):

scripts/bloat-o-meter busybox_old busybox_unstripped
function                                             old     new   delta
packed_usage                             22068   22058     -10
bb_internal_fgetgrent_r                      51          -      -51
.rodata                                      124387 124323     -64
addgroup_main                               380       237   -143
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/3 up/down: 0/-268)           Total: -268 bytes
 
The size reduction was achieved through an almost complete rewrite of
the functions group_study and addgroup and a tighter integration
with libbb.

2) crippled function removal:
the current addgroup applet when called with 2 arguments
permits only to add an existing user to an still to be created group.
This seems to me a crippled behavior as it could be used just one time
at group creation time: 

root at localhost:~/Desktop/busybox.new# ./busybox_old addgroup prova tito
root at localhost:~/Desktop/busybox.new# ./busybox_old addgroup prova dina
addgroup: prova: group already in use

3) the above mentioned feature was re-added as optional
    function enabled by ENABLE_FEATURE_ADDUSER_TO_GROUP.
    Now    if  called  with two non-option arguments, addgroup will add an existing
    user to an existing group like the full blown addgroup does (at least on my system).

	addgroup dina prova
	Adding user `dina' to group `prova'...
	Done.

	./busybox_unstripped addgroup prova
	./busybox_unstripped addgroup dina prova
	./busybox_unstripped addgroup tito prova

	prova:x:1004:dina,tito
	prova:!::dina,tito

Bloat-o-meter says:

scripts/bloat-o-meter busybox_old busybox_unstripped
function                                             old       new   delta
add_user_to_group                                -       237  +237
packed_usage                               22068  22058      -10
addgroup_main                                 380     354       -26
.rodata                                        124387 124355     -32
bb_internal_fgetgrent_r                       51            -     -51
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/3 up/down: 237/-119)          Total: 118 bytes

This feature is turned of by default.

This patch is tested and seems to work as expected.
Comments and critics are as always welcome.
Please apply if you like it.

Ciao,
Tito
-------------- next part --------------
A non-text attachment was scrubbed...
Name: addgroup.patch
Type: text/x-diff
Size: 6591 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20070327/1f19abcd/attachment-0002.bin 


More information about the busybox mailing list