bool findKillAndUmount(const std::string &devPath)
{
- std::string realMntPath = findMntPath(devPath);
- if (!realMntPath.empty()) {
+ for(;;) {
+ std::string mntPath = findMntPath(devPath);
+
+ if (mntPath.empty()) {
+ break;
+ }
+
INFO(SINK, "Closing all applications using an SD card...");
- killDependentApplications(realMntPath);
+ killDependentApplications(mntPath);
- int ret = ::umount(realMntPath.c_str());
- if (ret != 0) {
- ERROR(SINK, "The card is still mounted, umount failed with: "
- + std::to_string(ret));
- return false;
+ while (::umount(mntPath.c_str()) == -1) {
+ if (errno != EBUSY) {
+ ERROR(SINK, "The card is still mounted, umount failed with: "
+ + std::to_string(errno));
+ return false;
+ }
+ killDependentApplications(mntPath);
}
}
// TODO: this probably needs a rework, some sort of communication
// and/or merge with External. The use case for it might be:
// 1. The mmc is mounted by something else, somewhere else. Do we care?
- // 2. We take over the cd card from External.
- if (!findKillAndUmount(EXTENSION_DEV_PATH))
+ // 2. We take over the (possibly mounted and/or encrypted) cd card from External.
+ if (!findKillAndUmount(EXTENSION_DEV_PATH)) {
return;
+ }
INFO(SINK, "Creating LUKS...");
engine->format(CryptsetupEngine::DeviceType::LUKS, masterKey);