Exclusive exec() path, format after partition.
Sadly setexeccon() is process global, so we need to carefully ensure
that all exec() are mutually exclusive to avoid transitioning into
unwanted domains. Also, because we have several threads floating
around, we need to guard all our FDs with O_CLOEXEC.
Format all newly created volumes immediately after partitioning,
but silence all events emitted from those volumes to prevent the
framework from getting all excited. Unify all notify events under a
single codepath to make them easy to silence.
Sent SIGINT before escalating to SIGTERM when unmounting.
Bug: 19993667
Change-Id: Idc6c806afc7919a004a93e2240b42884f6b52d6b
diff --git a/VolumeBase.cpp b/VolumeBase.cpp
index 2590ecf..de5b072 100644
--- a/VolumeBase.cpp
+++ b/VolumeBase.cpp
@@ -36,7 +36,8 @@
namespace vold {
VolumeBase::VolumeBase(Type type) :
- mType(type), mFlags(0), mUser(-1), mCreated(false), mState(State::kUnmounted) {
+ mType(type), mFlags(0), mUser(-1), mCreated(false), mState(
+ State::kUnmounted), mSilent(false) {
}
VolumeBase::~VolumeBase() {
@@ -45,10 +46,7 @@
void VolumeBase::setState(State state) {
mState = state;
-
- VolumeManager::Instance()->getBroadcaster()->sendBroadcast(
- ResponseCode::VolumeStateChanged,
- StringPrintf("%s %d", getId().c_str(), mState).c_str(), false);
+ notifyEvent(ResponseCode::VolumeStateChanged, StringPrintf("%d", mState));
}
status_t VolumeBase::setFlags(int flags) {
@@ -71,6 +69,16 @@
return OK;
}
+status_t VolumeBase::setSilent(bool silent) {
+ if (mCreated) {
+ LOG(WARNING) << getId() << " silence change requires destroyed";
+ return -EBUSY;
+ }
+
+ mSilent = silent;
+ return OK;
+}
+
status_t VolumeBase::setId(const std::string& id) {
if (mCreated) {
LOG(WARNING) << getId() << " id change requires not created";
@@ -88,12 +96,22 @@
}
mPath = path;
- VolumeManager::Instance()->getBroadcaster()->sendBroadcast(
- ResponseCode::VolumePathChanged,
- StringPrintf("%s %s", getId().c_str(), mPath.c_str()).c_str(), false);
+ notifyEvent(ResponseCode::VolumePathChanged, mPath);
return OK;
}
+void VolumeBase::notifyEvent(int event) {
+ if (mSilent) return;
+ VolumeManager::Instance()->getBroadcaster()->sendBroadcast(event,
+ getId().c_str(), false);
+}
+
+void VolumeBase::notifyEvent(int event, const std::string& value) {
+ if (mSilent) return;
+ VolumeManager::Instance()->getBroadcaster()->sendBroadcast(event,
+ StringPrintf("%s %s", getId().c_str(), value.c_str()).c_str(), false);
+}
+
void VolumeBase::addVolume(const std::shared_ptr<VolumeBase>& volume) {
mVolumes.push_back(volume);
}
@@ -116,9 +134,7 @@
mCreated = true;
status_t res = doCreate();
- VolumeManager::Instance()->getBroadcaster()->sendBroadcast(
- ResponseCode::VolumeCreated,
- StringPrintf("%s %d", getId().c_str(), mType).c_str(), false);
+ notifyEvent(ResponseCode::VolumeCreated, StringPrintf("%d", mType));
return res;
}
@@ -133,8 +149,7 @@
unmount();
}
- VolumeManager::Instance()->getBroadcaster()->sendBroadcast(
- ResponseCode::VolumeDestroyed, getId().c_str(), false);
+ notifyEvent(ResponseCode::VolumeDestroyed);
status_t res = doDestroy();
mCreated = false;
return res;