aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Hatle <mark.hatle@windriver.com>2010-06-14 12:44:31 -0500
committerMark Hatle <mark.hatle@windriver.com>2010-07-22 18:21:56 -0500
commit8bcdedc34ed809dc0582d10fb25c97ff610b1067 (patch)
treea786b009693801fb759ea4977654b3349db37166
parent8871f1564992fdb404a64a4ea16741aeaa724285 (diff)
downloadprelink-cross-8bcdedc34ed809dc0582d10fb25c97ff610b1067.tar.gz
prelink-cross-8bcdedc34ed809dc0582d10fb25c97ff610b1067.tar.bz2
prelink-cross-8bcdedc34ed809dc0582d10fb25c97ff610b1067.zip
fsync files before closing
2009-03-19 Joseph Myers <joseph@codesourcery.com> Issue #4626 * src/cache.c, src/dso-readonly.c, src/dso.c, src/execstack.c, src/gather.c, src/layout.c, src/mapfile.c, src/verify.c: fsync file descriptors before closing them. Mark Hatle <mark.hatle@windriver.com> * src/dso-readonly.c: sync with changes above
-rw-r--r--trunk/ChangeLog.cross7
-rw-r--r--trunk/src/cache.c1
-rw-r--r--trunk/src/dso-readonly.c7
-rw-r--r--trunk/src/dso.c8
-rw-r--r--trunk/src/execstack.c2
-rw-r--r--trunk/src/gather.c5
-rw-r--r--trunk/src/layout.c1
-rw-r--r--trunk/src/verify.c19
8 files changed, 45 insertions, 5 deletions
diff --git a/trunk/ChangeLog.cross b/trunk/ChangeLog.cross
index 5edb54e..946a154 100644
--- a/trunk/ChangeLog.cross
+++ b/trunk/ChangeLog.cross
@@ -2,6 +2,13 @@
* Integrate prelinker/cross-prelinking patches
+ 2009-03-19 Joseph Myers <joseph@codesourcery.com>
+
+ Issue #4626
+ * src/cache.c, src/dso-readonly.c, src/dso.c, src/execstack.c,
+ src/gather.c, src/layout.c, src/mapfile.c, src/verify.c: fsync
+ file descriptors before closing them.
+
2008-09-23 Joseph Myers <joseph@codesourcery.com>
* src/arch-arm.c (arm_prelink_conflict_rela): Correct
diff --git a/trunk/src/cache.c b/trunk/src/cache.c
index 311dfa3..4c6bffd 100644
--- a/trunk/src/cache.c
+++ b/trunk/src/cache.c
@@ -682,6 +682,7 @@ prelink_save_cache (int do_warn)
if (write (fd, &cache, sizeof (cache)) != sizeof (cache)
|| write (fd, data, len) != len
|| fchmod (fd, 0644)
+ || fsync (fd)
|| close (fd)
|| wrap_rename (prelink_cache_tmp, prelink_cache))
{
diff --git a/trunk/src/dso-readonly.c b/trunk/src/dso-readonly.c
index 06f5f09..a7bf206 100644
--- a/trunk/src/dso-readonly.c
+++ b/trunk/src/dso-readonly.c
@@ -563,7 +563,10 @@ error_out:
if (elf)
elf_end (elf);
if (fd != -1)
- close (fd);
+ {
+ fsync (fd);
+ close (fd);
+ }
return NULL;
}
@@ -1658,10 +1661,12 @@ close_dso_1 (DSO *dso)
}
elf_end (dso->elf);
+ fsync (dso->fd);
close (dso->fd);
if (dso->elfro)
{
elf_end (dso->elfro);
+ fsync (dso->fdro);
close (dso->fdro);
}
if (dso->filename != dso->soname)
diff --git a/trunk/src/dso.c b/trunk/src/dso.c
index 94a0176..3c61ff2 100644
--- a/trunk/src/dso.c
+++ b/trunk/src/dso.c
@@ -553,7 +553,10 @@ error_out:
if (elf)
elf_end (elf);
if (fd != -1)
- close (fd);
+ {
+ fsync (fd);
+ close (fd);
+ }
return NULL;
}
@@ -1017,6 +1020,7 @@ error_out:
if (fd != -1)
{
wrap_unlink (filename);
+ fsync (fd);
close (fd);
}
return 1;
@@ -1636,10 +1640,12 @@ close_dso_1 (DSO *dso)
}
elf_end (dso->elf);
+ fsync (dso->fd);
close (dso->fd);
if (dso->elfro)
{
elf_end (dso->elfro);
+ fsync (dso->fdro);
close (dso->fdro);
}
if (dso->filename != dso->soname)
diff --git a/trunk/src/execstack.c b/trunk/src/execstack.c
index 28ca9c8..b75c5bd 100644
--- a/trunk/src/execstack.c
+++ b/trunk/src/execstack.c
@@ -198,6 +198,7 @@ execstack_make_rdwr (DSO *dso, int flag)
p = NULL;
wrap_unlink (filename);
+ fsync (fd);
close (fd);
fd = -1;
close_dso (dso);
@@ -210,6 +211,7 @@ error_out:
if (fd != -1)
{
wrap_unlink (filename);
+ fsync (fd);
close (fd);
}
close_dso (dso);
diff --git a/trunk/src/gather.c b/trunk/src/gather.c
index a8caefc..958a8ad 100644
--- a/trunk/src/gather.c
+++ b/trunk/src/gather.c
@@ -810,6 +810,7 @@ gather_func (const char *name, const struct stat64 *st, int type,
if (read (fd, e_ident, sizeof (e_ident)) != sizeof (e_ident))
{
close_it:
+ fsync (fd);
close (fd);
return FTW_CONTINUE;
}
@@ -828,6 +829,7 @@ make_unprelinkable:
ent->type = ET_UNPRELINKABLE;
}
}
+ fsync (fd);
close (fd);
return FTW_CONTINUE;
}
@@ -969,6 +971,7 @@ gather_binlib (const char *name, const struct stat64 *st)
if (read (fd, e_ident, sizeof (e_ident)) != sizeof (e_ident))
{
error (0, errno, "Could not read ELF header from %s", name);
+ fsync (fd);
close (fd);
return 1;
}
@@ -978,6 +981,7 @@ gather_binlib (const char *name, const struct stat64 *st)
if (memcmp (e_ident, ELFMAG, SELFMAG) != 0)
{
error (0, 0, "%s is not an ELF object", name);
+ fsync (fd);
close (fd);
return 1;
}
@@ -1002,6 +1006,7 @@ gather_binlib (const char *name, const struct stat64 *st)
{
unsupported_type:
error (0, 0, "%s is neither ELF executable nor ELF shared library", name);
+ fsync (fd);
close (fd);
return 1;
}
diff --git a/trunk/src/layout.c b/trunk/src/layout.c
index 9e521e1..de98e1f 100644
--- a/trunk/src/layout.c
+++ b/trunk/src/layout.c
@@ -385,6 +385,7 @@ layout_libs (void)
mmap_start += mmap_base;
}
+ fsync (fd);
close (fd);
}
diff --git a/trunk/src/verify.c b/trunk/src/verify.c
index 8acecfb..8a3d89a 100644
--- a/trunk/src/verify.c
+++ b/trunk/src/verify.c
@@ -409,6 +409,9 @@ prelink_verify (const char *filename)
if (handle_verify (fdundone, filename))
goto failure;
+ fsync (fd);
+ fsync (fdorig);
+ fsync (fdundone);
close (fd);
close (fdorig);
close (fdundone);
@@ -418,11 +421,20 @@ failure_unlink:
unlink (ent->filename);
failure:
if (fd != -1)
- close (fd);
+ {
+ fsync (fd);
+ close (fd);
+ }
if (fdorig != -1)
- close (fdorig);
+ {
+ fsync (fdorig);
+ close (fdorig);
+ }
if (fdundone != -1)
- close (fdundone);
+ {
+ fsync (fdundone);
+ close (fdundone);
+ }
if (dso)
close_dso (dso);
if (dso2)
@@ -437,6 +449,7 @@ not_prelinked:
error (EXIT_FAILURE, errno, "Couldn't open %s", filename);
if (handle_verify (fd, filename))
return EXIT_FAILURE;
+ fsync (fd);
close (fd);
return 0;
}