@@ -843,6 +843,14 @@ static std::atomic_bool init_called{false};
843
843
int InitializeNodeWithArgs (std::vector<std::string>* argv,
844
844
std::vector<std::string>* exec_argv,
845
845
std::vector<std::string>* errors) {
846
+ return InitializeNodeWithArgs (argv, exec_argv, errors,
847
+ ProcessFlags::kNoFlags );
848
+ }
849
+
850
+ int InitializeNodeWithArgs (std::vector<std::string>* argv,
851
+ std::vector<std::string>* exec_argv,
852
+ std::vector<std::string>* errors,
853
+ ProcessFlags::Flags flags) {
846
854
// Make sure InitializeNodeWithArgs() is called only once.
847
855
CHECK (!init_called.exchange (true ));
848
856
@@ -853,7 +861,8 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv,
853
861
binding::RegisterBuiltinModules ();
854
862
855
863
// Make inherited handles noninheritable.
856
- uv_disable_stdio_inheritance ();
864
+ if (!(flags & ProcessFlags::kEnableStdioInheritance ))
865
+ uv_disable_stdio_inheritance ();
857
866
858
867
// Cache the original command line to be
859
868
// used in diagnostic reports.
@@ -869,67 +878,73 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv,
869
878
HandleEnvOptions (per_process::cli_options->per_isolate ->per_env );
870
879
871
880
#if !defined(NODE_WITHOUT_NODE_OPTIONS)
872
- std::string node_options;
881
+ if (!(flags & ProcessFlags::kDisableNodeOptionsEnv )) {
882
+ std::string node_options;
873
883
874
- if (credentials::SafeGetenv (" NODE_OPTIONS" , &node_options)) {
875
- std::vector<std::string> env_argv =
876
- ParseNodeOptionsEnvVar (node_options, errors);
884
+ if (credentials::SafeGetenv (" NODE_OPTIONS" , &node_options)) {
885
+ std::vector<std::string> env_argv =
886
+ ParseNodeOptionsEnvVar (node_options, errors);
877
887
878
- if (!errors->empty ()) return 9 ;
888
+ if (!errors->empty ()) return 9 ;
879
889
880
- // [0] is expected to be the program name, fill it in from the real argv.
881
- env_argv.insert (env_argv.begin (), argv->at (0 ));
890
+ // [0] is expected to be the program name, fill it in from the real argv.
891
+ env_argv.insert (env_argv.begin (), argv->at (0 ));
882
892
883
- const int exit_code = ProcessGlobalArgs (&env_argv,
884
- nullptr ,
885
- errors,
886
- kAllowedInEnvironment );
887
- if (exit_code != 0 ) return exit_code;
893
+ const int exit_code = ProcessGlobalArgs (&env_argv,
894
+ nullptr ,
895
+ errors,
896
+ kAllowedInEnvironment );
897
+ if (exit_code != 0 ) return exit_code;
898
+ }
888
899
}
889
900
#endif
890
901
891
- const int exit_code = ProcessGlobalArgs (argv,
892
- exec_argv,
893
- errors,
894
- kDisallowedInEnvironment );
895
- if (exit_code != 0 ) return exit_code;
902
+ if (!(flags & ProcessFlags::kDisableCLIOptions )) {
903
+ const int exit_code = ProcessGlobalArgs (argv,
904
+ exec_argv,
905
+ errors,
906
+ kDisallowedInEnvironment );
907
+ if (exit_code != 0 ) return exit_code;
908
+ }
896
909
897
910
// Set the process.title immediately after processing argv if --title is set.
898
911
if (!per_process::cli_options->title .empty ())
899
912
uv_set_process_title (per_process::cli_options->title .c_str ());
900
913
901
914
#if defined(NODE_HAVE_I18N_SUPPORT)
902
- // If the parameter isn't given, use the env variable.
903
- if (per_process::cli_options->icu_data_dir .empty ())
904
- credentials::SafeGetenv (" NODE_ICU_DATA" ,
905
- &per_process::cli_options->icu_data_dir );
915
+ if (!(flags & ProcessFlags::kNoICU )) {
916
+ // If the parameter isn't given, use the env variable.
917
+ if (per_process::cli_options->icu_data_dir .empty ())
918
+ credentials::SafeGetenv (" NODE_ICU_DATA" ,
919
+ &per_process::cli_options->icu_data_dir );
906
920
907
921
#ifdef NODE_ICU_DEFAULT_DATA_DIR
908
- // If neither the CLI option nor the environment variable was specified,
909
- // fall back to the configured default
910
- if (per_process::cli_options->icu_data_dir .empty ()) {
911
- // Check whether the NODE_ICU_DEFAULT_DATA_DIR contains the right data
912
- // file and can be read.
913
- static const char full_path[] =
914
- NODE_ICU_DEFAULT_DATA_DIR " /" U_ICUDATA_NAME " .dat" ;
915
-
916
- FILE* f = fopen (full_path, " rb" );
917
-
918
- if (f != nullptr ) {
919
- fclose (f);
920
- per_process::cli_options->icu_data_dir = NODE_ICU_DEFAULT_DATA_DIR;
922
+ // If neither the CLI option nor the environment variable was specified,
923
+ // fall back to the configured default
924
+ if (per_process::cli_options->icu_data_dir .empty ()) {
925
+ // Check whether the NODE_ICU_DEFAULT_DATA_DIR contains the right data
926
+ // file and can be read.
927
+ static const char full_path[] =
928
+ NODE_ICU_DEFAULT_DATA_DIR " /" U_ICUDATA_NAME " .dat" ;
929
+
930
+ FILE* f = fopen (full_path, " rb" );
931
+
932
+ if (f != nullptr ) {
933
+ fclose (f);
934
+ per_process::cli_options->icu_data_dir = NODE_ICU_DEFAULT_DATA_DIR;
935
+ }
921
936
}
922
- }
923
937
#endif // NODE_ICU_DEFAULT_DATA_DIR
924
938
925
- // Initialize ICU.
926
- // If icu_data_dir is empty here, it will load the 'minimal' data.
927
- if (!i18n::InitializeICUDirectory (per_process::cli_options->icu_data_dir )) {
928
- errors->push_back (" could not initialize ICU "
929
- " (check NODE_ICU_DATA or --icu-data-dir parameters)\n " );
930
- return 9 ;
939
+ // Initialize ICU.
940
+ // If icu_data_dir is empty here, it will load the 'minimal' data.
941
+ if (!i18n::InitializeICUDirectory (per_process::cli_options->icu_data_dir )) {
942
+ errors->push_back (" could not initialize ICU "
943
+ " (check NODE_ICU_DATA or --icu-data-dir parameters)\n " );
944
+ return 9 ;
945
+ }
946
+ per_process::metadata.versions .InitializeIntlVersions ();
931
947
}
932
- per_process::metadata.versions .InitializeIntlVersions ();
933
948
934
949
# ifndef __POSIX__
935
950
std::string tz;
@@ -956,7 +971,8 @@ InitializationResult InitializeOncePerProcess(int argc, char** argv) {
956
971
InitializationResult InitializeOncePerProcess (
957
972
int argc,
958
973
char ** argv,
959
- InitializationSettingsFlags flags) {
974
+ InitializationSettingsFlags flags,
975
+ ProcessFlags::Flags process_flags) {
960
976
uint64_t init_flags = flags;
961
977
if (init_flags & kDefaultInitialization ) {
962
978
init_flags = init_flags | kInitializeV8 | kInitOpenSSL | kRunPlatformInit ;
@@ -982,8 +998,8 @@ InitializationResult InitializeOncePerProcess(
982
998
983
999
// This needs to run *before* V8::Initialize().
984
1000
{
985
- result.exit_code =
986
- InitializeNodeWithArgs ( &(result.args ), &(result.exec_args ), &errors);
1001
+ result.exit_code = InitializeNodeWithArgs (
1002
+ &(result.args ), &(result.exec_args ), &errors, process_flags );
987
1003
for (const std::string& error : errors)
988
1004
fprintf (stderr, " %s: %s\n " , result.args .at (0 ).c_str (), error.c_str ());
989
1005
if (result.exit_code != 0 ) {
0 commit comments