qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: "QEMU Trivial" <qemu-trivial@nongnu.org>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"David CARLIER" <devnexen@gmail.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [PATC 7/9] Skipping drm build, unsupported
Date: Wed, 1 Jul 2020 17:15:24 +0200	[thread overview]
Message-ID: <20200701151524.wogl4ihbdevgf4bt@sirius.home.kraxel.org> (raw)
In-Reply-To: <3eb3c266-1a83-9f40-4760-1ab2578ae5d6@redhat.com>

> > Ah, that is the problem.  Yes, DT_CHR is an non-posix optimization which
> > allows to get the file type directly, without another round-trip to the
> > kernel.  If that isn't available you can stat() the file and check
> > ((st_mode & S_IFMT) == S_IFCHR) instead.
> 
> Even when d_type and DT_CHR is available, there are filesystems where the
> Linux kernel reports d_type of DT_UNKNOWN, and where you are best having
> that code also falling back to an fstat().

Given this isn't perforance critical at all it is probably simplest to
avoid non-portable d_type altogether and just to the fstat
unconditionally.

David, does that work for haiku?

take care,
  Gerd

diff --git a/util/drm.c b/util/drm.c
index a23ff2453826..a1d3520d00f2 100644
--- a/util/drm.c
+++ b/util/drm.c
@@ -24,6 +24,7 @@ int qemu_drm_rendernode_open(const char *rendernode)
 {
     DIR *dir;
     struct dirent *e;
+    struct stat st;
     int r, fd;
     char *p;
 
@@ -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,12 @@ int qemu_drm_rendernode_open(const char *rendernode)
             g_free(p);
             continue;
         }
+        fstat(r, &st);
+        if ((st.st_mode & S_IFMT) != S_IFCHR) {
+            close(r);
+            g_free(p);
+            continue;
+        }
         fd = r;
         g_free(p);
         break;



  reply	other threads:[~2020-07-01 15:17 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-29 21:48 [PATC 7/9] Skipping drm build, unsupported David CARLIER
2020-06-30  6:44 ` Philippe Mathieu-Daudé
2020-06-30  8:23   ` Gerd Hoffmann
2020-06-30  8:46     ` Philippe Mathieu-Daudé
2020-06-30 15:48       ` Gerd Hoffmann
2020-06-30 15:55         ` David CARLIER
2020-06-30 16:13           ` David CARLIER
2020-06-30 15:53     ` Peter Maydell
2020-06-30 16:53       ` Gerd Hoffmann
2020-07-01 14:16         ` Eric Blake
2020-07-01 15:15           ` Gerd Hoffmann [this message]
2020-07-01 15:48             ` David CARLIER
2020-07-01 16:04             ` Philippe Mathieu-Daudé
2020-07-01 16:53             ` Peter Maydell

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=20200701151524.wogl4ihbdevgf4bt@sirius.home.kraxel.org \
    --to=kraxel@redhat.com \
    --cc=devnexen@gmail.com \
    --cc=eblake@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@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).