struct HelloMessage
{
- int pid;
int reverse; // if the connection is for reverse message
};
GSource* pGSource = null;
GIOChannel* pChannel = null;
ssize_t readBytes = 0;
+ int ret = 0;
int server = -1;
int client = -1;
struct sockaddr_un clientAddress;
socklen_t clientLen = sizeof(clientAddress);
+ struct ucred cr;
+ socklen_t ucredLen = sizeof(cr);
+
SysAssertf(pIpcServer != null, "Not yet constructed. Construct() should be called before use.\n");
SysAssertf(pIpcServer->__pListener != null, "Listener is null.\n");
g_io_channel_set_flags(pChannel, G_IO_FLAG_NONBLOCK, &pGError);
g_io_channel_set_close_on_unref(pChannel, TRUE);
+
+ ret = getsockopt(client, SOL_SOCKET, SO_PEERCRED, &cr, &ucredLen);
+ SysTryCatch(NID_IO, ret >= 0, , E_SYSTEM, "[E_SYSTEM] Failed to get peercred information: %s", strerror(errno));
+
client = -1;
- pClientInfo = pIpcServer->__clients[helloMessage.pid];
+ pClientInfo = pIpcServer->__clients[cr.pid];
if (pClientInfo == null) // first connection request from this client
{
pClientInfo = new (std::nothrow) _ClientInfo;
SysTryCatch(NID_IO, pClientInfo != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
pClientInfo->pIpcServer = pIpcServer;
- pClientInfo->clientId = helloMessage.pid;
+ pClientInfo->clientId = cr.pid;
char* pAppId = NULL;
- int ret = app_manager_get_app_id(helloMessage.pid, &pAppId);
+ ret = app_manager_get_app_id(cr.pid, &pAppId);
SysTryCatch(NID_IO, ret >= 0, delete pClientInfo, E_SYSTEM, "[E_SYSTEM] Failed to get_app_id: %d", ret);
pClientInfo->appId = pAppId;
pClientInfo->pReverseChannel = null;
- pIpcServer->__clients[helloMessage.pid] = pClientInfo;
+ pIpcServer->__clients[cr.pid] = pClientInfo;
pIpcServer->__pCurrentClientInfo = pClientInfo;
- pIpcServer->__pListener->OnIpcClientConnected(*pIpcServer, helloMessage.pid);
+ pIpcServer->__pListener->OnIpcClientConnected(*pIpcServer, cr.pid);
pIpcServer->__pCurrentClientInfo = null;
}