{"id":813803,"url":"http://patchwork.ozlabs.org/api/patches/813803/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170914114236.25343-2-kraxel@redhat.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170914114236.25343-2-kraxel@redhat.com>","list_archive_url":null,"date":"2017-09-14T11:42:35","name":"[v2,1/2] add qemu_add_data_dir()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"84a393feabeca109b98f602226c9091f74d1f18f","submitter":{"id":589,"url":"http://patchwork.ozlabs.org/api/people/589/?format=json","name":"Gerd Hoffmann","email":"kraxel@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170914114236.25343-2-kraxel@redhat.com/mbox/","series":[{"id":3085,"url":"http://patchwork.ozlabs.org/api/series/3085/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=3085","date":"2017-09-14T11:42:35","name":"Add --firmwarepath to configure","version":2,"mbox":"http://patchwork.ozlabs.org/series/3085/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/813803/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/813803/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx01.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx01.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=kraxel@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xtGr64zdnz9sCZ\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 14 Sep 2017 21:43:18 +1000 (AEST)","from localhost ([::1]:47056 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dsSY8-00089z-OG\n\tfor incoming@patchwork.ozlabs.org; Thu, 14 Sep 2017 07:43:16 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:55432)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <kraxel@redhat.com>) id 1dsSXd-00089j-FF\n\tfor qemu-devel@nongnu.org; Thu, 14 Sep 2017 07:42:46 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <kraxel@redhat.com>) id 1dsSXY-0005Va-JQ\n\tfor qemu-devel@nongnu.org; Thu, 14 Sep 2017 07:42:45 -0400","from mx1.redhat.com ([209.132.183.28]:43021)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <kraxel@redhat.com>) id 1dsSXY-0005UT-92\n\tfor qemu-devel@nongnu.org; Thu, 14 Sep 2017 07:42:40 -0400","from smtp.corp.redhat.com\n\t(int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 4ABD081DE3\n\tfor <qemu-devel@nongnu.org>; Thu, 14 Sep 2017 11:42:39 +0000 (UTC)","from sirius.home.kraxel.org (ovpn-117-51.ams2.redhat.com\n\t[10.36.117.51])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 211C65C66F;\n\tThu, 14 Sep 2017 11:42:37 +0000 (UTC)","by sirius.home.kraxel.org (Postfix, from userid 1000)\n\tid 37F613F10F; Thu, 14 Sep 2017 13:42:36 +0200 (CEST)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 4ABD081DE3","From":"Gerd Hoffmann <kraxel@redhat.com>","To":"qemu-devel@nongnu.org","Date":"Thu, 14 Sep 2017 13:42:35 +0200","Message-Id":"<20170914114236.25343-2-kraxel@redhat.com>","In-Reply-To":"<20170914114236.25343-1-kraxel@redhat.com>","References":"<20170914114236.25343-1-kraxel@redhat.com>","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.16","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.25]);\n\tThu, 14 Sep 2017 11:42:39 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"[Qemu-devel] [PATCH v2 1/2] add qemu_add_data_dir()","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Paolo Bonzini <pbonzini@redhat.com>, Gerd Hoffmann <kraxel@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"Add helper function to add a directory to the qemu search path, so we\ndon't duplicate the checks.  Add a check for duplicate entries, so we\nstop trying to open files twice.\n\nSigned-off-by: Gerd Hoffmann <kraxel@redhat.com>\n---\n vl.c | 34 +++++++++++++++++++++++-----------\n 1 file changed, 23 insertions(+), 11 deletions(-)","diff":"diff --git a/vl.c b/vl.c\nindex fb1f05b937..37a3401920 100644\n--- a/vl.c\n+++ b/vl.c\n@@ -2272,6 +2272,24 @@ char *qemu_find_file(int type, const char *name)\n     return NULL;\n }\n \n+static void qemu_add_data_dir(const char *path)\n+{\n+    int i;\n+\n+    if (path == NULL) {\n+        return;\n+    }\n+    if (data_dir_idx == ARRAY_SIZE(data_dir)) {\n+        return;\n+    }\n+    for (i = 0; i < data_dir_idx; i++) {\n+        if (strcmp(data_dir[i], path) == 0) {\n+            return; /* duplicate */\n+        }\n+    }\n+    data_dir[data_dir_idx++] = path;\n+}\n+\n static inline bool nonempty_str(const char *str)\n {\n     return str && *str;\n@@ -3450,8 +3468,8 @@ int main(int argc, char **argv, char **envp)\n             case QEMU_OPTION_L:\n                 if (is_help_option(optarg)) {\n                     list_data_dirs = true;\n-                } else if (data_dir_idx < ARRAY_SIZE(data_dir)) {\n-                    data_dir[data_dir_idx++] = optarg;\n+                } else {\n+                    qemu_add_data_dir(optarg);\n                 }\n                 break;\n             case QEMU_OPTION_bios:\n@@ -4216,16 +4234,10 @@ int main(int argc, char **argv, char **envp)\n \n     /* If no data_dir is specified then try to find it relative to the\n        executable path.  */\n-    if (data_dir_idx < ARRAY_SIZE(data_dir)) {\n-        data_dir[data_dir_idx] = os_find_datadir();\n-        if (data_dir[data_dir_idx] != NULL) {\n-            data_dir_idx++;\n-        }\n-    }\n+    qemu_add_data_dir(os_find_datadir());\n+\n     /* If all else fails use the install path specified when building. */\n-    if (data_dir_idx < ARRAY_SIZE(data_dir)) {\n-        data_dir[data_dir_idx++] = CONFIG_QEMU_DATADIR;\n-    }\n+    qemu_add_data_dir(CONFIG_QEMU_DATADIR);\n \n     /* -L help lists the data directories and exits. */\n     if (list_data_dirs) {\n","prefixes":["v2","1/2"]}