From e0c3324695cd0232ef08df0394ba8922766bef3d Mon Sep 17 00:00:00 2001 From: Joshua Watt Date: Wed, 31 Aug 2022 08:15:29 -0500 Subject: [PATCH] drm-shim: Use anonymous file for file override Using a pipe might mean that either the read or write call can block, most likely deadlocking the calling process. Instead, write the contents in an anonymous file when the file is opened to be read back. Signed-off-by: Joshua Watt Part-of: --- src/drm-shim/drm_shim.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/drm-shim/drm_shim.c b/src/drm-shim/drm_shim.c index dec8e69..a048735 100644 --- a/src/drm-shim/drm_shim.c +++ b/src/drm-shim/drm_shim.c @@ -48,6 +48,7 @@ #include #include +#include "util/anon_file.h" #include "util/set.h" #include "util/u_debug.h" #include "drm_shim.h" @@ -297,12 +298,11 @@ static int file_override_open(const char *path) { for (int i = 0; i < file_overrides_count; i++) { if (strcmp(file_overrides[i].path, path) == 0) { - int fds[2]; - pipe(fds); - write(fds[1], file_overrides[i].contents, + int fd = os_create_anonymous_file(0, "shim file"); + write(fd, file_overrides[i].contents, strlen(file_overrides[i].contents)); - close(fds[1]); - return fds[0]; + lseek(fd, 0, SEEK_SET); + return fd; } } -- 2.7.4