'free' Busybox applet "broken"

Well, not broken, but changed, and it breaks some scripts.

The Busybox 'free' applet is used in many scripts. The initramfs has Busybox 1.14.x, recent Woof-built puppies have 1.16.x. For these, this is the output of free:

# free

total used free shared buffers
Mem: 505608 397120 108488 0 26648
Swap: 1012052 0 1012052
Total: 1517660 397120 1120540


However, this is running free in Busybox 1.18.4:

             total         used         free       shared      buffers

Mem: 505608 415620 89988 0 27360
-/+ buffers: 388260 117348
Swap: 1012052 0 1012052


If you parse that output in a pipe in a script, the lack of spaces before "Mem:" and "Swap:", plus no "Total:" line can break a script.

I have fixed the following scripts in Woof to work with old and new versions of free:

/etc/rc.d/rc.shutdown, rc.sysinit
/sbin/pup_event_frontend_d
/usr/sbin/chooselocale, alsaconf


I also fixed the 'init' script in the initramfs, in anticipation of future upgrade of Busybox.

If you are a developer of any application for Puppy and you have used the 'free' applet, please check your script!

I hope that Busybox 1.18.4 has no more surprises!


Posted on 5 Apr 2011, 8:56


Comments:

Posted on 5 Apr 2011, 20:17 by shinobar
freemem
I guess you have already got the solution...
RAMSIZE=`free | grep 'Mem:' | cut -f 2 -d ':' | tr -s ' ' | cut -f 2 -d ' '` #total physical ram (less shared video). # 2Mar11 shinobar




Posted on 5 Apr 2011, 20:20 by anon565
anon565
One shouldn't use "free" output, it results in breakage like that. Parse /proc/meminfo instead.