summaryrefslogtreecommitdiff
path: root/pcr/qemu-user-static-git/0001-fix-program-invocation-name.patch
blob: f2b915b67bab9ac3ba272b975b00be410762559c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
diff --git a/linux-user/main.c b/linux-user/main.c
index 108e1f202c..30cbb73496 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -4450,7 +4450,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;
@@ -4467,6 +4467,19 @@ static int parse_args(int argc, char **argv)
         }
     }
 
+    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);
+        }
+        filename = argv[1];
+        exec_path = argv[1];
+        /* Next argv must be argv0 for the app */
+        return 2;
+    }
+
     optind = 1;
     for (;;) {
         if (optind >= argc) {
@@ -4565,7 +4578,8 @@ int main(int argc, char **argv, char **envp)
 
     qemu_add_opts(&qemu_trace_opts);
 
-    optind = parse_args(argc, argv);
+    execfd = qemu_getauxval(AT_EXECFD);
+    optind = parse_args(argc, argv, execfd > 0);
 
     if (!trace_init_backends()) {
         exit(1);
@@ -4585,7 +4599,6 @@ int main(int argc, char **argv, char **envp)
 
     init_qemu_uname_release();
 
-    execfd = qemu_getauxval(AT_EXECFD);
     if (execfd == 0) {
         execfd = open(filename, O_RDONLY);
         if (execfd < 0) {
diff --git a/scripts/qemu-binfmt-conf.sh b/scripts/qemu-binfmt-conf.sh
index f39ad344fc..d070c33a74 100755
--- a/scripts/qemu-binfmt-conf.sh
+++ b/scripts/qemu-binfmt-conf.sh
@@ -292,7 +292,7 @@ SYSTEMDDIR="/etc/binfmt.d"
 DEBIANDIR="/usr/share/binfmts"
 
 QEMU_PATH=/usr/local/bin
-FLAGS=""
+FLAGS="P"
 
 options=$(getopt -o ds:Q:e:hc: -l debian,systemd:,qemu-path:,exportdir:,help,credential: -- "$@")
 eval set -- "$options"
@@ -341,9 +341,7 @@ while true ; do
     -c|--credential)
         shift
         if [ "$1" = "yes" ] ; then
-            FLAGS="OC"
-        else
-            FLAGS=""
+            FLAGS+="OC"
         fi
         ;;
     *)