1 /**************************************************************************
5 Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
7 Contact: Boram Park <boram1288.park@samsung.com>
8 Sangjin LEE <lsj119@samsung.com>
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 **************************************************************************/
41 #include "xdbg_types.h"
42 #include "xdbg_module.h"
43 #include "xdbg_module_clist.h"
45 static ModuleTraceClientOption*
46 _findTraceClientOption (XDbgModule *pMod, char *client_name)
50 for (i = 0 ; i < pMod->trace_cnt ; i++)
52 ModuleTraceClientOption *option = &pMod->trace_options[i];
53 if (!strcmp(client_name, option->name))
62 xDbgModuleCList (XDbgModule *pMod, char *reply, int *len)
66 XDBG_REPLY ("%6s %6s %s %s\n", "INDEX", "PID", "BLOCKED", "NAME");
68 for (i = 1; i < currentMaxClients && (0 < *len); i++)
70 ClientPtr pClient = clients[i];
71 ModuleClientInfo *info;
76 info = GetClientInfo (pClient);
80 XDBG_REPLY ("%6d %6d %4d %9s\n",
81 info->index, info->pid, pClient->ignoreCount, info->command);
87 xDbgModuleClistTraceInit (XDbgModule *pMod)
91 for (i = 1 ; i < currentMaxClients ; i++)
93 ClientPtr pClient = clients[i];
94 ModuleClientInfo *info;
99 info = GetClientInfo (pClient);
100 xDbgModuleClistTraceAdd (pMod, info);
105 xDbgModuleClistTraceAdd (XDbgModule *pMod, ModuleClientInfo *info)
107 char *client_name = strrchr (info->command, '/');
108 ModuleTraceClient *trace_client = NULL;
109 ModuleTraceClient *client = NULL, *tmp = NULL;
110 ModuleTraceClientOption *option = NULL;
112 XDBG_DEBUG (MXDBG, "[TRACE_CLIENT] AddClist Trace command %s\n", info->command);
115 client_name = client_name+1;
117 client_name = info->command;
119 if (!(option = _findTraceClientOption (pMod, client_name)))
122 xorg_list_for_each_entry_safe(client, tmp, &pMod->trace_list, link) {
123 if (client->pid == info->pid)
125 XDBG_DEBUG (MXDBG, "[TRACE_CLIENT] Find Trace list:%s conn_cnt:%d+1\n", client_name, client->conn_cnt);
131 trace_client = (ModuleTraceClient *) calloc (1, sizeof(ModuleTraceClient));
132 XDBG_RETURN_IF_FAIL (trace_client != NULL);
134 trace_client->pid = info->pid;
135 trace_client->conn_cnt = 1;
136 strncpy (trace_client->name, client_name, strlen(client_name)+1);
138 XDBG_DEBUG (MXDBG, "[TRACE_CLIENT] Add Trace list:%s conn_cnt:%d\n", client_name, trace_client->conn_cnt);
139 xorg_list_add (&trace_client->link, &pMod->trace_list);
145 xDbgModuleClistTraceRemove (XDbgModule *pMod, ModuleClientInfo *info)
147 char *client_name = strrchr (info->command, '/');
148 ModuleTraceClient *client = NULL, *tmp = NULL;
149 ModuleTraceClientOption *option = NULL;
151 XDBG_DEBUG (MXDBG, "[TRACE_CLIENT] RevmoeClist Trace command %s\n", info->command);
154 client_name = client_name+1;
156 client_name = info->command;
158 if (!(option = _findTraceClientOption (pMod, client_name)))
161 xorg_list_for_each_entry_safe(client, tmp, &pMod->trace_list, link) {
162 if (client->pid == info->pid)
164 if (client->conn_cnt == 1)
166 if (!strcmp(option->action, "cmd"))
169 ErrorF ("[TRACE_CLIENT] Disconnect Trace client:%s pid:%d cmd:%s", client->name, client->pid, option->cmd);
170 if (strstr(option->cmd, "reboot"))
173 ret = system (option->cmd);
174 ErrorF (" ret:%d\n", ret);
176 else if (!strcmp(option->action, "error"))
179 FatalError ("[TRACE_CLIENT] %s\n", option->cmd);
180 ErrorF ("[TRACE_CLIENT] Disconnect Trace client:%s pid:%d msg:%s\n", client->name, client->pid, option->cmd);
183 else if (!strcmp(option->action, "log"))
185 ErrorF ("[TRACE_CLIENT] Disconnect Trace client:%s pid:%d msg:%s\n", client->name, client->pid, option->cmd);
189 XDBG_DEBUG (MXDBG, "[TRACE_CLIENT] Unkown action Trace client:%s pid:%d action:%s cmd:%s\n",
190 client->name, client->pid, option->action, option->cmd);
193 xorg_list_del (&client->link);
197 XDBG_DEBUG (MXDBG, "[TRACE_CLIENT] Unref client:%s conn_cnt:%d-1 \n", client_name, client->conn_cnt);