@@ -3322,6 +3322,36 @@ static void DebugEnd(const FunctionCallbackInfo<Value>& args) {
3322
3322
}
3323
3323
3324
3324
3325
+ inline void PlatformInit () {
3326
+ #ifdef __POSIX__
3327
+ // Raise the open file descriptor limit.
3328
+ struct rlimit lim;
3329
+ if (getrlimit (RLIMIT_NOFILE, &lim) == 0 && lim.rlim_cur != lim.rlim_max ) {
3330
+ // Do a binary search for the limit.
3331
+ rlim_t min = lim.rlim_cur ;
3332
+ rlim_t max = 1 << 20 ;
3333
+ // But if there's a defined upper bound, don't search, just set it.
3334
+ if (lim.rlim_max != RLIM_INFINITY) {
3335
+ min = lim.rlim_max ;
3336
+ max = lim.rlim_max ;
3337
+ }
3338
+ do {
3339
+ lim.rlim_cur = min + (max - min) / 2 ;
3340
+ if (setrlimit (RLIMIT_NOFILE, &lim)) {
3341
+ max = lim.rlim_cur ;
3342
+ } else {
3343
+ min = lim.rlim_cur ;
3344
+ }
3345
+ } while (min + 1 < max);
3346
+ }
3347
+ // Ignore SIGPIPE
3348
+ RegisterSignalHandler (SIGPIPE, SIG_IGN);
3349
+ RegisterSignalHandler (SIGINT, SignalExit, true );
3350
+ RegisterSignalHandler (SIGTERM, SignalExit, true );
3351
+ #endif // __POSIX__
3352
+ }
3353
+
3354
+
3325
3355
void Init (int * argc,
3326
3356
const char ** argv,
3327
3357
int * exec_argc,
@@ -3396,35 +3426,6 @@ void Init(int* argc,
3396
3426
3397
3427
V8::SetArrayBufferAllocator (&ArrayBufferAllocator::the_singleton);
3398
3428
3399
- #ifdef __POSIX__
3400
- // Raise the open file descriptor limit.
3401
- { // NOLINT (whitespace/braces)
3402
- struct rlimit lim;
3403
- if (getrlimit (RLIMIT_NOFILE, &lim) == 0 && lim.rlim_cur != lim.rlim_max ) {
3404
- // Do a binary search for the limit.
3405
- rlim_t min = lim.rlim_cur ;
3406
- rlim_t max = 1 << 20 ;
3407
- // But if there's a defined upper bound, don't search, just set it.
3408
- if (lim.rlim_max != RLIM_INFINITY) {
3409
- min = lim.rlim_max ;
3410
- max = lim.rlim_max ;
3411
- }
3412
- do {
3413
- lim.rlim_cur = min + (max - min) / 2 ;
3414
- if (setrlimit (RLIMIT_NOFILE, &lim)) {
3415
- max = lim.rlim_cur ;
3416
- } else {
3417
- min = lim.rlim_cur ;
3418
- }
3419
- } while (min + 1 < max);
3420
- }
3421
- }
3422
- // Ignore SIGPIPE
3423
- RegisterSignalHandler (SIGPIPE, SIG_IGN);
3424
- RegisterSignalHandler (SIGINT, SignalExit, true );
3425
- RegisterSignalHandler (SIGTERM, SignalExit, true );
3426
- #endif // __POSIX__
3427
-
3428
3429
if (!use_debug_agent) {
3429
3430
RegisterDebugSignalHandler ();
3430
3431
}
@@ -3610,6 +3611,8 @@ Environment* CreateEnvironment(Isolate* isolate,
3610
3611
3611
3612
3612
3613
int Start (int argc, char ** argv) {
3614
+ PlatformInit ();
3615
+
3613
3616
const char * replaceInvalid = secure_getenv (" NODE_INVALID_UTF8" );
3614
3617
3615
3618
if (replaceInvalid == nullptr )
0 commit comments