qemu-helper-native: Correctly pass program name as argv[0]
PATCH 1/1 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.
--- .../qemu/qemu-helper/qemu-oe-bridge-helper.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper.c +4 -11
@@ -8,6 +8,7 @@#include <stdio.h> #include <unistd.h> +#include <stdlib.h> void try_program (char const * path,char ** args) {if (access (path,X_OK ) ==0 ) {
@@ -18,22 +19,14 @@ void try_program(char const* path, char** args) {int main (int argc,char ** argv) {char * var; -/* Copy arguments so that they are a NULL terminated list, skipping argv[0] -* since it is this program name */ -char ** args =malloc (argc *sizeof (char *)); -for (int i =0 ; i < argc -1 ; i++) { - args[i] = argv[i +1 ]; - } - args[argc -1 ] =NULL ; - var =getenv ("QEMU_BRIDGE_HELPER" );if (var && var[0 ] !='\0' ) { -execvp (var, args); +execvp (var, argv);return 1 ; } -try_program ("/usr/libexec/qemu-bridge-helper" , args); -try_program ("/usr/lib/qemu/qemu-bridge-helper" , args); +try_program ("/usr/libexec/qemu-bridge-helper" , argv); +try_program ("/usr/lib/qemu/qemu-bridge-helper" , argv);fprintf (stderr,"No bridge helper found\n" );return 1 ;
Signature · 1 line
2.33.0
Quoted 16 lines · Joshua Watt
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.
Signed-off-by Joshua Watt <[email protected]>--- .../qemu/qemu-helper/qemu-oe-bridge-helper.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper.c +0
-0
meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper.c line 11
Quoted 4 lines
meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper.c +1
-0@@ -8,6 +8,7 @@#include <stdio.h> #include <unistd.h> +#include <stdlib.h>
why do we need stdlib.h header ?
Quoted 41 lines
meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper.c +3
-12void try_program (char const * path,char ** args) {if (access (path,X_OK ) ==0 ) {@@ -18,22 +19,14 @@ void try_program(char const* path, char** args) {int main (int argc,char ** argv) {char * var; -/* Copy arguments so that they are a NULL terminated list, skipping argv[0] -* since it is this program name */ -char ** args =malloc (argc *sizeof (char *)); -for (int i =0 ; i < argc -1 ; i++) { - args[i] = argv[i +1 ]; - } - args[argc -1 ] =NULL ; - var =getenv ("QEMU_BRIDGE_HELPER" );if (var && var[0 ] !='\0' ) { -execvp (var, args); +execvp (var, argv);return 1 ; } -try_program ("/usr/libexec/qemu-bridge-helper" , args); -try_program ("/usr/lib/qemu/qemu-bridge-helper" , args); +try_program ("/usr/libexec/qemu-bridge-helper" , argv); +try_program ("/usr/lib/qemu/qemu-bridge-helper" , argv);fprintf (stderr,"No bridge helper found\n" );return 1 ; --2.33.0
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#173389): https://lists.openembedded.org/g/openembedded-core/message/173389
Mute This Topic: https://lists.openembedded.org/mt/95073277/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Steve,
Please backport this to Langdale (note you'll need the other qemu-helper-native patch first)
Thanks
Quoted 52 lines · Joshua Watt
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.
Signed-off-by Joshua Watt <[email protected]>--- .../qemu/qemu-helper/qemu-oe-bridge-helper.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper.c +4
-12@@ -8,6 +8,7 @@#include <stdio.h> #include <unistd.h> +#include <stdlib.h> void try_program (char const * path,char ** args) {if (access (path,X_OK ) ==0 ) {@@ -18,22 +19,14 @@ void try_program(char const* path, char** args) {int main (int argc,char ** argv) {char * var; -/* Copy arguments so that they are a NULL terminated list, skipping argv[0] -* since it is this program name */ -char ** args =malloc (argc *sizeof (char *)); -for (int i =0 ; i < argc -1 ; i++) { - args[i] = argv[i +1 ]; - } - args[argc -1 ] =NULL ; - var =getenv ("QEMU_BRIDGE_HELPER" );if (var && var[0 ] !='\0' ) { -execvp (var, args); +execvp (var, argv);return 1 ; } -try_program ("/usr/libexec/qemu-bridge-helper" , args); -try_program ("/usr/lib/qemu/qemu-bridge-helper" , args); +try_program ("/usr/libexec/qemu-bridge-helper" , argv); +try_program ("/usr/lib/qemu/qemu-bridge-helper" , argv);fprintf (stderr,"No bridge helper found\n" );return 1 ; --2.33.0