From: Dariusz Michaluk Date: Wed, 18 Oct 2017 08:13:31 +0000 (+0200) Subject: Fix: Check if file exist before umount is made X-Git-Tag: accepted/tizen/4.0/unified/20171019.082002~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=495e1e714a58f26fa9f93ba451807ea5ff0031bb;p=platform%2Fcore%2Fsecurity%2Fsecurity-manager.git Fix: Check if file exist before umount is made Change-Id: I03aaa60dd23021fd19d716ccf995a0ff737f108c --- diff --git a/src/common/filesystem.cpp b/src/common/filesystem.cpp index dda400c..fe44295 100644 --- a/src/common/filesystem.cpp +++ b/src/common/filesystem.cpp @@ -167,6 +167,20 @@ int removeDirectory(const std::string &path) return SECURITY_MANAGER_SUCCESS; } +int fileStatus(const std::string &path) +{ + struct stat st; + if (-1 == lstat(path.c_str(), &st)) { + if (ENOENT == errno) + return 0; // no, file does not exist + return -1; // error + + } + if (S_ISREG(st.st_mode)) + return 1; // yes, file exists + return -1; // this is not a file -> error +} + int createFile(const std::string &path) { int fd = open(path.c_str(), O_RDONLY|O_CREAT, 0644); diff --git a/src/common/include/filesystem.h b/src/common/include/filesystem.h index ee681aa..ba0fe36 100644 --- a/src/common/include/filesystem.h +++ b/src/common/include/filesystem.h @@ -43,6 +43,7 @@ std::string getParentDirectoryName(const std::string &path); int directoryStatus(const std::string &path); int createDirectory(const std::string &path); int removeDirectory(const std::string &path); +int fileStatus(const std::string &path); int createFile(const std::string &path); int removeFile(const std::string &path); diff --git a/src/common/service_impl.cpp b/src/common/service_impl.cpp index a8278f2..b07ce23 100644 --- a/src/common/service_impl.cpp +++ b/src/common/service_impl.cpp @@ -1973,11 +1973,13 @@ int ServiceImpl::appBindNamespace(const Credentials &creds, const std::string &a } } - ret = FS::createFile(appFile); - if (ret != SECURITY_MANAGER_SUCCESS) - return ret; - - MountNS::uMount(appFile); + if (FS::fileStatus(appFile) == 0) { // file does not exist + ret = FS::createFile(appFile); + if (ret != SECURITY_MANAGER_SUCCESS) + return ret; + } else { + MountNS::uMount(appFile); + } ret = MountNS::bindMount(procFile, appFile); if (ret != SECURITY_MANAGER_SUCCESS) {