Fix to get real mount state in ecryptfs engine 73/125373/1 accepted/tizen/unified/20170418.072805 submit/tizen/20170418.055622
authorSungbae Yoo <sungbae.yoo@samsung.com>
Fri, 14 Apr 2017 09:32:00 +0000 (18:32 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Mon, 17 Apr 2017 02:34:31 +0000 (11:34 +0900)
This prevents an inconsistency of the state due to unexpected
SD card removal.

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

server/engine/encryption/ecryptfs-engine.cpp
server/engine/encryption/ecryptfs-engine.h

index 02d620e..b78e614 100644 (file)
@@ -14,6 +14,7 @@
  *  limitations under the License
  */
 #include <iomanip>
+#include <fstream>
 
 #include <unistd.h>
 #include <sys/vfs.h>
@@ -331,7 +332,7 @@ void ecryptfsUmount(const std::string &destination)
 } // namespace
 
 EcryptfsEngine::EcryptfsEngine(const std::string &src, const std::string &dest, const ProgressBar &prg) :
-       source(src), destination(dest), progress(prg), mounted(false)
+       source(src), destination(dest), progress(prg)
 {
 }
 
@@ -342,20 +343,29 @@ EcryptfsEngine::~EcryptfsEngine()
 void EcryptfsEngine::mount(const data &key, unsigned int options)
 {
        ecryptfsMount(source, destination, key, options);
-
-       mounted = true;
 }
 
 void EcryptfsEngine::umount()
 {
        ecryptfsUmount(destination);
-
-       mounted = false;
 }
 
 bool EcryptfsEngine::isMounted()
 {
-       return mounted;
+       std::ifstream file("/proc/mounts");
+       std::string line;
+
+       while (std::getline(file, line)) {
+               std::stringstream info(line);
+               std::string src, dest, type;
+
+               info >> src >> dest >> type;
+               if (type == "ecryptfs" && src == source && dest == destination) {
+                       return true;
+               }
+       }
+
+       return false;
 }
 
 void EcryptfsEngine::encrypt(const data &key, unsigned int options)
index 1adeec7..96982e0 100644 (file)
@@ -64,7 +64,6 @@ public:
 private:
        std::string source, destination;
        ProgressBar progress;
-       std::atomic<bool> mounted;
 };
 
 } // namespace ode