From patchwork Tue Oct 30 02:11:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Baron X-Patchwork-Id: 195260 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 66E692C009B for ; Tue, 30 Oct 2012 13:41:14 +1100 (EST) Received: from localhost ([::1]:32866 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT1K6-0000F7-LA for incoming@patchwork.ozlabs.org; Mon, 29 Oct 2012 22:12:58 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT1Ij-0005Wm-A3 for qemu-devel@nongnu.org; Mon, 29 Oct 2012 22:11:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TT1Ii-0001SX-7t for qemu-devel@nongnu.org; Mon, 29 Oct 2012 22:11:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60030) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TT1Ii-0001SM-08 for qemu-devel@nongnu.org; Mon, 29 Oct 2012 22:11:32 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9U2BTUw014368 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 29 Oct 2012 22:11:30 -0400 Received: from redhat.com (dhcp-185-114.bos.redhat.com [10.16.185.114]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9U2BTZj001578; Mon, 29 Oct 2012 22:11:29 -0400 Date: Mon, 29 Oct 2012 22:11:29 -0400 From: Jason Baron To: qemu-devel@nongnu.org Message-Id: <30134513a5af45cebbaaca33830599b57adc65ab.1351561225.git.jbaron@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 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 v1 10/13] 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 824d8ae..59e8d2f 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; @@ -1904,16 +1905,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 = ""; @@ -1924,9 +1925,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; @@ -1934,6 +1935,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); @@ -3377,12 +3393,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; } /*