worker: also replaces fd 0/1 so we don't accidentally re-use them
@@ -883,11 +883,17 @@ u3_worker_boot(void)
c3_i
main(c3_i argc, c3_c* argv[])
{
- // Close file descriptors 0 and 1 so that we don't use them by accident.
- int inn_i = dup(0);
- int out_i = dup(1);
- close(0);
- close(1);
+ // the worker is spawned with [FD 0] = events and [FD 1] = effects
+ // we dup [FD 0 & 1] so we don't accidently use them for something else
+ // we replace [FD 0] (stdin) with a fd pointing to /dev/null
+ // we replace [FD 1] (stdout) with a dup of [FD 2] (stderr)
+ //
+ c3_i nul_i = open("/dev/null", O_RDWR, 0);
+ c3_i inn_i = dup(0);
+ c3_i out_i = dup(1);
+ dup2(nul_i, 0);
+ dup2(2, 1);
+ close(nul_i);
uv_loop_t* lup_u = uv_default_loop();
c3_c* dir_c = argv[1];
