Add cache dropping after application exit 75/118075/5
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 8 Mar 2017 12:40:17 +0000 (13:40 +0100)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Thu, 16 Mar 2017 13:21:32 +0000 (06:21 -0700)
Change-Id: I646ff6b8ee064878e4d086f9b965a5e8ce056c09

test/app_encryption/encryption_setting.cpp
test/app_encryption/launcher.cpp

index a548a4847bf7d5ba8fad13483cd31286140d71be..7f75a9fb67610b237938107300783401a50f4d20 100644 (file)
@@ -142,8 +142,6 @@ int main(int argc, char* argv[])
         return 1;
     }
 
-    // TODO drop cache
-
     std::cout << "Password successfully changed" << std::endl;
     return 0;
 }
index 4ad5b49f593440457b1b5f6518cdf218c405a59d..8fe5b32ae768fa7797c212627b37f0fdd2a665cd 100644 (file)
  */
 
 #include <iostream>
+#include <fstream>
 #include <string>
 #include <memory>
+#include <stdexcept>
 
 #include <unistd.h>
-#include <sys/types.h>
-#include <sys/wait.h>
 #include <pwd.h>
 #include <sys/prctl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 #include <cstring>
 #include <sys/capability.h>
 
 
 const cap_value_t ADMIN[] = { CAP_SETGID, CAP_DAC_OVERRIDE, CAP_SYS_ADMIN, CAP_MAC_OVERRIDE, CAP_MAC_ADMIN };
 const cap_value_t LIMITED[] = { CAP_SETGID };
+const char* CACHE_DROP = "/proc/sys/vm/drop_caches";
 
 int main(int argc, char* argv[])
 {
     pid_t pid = fork();
     if (pid < 0) {
         std::cerr << "fork() failed" << std::endl;
-        return 1;
+        exit(1);
     }
 
     if (pid > 0) {
@@ -51,7 +54,24 @@ int main(int argc, char* argv[])
         do
             child = waitpid(pid, &status, 0);
         while (child != pid);
-        return 0;
+
+        try {
+            sync();
+
+            std::ofstream of(CACHE_DROP);
+            if (!of) {
+                std::cerr << "Failed to open " << CACHE_DROP << std:: endl;
+                return 1;
+            }
+
+            of << 2 << std::endl;;
+        } catch (const std::exception& e) {
+            std::cerr << e.what() << std::endl;
+            return 1;
+        } catch (...) {
+            std::cerr << "Unknown exception" << std::endl;
+            return 1;
+        }
     } else {
         // prevent capabilities drop
         if (0 != prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) {
@@ -136,4 +156,5 @@ int main(int argc, char* argv[])
         free(user_argv[0]);
         return 1;
     }
+    return 0;
 }