Commit eaf5e6be authored by Matthieu Dorier's avatar Matthieu Dorier

added the correct protection mechanism

parent b6aa3898
...@@ -56,6 +56,7 @@ struct operation { ...@@ -56,6 +56,7 @@ struct operation {
std::vector<mode_t> m_modes; std::vector<mode_t> m_modes;
std::vector<int> m_fds; std::vector<int> m_fds;
std::vector<device*> m_devices; std::vector<device*> m_devices;
tl::mutex m_mutex;
int m_error = REMI_SUCCESS; int m_error = REMI_SUCCESS;
}; };
...@@ -165,27 +166,32 @@ struct remi_provider : public tl::provider<remi_provider> { ...@@ -165,27 +166,32 @@ struct remi_provider : public tl::provider<remi_provider> {
} }
auto& op = it->second; auto& op = it->second;
// close all the file descriptors {
for(int fd : op.m_fds) { std::lock_guard<tl::mutex> guard(op.m_mutex);
close(fd);
}
if(op.m_error != REMI_SUCCESS) { // close all the file descriptors
result.first = op.m_error; for(int fd : op.m_fds) {
req.respond(result); close(fd);
m_op_in_progress.erase(it); }
return;
} if(op.m_error != REMI_SUCCESS) {
result.first = op.m_error;
req.respond(result);
m_op_in_progress.erase(it);
return;
}
// find the class of migration
auto& klass = m_migration_classes[op.m_fileset.m_class];
// find the class of migration // call the "after" migration callback associated with the class of fileset
auto& klass = m_migration_classes[op.m_fileset.m_class]; if(klass.m_after_callback != nullptr) {
result.second = klass.m_after_callback(&(op.m_fileset), klass.m_uargs);
}
result.first = result.second == 0 ? REMI_SUCCESS : REMI_ERR_USER;
req.respond(result);
// call the "after" migration callback associated with the class of fileset
if(klass.m_after_callback != nullptr) {
result.second = klass.m_after_callback(&(op.m_fileset), klass.m_uargs);
} }
result.first = result.second == 0 ? REMI_SUCCESS : REMI_ERR_USER;
req.respond(result);
m_op_in_progress.erase(it); m_op_in_progress.erase(it);
...@@ -295,6 +301,9 @@ struct remi_provider : public tl::provider<remi_provider> { ...@@ -295,6 +301,9 @@ struct remi_provider : public tl::provider<remi_provider> {
return; return;
} }
auto& op = it->second; auto& op = it->second;
std::lock_guard<tl::mutex> guard(op.m_mutex);
// we found the operation, let's open some files! // we found the operation, let's open some files!
std::vector<int> openedFileDescriptors; std::vector<int> openedFileDescriptors;
...@@ -346,7 +355,6 @@ struct remi_provider : public tl::provider<remi_provider> { ...@@ -346,7 +355,6 @@ struct remi_provider : public tl::provider<remi_provider> {
} }
} }
return; return;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment