From patchwork Sat Dec 14 12:20:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joakim Tjernlund X-Patchwork-Id: 1209822 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=infinera.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47b2kJ5XZBz9sP6 for ; Sun, 15 Dec 2019 09:48:06 +1100 (AEDT) Received: from localhost ([::1]:34196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1igGCh-0002DN-BO for incoming@patchwork.ozlabs.org; Sat, 14 Dec 2019 17:48:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41543) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1igFGk-0002PV-L2 for qemu-devel@nongnu.org; Sat, 14 Dec 2019 16:48:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1igFGj-0008Dj-2Y for qemu-devel@nongnu.org; Sat, 14 Dec 2019 16:48:10 -0500 Received: from [31.15.61.139] (port=53679 helo=smtp.transmode.se) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1igFGi-0007rc-Qy for qemu-devel@nongnu.org; Sat, 14 Dec 2019 16:48:08 -0500 Received: from gentoo-jocke.infinera.com (gentoo-jocke.infinera.com [10.210.71.11]) by smtp.transmode.se (Postfix) with ESMTP id 35153118C7C6; Sat, 14 Dec 2019 13:20:25 +0100 (CET) Received: from gentoo-jocke.infinera.com (gentoo-jocke.infinera.com [127.0.0.1]) by gentoo-jocke.infinera.com (8.15.2/8.14.9) with ESMTP id xBECKO5P017611; Sat, 14 Dec 2019 13:20:25 +0100 Received: (from jocke@localhost) by gentoo-jocke.infinera.com (8.15.2/8.15.2/Submit) id xBECKO39017610; Sat, 14 Dec 2019 13:20:24 +0100 From: Joakim Tjernlund To: qemu-devel@nongnu.org Subject: [PATCH] linux-user: make binfmt flag O require P Date: Sat, 14 Dec 2019 13:20:22 +0100 Message-Id: <20191214122022.17255-1-joakim.tjernlund@infinera.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 31.15.61.139 X-Mailman-Approved-At: Sat, 14 Dec 2019 17:47:43 -0500 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: , Cc: Joakim Tjernlund Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Joakim Tjernlund QEMU can autodetect if it is started from Linux binfmt loader when binfmt flag O is on. Use that and require binfmt flag P as well which will enable QEMU to pass in correct argv0 to the application. Signed-off-by: Joakim Tjernlund --- linux-user/main.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 6ff7851e86..1b626e5762 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -544,7 +544,7 @@ static void usage(int exitcode) exit(exitcode); } -static int parse_args(int argc, char **argv) +static int parse_args(int argc, char **argv, int assume_P_flag) { const char *r; int optind; @@ -560,7 +560,17 @@ static int parse_args(int argc, char **argv) arginfo->handle_opt(r); } } - + if (assume_P_flag) { + /* Assume started by binmisc and binfmt P flag is set */ + if (argc < 3) { + fprintf(stderr, "%s: Please use me through binfmt with P flag\n", + argv[0]); + exit(1); + } + exec_path = argv[1]; + /* Next argv must be argv0 for the app */ + return 2; + } optind = 1; for (;;) { if (optind >= argc) { @@ -659,7 +669,8 @@ int main(int argc, char **argv, char **envp) qemu_add_opts(&qemu_trace_opts); qemu_plugin_add_opts(); - optind = parse_args(argc, argv); + execfd = qemu_getauxval(AT_EXECFD); + optind = parse_args(argc, argv, execfd > 0); if (!trace_init_backends()) { exit(1); @@ -682,7 +693,6 @@ int main(int argc, char **argv, char **envp) init_qemu_uname_release(); - execfd = qemu_getauxval(AT_EXECFD); if (execfd == 0) { execfd = open(exec_path, O_RDONLY); if (execfd < 0) {