summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryingying <yingying@codeaurora.org>2014-11-25 13:21:49 +0800
committerGerrit - the friendly Code Review server <code-review@localhost>2015-10-12 20:33:54 -0700
commit1d246f680f8d0fcec53961391fe9a36e8728a219 (patch)
treeaaf129ccf8426a2f3ad6454aa54d2f25dfbdf0a7
parent1c6d9d680d7d3717038019c11a30d8e4c7811120 (diff)
downloadframeworks_base-1d246f680f8d0fcec53961391fe9a36e8728a219.zip
frameworks_base-1d246f680f8d0fcec53961391fe9a36e8728a219.tar.gz
frameworks_base-1d246f680f8d0fcec53961391fe9a36e8728a219.tar.bz2
idmap: Do not unlink the file if it is locked by another process.
The idmap file will be locked if it is used by one process. Then if another process need to access this file, it will get the file locked state. So in this case, should not unlink the file. Otherwise this file will be deleted by this process, and the another process which locked it will fail to write the file. CRs-fixed: 763809 Change-Id: I2bca8b04dd82b5a56d30b103325ba7e22f0072d9
-rw-r--r--cmds/idmap/create.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/cmds/idmap/create.cpp b/cmds/idmap/create.cpp
index 41395f1..929f047 100644
--- a/cmds/idmap/create.cpp
+++ b/cmds/idmap/create.cpp
@@ -33,6 +33,7 @@ namespace {
int open_idmap(const char *path)
{
int fd = TEMP_FAILURE_RETRY(open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644));
+ bool needUnlink = true;
if (fd == -1) {
ALOGD("error: open %s: %s\n", path, strerror(errno));
goto fail;
@@ -43,6 +44,8 @@ namespace {
}
if (TEMP_FAILURE_RETRY(flock(fd, LOCK_EX | LOCK_NB)) != 0) {
ALOGD("error: flock %s: %s\n", path, strerror(errno));
+ // If the file is locked by another process, then we needn't unlink the file.
+ needUnlink = false;
goto fail;
}
@@ -50,7 +53,7 @@ namespace {
fail:
if (fd != -1) {
close(fd);
- unlink(path);
+ if (needUnlink) unlink(path);
}
return -1;
}