Add megabytes display format to free
Matthew Hiles
matthew.hiles at gmail.com
Tue Nov 18 11:01:59 PST 2008
Hello Busybox mailing list:
I just joined the mailing list because I'm interested in helping out
with busybox.
I've been reading TODOs and the bug tracker to find out what I can do.
I'm not sure how opposed everyone is to feature creep, as I'm sure
it's an issue, but one thing that always bothered me when using a
busybox system was the lack of the -m option for free.
I also checked out the TODO in free about fixing the integer overflow
on systems with >4gb of RAM. I tried busybox's free command on a 6 GB
system and it did not overflow--it showed exactly the same output as
the in-distro free command. Does anyone know what's up with that?
The following patch allows free to display in megabytes.
--- procps/free.c 2008-11-18 09:08:29.000000000 -0500
+++ procps/free.c 2008-11-18 08:06:16.000000000 -0500
@@ -46,8 +46,21 @@
info.bufferram*=info.mem_unit;
}
- if (argc > 1 && *argv[1] == '-')
- bb_show_usage();
+ if ( argc > 1 )
+ {
+ if ( argv[1][1] == 'm' ) /* I see no point invoking getopt */
+ { /* or even strcmp for one option */
+ /* give output in megabytes */
+ info.totalram /= 1024;
+ info.freeram /= 1024;
+ info.sharedram /= 1024;
+ info.bufferram /= 1024;
+#ifndef __uClinux__
+ info.totalswap /= 1024;
+ info.freeswap /= 1024;
+#endif
+ } else bb_show_usage();
+ }
printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free",
"shared", "buffers");
More information about the busybox
mailing list