* @brief Deparents itself by forking and terminating the parent process. */
| 105 | * @brief Deparents itself by forking and terminating the parent process. |
| 106 | */ |
| 107 | void DeparentSelf() { |
| 108 | auto SystemdEnv = getenv("INVOCATION_ID"); |
| 109 | if (SystemdEnv) { |
| 110 | // If FEXServer was launched through systemd then don't deparent, otherwise systemd kills the entire server. |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | pid_t pid = fork(); |
| 115 | |
| 116 | if (pid != 0) { |
| 117 | // Parent is leaving to force this process to deparent itself |
| 118 | // This lets this process become the child of whatever the reaper parent is |
| 119 | _exit(0); |
| 120 | } |
| 121 | } |
| 122 | } // namespace |
| 123 | |
| 124 | int main(int argc, char** argv, char** const envp) { |