From patchwork Mon Jul 13 14:10:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 235423 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2887785ilg; Mon, 13 Jul 2020 07:25:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmFm8xm9XOwEcayd7xAx0RQoJjHPqVfiYlyWXjTIwMc5wYvbAPokwOwJcn7/Po/uhGX1Gx X-Received: by 2002:a25:6ec2:: with SMTP id j185mr343572ybc.135.1594650349135; Mon, 13 Jul 2020 07:25:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594650349; cv=none; d=google.com; s=arc-20160816; b=hWpUY4A8xXjG6hJjtmK3K3zU7Mq+lMlGcKprIPk9i+37MZdGAQ3+YG92ETkLJtYWsy +NKX8fJlU4KpMcTExDPq5fUgN8sC93Z7uF+lDSQ9Eqxk/TkO6M7VHoE9nf9S/Ii7ixi+ D5SlyjR5qpIHhxtaTZTjSyCKtj0IuGtw8LMuvaKKzYvtsSGEXlxiKvhYmEtTLJ4ASELp IzhujtUbI+T/HZHtdlV9ZbY2Vv1h6rkjRDRjNM0Ico2NdapCxNoEGGhPao/wvFCJVrRI ctZuckujVjLhH5OgwADAfTCYEYB8d4lEC663hkuN0MWAKKTloota1o0VykQGUFHI2qW+ mbxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=OhiRntG58GDC0YrDMGX+/f9xZGwt8SVRtnGNjupJDac=; b=K0htSRAa4Uc/CCJL+3ikIBoOg1V0saJAgMmdHez9/FcGNJqA2IllznFzGTIsGWJgIR wgBwsIUpg51Skn2ClOwzJx71FqBjnqaAMS9OaBT/HgosLR/PgvgDNsBVcwnuq69DCuVC MSj2adaGLpr+cgReM+gaMp0y60nxr8BYckpPPp8JU56TbhFYRr5XUOoCyCOj+nHUxgHm vrB9Nq7YXcj06g3bHQDlj3fdJrfkjtdhE3WsHNUhVRqoJLZ4gF3nQ9YdFtxNjhzsuZgo UgmH9jV/r7tGMWspyB6hWUuaJPkHFmNV33W9Xd0rcOQmLG5LCGX2hhtBpwhPCAVroq+s icnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qiimElh+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r11si7375275ybl.442.2020.07.13.07.25.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 Jul 2020 07:25:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qiimElh+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1juzOu-0005iP-Jl for patch@linaro.org; Mon, 13 Jul 2020 10:25:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1juzB2-0005WQ-8K for qemu-devel@nongnu.org; Mon, 13 Jul 2020 10:11:28 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:53219) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1juzB0-0006ef-G8 for qemu-devel@nongnu.org; Mon, 13 Jul 2020 10:11:27 -0400 Received: by mail-wm1-x333.google.com with SMTP id q15so13462070wmj.2 for ; Mon, 13 Jul 2020 07:11:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=OhiRntG58GDC0YrDMGX+/f9xZGwt8SVRtnGNjupJDac=; b=qiimElh+YcKrUf7jd3hE09/IvdvkMZDia3108rcbqcg7A3sAW00m1sBlAruyAe9FEa pf96JwnrO0CZZ3R2nX7WswX/UScZd89Y+pvwdKdo7YuGiXZTZ89dS5+xLzl5TKiW6fJX Dpcs72bAyxyevwyinbdi5GqlkgdD1vI5TZa/i2FqU6UasfbhWudKUlcKpmKQ/2Q3Sk7X BsMJn3DK09/aRZtic12GI9J0B5UIgzcd0gcnN2fmrZu/617UZWTZbDoCL88CvLmoF87N ZOlMypit4XMTjE28VvpJTJyN0a1a6DX4h+a4YSh3ztHAhFNjbrs8lxCmpV70moU+kA4R 2xzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OhiRntG58GDC0YrDMGX+/f9xZGwt8SVRtnGNjupJDac=; b=m+s5jVa22YVr6q/ltQxMGki2d8m3CCpYsuwESugF7PW+oTda8SyRMuaX8Oe6/yYJGm jnQMpqhvGlOPftrhiwK80wxKtOU5i1Q8Qmm6eiA9v8oIli48HCFC1amGk0MQLA5aGxkM qX+wVPy4uTJtjyWUxYkNAPAbwu5A62TPav6GMg4NcbR14prf8Dew6lxJi4qXi3WGb0T+ mqvKBtTWE+7PTHOl8IR1+crUPuvGL7/aKExnIa7Q5CVZTiElEO6x6I/Sj+/Wu2mHgCqg EhJREHvMKpbwHduuK7TRy7tYaFjjUfrZNwJyvTj41Cumqfe6SiZ/Bjx9emI+I9cdeYCG Hvrw== X-Gm-Message-State: AOAM531K+EFuU8IFzx0f0psVAVJ4ZwGu9dFedl8Dvbd6WQL+4pn36ldK tYc6ZTnzTF4pgf0tSipxVT2B5cgX98yYLw== X-Received: by 2002:a1c:dd09:: with SMTP id u9mr175003wmg.70.1594649484792; Mon, 13 Jul 2020 07:11:24 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id c136sm24031297wmd.10.2020.07.13.07.11.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 07:11:24 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 16/25] util/drm: make portable by avoiding struct dirent d_type Date: Mon, 13 Jul 2020 15:10:55 +0100 Message-Id: <20200713141104.5139-17-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200713141104.5139-1-peter.maydell@linaro.org> References: <20200713141104.5139-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Gerd Hoffmann 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 Reported-by: David Carlier Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell Message-id: 20200703145614.16684-10-peter.maydell@linaro.org Message-id: 20200701180302.14821-1-kraxel@redhat.com [PMM: fixed comment style; tweaked subject line] Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- util/drm.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) -- 2.20.1 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;