From b21ee1fc42939661c5ed3f60004ccad4b5c0f3c5 Mon Sep 17 00:00:00 2001 From: Vincent Penquerc'h Date: Sun, 4 May 2014 18:16:30 +0100 Subject: [PATCH] vm-file-editor: remove temporary file on exit This allows editing the same file more than once on the same (non disposable) VM, as well as keeping /tmp from ballooning indefinitely. --- qubes-rpc/vm-file-editor.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/qubes-rpc/vm-file-editor.c b/qubes-rpc/vm-file-editor.c index 2b8cbdc..0be381e 100644 --- a/qubes-rpc/vm-file-editor.c +++ b/qubes-rpc/vm-file-editor.c @@ -14,6 +14,17 @@ #define MIMEINFO_DATABASES "/usr/share/mime:/usr/local/share:" USER_HOME "/.local/share:/usr/share/qubes/mime-override" #define TMP_LOC "/tmp/qopen/" +static const char *cleanup_filename = NULL; + +static void cleanup_file(void) +{ + if (cleanup_filename) { + if (unlink(cleanup_filename) < 0) + fprintf(stderr, "Failed to remove file at exit\n"); + cleanup_filename = NULL; + } +} + const char *gettime(void) { static char retbuf[60]; @@ -110,6 +121,9 @@ void copy_file_by_name(const char *filename) perror("open file"); exit(1); } + /* we now have created a new file, ensure we delete it at the end */ + cleanup_filename = filename; + atexit(cleanup_file); if (!copy_fd_all(fd, 0)) exit(1); close(fd);