diff options
author | Linux Build Service Account <lnxbuild@localhost> | 2015-10-15 10:51:55 -0700 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2015-10-15 10:51:55 -0700 |
commit | e453561469f001ac7e6710d9965f6ced27488668 (patch) | |
tree | c484a2fcabf653e4e4eb1f88ff1b03b9b96ff0c0 | |
parent | 6505e93be1af8500bc8ffbd1dcd78c9a501e7e7f (diff) | |
parent | 1d246f680f8d0fcec53961391fe9a36e8728a219 (diff) | |
download | frameworks_base-e453561469f001ac7e6710d9965f6ced27488668.zip frameworks_base-e453561469f001ac7e6710d9965f6ced27488668.tar.gz frameworks_base-e453561469f001ac7e6710d9965f6ced27488668.tar.bz2 |
Merge "idmap: Do not unlink the file if it is locked by another process."
-rw-r--r-- | cmds/idmap/create.cpp | 5 |
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; } |