Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove function calls with side effects from xbt_assert.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 30 Mar 2021 09:12:12 +0000 (11:12 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 30 Mar 2021 20:02:10 +0000 (22:02 +0200)
src/mc/ModelChecker.cpp
src/mc/Session.cpp
src/mc/remote/AppSide.cpp

index 4ae4fc5..102133f 100644 (file)
@@ -267,7 +267,8 @@ void ModelChecker::handle_waitpid()
       // From PTRACE_O_TRACEEXIT:
 #ifdef __linux__
       if (status>>8 == (SIGTRAP | (PTRACE_EVENT_EXIT<<8))) {
-        xbt_assert(ptrace(PTRACE_GETEVENTMSG, remote_process_->pid(), 0, &status) != -1, "Could not get exit status");
+        int ptrace_res = ptrace(PTRACE_GETEVENTMSG, remote_process_->pid(), 0, &status);
+        xbt_assert(ptrace_res != -1, "Could not get exit status");
         if (WIFSIGNALED(status)) {
           MC_report_crash(status);
           this->exit(SIMGRID_MC_EXIT_PROGRAM_CRASH);
index fe6b08a..1eaae21 100644 (file)
@@ -39,14 +39,16 @@ template <class Code> void run_child_process(int socket, Code code)
   // Make sure we do not outlive our parent
   sigset_t mask;
   sigemptyset (&mask);
-  xbt_assert(sigprocmask(SIG_SETMASK, &mask, nullptr) >= 0, "Could not unblock signals");
-  xbt_assert(prctl(PR_SET_PDEATHSIG, SIGHUP) == 0, "Could not PR_SET_PDEATHSIG");
+  int sigprocmask_res = sigprocmask(SIG_SETMASK, &mask, nullptr);
+  xbt_assert(sigprocmask_res >= 0, "Could not unblock signals");
+  int prctl_res = prctl(PR_SET_PDEATHSIG, SIGHUP);
+  xbt_assert(prctl_res == 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");
+  int fdflags   = fcntl(socket, F_GETFD, 0);
+  int fcntl_res = fdflags != -1 ? fcntl(socket, F_SETFD, fdflags & ~FD_CLOEXEC) : -1;
+  xbt_assert(fcntl_res != -1, "Could not remove CLOEXEC for socket");
 
   // Disable lazy relocation in the model-checked process to prevent the application from
   // modifying its .got.plt during snapshot.
index abf4c25..f97e2f8 100644 (file)
@@ -67,7 +67,8 @@ AppSide* AppSide::initialize()
   s_mc_message_initial_addresses_t message{
       MessageType::INITIAL_ADDRESSES, mmalloc_preinit(), simgrid::kernel::actor::get_maxpid_addr(),
       simgrid::simix::simix_global_get_actors_addr(), simgrid::simix::simix_global_get_dead_actors_addr()};
-  xbt_assert(instance_->channel_.send(message) == 0, "Could not send the initial message with addresses.");
+  int send_res = instance_->channel_.send(message);
+  xbt_assert(send_res == 0, "Could not send the initial message with addresses.");
 
   instance_->handle_messages();
   return instance_.get();
@@ -87,7 +88,8 @@ void AppSide::handle_deadlock_check(const s_mc_message_t*) const
 
   // Send result:
   s_mc_message_int_t answer{MessageType::DEADLOCK_CHECK_REPLY, deadlock};
-  xbt_assert(channel_.send(answer) == 0, "Could not send response");
+  int send_res = channel_.send(answer);
+  xbt_assert(send_res == 0, "Could not send response");
 }
 void AppSide::handle_simcall_execute(const s_mc_message_simcall_handle_t* message) const
 {
@@ -145,7 +147,8 @@ void AppSide::handle_messages() const
 
         // Send result:
         s_mc_message_simcall_is_visible_answer_t answer{MessageType::SIMCALL_IS_VISIBLE_ANSWER, value};
-        xbt_assert(channel_.send(answer) == 0, "Could not send response");
+        int send_res = channel_.send(answer);
+        xbt_assert(send_res == 0, "Could not send response");
         break;
       }
 
@@ -160,7 +163,8 @@ void AppSide::handle_messages() const
         // Send result:
         s_mc_message_simcall_to_string_answer_t answer{MessageType::SIMCALL_TO_STRING_ANSWER, {0}};
         value.copy(answer.value, (sizeof answer.value) - 1); // last byte was set to '\0' by initialization above
-        xbt_assert(channel_.send(answer) == 0, "Could not send response");
+        int send_res = channel_.send(answer);
+        xbt_assert(send_res == 0, "Could not send response");
         break;
       }
 
@@ -175,7 +179,8 @@ void AppSide::handle_messages() const
         // Send result:
         s_mc_message_simcall_to_string_answer_t answer{MessageType::SIMCALL_TO_STRING_ANSWER, {0}};
         value.copy(answer.value, (sizeof answer.value) - 1); // last byte was set to '\0' by initialization above
-        xbt_assert(channel_.send(answer) == 0, "Could not send response");
+        int send_res = channel_.send(answer);
+        xbt_assert(send_res == 0, "Could not send response");
         break;
       }
 
@@ -192,7 +197,8 @@ void AppSide::handle_messages() const
           SMPI_finalize();
 #endif
         s_mc_message_int_t answer{MessageType::DEADLOCK_CHECK_REPLY, 0};
-        xbt_assert(channel_.send(answer) == 0, "Could answer to FINALIZE");
+        int send_res = channel_.send(answer);
+        xbt_assert(send_res == 0, "Could answer to FINALIZE");
         break;
       }
 
@@ -207,7 +213,8 @@ void AppSide::main_loop() const
 {
   while (true) {
     simgrid::mc::execute_actors();
-    xbt_assert(channel_.send(MessageType::WAITING) == 0, "Could not send WAITING message to model-checker");
+    int send_res = channel_.send(MessageType::WAITING);
+    xbt_assert(send_res == 0, "Could not send WAITING message to model-checker");
     this->handle_messages();
   }
 }