From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: David Carlier <devnexen@gmail.com>, Gerd Hoffmann <kraxel@redhat.com>
Subject: [PATCH v3 9/9] util/drm: make portable by avoiding struct dirent d_type
Date: Fri, 3 Jul 2020 15:56:14 +0100 [thread overview]
Message-ID: <20200703145614.16684-10-peter.maydell@linaro.org> (raw)
In-Reply-To: <20200703145614.16684-1-peter.maydell@linaro.org>
From: Gerd Hoffmann <kraxel@redhat.com>
Given this isn't perforance critical at all lets avoid the non-portable
d_type and use fstat instead to check whenever the file is a chardev.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reported-by: David Carlier <devnexen@gmail.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20200701180302.14821-1-kraxel@redhat.com
[PMM: fixed comment style; tweaked subject line]
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
util/drm.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/util/drm.c b/util/drm.c
index a23ff245382..dae8ffebc81 100644
--- a/util/drm.c
+++ b/util/drm.c
@@ -24,7 +24,8 @@ int qemu_drm_rendernode_open(const char *rendernode)
{
DIR *dir;
struct dirent *e;
- int r, fd;
+ struct stat st;
+ int r, fd, ret;
char *p;
if (rendernode) {
@@ -38,10 +39,6 @@ int qemu_drm_rendernode_open(const char *rendernode)
fd = -1;
while ((e = readdir(dir))) {
- if (e->d_type != DT_CHR) {
- continue;
- }
-
if (strncmp(e->d_name, "renderD", 7)) {
continue;
}
@@ -53,6 +50,18 @@ int qemu_drm_rendernode_open(const char *rendernode)
g_free(p);
continue;
}
+
+ /*
+ * prefer fstat() over checking e->d_type == DT_CHR for
+ * portability reasons
+ */
+ ret = fstat(r, &st);
+ if (ret < 0 || (st.st_mode & S_IFMT) != S_IFCHR) {
+ close(r);
+ g_free(p);
+ continue;
+ }
+
fd = r;
g_free(p);
break;
--
2.20.1
next prev parent reply other threads:[~2020-07-03 15:06 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-03 14:56 [PATCH v3 0/9] Build fixes for Haiku Peter Maydell
2020-07-03 14:56 ` [PATCH v3 1/9] build: Enable BSD symbols " Peter Maydell
2020-07-03 14:56 ` [PATCH v3 2/9] util/qemu-openpty.c: Don't assume pty.h is glibc-only Peter Maydell
2020-07-03 15:12 ` Thomas Huth
2020-07-06 14:00 ` Eric Blake
2020-07-06 16:50 ` Thomas Huth
2020-07-03 14:56 ` [PATCH v3 3/9] build: Check that mlockall() exists Peter Maydell
2020-07-03 15:13 ` Thomas Huth
2020-07-03 14:56 ` [PATCH v3 4/9] osdep.h: Always include <sys/signal.h> if it exists Peter Maydell
2020-07-03 15:15 ` Thomas Huth
2020-07-03 15:21 ` Philippe Mathieu-Daudé
2020-07-03 14:56 ` [PATCH v3 5/9] osdep.h: For Haiku, define SIGIO as equivalent to SIGPOLL Peter Maydell
2020-07-03 15:16 ` Thomas Huth
2020-07-03 14:56 ` [PATCH v3 6/9] bswap.h: Include <endian.h> on Haiku for bswap operations Peter Maydell
2020-07-03 15:19 ` Thomas Huth
2020-07-03 15:22 ` Philippe Mathieu-Daudé
2020-07-03 14:56 ` [PATCH v3 7/9] util/compatfd.c: Only include <sys/syscall.h> if CONFIG_SIGNALFD Peter Maydell
2020-07-03 15:19 ` Thomas Huth
2020-07-03 15:29 ` Philippe Mathieu-Daudé
2020-07-03 14:56 ` [PATCH v3 8/9] util/oslib-posix.c: Implement qemu_init_exec_dir() for Haiku Peter Maydell
2020-07-03 14:56 ` Peter Maydell [this message]
2020-07-11 18:44 ` [PATCH v3 0/9] Build fixes " Peter Maydell
2020-07-11 19:02 ` David CARLIER
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200703145614.16684-10-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=devnexen@gmail.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).