@@ -457,6 +457,41 @@ bool readFile(char* filename, int* size, char** buffer) {
457
457
return TRUE;
458
458
}
459
459
460
+ /* run a command outside the current appimage, block environs like LD_LIBRARY_PATH */
461
+ int run_external (const char * filename , char * const argv []) {
462
+ int pid = fork ();
463
+ if (pid < 0 ) {
464
+ g_print ("run_external: fork failed" );
465
+ // fork failed
466
+ exit (1 );
467
+ } else if (pid == 0 ) {
468
+ // blocks env defined in resources/AppRun
469
+ unsetenv ("LD_LIBRARY_PATH" );
470
+ unsetenv ("PYTHONPATH" );
471
+ unsetenv ("XDG_DATA_DIRS" );
472
+ unsetenv ("PERLLIB" );
473
+ unsetenv ("GSETTINGS_SCHEMA_DIR" );
474
+ unsetenv ("QT_PLUGIN_PATH" );
475
+ // runs command
476
+ execv (filename , argv );
477
+ // execv(3) returns, indicating error
478
+ g_print ("run_external: subprocess execv(3) got error %s" , g_strerror (errno ));
479
+ exit (1 );
480
+ } else {
481
+ int wstatus ;
482
+ if (waitpid (pid , & wstatus , 0 ) == -1 ) {
483
+ g_print ("run_external: wait failed" );
484
+ return -1 ;
485
+ }
486
+ if (WIFEXITED (wstatus ) && (WEXITSTATUS (wstatus ) == 0 )) {
487
+ return 0 ;
488
+ } else {
489
+ g_print ("run_external: subprocess exited with status %d" , WEXITSTATUS (wstatus ));
490
+ return 1 ;
491
+ }
492
+ }
493
+ }
494
+
460
495
// #####################################################################
461
496
462
497
static GOptionEntry entries [] =
@@ -794,19 +829,29 @@ main (int argc, char *argv[])
794
829
fprintf (stderr , "AppStream upstream metadata found in usr/share/metainfo/%s\n" , application_id );
795
830
/* Use ximion's appstreamcli to make sure that desktop file and appdata match together */
796
831
if (g_find_program_in_path ("appstreamcli" )) {
797
- sprintf (command , "%s validate-tree %s" , g_find_program_in_path ("appstreamcli" ), source );
832
+ char * args [] = {
833
+ "appstreamcli" ,
834
+ "validate-tree" ,
835
+ source ,
836
+ NULL
837
+ };
798
838
g_print ("Trying to validate AppStream information with the appstreamcli tool\n" );
799
839
g_print ("In case of issues, please refer to https://github.com/ximion/appstream\n" );
800
- int ret = system ( command );
840
+ int ret = run_external ( g_find_program_in_path ( "appstreamcli" ), args );
801
841
if (ret != 0 )
802
842
die ("Failed to validate AppStream information with appstreamcli" );
803
843
}
804
844
/* It seems that hughsie's appstream-util does additional validations */
805
845
if (g_find_program_in_path ("appstream-util" )) {
806
- sprintf (command , "%s validate-relax %s" , g_find_program_in_path ("appstream-util" ), appdata_path );
846
+ char * args [] = {
847
+ "appstream-util" ,
848
+ "validate-relax" ,
849
+ appdata_path ,
850
+ NULL
851
+ };
807
852
g_print ("Trying to validate AppStream information with the appstream-util tool\n" );
808
853
g_print ("In case of issues, please refer to https://github.com/hughsie/appstream-glib\n" );
809
- int ret = system ( command );
854
+ int ret = run_external ( g_find_program_in_path ( "appstream-util" ), args );
810
855
if (ret != 0 )
811
856
die ("Failed to validate AppStream information with appstream-util" );
812
857
}
0 commit comments