···206206static bool
207207ipc_client_socket_connect(struct ipc_connection *ipc_c)
208208{
209209+#ifdef SOCK_CLOEXEC
210210+ // Make sure the socket is not inherited by child processes. For one, when there is an fd to the socket
211211+ // in the child process closing the client connection (or killing the connected process)
212212+ // may not be seen in the server as client disconnection.
213213+ const int flags = SOCK_CLOEXEC;
214214+#else
215215+ const int flags = 0;
216216+#endif
209217 struct sockaddr_un addr;
210218 int ret;
211219212220213221 // create our IPC socket
214222215215- ret = socket(PF_UNIX, SOCK_STREAM, 0);
223223+ ret = socket(PF_UNIX, SOCK_STREAM | flags, 0);
216224 if (ret < 0) {
217225 IPC_ERROR(ipc_c, "Socket Create Error!");
218226 return false;