vold: Fix devmapper/ptmx fd leak, and give asec unmount more time
Signed-off-by: San Mehat <san@google.com>
This commit is contained in:
parent
c6fc646af4
commit
8c940ef7db
5 changed files with 52 additions and 43 deletions
|
@ -167,6 +167,7 @@ int Devmapper::create(const char *name, const char *loopFile, const char *key,
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
|
close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,8 +179,14 @@ static int get_pid(const char* s)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hunt down processes that have files open at the given mount point.
|
||||||
|
* action = 0 to just warn,
|
||||||
|
* action = 1 to SIGHUP,
|
||||||
|
* action = 2 to SIGKILL
|
||||||
|
*/
|
||||||
// hunt down and kill processes that have files open on the given mount point
|
// hunt down and kill processes that have files open on the given mount point
|
||||||
void KillProcessesWithOpenFiles(const char* mountPoint, int sigkill, int *excluded, int num_excluded)
|
void KillProcessesWithOpenFiles(const char* mountPoint, int action)
|
||||||
{
|
{
|
||||||
DIR* dir;
|
DIR* dir;
|
||||||
struct dirent* de;
|
struct dirent* de;
|
||||||
|
@ -202,28 +208,12 @@ void KillProcessesWithOpenFiles(const char* mountPoint, int sigkill, int *exclud
|
||||||
|| CheckSymLink(pid, mountPoint, "exe", "executable path") // check executable path
|
|| CheckSymLink(pid, mountPoint, "exe", "executable path") // check executable path
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int i;
|
if (action == 1) {
|
||||||
int hit = 0;
|
LOGW("Sending SIGHUP to process %d", pid);
|
||||||
|
kill(pid, SIGTERM);
|
||||||
for (i = 0; i < num_excluded; i++) {
|
} else if (action == 2) {
|
||||||
if (pid == excluded[i]) {
|
LOGE("Sending SIGKILL to process %d", pid);
|
||||||
LOGE("I just need a little more TIME captain!");
|
kill(pid, SIGKILL);
|
||||||
hit = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hit) {
|
|
||||||
if (!sigkill) {
|
|
||||||
kill(pid, SIGTERM);
|
|
||||||
} else {
|
|
||||||
// Log this as an error since the app should
|
|
||||||
// have released it's resources long before
|
|
||||||
// this point.
|
|
||||||
|
|
||||||
LOGE("Sending SIGKILL to process %d", pid);
|
|
||||||
kill(pid, SIGKILL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
25
Volume.cpp
25
Volume.cpp
|
@ -41,7 +41,7 @@
|
||||||
#include "ResponseCode.h"
|
#include "ResponseCode.h"
|
||||||
#include "Fat.h"
|
#include "Fat.h"
|
||||||
|
|
||||||
extern "C" void KillProcessesWithOpenFiles(const char *, int, int, int);
|
extern "C" void KillProcessesWithOpenFiles(const char *, int);
|
||||||
extern "C" void dos_partition_dec(void const *pp, struct dos_partition *d);
|
extern "C" void dos_partition_dec(void const *pp, struct dos_partition *d);
|
||||||
extern "C" void dos_partition_enc(void *pp, struct dos_partition *d);
|
extern "C" void dos_partition_enc(void *pp, struct dos_partition *d);
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ int Volume::unmountVol() {
|
||||||
|
|
||||||
setState(Volume::State_Unmounting);
|
setState(Volume::State_Unmounting);
|
||||||
usleep(1000 * 200); // Give the framework some time to react
|
usleep(1000 * 200); // Give the framework some time to react
|
||||||
for (i = 0; i < 10; i++) {
|
for (i = 1; i <= 10; i++) {
|
||||||
rc = umount(getMountpoint());
|
rc = umount(getMountpoint());
|
||||||
if (!rc)
|
if (!rc)
|
||||||
break;
|
break;
|
||||||
|
@ -297,16 +297,19 @@ int Volume::unmountVol() {
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGW("Volume %s unmount attempt %d failed (%s)",
|
LOGW("Volume %s unmount attempt %d failed (%s)",
|
||||||
getLabel(), i + 1, strerror(errno));
|
getLabel(), i, strerror(errno));
|
||||||
|
|
||||||
if (i < 5) {
|
int action;
|
||||||
usleep(1000 * 250);
|
|
||||||
} else {
|
if (i > 8) {
|
||||||
KillProcessesWithOpenFiles(getMountpoint(),
|
action = 2; // SIGKILL
|
||||||
(i < 7 ? 0 : 1),
|
} else if (i > 7) {
|
||||||
NULL, 0);
|
action = 1; // SIGHUP
|
||||||
usleep(1000 * 250);
|
} else
|
||||||
}
|
action = 0; // just complain
|
||||||
|
|
||||||
|
KillProcessesWithOpenFiles(getMountpoint(), action);
|
||||||
|
usleep(1000*250);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include "Fat.h"
|
#include "Fat.h"
|
||||||
#include "Devmapper.h"
|
#include "Devmapper.h"
|
||||||
|
|
||||||
extern "C" void KillProcessesWithOpenFiles(const char *, int, int, int);
|
extern "C" void KillProcessesWithOpenFiles(const char *, int);
|
||||||
|
|
||||||
VolumeManager *VolumeManager::sInstance = NULL;
|
VolumeManager *VolumeManager::sInstance = NULL;
|
||||||
|
|
||||||
|
@ -320,6 +320,7 @@ out_err:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ASEC_UNMOUNT_RETRIES 10
|
||||||
int VolumeManager::unmountAsec(const char *id) {
|
int VolumeManager::unmountAsec(const char *id) {
|
||||||
char asecFileName[255];
|
char asecFileName[255];
|
||||||
char mountPoint[255];
|
char mountPoint[255];
|
||||||
|
@ -335,7 +336,7 @@ int VolumeManager::unmountAsec(const char *id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int i, rc;
|
int i, rc;
|
||||||
for (i = 0; i < 10; i++) {
|
for (i = 1; i <= ASEC_UNMOUNT_RETRIES; i++) {
|
||||||
rc = umount(mountPoint);
|
rc = umount(mountPoint);
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
break;
|
break;
|
||||||
|
@ -345,13 +346,18 @@ int VolumeManager::unmountAsec(const char *id) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
LOGW("ASEC %s unmount attempt %d failed (%s)",
|
LOGW("ASEC %s unmount attempt %d failed (%s)",
|
||||||
id, i +1, strerror(errno));
|
id, i, strerror(errno));
|
||||||
|
|
||||||
if (i >= 5) {
|
int action;
|
||||||
KillProcessesWithOpenFiles(mountPoint, (i < 7 ? 0 : 1),
|
if (i > (ASEC_UNMOUNT_RETRIES - 2))
|
||||||
NULL, 0);
|
action = 2; // SIGKILL
|
||||||
}
|
else if (i > (ASEC_UNMOUNT_RETRIES - 3))
|
||||||
usleep(1000 * 250);
|
action = 1; // SIGHUP
|
||||||
|
else
|
||||||
|
action = 0; // Just complain
|
||||||
|
|
||||||
|
KillProcessesWithOpenFiles(mountPoint, action);
|
||||||
|
usleep(1000 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
|
|
11
logwrapper.c
11
logwrapper.c
|
@ -119,6 +119,7 @@ int logwrap(int argc, const char* argv[], int background)
|
||||||
if (grantpt(parent_ptty) || unlockpt(parent_ptty) ||
|
if (grantpt(parent_ptty) || unlockpt(parent_ptty) ||
|
||||||
((child_devname = (char*)ptsname(parent_ptty)) == 0)) {
|
((child_devname = (char*)ptsname(parent_ptty)) == 0)) {
|
||||||
LOG(LOG_ERROR, "logwrapper", "Problem with /dev/ptmx");
|
LOG(LOG_ERROR, "logwrapper", "Problem with /dev/ptmx");
|
||||||
|
close(parent_ptty);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +128,9 @@ int logwrap(int argc, const char* argv[], int background)
|
||||||
LOG(LOG_ERROR, "logwrapper", "Failed to fork");
|
LOG(LOG_ERROR, "logwrapper", "Failed to fork");
|
||||||
return -errno;
|
return -errno;
|
||||||
} else if (pid == 0) {
|
} else if (pid == 0) {
|
||||||
|
/*
|
||||||
|
* Child
|
||||||
|
*/
|
||||||
child_ptty = open(child_devname, O_RDWR);
|
child_ptty = open(child_devname, O_RDWR);
|
||||||
if (child_ptty < 0) {
|
if (child_ptty < 0) {
|
||||||
LOG(LOG_ERROR, "logwrapper", "Problem with child ptty");
|
LOG(LOG_ERROR, "logwrapper", "Problem with child ptty");
|
||||||
|
@ -160,7 +164,12 @@ int logwrap(int argc, const char* argv[], int background)
|
||||||
|
|
||||||
child(argc, argv);
|
child(argc, argv);
|
||||||
} else {
|
} else {
|
||||||
return parent(argv[0], parent_ptty);
|
/*
|
||||||
|
* Parent
|
||||||
|
*/
|
||||||
|
int rc = parent(argv[0], parent_ptty);
|
||||||
|
close(parent_ptty);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue