Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Private Process::pid
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 22 May 2015 08:20:03 +0000 (10:20 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 22 May 2015 11:26:02 +0000 (13:26 +0200)
src/mc/mc_checkpoint.cpp
src/mc/mc_process.cpp
src/mc/mc_process.h
src/mc/mc_server.cpp

index aca9153..081aead 100644 (file)
@@ -606,13 +606,12 @@ static void MC_snapshot_ignore_restore(mc_snapshot_t snapshot)
 
 static void MC_get_current_fd(mc_snapshot_t snapshot)
 {
-
   snapshot->total_fd = 0;
 
   const size_t fd_dir_path_size = 20;
   char fd_dir_path[fd_dir_path_size];
   int res = snprintf(fd_dir_path, fd_dir_path_size,
-    "/proc/%lli/fd", (long long int) snapshot->process->pid);
+    "/proc/%lli/fd", (long long int) snapshot->process->pid());
   xbt_assert(res >= 0);
   if ((size_t) res > fd_dir_path_size)
     xbt_die("Unexpected buffer is too small for fd_dir_path");
@@ -633,7 +632,7 @@ static void MC_get_current_fd(mc_snapshot_t snapshot)
     const size_t source_size = 25;
     char source[25];
     int res = snprintf(source, source_size, "/proc/%lli/fd/%s",
-        (long long int) snapshot->process->pid, fd_number->d_name);
+        (long long int) snapshot->process->pid(), fd_number->d_name);
     xbt_assert(res >= 0);
     if ((size_t) res > source_size)
       xbt_die("Unexpected buffer is too small for fd %s", fd_number->d_name);
index e80715b..0b4a9ba 100644 (file)
@@ -191,7 +191,7 @@ Process::Process(pid_t pid, int sockfd)
 
   process->process_flags = MC_PROCESS_NO_FLAG;
   process->socket = sockfd;
-  process->pid = pid;
+  process->pid_ = pid;
   if (pid==getpid())
     process->process_flags |= MC_PROCESS_SELF_FLAG;
   process->running = true;
@@ -206,7 +206,7 @@ Process::Process(pid_t pid, int sockfd)
   if (process->is_self())
     process->memory_file = -1;
   else {
-    int fd = open_vm(process->pid, O_RDWR);
+    int fd = open_vm(process->pid_, O_RDWR);
     if (fd<0)
       xbt_die("Could not open file for process virtual address space");
     process->memory_file = fd;
@@ -240,7 +240,7 @@ Process::~Process()
   Process* process = this;
 
   process->process_flags = MC_PROCESS_NO_FLAG;
-  process->pid = 0;
+  process->pid_ = 0;
 
   MC_free_memory_map(process->memory_map);
   process->memory_map = NULL;
@@ -550,7 +550,7 @@ const void *Process::read_bytes(void* buffer, std::size_t size,
     }
   } else {
     if (pread_whole(this->memory_file, buffer, size, (off_t) address.address()) < 0)
-      xbt_die("Read from process %lli failed", (long long) this->pid);
+      xbt_die("Read from process %lli failed", (long long) this->pid_);
     return buffer;
   }
 }
@@ -568,7 +568,7 @@ void Process::write_bytes(const void* buffer, size_t len, remote_ptr<void> addre
     memcpy((void*)address.address(), buffer, len);
   } else {
     if (pwrite_whole(this->memory_file, buffer, len, address.address()) < 0)
-      xbt_die("Write to process %lli failed", (long long) this->pid);
+      xbt_die("Write to process %lli failed", (long long) this->pid_);
   }
 }
 
index b8408c1..238fa36 100644 (file)
@@ -104,13 +104,16 @@ public:
   }
   void ignore_region(std::uint64_t address, std::size_t size);
 
+  pid_t pid() const { return pid_; }
+
 private:
   void init_memory_map_info();
   void refresh_heap();
   void refresh_malloc_info();
-public: // to be private
+private:
   mc_process_flags_t process_flags;
-  pid_t pid;
+  pid_t pid_;
+public: // to be private
   int socket;
   int status;
   bool running;
index 0e567b1..92c0e2e 100644 (file)
@@ -98,8 +98,8 @@ void s_mc_server::shutdown()
   int status = process->status;
   if (process->running) {
     XBT_DEBUG("Killing process");
-    kill(process->pid, SIGTERM);
-    if (waitpid(process->pid, &status, 0) == -1)
+    kill(process->pid(), SIGTERM);
+    if (waitpid(process->pid(), &status, 0) == -1)
       throw std::system_error(errno, std::system_category());
     // TODO, handle the case when the process does not want to die with a timeout
     process->status = status;
@@ -115,7 +115,7 @@ void s_mc_server::exit()
   else if (WIFSIGNALED(status)) {
     // Try to uplicate the signal of the model-checked process.
     // This is a temporary hack so we don't try too hard.
-    kill(mc_model_checker->process().pid, WTERMSIG(status));
+    kill(mc_model_checker->process().pid(), WTERMSIG(status));
     abort();
   } else {
     xbt_die("Unexpected status from model-checked process");
@@ -315,7 +315,7 @@ void s_mc_server::handle_waitpid()
       }
     }
 
-    if (pid == mc_model_checker->process().pid) {
+    if (pid == mc_model_checker->process().pid()) {
       if (WIFEXITED(status) || WIFSIGNALED(status)) {
         XBT_DEBUG("Child process is over");
         mc_model_checker->process().status = status;