OSDN Git Service

osdep: add qemu_unlink()
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Fri, 8 Nov 2019 14:09:56 +0000 (18:09 +0400)
committerMarc-André Lureau <marcandre.lureau@redhat.com>
Thu, 2 Jan 2020 12:29:32 +0000 (16:29 +0400)
Add a helper function to match qemu_open() which may return files
under the /dev/fdset prefix. Those shouldn't be removed, since it's
only a qemu namespace.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
include/qemu/osdep.h
util/osdep.c

index 0f97d68..9bd3dcf 100644 (file)
@@ -462,6 +462,7 @@ int qemu_mprotect_none(void *addr, size_t size);
 
 int qemu_open(const char *name, int flags, ...);
 int qemu_close(int fd);
+int qemu_unlink(const char *name);
 #ifndef _WIN32
 int qemu_dup(int fd);
 #endif
index 3f04326..f7d0605 100644 (file)
@@ -371,6 +371,21 @@ int qemu_close(int fd)
 }
 
 /*
+ * Delete a file from the filesystem, unless the filename is /dev/fdset/...
+ *
+ * Returns: On success, zero is returned.  On error, -1 is returned,
+ * and errno is set appropriately.
+ */
+int qemu_unlink(const char *name)
+{
+    if (g_str_has_prefix(name, "/dev/fdset/")) {
+        return 0;
+    }
+
+    return unlink(name);
+}
+
+/*
  * A variant of write(2) which handles partial write.
  *
  * Return the number of bytes transferred.