Comment 31 for bug 439784

Revision history for this message
Felix Zielcke (fzielcke) wrote : Re: [Bug 439784] Re: invalid: environment block

Am Dienstag, den 13.10.2009, 18:59 +0000 schrieb Jordan:
> However, it looks like grub-editenv is still not atomic: If you run
> "grub-editenv /boot/grub/grubenv set foo=bar" the first thing it does
> in
> create_env_blk_file() is call fopen( "/boot/grub/grubenv", "wb" )
> truncating the actual file, not a temporary version. So if
> grub-editenv
> crashes between the fopen() and the fwrite() ( admittedly only two
> real
> lines of code ) or somehow fopen() succeeds but fwrite() fails, you
> will
> be left with a zero byte file.
>
> Is there a reason why grub-editenv doesn't write to a temporary file?

Colin already fixed this on 1st October upstream.
Now it's:

  asprintf (&namenew, "%s.new", name);
  fp = fopen (namenew, "wb");
[...]
  fclose (fp);

  if (rename (namenew, name) < 0)
    grub_util_error ("cannot rename the file %s to %s", namenew, name);

That's included in beta4 which is already in Debian.

--
Felix Zielcke
Proud Debian Maintainer and GNU GRUB developer