changeset:   23594:2fe46305a00d
user:        Olaf Hering <olaf@aepfle.de>
date:        Fri Jun 10 10:47:25 2011 +0200
files:       tools/xenpaging/xenpaging.c
description:
xenpaging: add helper function for unlinking pagefile

Unlink pagefile in the signal handler and also in the exit path.
This does not leave a stale pagefile if an error occoured.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Committed-by: Ian Jackson <ian.jackson.citrix.com>


---
 tools/xenpaging/xenpaging.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Index: xen-4.1.2-testing/tools/xenpaging/xenpaging.c
===================================================================
--- xen-4.1.2-testing.orig/tools/xenpaging/xenpaging.c
+++ xen-4.1.2-testing/tools/xenpaging/xenpaging.c
@@ -41,11 +41,20 @@
 
 static char filename[80];
 static int interrupted;
-static void close_handler(int sig)
+
+static void unlink_pagefile(void)
 {
-    interrupted = sig;
     if ( filename[0] )
+    {
         unlink(filename);
+        filename[0] = '\0';
+    }
+}
+
+static void close_handler(int sig)
+{
+    interrupted = sig;
+    unlink_pagefile();
 }
 
 static int xenpaging_mem_paging_flush_ioemu_cache(xenpaging_t *paging)
@@ -716,6 +725,7 @@ int main(int argc, char *argv[])
 
  out:
     close(fd);
+    unlink_pagefile();
     free(victims);
 
     /* Tear down domain paging */