service: Support and enable on-demand activation of dumpsys-service 46/245046/4
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 29 Sep 2020 12:17:30 +0000 (14:17 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 30 Sep 2020 08:05:27 +0000 (10:05 +0200)
Change-Id: I0f2ae67924f66fd93f5f7f25832c89f189397aa7

packaging/dumpsys.spec
src/service/CMakeLists.txt
src/service/dumpsys-service.c
src/service/dumpsys-service.service
src/service/org.tizen.dumpsys.service.service [new file with mode: 0644]

index f14d210a3173523c275906784a5cd4919b3e16c0..d6a8bcafa9bd1b23b4c4cf5d9945ed2d0f651d23 100644 (file)
@@ -92,9 +92,6 @@ make coverage
 rm -rf %{buildroot}
 %make_install
 
-mkdir -p %{buildroot}/%{_unitdir}/basic.target.wants/
-ln -s ../dumpsys-service.service %{buildroot}/%{_unitdir}/basic.target.wants/dumpsys-service.service
-
 %files
 %license LICENSE
 %manifest %{name}.manifest
@@ -105,9 +102,9 @@ ln -s ../dumpsys-service.service %{buildroot}/%{_unitdir}/basic.target.wants/dum
 %{_bindir}/dumpsys-service
 
 %defattr(0644,root,root)
-%{_unitdir}/basic.target.wants/dumpsys-service.service
 %{_unitdir}/dumpsys-service.service
 %{_prefix}/lib/tmpfiles.d/dumpsys-run.conf
+%{_prefix}/share/dbus-1/system-services/org.tizen.dumpsys.service.service
 
 %files -n dumpsys-common
 %manifest %{name}.manifest
index c6850cf2f63a969f6b79f088e32e0298afbc6d34..c15e0e9f22e92efe0b59245070e8be24b5f219fb 100644 (file)
@@ -33,3 +33,5 @@ INSTALL (FILES dumpsys-service.conf DESTINATION /etc/dbus-1/system.d/
        PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
 INSTALL (FILES dumpsys-service.service DESTINATION /usr/lib/systemd/system/
        PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
+INSTALL (FILES org.tizen.dumpsys.service.service DESTINATION /usr/share/dbus-1/system-services/
+       PERMISSIONS OWNER_READ OWNER_WRITE)
index b37197cacae1e387380502068554069582ead27a..d9ba29903953dc918fe9a09c6cd70e706a04a439 100644 (file)
@@ -31,6 +31,8 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#define INACTIVITY_TIMEOUT_SEC 10
+
 #ifndef LOG_TAG
 #define LOG_TAG "DUMPSYS_SERVICE"
 #endif
@@ -61,6 +63,53 @@ static const gchar introspection_xml[] =
 "</node>";
 
 static GMainLoop* loop;
+static GMutex nclients_mutex;
+static unsigned int nclients;
+static guint timeout_id;
+
+static int timeout_cb(gpointer data)
+{
+       LOGI("Dumpsys-service unused for %dsec. Terminating.", INACTIVITY_TIMEOUT_SEC);
+       g_main_loop_quit(loop);
+
+       return 0;
+}
+
+static void up_usage(void)
+{
+       g_mutex_lock(&nclients_mutex);
+
+       ++nclients;
+
+       LOGD("%u client(s) are using dumpsys-service", nclients);
+
+       if (timeout_id) {
+               g_source_remove(timeout_id);
+               timeout_id = 0;
+       }
+
+       g_mutex_unlock(&nclients_mutex);
+}
+
+static void down_usage(void)
+{
+       g_mutex_lock(&nclients_mutex);
+
+       if (nclients > 0)
+               --nclients;
+
+       LOGD("%u client(s) are using dumpsys-service", nclients);
+
+       if (nclients == 0) {
+               if (timeout_id) {
+                       g_source_remove(timeout_id);
+                       timeout_id = 0;
+               }
+               timeout_id = g_timeout_add_seconds(INACTIVITY_TIMEOUT_SEC, timeout_cb, 0);
+       }
+
+       g_mutex_unlock(&nclients_mutex);
+}
 
 static bool reset_fd_flag(int fd, int flag)
 {
@@ -364,8 +413,12 @@ static void method_call_handler(GDBusConnection *conn,
                                 GDBusMethodInvocation *invocation,
                                 gpointer user_data)
 {
+       up_usage();
+
        if (g_strcmp0(method_name, METHOD_DUMP) == 0)
                dump_call_handler(conn, parameters, invocation);
+
+       down_usage();
 }
 
 static const GDBusInterfaceVTable interface_vtable = {
index 2c0dddc4c77253f329004f591d7796eca2c579f8..5ef6e139171783c8d8a7536d320965287f0aba84 100644 (file)
@@ -4,7 +4,8 @@ DefaultDependencies=false
 After=dbus.socket systemd-tmpfiles-setup.service
 
 [Service]
-Type=simple
+Type=dbus
+BusName=org.tizen.dumpsys.service
 User=log
 Group=log
 SmackProcessLabel=System
diff --git a/src/service/org.tizen.dumpsys.service.service b/src/service/org.tizen.dumpsys.service.service
new file mode 100644 (file)
index 0000000..05f4fc9
--- /dev/null
@@ -0,0 +1,4 @@
+[D-BUS Service]
+Name=org.tizen.dumpsys.service
+Exec=/bin/false
+SystemdService=dumpsys-service.service