Comment 4 for bug 400409

Revision history for this message
Gert Hulselmans (hulselmansgert) wrote :

mawk 1.33 of Ubuntu 10.10 still has problems with RS="\0".

Part of boot info script where RS="\0" is used:
------------------------------------------------------------------------------------------
get_embedded_menu () {
  local source=$1 titlename=$2;

  # Check if magic bytes that go before the embedded menu, are present.
  offset_menu=$(dd if="${source}" count=4 bs=128k 2>> ${Trash} | hexdump -v -e '/1 "%02x"' | grep -b -o 'b0021ace000000000000000000000000');

  if [ -n ${offset_menu} ] ; then
     # Magic found.
     titlebar_gen "${titlename}" " embedded menu";
     echo '--------------------------------------------------------------------------------' >> "${Log1}";

     # Calcutate the exact offset to the embedded menu.
     offset_menu=$(( ( ${offset_menu%:*} / 2 ) + 16 ));
  dd if="${source}" count=1 skip=1 bs=${offset_menu} 2>> ${Trash} | ${AWK} 'BEGIN { RS="\0" } { if (NR == 1) print $0 }' >> "${Log1}";

     echo '--------------------------------------------------------------------------------' >> "${Log1}";
  fi
}
------------------------------------------------------------------------------------------

I found a version of mawk, maintained by a new developer:
  http://invisible-island.net/mawk/

New mawk changelog (debian patches included + new things):
  http://invisible-island.net/mawk/CHANGES

How to reproduce:
-----------------

Download the development version of boot_info_script:
  wget -O boot_info_script-gawk.sh 'http://bootinfoscript.git.sourceforge.net/git/gitweb.cgi?p=bootinfoscript/bootinfoscript;a=blob_plain;f=boot_info_script.sh;hb=2cc05957ff2c1ac777be114514e57ed54fb22989'

Replace gawk with mawk:
  sed -e 's|gawk|mawk|' boot_info_script-gawk.sh > boot_info_script-mawk-1.3.3.sh

Copy grldr (grub4dos) file to the root of a partition:
http://code.google.com/p/grub4dos-chenall/downloads/list

Compile the new version of mawk and do:
  sed -e 's|gawk|/home/user/mawk-1.3.4-20100625/mawk|' boot_info_script-gawk.sh > boot_info_script-mawk-1.3.4.sh

Run boot_info_script-gawk.sh and boot_info_script-mawk-1.3.3.sh:
  sudo bash boot_info_script-gawk.sh RESULT-gawk.txt
  sudo bash boot_info_script-mawk-1.3.3.sh RESULT-mawk-1.3.3.txt
  sudo bash boot_info_script-mawk-1.3.4.sh RESULT-mawk-1.3.4.txt

Compare the output files:
  diff -u RESULT-mawk-1.3.3.txt RESULT-gawk.txt ==> a lot of differences
  diff -u RESULT-mawk-1.3.4.txt RESULT-gawk.txt ==> no difference

For mawk-1.3.3, you will see something like this:
========================== sdb1/grldr embedded menu: ===========================

--------------------------------------------------------------------------------
pxe detect
configfile
default 0
timeout 1
--------------------------------------------------------------------------------

For gawk and mawk-1.3.4, you will see something like this (correct):
========================== sdb1/grldr embedded menu: ===========================

--------------------------------------------------------------------------------
pxe detect
configfile
default 0
timeout 1

title find /menu.lst, /boot/grub/menu.lst, /grub/menu.lst
        errorcheck off
        configfile /menu.lst || configfile /MENU.LST
        configfile /boot/grub/menu.lst || configfile /BOOT/GRUB/MENU.LST
        configfile /grub/menu.lst || configfile /GRUB/MENU.LST
        find --set-root --ignore-floppies --ignore-cd /menu.lst && configfile /menu.lst
        find --set-root --ignore-floppies --ignore-cd /boot/grub/menu.lst && configfile /boot/grub/menu.lst
        find --set-root --ignore-floppies --ignore-cd /grub/menu.lst && configfile /grub/menu.lst
        errorcheck on
        commandline

title commandline
        commandline

title reboot
        reboot

title halt
        halt

--------------------------------------------------------------------------------

Another bug in mawk is also solved in the mawk 0.3.4 version:
  https://bugs.launchpad.net/ubuntu/+source/mawk/+bug/716920

Can this mawk binary be upgraded or can the default awk been set to gawk if mawk can't be updated?
Shipping a broken awk (mawk v1.33) as default is wrong, IMHO.

mawk 0.3.4 probably solves a lot of other reported bugs too.