From 35fea3086fcc142b010b05966a2299c3be3fdb06 Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Thu, 27 Aug 2020 19:40:38 +0900 Subject: [PATCH] fix not working trace by rule without all case and add log about cmd part Change-Id: Ic6696761b25ee43276a05b0cc09df0e96be6be25 --- src/DSWaylandServer/DSWaylandProtocolTrace.cpp | 47 ++++++++++++++++++++-- .../DSWaylandProtocolTracePrivate.h | 1 + 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/DSWaylandServer/DSWaylandProtocolTrace.cpp b/src/DSWaylandServer/DSWaylandProtocolTrace.cpp index 9122a09..1d4194f 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTrace.cpp +++ b/src/DSWaylandServer/DSWaylandProtocolTrace.cpp @@ -23,6 +23,7 @@ #include "DSWaylandProtocolTrace.h" #include "DSWaylandProtocolTracePrivate.h" +#include "DSWaylandClient.h" #include #include @@ -552,6 +553,31 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_validate(ProtocolTrace_Protoco return rulechecker_rule_validate(rc, log->type, log->target_id, log->name, log->client_pid, cmd); } +void DSWaylandProtocolTracePrivate::wl_client_proc_name_get(pid_t pid, char *name, int size) + { + if(!name) return; + + FILE *h; + char proc[512], pname[512]; + size_t len; + + snprintf(proc, 512, "/proc/%d/cmdline", pid); + + h = fopen(proc, "r"); + if(!h) return; + + len = fread(pname, sizeof(char), 512, h); + if(len >0) + pname[len-1]='\0'; + else + { + strncpy(pname, "NO NAME", sizeof(pname)); + } + fclose(h); + + strncpy(name, pname, size); +} + void DSWaylandProtocolTracePrivate::protocol_trace_set(void) { DSLOG_DBG("DSWaylandProtocolTracePriv","IN >> protocol trace set"); @@ -575,7 +601,7 @@ void DSWaylandProtocolTracePrivate::protocol_trace_set(void) DSLOG_DBG("DSWaylandProtocolTracePriv","get display "); //check working - ds_wl_protocol_logger = wl_display_add_protocol_logger(display, protocol_trace_func, nullptr); + ds_wl_protocol_logger = wl_display_add_protocol_logger(display, protocol_trace_func, __wlCompositor); DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << protocol trace set"); } @@ -671,6 +697,18 @@ void DSWaylandProtocolTracePrivate::protocol_trace_func(void *user_data, enum wl elog.target_id = wl_resource_get_id(message->resource); snprintf(elog.name, PATH_MAX,"%s:%s", wl_resource_get_class(message->resource), message->message->name); + DSWaylandCompositor * comp = (DSWaylandCompositor * )user_data; + std::list clients = comp->clients(); + for(auto client : clients) + { + char name[512]; + wl_client_proc_name_get(client->pid(), name, sizeof(name)); + if(client->pid() == client_pid) + { + snprintf(elog.cmd, PATH_MAX, "%s", name); + } + } + if(!protocol_rule_validate(&elog)) return; BUF_SNPRINTF("[%10.3f] %s%d%s%s@%u.%s(", @@ -1370,10 +1408,11 @@ int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree, { char iface[64] = {0,}; char *msg = nullptr; - int colon = atoi(":"); if(args->name) - msg = (char *) index(args->name, colon); + { + msg = (char *) strchr(args->name, ':'); + } if(msg) { int min = MIN(sizeof(iface)-1, msg-args->name); @@ -1401,7 +1440,7 @@ int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree, } else if(!strcasecmp(data->variable_name, "IFACE")) { - if(msg && !iface[0] && rulechecker_string_compare(data->comparer, data->value.string, iface)) + if(msg && iface[0] && rulechecker_string_compare(data->comparer, data->value.string, iface)) data->result = PROTOCOLTRACE_RESULT_TRUE; else data->result = PROTOCOLTRACE_RESULT_FALSE; diff --git a/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h b/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h index ffecf2d..569b462 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h +++ b/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h @@ -284,6 +284,7 @@ private: static int rule_print_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg); static int rule_validate_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg); int chk(const char *str); + static void wl_client_proc_name_get(pid_t pid, char *name, int size); }; } -- 2.7.4