[Spice-devel] [vdagent-linux v2 2/2] vdagent: Favour access() over stat()

Christophe Fergeau cfergeau at redhat.com
Wed Jan 30 12:22:55 UTC 2019


vdagent.c has a 'file_test' function which tests for the existence of
the /dev entry for the spicevmc channel. This commit reworks it to give
it a better name, to make it return a boolean, and to use access()
rather than stat() which makes the goal of that function more obvious.

Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
---
 src/vdagent/vdagent.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
index ff3328c..b077d1d 100644
--- a/src/vdagent/vdagent.c
+++ b/src/vdagent/vdagent.c
@@ -20,6 +20,7 @@
 */
 #include <config.h>
 
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -28,8 +29,6 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <signal.h>
-#include <sys/select.h>
-#include <sys/stat.h>
 #include <spice/vd_agent.h>
 #include <poll.h>
 #include <glib-unix.h>
@@ -319,11 +318,9 @@ static int daemonize(void)
     return 0;
 }
 
-static int file_test(const char *path)
+static bool file_exists(const char *path)
 {
-    struct stat buffer;
-
-    return stat(path, &buffer);
+    return (access(path, F_OK) == 0);
 }
 
 static gboolean x11_io_channel_cb(GIOChannel *source,
@@ -450,7 +447,7 @@ int main(int argc, char *argv[])
     openlog("spice-vdagent", do_daemonize ? LOG_PID : (LOG_PID | LOG_PERROR),
             LOG_USER);
 
-    if (file_test(portdev) != 0) {
+    if (!file_exists(portdev)) {
         g_debug("vdagent virtio channel %s does not exist, exiting", portdev);
         return 0;
     }
-- 
2.20.1



More information about the Spice-devel mailing list