Galaxip wrote: ↑Tue May 26, 2020 11:42 pm
I understand what you just said but for me to actually implement it is another thing entirely lol
Heh, I'm stumped as well. I see several approaches:
1. Keep things basically as they are now, but before calling the script in the forked process, SILENTLY close all sockets and files other than the standard input/output (I don't think we have any), and when you shut down after the script is done, do so without side effects.
The 'without side effects' is the tricky bit, this is C++ and we make use of static objects, they do work in their destructors. Apparently even if you call exit(-1).
2. fork() earlier. Do a preemptive fork() of a single script process right at the start of main() so it doesn't know anything about sockets or the game state. Communicate with that over input/output streams. This is the clean option, but also tons of work. There are still the static objects with init/exit side effects to worry about, but I think at this stage they don't pose problems.
3. look for a different way to spawn a subprocess that does not involve fork(), but still allows communication. All we need to control in the subprocess are the input/output pipelines and environment variables.
To patch your problem, I'd go with 1). Disable console output (is it already possible? If not, we're in the right file, a static flag could do the job), kill off the network sockets (Do we have direct access from this point? We're in the render subsystem for some reason...), worry about the exit problems later.
For a better solution, I'd research 3) first, but grudgingly settle for option 2) if nothing comes up.
Edit: Ah, fork() followed by exec...() should be right thing already. exec... completely replaces the current process, meaning there are no shutdown side effects. Only in the investigated case, exec... fails. We should not call exit(), then, but another exec...() that's bound to succeed. Still, sockets probably need silent closing. I don't know why this is required even in the success case.
Galaxip wrote: ↑Tue May 26, 2020 11:42 pmim curious but that quick hack system call thing i posted previously doesnt do any fork stuff but I still had the issue of the server port increasing after everyone leaves the game
The man page of system() says it is using fork(), so you're just hiding the call.