Add listing running apps based on namespace 61/230561/8
authorZofia Abramowska <z.abramowska@samsung.com>
Fri, 10 Apr 2020 10:47:47 +0000 (12:47 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 5 May 2020 11:39:50 +0000 (13:39 +0200)
Change-Id: I8240646edef06fc267cc4a2177764494ec081fdb

packaging/security-manager.spec
test/CMakeLists.txt
test/list-running-apps-ns.cpp [new file with mode: 0644]

index 11100a1..f21a196 100644 (file)
@@ -333,6 +333,7 @@ chsmack -a System %{db_test_dir}/.security-manager-test-rules*.txt
 %attr(755,root,root) %{_bindir}/security-manager-unit-tests
 %attr(755,root,root) %{_bindir}/security-manager-performance-tests
 %attr(755,root,root) %{_bindir}/security-manager-test-rules-loader
+%attr(755,root,root) %{_bindir}/list-running-apps-ns
 %attr(0600,root,root) %{db_test_dir}/.security-manager-test.db
 %attr(0600,root,root) %{db_test_dir}/.security-manager-test.db-journal
 %attr(0600,root,root) %{db_test_dir}/.security-manager-test-v0.db
index e73f0e0..3ccaacf 100644 (file)
@@ -179,3 +179,18 @@ TARGET_LINK_LIBRARIES(${TARGET_SM_PERFORMANCE_TESTS}
 )
 
 INSTALL(TARGETS ${TARGET_SM_TESTS} ${TARGET_SM_PERFORMANCE_TESTS} DESTINATION ${BIN_INSTALL_DIR})
+
+########################### list running apps based on namespace ################################
+
+SET(LIST_SOURCES
+    ${SM_TEST_SRC}/list-running-apps-ns.cpp)
+
+SET(LIST_TARGET "list-running-apps-ns")
+
+ADD_EXECUTABLE(${LIST_TARGET} ${LIST_SOURCES})
+
+TARGET_LINK_LIBRARIES(${LIST_TARGET}
+    boost_regex
+    boost_filesystem)
+
+INSTALL(TARGETS ${LIST_TARGET} DESTINATION ${BIN_INSTALL_DIR})
diff --git a/test/list-running-apps-ns.cpp b/test/list-running-apps-ns.cpp
new file mode 100644 (file)
index 0000000..c44d17f
--- /dev/null
@@ -0,0 +1,51 @@
+#include <boost/filesystem.hpp>
+#include <boost/regex.hpp>
+#include <boost/tokenizer.hpp>
+#include <string>
+#include <iostream>
+
+std::string ROOT_DIR = "/run/user";
+
+std::string default_regexp =
+    "/run/user/(\\d*)/apps/(User::Pkg::([^/]*))|(User::Pkg::User::App::([^/]*))";
+
+int main(int argc, char **argv) {
+    std::string regexp = default_regexp;
+    if (argc > 1) {
+        regexp = argv[1];
+    }
+
+    boost::system::error_code ec;
+    boost::filesystem::path root(ROOT_DIR);
+    boost::regex appFilter(regexp);
+
+    if (boost::filesystem::is_directory(root)) {
+        for (boost::filesystem::recursive_directory_iterator it(root, ec), eit;
+             it != eit;
+             it.increment(ec))
+        {
+            if (ec) {
+                it.pop();
+                continue;
+            }
+
+            boost::smatch matches;
+            std::string path = it->path().string();
+            if (boost::regex_match(path, matches, appFilter)) {
+                if (matches.size() < 4) {
+                    std::cerr << "Something went wrong with regexp!" << std::endl;
+                    continue;
+                }
+                std::string uidStr = matches[1];
+                std::string appLabel = matches[2];
+                std::string appId = matches[3];
+
+                std::cout << uidStr << " : " << appLabel << " : " << appId << std::endl;
+            }
+        }
+    }
+    else {
+        std::cerr << ROOT_DIR << " is not a directory" << std::endl;
+    }
+    return 0;
+}