[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[2618] 2009-10-01 Colin Watson <address@hidden>
From: |
Colin Watson |
Subject: |
[2618] 2009-10-01 Colin Watson <address@hidden> |
Date: |
Thu, 01 Oct 2009 18:22:45 +0000 |
Revision: 2618
http://svn.sv.gnu.org/viewvc/?view=rev&root=grub&revision=2618
Author: cjwatson
Date: 2009-10-01 18:22:43 +0000 (Thu, 01 Oct 2009)
Log Message:
-----------
2009-10-01 Colin Watson <address@hidden>
* util/grub-editenv.c (create_envblk_file): Write new block with a
.new suffix and then rename it into place, to ensure atomic
creation.
Modified Paths:
--------------
trunk/grub2/ChangeLog
trunk/grub2/util/grub-editenv.c
Modified: trunk/grub2/ChangeLog
===================================================================
--- trunk/grub2/ChangeLog 2009-09-28 14:24:43 UTC (rev 2617)
+++ trunk/grub2/ChangeLog 2009-10-01 18:22:43 UTC (rev 2618)
@@ -1,3 +1,9 @@
+2009-10-01 Colin Watson <address@hidden>
+
+ * util/grub-editenv.c (create_envblk_file): Write new block with a
+ .new suffix and then rename it into place, to ensure atomic
+ creation.
+
2009-09-28 Robert Millan <address@hidden>
Do not automatically install headers.
Modified: trunk/grub2/util/grub-editenv.c
===================================================================
--- trunk/grub2/util/grub-editenv.c 2009-09-28 14:24:43 UTC (rev 2617)
+++ trunk/grub2/util/grub-editenv.c 2009-10-01 18:22:43 UTC (rev 2618)
@@ -95,25 +95,31 @@
{
FILE *fp;
char *buf;
+ char *namenew;
buf = malloc (DEFAULT_ENVBLK_SIZE);
if (! buf)
grub_util_error ("out of memory");
- fp = fopen (name, "wb");
+ asprintf (&namenew, "%s.new", name);
+ fp = fopen (namenew, "wb");
if (! fp)
- grub_util_error ("cannot open the file %s", name);
+ grub_util_error ("cannot open the file %s", namenew);
memcpy (buf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1);
memset (buf + sizeof (GRUB_ENVBLK_SIGNATURE) - 1, '#',
DEFAULT_ENVBLK_SIZE - sizeof (GRUB_ENVBLK_SIGNATURE) + 1);
if (fwrite (buf, 1, DEFAULT_ENVBLK_SIZE, fp) != DEFAULT_ENVBLK_SIZE)
- grub_util_error ("cannot write to the file %s", name);
+ grub_util_error ("cannot write to the file %s", namenew);
fsync (fileno (fp));
free (buf);
fclose (fp);
+
+ if (rename (namenew, name) < 0)
+ grub_util_error ("cannot rename the file %s to %s", namenew, name);
+ free (namenew);
}
static grub_envblk_t
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [2618] 2009-10-01 Colin Watson <address@hidden>,
Colin Watson <=