From patchwork Thu Sep 13 20:12:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Baron X-Patchwork-Id: 183728 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4CC602C007F for ; Fri, 14 Sep 2012 07:01:42 +1000 (EST) Received: from localhost ([::1]:40416 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCGXc-0006rE-EQ for incoming@patchwork.ozlabs.org; Thu, 13 Sep 2012 17:01:40 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCFmV-0001Sr-9e for qemu-devel@nongnu.org; Thu, 13 Sep 2012 16:13:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TCFmP-00030O-Dn for qemu-devel@nongnu.org; Thu, 13 Sep 2012 16:12:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11778) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCFmP-0002zx-0a for qemu-devel@nongnu.org; Thu, 13 Sep 2012 16:12:53 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8DKCpLF009097 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 13 Sep 2012 16:12:51 -0400 Received: from redhat.com (dhcp-185-114.bos.redhat.com [10.16.185.114]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q8DKCpXP028770; Thu, 13 Sep 2012 16:12:51 -0400 Date: Thu, 13 Sep 2012 16:12:51 -0400 From: Jason Baron To: qemu-devel@nongnu.org Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com, alex.williamson@redhat.com, mst@redhat.com, jan.kiszka@siemens.com, agraf@suse.de, armbru@redhat.com, yamahata@valinux.co.jp, juzhang@redhat.com, kevin@koconnor.net, avi@redhat.com, mkletzan@redhat.com, lcapitulino@redhat.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH 24/25] Add a fallback bios file search, if -L fails. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If -L is specified, and qemu does not find the bios file in , then the search fails. Add infrastructure such that the search will continue in the default paths, if not found in the -L path. Signed-off-by: Jason Baron --- vl.c | 28 +++++++++++++++++++++------- 1 files changed, 21 insertions(+), 7 deletions(-) diff --git a/vl.c b/vl.c index 7c577fa..656a210 100644 --- a/vl.c +++ b/vl.c @@ -177,6 +177,7 @@ int main(int argc, char **argv) #define MAX_VIRTIO_CONSOLES 1 static const char *data_dir; +static const char *data_dir_fallback; const char *bios_name = NULL; enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; DisplayType display_type = DT_DEFAULT; @@ -1872,12 +1873,15 @@ static int balloon_parse(const char *arg) return -1; } -char *qemu_find_file(int type, const char *name) +static char *__qemu_find_file(int type, const char *name, const char *dir) { int len; const char *subdir; char *buf; + if (!dir) + return NULL; + /* Try the name as a straight path first */ if (access(name, R_OK) == 0) { return g_strdup(name); @@ -1892,9 +1896,9 @@ char *qemu_find_file(int type, const char *name) default: abort(); } - len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2; + len = strlen(dir) + strlen(name) + strlen(subdir) + 2; buf = g_malloc0(len); - snprintf(buf, len, "%s/%s%s", data_dir, subdir, name); + snprintf(buf, len, "%s/%s%s", dir, subdir, name); if (access(buf, R_OK)) { g_free(buf); return NULL; @@ -1902,6 +1906,18 @@ char *qemu_find_file(int type, const char *name) return buf; } +char *qemu_find_file(int type, const char *name) +{ + char *filename; + + filename = __qemu_find_file(type, name, data_dir); + if (!filename) { + filename = __qemu_find_file(type, name, data_dir_fallback); + } + + return filename; +} + static int device_help_func(QemuOpts *opts, void *opaque) { return qdev_device_help(opts); @@ -3338,11 +3354,9 @@ int main(int argc, char **argv, char **envp) /* If no data_dir is specified then try to find it relative to the executable path. */ - if (!data_dir) { - data_dir = os_find_datadir(argv[0]); - } + data_dir_fallback = os_find_datadir(argv[0]); /* If all else fails use the install path specified when building. */ - if (!data_dir) { + if (!data_dir_fallback) { data_dir = CONFIG_QEMU_DATADIR; }