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 **************************************************************************/
38 #include <windowstr.h>
42 #include "xdbg_dbus_server.h"
43 #include "xdbg_module.h"
44 #include "xdbg_module_command.h"
45 #include "xdbg_module_evlog.h"
48 #include <sys/socket.h>
50 DevPrivateKeyRec debug_client_key;
52 static XDbgDbusServerMethod method;
55 _debugClientInfo (ClientPtr client)
57 int fd = XaceGetConnectionNumber (client);
58 ModuleClientInfo *info = GetClientInfo (client);
60 /* For local clients, try and determine the executable name */
61 if (XaceIsLocal (client))
64 socklen_t len = sizeof (creds);
65 char path[PATH_MAX + 1] = {0,};
68 memset (&creds, 0, sizeof (creds));
69 if (getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &creds, &len) < 0)
72 snprintf (path, PATH_MAX + 1, "/proc/%d/cmdline", creds.pid);
73 fd = open (path, O_RDONLY);
77 bytes = read (fd, path, PATH_MAX + 1);
82 strncpy (info->command, path, PATH_MAX);
84 info->pid = creds.pid;
85 info->uid = creds.uid;
86 info->gid = creds.gid;
88 info->index = client->index;
93 info->index = client->index;
94 strncpy (info->command, "REMOTE", PATH_MAX);
100 XDBG_ERROR (MXDBG, "Failed to make client info(index:%d)\n",
106 _traceClientState (CallbackListPtr *list, pointer closure, pointer calldata)
108 NewClientInfoRec *clientinfo = (NewClientInfoRec*)calldata;
109 ClientPtr client = clientinfo->client;
110 ModuleClientInfo *info = GetClientInfo (client);
111 static char* clientState[]=
113 "ClientStateInitial",
114 "ClientStateAuthenticating",
115 "ClientStateRunning",
116 "ClientStateRetained",
118 "ClientStateCheckingDebug",
119 "ClientStateCheckedDebug"
125 if ((client->clientState == ClientStateInitial) || (client->clientState == ClientStateGone))
127 if (client->clientState == ClientStateInitial)
128 _debugClientInfo (client);
130 XDBG_INFO (MXDBG, "id:%d, conn_fd:%d, pid:%d, uid:%d, name:%s (%s)\n",
131 info->index, info->conn_fd, info->pid, info->uid, info->command,
132 clientState[client->clientState]);
136 XDBG_DEBUG (MXDBG, "id:%d, conn_fd:%d, pid:%d, uid:%d, name:%s (%s)\n",
137 info->index, info->conn_fd, info->pid, info->uid, info->command,
138 clientState[client->clientState]);
142 xDbgModuleMain (XDbgModule *pMod)
146 if (!dixRegisterPrivateKey (DebugClientKey, PRIVATE_CLIENT, sizeof (ModuleClientInfo)))
148 XDBG_ERROR (MXDBG, "failed: dixRegisterPrivateKey\n");
152 ret &= AddCallback (&ClientStateCallback, _traceClientState, pMod);
156 XDBG_ERROR (MXDBG, "failed: AddCallback\n");
160 xDbgModuleEvlogInstallHooks (pMod);
162 if (!xDbgDBusServerConnect ())
164 XDBG_ERROR (MXDBG, "failed: xDbgDBusServerConnect\n");
168 if (!xDbgModuleCommandInitLogPath (pMod))
170 XDBG_ERROR (MXDBG, "failed: xDbgModuleInitLogPath\n");
174 snprintf (method.name, sizeof (method.name), "%s", XDBG_DBUS_METHOD);
175 method.func = xDbgModuleCommand;
178 xDbgDBusServerAddMethod (&method);
184 xDbgModuleMainExit (XDbgModule *pMod)
186 DeleteCallback (&ClientStateCallback, _traceClientState, pMod);
188 xDbgModuleEvlogUninstallHooks (pMod);
190 xDbgDBusServerRemoveMethod (&method);
192 xDbgDBusServerDisconnect ();