summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-12-23 10:37:04 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-01-10 15:38:17 +0000
commite03acbc408879c252fe1680026429c564c73d467 (patch)
tree40992fc7c224eb9885f71ce3563013ce215fb5e7
parent653acdb826ba42783e668c3856b3355b6508b6b9 (diff)
downloadlibguestfs-e03acbc408879c252fe1680026429c564c73d467.tar.gz
libguestfs-e03acbc408879c252fe1680026429c564c73d467.tar.xz
libguestfs-e03acbc408879c252fe1680026429c564c73d467.zip
lib: Try harder to remove temporary directory along error paths (RHBZ#769680).
(cherry picked from commit 6032da66819b7ccf99001ba636926100f475cb89)
-rw-r--r--src/appliance.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/appliance.c b/src/appliance.c
index 5f77a562..57ff38f1 100644
--- a/src/appliance.c
+++ b/src/appliance.c
@@ -450,8 +450,10 @@ build_supermin_appliance (guestfs_h *g,
guestfs___print_timestamped_message (g, "run febootstrap-supermin-helper");
int r = run_supermin_helper (g, supermin_path, tmpcd, len);
- if (r == -1)
+ if (r == -1) {
+ guestfs___remove_tmpdir (tmpcd);
return -1;
+ }
if (g->verbose)
guestfs___print_timestamped_message (g, "finished building supermin appliance");
@@ -468,6 +470,7 @@ build_supermin_appliance (guestfs_h *g,
int fd = open (filename, O_WRONLY|O_CREAT, 0755);
if (fd == -1) {
perrorf (g, "open: %s", filename);
+ guestfs___remove_tmpdir (tmpcd);
return -1;
}
struct flock fl;
@@ -481,6 +484,7 @@ build_supermin_appliance (guestfs_h *g,
goto again;
perrorf (g, "fcntl: F_SETLKW: %s", filename);
close (fd);
+ guestfs___remove_tmpdir (tmpcd);
return -1;
}
@@ -492,6 +496,7 @@ build_supermin_appliance (guestfs_h *g,
if (ftruncate (fd, clen) == -1) {
perrorf (g, "ftruncate: %s", filename);
close (fd);
+ guestfs___remove_tmpdir (tmpcd);
return -1;
}
@@ -499,11 +504,13 @@ build_supermin_appliance (guestfs_h *g,
if (rr == -1) {
perrorf (g, "write: %s", filename);
close (fd);
+ guestfs___remove_tmpdir (tmpcd);
return -1;
}
if ((size_t) rr != clen) {
error (g, "partial write: %s", filename);
close (fd);
+ guestfs___remove_tmpdir (tmpcd);
return -1;
}
@@ -513,6 +520,7 @@ build_supermin_appliance (guestfs_h *g,
if (rename (filename, filename2) == -1) {
perrorf (g, "rename: %s %s", filename, filename2);
close (fd);
+ guestfs___remove_tmpdir (tmpcd);
return -1;
}
@@ -522,6 +530,7 @@ build_supermin_appliance (guestfs_h *g,
if (rename (filename, filename2) == -1) {
perrorf (g, "rename: %s %s", filename, filename2);
close (fd);
+ guestfs___remove_tmpdir (tmpcd);
return -1;
}
@@ -531,6 +540,7 @@ build_supermin_appliance (guestfs_h *g,
if (rename (filename, filename2) == -1) {
perrorf (g, "rename: %s %s", filename, filename2);
close (fd);
+ guestfs___remove_tmpdir (tmpcd);
return -1;
}