Change file-user APIs for klay change that uses lstat 51/140951/3 accepted/tizen/4.0/unified/20170816.010413 accepted/tizen/unified/20170728.195539 submit/tizen/20170727.084517 submit/tizen_4.0/20170811.094300
authorSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 27 Jul 2017 08:07:19 +0000 (17:07 +0900)
committeryeji kim <yeji01.kim@samsung.com>
Thu, 27 Jul 2017 08:43:42 +0000 (08:43 +0000)
Refer to commit d866a7170f87d406d8c9bc3722d9db08d54d7c17.

Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: Id07d7b3f344b611f1495bdf46f9113998ac5242c

src/file-user.cpp

index 2dbcfc1914b1975f73a7fed16ca784ad4fc27e4e..8172c4dd0f8df8591df83277d223484f3e75a93a 100644 (file)
@@ -24,6 +24,8 @@
 #include <klay/file-user.h>
 #include <klay/filesystem.h>
 
+#include <iostream>
+
 namespace runtime {
 
 bool FileUser::isUsedAsFD(const std::string &filePath, const pid_t pid, bool isMount)
@@ -34,12 +36,14 @@ bool FileUser::isUsedAsFD(const std::string &filePath, const pid_t pid, bool isM
                File file(filePath);
 
                for (runtime::DirectoryIterator iter(path), end; iter != end;) {
-                       File cur(path + "/" + iter->getName());
-                       if ((cur.getInode() == file.getInode() || isMount) &&
-                                       cur.getDevice() == file.getDevice()) {
-                               return true;
-                       }
-                       ++iter;
+                       File cur(File((++iter)->getPath()).readlink());
+                       std::cout << cur.getPath() << std::endl;
+                       try {
+                               if ((cur.getInode() == file.getInode() || isMount) &&
+                                               cur.getDevice() == file.getDevice()) {
+                                       return true;
+                               }
+                       } catch (runtime::Exception &e) {}
                }
        } catch (runtime::Exception &e) {}
 
@@ -81,7 +85,7 @@ bool FileUser::isUsedAsCwd(const std::string &filePath, const pid_t pid, bool is
        std::string path = "/proc/" + std::to_string(pid) + "/cwd";
 
        try {
-               File file(filePath), cwd(path);
+               File file(filePath), cwd(File(path).readlink());
 
                if ((cwd.getInode() == file.getInode() || isMount) &&
                                cwd.getDevice() == file.getDevice()) {
@@ -97,7 +101,7 @@ bool FileUser::isUsedAsRoot(const std::string &filePath, const pid_t pid, bool i
        std::string path = "/proc/" + std::to_string(pid) + "/root";
 
        try {
-               File file(filePath), root(path);
+               File file(filePath), root(File(path).readlink());
 
                if ((root.getInode() == file.getInode() || isMount) &&
                                root.getDevice() == file.getDevice()) {