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