From ecbca0601344d0463f199a4e74a5f10f3393953b Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 10 May 2019 15:14:44 -0700 Subject: [PATCH] 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 8052fd82..961239c8 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)); }