From 8cd522fa188768493253eb4318e18ecb62aec748 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 2 Apr 2023 10:04:10 +0200 Subject: [PATCH] Don't use CLOEXEC In one case (Checker->App), we were removing it after setup so we don't need it. In the other case (App->App), it was just to be tiddy but it's not really useful: Forking applications are barely supported anyway. --- src/mc/api/RemoteApp.cpp | 8 +++++++- src/mc/remote/AppSide.cpp | 8 +++++++- src/mc/remote/CheckerSide.cpp | 7 +------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/mc/api/RemoteApp.cpp b/src/mc/api/RemoteApp.cpp index cb9450d536..78dbdf8376 100644 --- a/src/mc/api/RemoteApp.cpp +++ b/src/mc/api/RemoteApp.cpp @@ -48,7 +48,13 @@ RemoteApp::RemoteApp(const std::vector& args, bool need_memory_introspect xbt_die("SimGrid was compiled without MC support."); #endif } else { - master_socket_ = socket(AF_LOCAL, SOCK_SEQPACKET | SOCK_CLOEXEC, 0); + master_socket_ = socket(AF_LOCAL, + SOCK_SEQPACKET +#ifdef SOCK_CLOEXEC + | SOCK_CLOEXEC /* MacOSX does not have it */ +#endif + , + 0); xbt_assert(master_socket_ != -1, "Cannot create the master socket: %s", strerror(errno)); struct sockaddr_un serv_addr = {}; diff --git a/src/mc/remote/AppSide.cpp b/src/mc/remote/AppSide.cpp index 3c5b688f19..9401138435 100644 --- a/src/mc/remote/AppSide.cpp +++ b/src/mc/remote/AppSide.cpp @@ -162,7 +162,13 @@ void AppSide::handle_fork(const s_mc_message_int_t* msg) xbt_assert(pid >= 0, "Could not fork application sub-process: %s.", strerror(errno)); if (pid == 0) { // Child - int sock = socket(AF_LOCAL, SOCK_SEQPACKET | SOCK_CLOEXEC, 0); + int sock = socket(AF_LOCAL, + SOCK_SEQPACKET +#ifdef SOCK_CLOEXEC + | SOCK_CLOEXEC /* MacOSX does not have it */ +#endif + , + 0); struct sockaddr_un addr = {}; addr.sun_family = AF_LOCAL; diff --git a/src/mc/remote/CheckerSide.cpp b/src/mc/remote/CheckerSide.cpp index 0d5778af4b..2e64dd8449 100644 --- a/src/mc/remote/CheckerSide.cpp +++ b/src/mc/remote/CheckerSide.cpp @@ -54,11 +54,6 @@ XBT_ATTRIB_NORETURN static void run_child_process(int socket, const std::vector< xbt_assert(prctl(PR_SET_PDEATHSIG, SIGHUP) == 0, "Could not PR_SET_PDEATHSIG"); #endif - // Remove CLOEXEC to pass the socket to the application - int fdflags = fcntl(socket, F_GETFD, 0); - xbt_assert(fdflags != -1 && fcntl(socket, F_SETFD, fdflags & ~FD_CLOEXEC) != -1, - "Could not remove CLOEXEC for socket"); - setenv(MC_ENV_SOCKET_FD, std::to_string(socket).c_str(), 1); if (need_ptrace) setenv("MC_NEED_PTRACE", "1", 1); @@ -181,7 +176,7 @@ CheckerSide::CheckerSide(const std::vector& args, bool need_memory_info) // Create an AF_LOCAL socketpair used for exchanging messages between the model-checker process (ancestor) // and the application process (child) int sockets[2]; - xbt_assert(socketpair(AF_LOCAL, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sockets) != -1, "Could not create socketpair: %s", + xbt_assert(socketpair(AF_LOCAL, SOCK_SEQPACKET, 0, sockets) != -1, "Could not create socketpair: %s", strerror(errno)); pid_ = fork(); -- 2.30.2