Bug#254475: The bug is still there in 0.97-21

dorileo ldorileo at gmail.com
Wed Mar 7 16:45:52 CET 2007


Hi Friedemann

Your changes has been applied to grub and is going to be present in the next 
release. Thanks for your help on it.

--
Dorileo

On Sunday 28 January 2007 20:35, Friedemann Baitinger wrote:
> sorry for the noise ... but I have to report additional findings as the
> patch above really has some side-effects.
>
> The previous version of my patch opened the /boot/grub/defaults file in
> "r+" mode so I could read the initial values, do a "rewind(fp)" and
> write the new values. Unfortunately the "grub-reboot" script keeps to
> append new comments and disclaimer lines, effectively making the file
> grow and grow.
>
> So the only thing that really works here is to open the file read-only,
> read the initial values, then close it and reopen it in "w" mode which
> truncates it to zero before we write to it. Now we write the new "x:y"
> values and let the script to its job of adding comment lines and
> disclaimers.
>
> Also, the original code added a newline where "grub-set-default" didn't
> have one. Not a big deal, shouldn't change the functionality but it
> isn't the same layout as before anymore.
>
> To make a long story short, here is a new patch which *should* do the
> job now as expected:
>
> --- builtins.c.orig     2007-01-28 16:46:18.000000000 +0100
> +++ builtins.c  2007-01-28 21:25:29.000000000 +0100
> @@ -3574,16 +3574,17 @@
>     default_file[i] = 0;
>     grub_strncat (default_file + i, "default", DEFAULT_FILE_BUFLEN - i);
>
> -  if(!(fp = fopen(default_file,"w")))
> +  if(!(fp = fopen(default_file,"r")))
>       {
>         errnum = ERR_READ;
>         goto fail;
>       }
>
> -  read(&line, -1);
> -
> +  fgets(line, bytes, fp);
> +  fclose(fp);
> +
>     sscanf(line, "%d:%d", &curr_prev_default, &curr_default);
> -
> +
>     if(curr_default != -1)
>       new_prev_default = curr_default;
>     else
> @@ -3595,10 +3596,16 @@
>       }
>
>     if(once_only)
> -    sprintf(buf, "%d:%d\n", new_prev_default, new_default);
> +    sprintf(buf, "%d:%d", new_prev_default, new_default);
>     else
> -    sprintf(buf, "%d\n", new_default);
> -
> +    sprintf(buf, "%d", new_default);
> +
> +  if(!(fp = fopen(default_file,"w")))
> +    {
> +      errnum = ERR_READ;
> +      goto fail;
> +    }
> +
>     fprintf(fp, buf);
>
>   fail:

-- 
Dorileo




More information about the Pkg-grub-devel mailing list