From: Joakim Tjernlund <joakim.tjernlund@infinera.com>
To: qemu-devel@nongnu.org
Cc: Joakim Tjernlund <Joakim.Tjernlund@infinera.com>
Subject: [PATCH] linux-user: make binfmt flag O require P
Date: Sat, 14 Dec 2019 13:20:22 +0100 [thread overview]
Message-ID: <20191214122022.17255-1-joakim.tjernlund@infinera.com> (raw)
From: Joakim Tjernlund <Joakim.Tjernlund@infinera.com>
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 <Joakim.Tjernlund@infinera.com>
---
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) {
--
2.24.1
next reply other threads:[~2019-12-14 22:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-14 12:20 Joakim Tjernlund [this message]
2019-12-15 16:54 ` [PATCH] linux-user: make binfmt flag O require P Laurent Vivier
2019-12-15 21:07 ` Joakim Tjernlund
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191214122022.17255-1-joakim.tjernlund@infinera.com \
--to=joakim.tjernlund@infinera.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).