diff options
author | Joshua Watt <JPEWhacker@gmail.com> | 2022-11-16 12:49:19 -0600 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-11-20 08:29:08 +0000 |
commit | 93707ae156e59b835c4ae0c6d301ed5a8f4a603b (patch) | |
tree | ed39436fb6235ec26fecdd9e911d6456c64e41a3 /meta/recipes-devtools/qemu/qemu-helper | |
parent | af9f61520bff21adf850c7f72e3bb69bec9fb2d2 (diff) | |
download | poky-93707ae156e59b835c4ae0c6d301ed5a8f4a603b.tar.gz |
qemu-helper-native: Correctly pass program name as argv[0]
The previous version of this wasn't correctly passing the program name
as argv[0], and was also over-complicated anyway because argv[] is
guaranteed to be terminated with a NULL pointer, so it can be passed
directly to the execv'd process without needing to be copied.
(From OE-Core rev: 6edf38add3c20c44efe0588e2815bb280d22e0c4)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/qemu/qemu-helper')
-rw-r--r-- | meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper.c | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper.c b/meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper.c index cadf2a012a..9434e1d269 100644 --- a/meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper.c +++ b/meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper.c | |||
@@ -8,6 +8,7 @@ | |||
8 | 8 | ||
9 | #include <stdio.h> | 9 | #include <stdio.h> |
10 | #include <unistd.h> | 10 | #include <unistd.h> |
11 | #include <stdlib.h> | ||
11 | 12 | ||
12 | void try_program(char const* path, char** args) { | 13 | void try_program(char const* path, char** args) { |
13 | if (access(path, X_OK) == 0) { | 14 | if (access(path, X_OK) == 0) { |
@@ -18,22 +19,14 @@ void try_program(char const* path, char** args) { | |||
18 | int main(int argc, char** argv) { | 19 | int main(int argc, char** argv) { |
19 | char* var; | 20 | char* var; |
20 | 21 | ||
21 | /* Copy arguments so that they are a NULL terminated list, skipping argv[0] | ||
22 | * since it is this program name */ | ||
23 | char** args = malloc(argc * sizeof(char*)); | ||
24 | for (int i = 0; i < argc - 1; i++) { | ||
25 | args[i] = argv[i + 1]; | ||
26 | } | ||
27 | args[argc - 1] = NULL; | ||
28 | |||
29 | var = getenv("QEMU_BRIDGE_HELPER"); | 22 | var = getenv("QEMU_BRIDGE_HELPER"); |
30 | if (var && var[0] != '\0') { | 23 | if (var && var[0] != '\0') { |
31 | execvp(var, args); | 24 | execvp(var, argv); |
32 | return 1; | 25 | return 1; |
33 | } | 26 | } |
34 | 27 | ||
35 | try_program("/usr/libexec/qemu-bridge-helper", args); | 28 | try_program("/usr/libexec/qemu-bridge-helper", argv); |
36 | try_program("/usr/lib/qemu/qemu-bridge-helper", args); | 29 | try_program("/usr/lib/qemu/qemu-bridge-helper", argv); |
37 | 30 | ||
38 | fprintf(stderr, "No bridge helper found\n"); | 31 | fprintf(stderr, "No bridge helper found\n"); |
39 | return 1; | 32 | return 1; |