Optimized /proc/meminfo parsing 1363/head
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 14 Jun 2015 19:21:01 +0000 (21:21 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 14 Jun 2015 19:21:04 +0000 (21:21 +0200)
Suggested by @jow-

Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
net/transmission/files/transmission.init

index d9b52bb67270141493356507f61b66c95f514741..463e8ddb910f2f6d1608c8e8d5cafefa70efeaaa 100644 (file)
@@ -57,7 +57,7 @@ transmission() {
        config_get download_dir "$cfg" 'download_dir' '/var/etc/transmission'
        config_get mem_percentage "$cfg" 'mem_percentage' '50'
 
-       local MEM=$(grep MemTotal /proc/meminfo|sed 's/ \+/ /g'|cut -d ' ' -f 2)
+       local MEM=$(sed -ne 's!^MemTotal:[[:space:]]*\([0-9]*\) kB$!\1!p' /proc/meminfo)
        if test "$MEM" -gt 1;then
                USE=$(expr $MEM \* $mem_percentage \* 10)
        fi