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);
83 info->command[PATH_MAX] = '\0';
85 info->pid = creds.pid;
86 info->uid = creds.uid;
87 info->gid = creds.gid;
89 info->index = client->index;
94 info->index = client->index;
95 strncpy (info->command, "REMOTE", PATH_MAX);
96 info->command[PATH_MAX] = '\0';
102 XDBG_ERROR (MXDBG, "Failed to make client info(index:%d)\n",
108 _traceClientState (CallbackListPtr *list, pointer closure, pointer calldata)
110 NewClientInfoRec *clientinfo = (NewClientInfoRec*)calldata;
111 ClientPtr client = clientinfo->client;
112 ModuleClientInfo *info = GetClientInfo (client);
113 static char* clientState[]=
115 "ClientStateInitial",
116 "ClientStateAuthenticating",
117 "ClientStateRunning",
118 "ClientStateRetained",
120 "ClientStateCheckingDebug",
121 "ClientStateCheckedDebug"
127 if ((client->clientState == ClientStateInitial) || (client->clientState == ClientStateGone))
129 if (client->clientState == ClientStateInitial)
130 _debugClientInfo (client);
132 XDBG_SECURE (MXDBG, "id:%d, conn_fd:%d, pid:%d, uid:%d, name:%s (%s)\n",
133 info->index, info->conn_fd, info->pid, info->uid, info->command,
134 clientState[client->clientState]);
138 XDBG_DEBUG (MXDBG, "id:%d, conn_fd:%d, pid:%d, uid:%d, name:%s (%s)\n",
139 info->index, info->conn_fd, info->pid, info->uid, info->command,
140 clientState[client->clientState]);
144 xDbgModuleMain (XDbgModule *pMod)
148 if (!dixRegisterPrivateKey (DebugClientKey, PRIVATE_CLIENT, sizeof (ModuleClientInfo)))
150 XDBG_ERROR (MXDBG, "failed: dixRegisterPrivateKey\n");
154 ret &= AddCallback (&ClientStateCallback, _traceClientState, pMod);
158 XDBG_ERROR (MXDBG, "failed: AddCallback\n");
162 xDbgModuleEvlogInstallHooks (pMod);
164 if (!xDbgDBusServerConnect ())
166 XDBG_ERROR (MXDBG, "failed: xDbgDBusServerConnect\n");
170 snprintf (method.name, sizeof (method.name), "%s", XDBG_DBUS_METHOD);
171 method.func = xDbgModuleCommand;
174 xDbgDBusServerAddMethod (&method);
180 xDbgModuleMainExit (XDbgModule *pMod)
182 DeleteCallback (&ClientStateCallback, _traceClientState, pMod);
184 xDbgModuleEvlogUninstallHooks (pMod);
186 xDbgDBusServerRemoveMethod (&method);
188 xDbgDBusServerDisconnect ();