-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable preserve-argv0 by default on mainline
P flag is needed in order for qemu to not lose argv0 value. Problem is that qemu can only detect that flag was set on 5.12+ kernels and if it doesn’t detect it then all argument values are wrong. This introduces a patch that is enabled on mainline target that assumes P flag was set if the kernel does not provide any flags. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
- Loading branch information
1 parent
eed5db1
commit c5e2139
Showing
6 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
patches/preserve-argv0/0001-linux-user-default-to-preserve-argv0.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
From eb4410de7f5297c643081e79a89f226210e3f4dd Mon Sep 17 00:00:00 2001 | ||
From: Tonis Tiigi <tonistiigi@gmail.com> | ||
Date: Thu, 20 Jan 2022 20:21:07 -0800 | ||
Subject: [PATCH] linux-user: default to preserve-argv0 | ||
|
||
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com> | ||
--- | ||
linux-user/main.c | 5 +++++ | ||
1 file changed, 5 insertions(+) | ||
|
||
diff --git a/linux-user/main.c b/linux-user/main.c | ||
index 37ed50d98e..87e76845dc 100644 | ||
--- a/linux-user/main.c | ||
+++ b/linux-user/main.c | ||
@@ -706,6 +706,11 @@ int main(int argc, char **argv, char **envp) | ||
* get binfmt_misc flags | ||
*/ | ||
preserve_argv0 = !!(qemu_getauxval(AT_FLAGS) & AT_FLAGS_PRESERVE_ARGV0); | ||
+ | ||
+ // default to preserve_argv0 on older kernels | ||
+ if (qemu_getauxval(AT_FLAGS) == 0) { | ||
+ preserve_argv0 = 1; | ||
+ } | ||
|
||
/* | ||
* Manage binfmt-misc preserve-arg[0] flag | ||
-- | ||
2.32.0 (Apple Git-132) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package tests | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func init() { | ||
if v := os.Getenv("BINFMT_ARGV0_TEST"); v != "" { | ||
fmt.Println(strings.Join(os.Args, ",")) | ||
os.Exit(0) | ||
} | ||
} | ||
|
||
func TestArgv0(t *testing.T) { | ||
self := "/proc/self/exe" | ||
if v, ok := os.LookupEnv("REEXEC_NAME"); ok { | ||
self = v | ||
} | ||
cmd := &exec.Cmd{ | ||
Path: self, | ||
Env: []string{"BINFMT_ARGV0_TEST=1"}, | ||
Args: []string{"first", "second", "third"}, | ||
} | ||
out, err := cmd.CombinedOutput() | ||
require.Equal(t, "first,second,third\n", string(out)) | ||
require.NoError(t, err) | ||
} |