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.
This commit is contained in:
parent
1733838b02
commit
b21ee1fc42
@ -14,6 +14,17 @@
|
|||||||
#define MIMEINFO_DATABASES "/usr/share/mime:/usr/local/share:" USER_HOME "/.local/share:/usr/share/qubes/mime-override"
|
#define MIMEINFO_DATABASES "/usr/share/mime:/usr/local/share:" USER_HOME "/.local/share:/usr/share/qubes/mime-override"
|
||||||
#define TMP_LOC "/tmp/qopen/"
|
#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)
|
const char *gettime(void)
|
||||||
{
|
{
|
||||||
static char retbuf[60];
|
static char retbuf[60];
|
||||||
@ -110,6 +121,9 @@ void copy_file_by_name(const char *filename)
|
|||||||
perror("open file");
|
perror("open file");
|
||||||
exit(1);
|
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))
|
if (!copy_fd_all(fd, 0))
|
||||||
exit(1);
|
exit(1);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
Loading…
Reference in New Issue
Block a user