Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't use CLOEXEC
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 2 Apr 2023 08:04:10 +0000 (10:04 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 2 Apr 2023 08:04:15 +0000 (10:04 +0200)
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
src/mc/remote/AppSide.cpp
src/mc/remote/CheckerSide.cpp

index cb9450d..78dbdf8 100644 (file)
@@ -48,7 +48,13 @@ RemoteApp::RemoteApp(const std::vector<char*>& 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 = {};
index 3c5b688..9401138 100644 (file)
@@ -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;
index 0d5778a..2e64dd8 100644 (file)
@@ -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<char*>& 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();