#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
+#include <unistd.h>
#include <limits.h>
#include <selinux/android.h>
#include <sys/mount.h>
#include <android-base/stringprintf.h>
using android::base::StringPrintf;
+using android::base::WriteStringToFile;
using android::vold::kEmptyAuthentication;
// NOTE: keep in sync with StorageManager
return true;
}
+static void drop_caches() {
+ // Clean any dirty pages (otherwise they won't be dropped).
+ sync();
+ // Drop inode and page caches.
+ if (!WriteStringToFile("3", "/proc/sys/vm/drop_caches")) {
+ PLOG(ERROR) << "Failed to drop caches during key eviction";
+ }
+}
+
static bool evict_ce_key(userid_t user_id) {
s_ce_keys.erase(user_id);
bool success = true;
// If we haven't loaded the CE key, no need to evict it.
if (lookup_key_ref(s_ce_key_raw_refs, user_id, &raw_ref)) {
success &= android::vold::evictKey(raw_ref);
+ drop_caches();
}
s_ce_key_raw_refs.erase(user_id);
return success;
#include "sehandle.h"
#include "Utils.h"
#include "Process.h"
+#include "VolumeManager.h"
#include <android-base/file.h>
#include <android-base/logging.h>
}
// Apps might still be handling eject request, so wait before
// we start sending signals
- sleep(5);
+ if (!VolumeManager::shutting_down) sleep(5);
Process::killProcessesWithOpenFiles(cpath, SIGINT);
- sleep(5);
+ if (!VolumeManager::shutting_down) sleep(5);
if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
return OK;
}
Process::killProcessesWithOpenFiles(cpath, SIGTERM);
- sleep(5);
+ if (!VolumeManager::shutting_down) sleep(5);
if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
return OK;
}
Process::killProcessesWithOpenFiles(cpath, SIGKILL);
- sleep(5);
+ if (!VolumeManager::shutting_down) sleep(5);
if (!umount2(cpath, UMOUNT_NOFOLLOW) || errno == EINVAL || errno == ENOENT) {
return OK;
}
if (Process::killProcessesWithOpenFiles(cpath, SIGINT) == 0) {
return OK;
}
- sleep(5);
+ if (!VolumeManager::shutting_down) sleep(5);
if (Process::killProcessesWithOpenFiles(cpath, SIGTERM) == 0) {
return OK;
}
- sleep(5);
+ if (!VolumeManager::shutting_down) sleep(5);
if (Process::killProcessesWithOpenFiles(cpath, SIGKILL) == 0) {
return OK;
}
- sleep(5);
+ if (!VolumeManager::shutting_down) sleep(5);
// Send SIGKILL a second time to determine if we've
// actually killed everyone with open files
*/
const char *VolumeManager::LOOPDIR = "/mnt/obb";
+bool VolumeManager::shutting_down = false;
+
static const char* kPathUserMount = "/mnt/user";
static const char* kPathVirtualDisk = "/data/misc/vold/virtual_disk";
if (mInternalEmulated == nullptr) {
return 0; // already shutdown
}
+ shutting_down = true;
mInternalEmulated->destroy();
mInternalEmulated = nullptr;
for (const auto& disk : mDisks) {
disk->destroy();
}
mDisks.clear();
+ shutting_down = false;
return 0;
}
static const char *ASECDIR;
static const char *LOOPDIR;
+ //TODO remove this with better solution, b/64143519
+ static bool shutting_down;
+
private:
static VolumeManager *sInstance;
const char* c_source = source.c_str();
const char* c_target = target.c_str();
- flags = MS_NODEV | MS_NOSUID | MS_DIRSYNC;
+ flags = MS_NODEV | MS_NOSUID | MS_DIRSYNC | MS_NOATIME;
flags |= (executable ? 0 : MS_NOEXEC);
flags |= (ro ? MS_RDONLY : 0);