[sysprof/wip/chergert/sysprof-3] sysprofd: add hook to postprocess cmdline



commit 38f43c77f5eaa69e9c588d6e948bb884c017d199
Author: Christian Hergert <chergert redhat com>
Date:   Fri May 10 15:14:44 2019 -0700

    sysprofd: add hook to postprocess cmdline

 src/sysprofd/ipc-service-impl.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/src/sysprofd/ipc-service-impl.c b/src/sysprofd/ipc-service-impl.c
index 8052fd8..961239c 100644
--- a/src/sysprofd/ipc-service-impl.c
+++ b/src/sysprofd/ipc-service-impl.c
@@ -189,10 +189,17 @@ ipc_service_impl_g_authorize_method (GDBusInterfaceSkeleton *skeleton,
   return ret;
 }
 
+static void
+postprocess_cmdline (gchar **str,
+                     gsize   len)
+{
+}
+
 static void
 add_pid_proc_file_to (gint          pid,
                       const gchar  *name,
-                      GVariantDict *dict)
+                      GVariantDict *dict,
+                     void (*postprocess) (gchar **, gsize))
 {
   g_autofree gchar *path = NULL;
   g_autofree gchar *contents = NULL;
@@ -205,7 +212,11 @@ add_pid_proc_file_to (gint          pid,
   path = g_strdup_printf ("/proc/%d/%s", pid, name);
 
   if (g_file_get_contents (path, &contents, &len, NULL))
-    g_variant_dict_insert (dict, name, "s", contents);
+    {
+      if (postprocess)
+        postprocess (&contents, len);
+      g_variant_dict_insert (dict, name, "s", contents);
+    }
 }
 
 static gboolean
@@ -240,19 +251,19 @@ ipc_service_impl_handle_get_process_info (IpcService            *service,
           GVariantDict dict;
 
           g_variant_dict_init (&dict, NULL);
-          g_variant_dict_insert (&dict, "pid", "i", pid);
+          g_variant_dict_insert (&dict, "pid", "i", pid, NULL);
 
           if (want_statm)
-            add_pid_proc_file_to (pid, "statm", &dict);
+            add_pid_proc_file_to (pid, "statm", &dict, NULL);
 
           if (want_cmdline)
-            add_pid_proc_file_to (pid, "cmdline", &dict);
+            add_pid_proc_file_to (pid, "cmdline", &dict, postprocess_cmdline);
 
           if (want_maps)
-            add_pid_proc_file_to (pid, "maps", &dict);
+            add_pid_proc_file_to (pid, "maps", &dict, NULL);
 
           if (want_mountinfo)
-            add_pid_proc_file_to (pid, "mountinfo", &dict);
+            add_pid_proc_file_to (pid, "mountinfo", &dict, NULL);
 
           g_variant_builder_add_value (&builder, g_variant_dict_end (&dict));
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]