From patchwork Fri Oct 19 20:43:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Baron X-Patchwork-Id: 192801 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 0A27D2C0090 for ; Sat, 20 Oct 2012 07:45:38 +1100 (EST) Received: from localhost ([::1]:58900 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TPJRo-0007T0-8D for incoming@patchwork.ozlabs.org; Fri, 19 Oct 2012 16:45:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49908) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TPJQ0-00051D-8Z for qemu-devel@nongnu.org; Fri, 19 Oct 2012 16:43:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TPJPy-0006ZR-M0 for qemu-devel@nongnu.org; Fri, 19 Oct 2012 16:43:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TPJPy-0006Z8-EB for qemu-devel@nongnu.org; Fri, 19 Oct 2012 16:43:42 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9JKhenw011272 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 19 Oct 2012 16:43:40 -0400 Received: from redhat.com (dhcp-185-114.bos.redhat.com [10.16.185.114]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9JKheV6021386; Fri, 19 Oct 2012 16:43:40 -0400 Date: Fri, 19 Oct 2012 16:43:40 -0400 From: Jason Baron To: qemu-devel@nongnu.org Message-Id: <38e5ef70b494a5e21fdb89b2105e9a87fd410f7c.1350677362.git.jbaron@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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, juzhang@redhat.com, mst@redhat.com, jan.kiszka@siemens.com, armbru@redhat.com, agraf@suse.de, blauwirbel@gmail.com, yamahata@valinux.co.jp, alex.williamson@redhat.com, kevin@koconnor.net, avi@redhat.com, mkletzan@redhat.com, pbonzini@redhat.com, lcapitulino@redhat.com, afaerber@suse.de, kraxel@redhat.com Subject: [Qemu-devel] [PATCH v3 22/26] 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 From: Jason Baron 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. Reviewed-by: Paolo Bonzini Signed-off-by: Jason Baron --- vl.c | 36 +++++++++++++++++++++++++----------- 1 files changed, 25 insertions(+), 11 deletions(-) diff --git a/vl.c b/vl.c index 6b1e546..2a2d217 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; @@ -1892,16 +1893,16 @@ static int balloon_parse(const char *arg) return -1; } -char *qemu_find_file(int type, const char *name) +static char *qemu_find_file_in_dir(int type, const char *name, const char *dir) { int len; const char *subdir; char *buf; - /* Try the name as a straight path first */ - if (access(name, R_OK) == 0) { - return g_strdup(name); + if (!dir) { + return NULL; } + switch (type) { case QEMU_FILE_TYPE_BIOS: subdir = ""; @@ -1912,9 +1913,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; @@ -1922,6 +1923,21 @@ char *qemu_find_file(int type, const char *name) return buf; } +char *qemu_find_file(int type, const char *name) +{ + char *filename; + + /* Try the name as a straight path first */ + if (access(name, R_OK) == 0) { + return g_strdup(name); + } + filename = qemu_find_file_in_dir(type, name, data_dir); + if (!filename) { + filename = qemu_find_file_in_dir(type, name, data_dir_fallback); + } + return filename; +} + static int device_help_func(QemuOpts *opts, void *opaque) { return qdev_device_help(opts); @@ -3359,12 +3375,10 @@ 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) { - data_dir = CONFIG_QEMU_DATADIR; + if (!data_dir_fallback) { + data_dir_fallback = CONFIG_QEMU_DATADIR; } /*