%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
)
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})
--- /dev/null
+#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;
+}