Remove to send the Pid/AppId in internal IPC
authorSunwook Bae <sunwook45.bae@samsung.com>
Mon, 19 Aug 2013 09:37:55 +0000 (18:37 +0900)
committerSunwook Bae <sunwook45.bae@samsung.com>
Tue, 20 Aug 2013 05:09:43 +0000 (14:09 +0900)
Change-Id: I7bbf969fc8cd744f8858c172f92fc7d7295551e5
Signed-off-by: Sunwook Bae <sunwook45.bae@samsung.com>
src/io/FIo_IpcClient.cpp
src/io/inc/FIo_IpcClient.h
src/server/io/FIo_IpcServer.cpp

index ef638b2..04cd4a7 100644 (file)
@@ -37,8 +37,6 @@
 #include <map>
 
 #include <FBaseRtMutex.h>
-#include <FApp_AppInfo.h>
-#include <FAppPkg_PackageManagerImpl.h>
 #include <FBaseSysLog.h>
 #include <FBase_StringConverter.h>
 #include "FIo_IpcClient.h"
@@ -47,7 +45,6 @@
 using namespace IPC;
 using namespace std;
 using namespace Tizen::App;
-using namespace Tizen::App::Package;
 using namespace Tizen::Base;
 using namespace Tizen::Base::Runtime;
 
@@ -56,7 +53,6 @@ namespace Tizen { namespace Io
 
 _IpcClient::_IpcClient(void)
        : __pReverseSource(null)
-       , __fdCount(0)
        , __pFdLock(null)
        , __pListener(null)
 {
@@ -132,9 +128,7 @@ _IpcClient::GetName(void) const
 
 struct HelloMessage
 {
-       int pid;
-       bool reverse;
-       char appId[256];
+       int reverse;
 };
 
 result
@@ -147,13 +141,12 @@ _IpcClient::MakeConnection(bool forReverse)
        int client = -1;
        int ret = 0;
        int retry = 0;
-       HelloMessage helloMessage = {0, 0};
+       HelloMessage helloMessage = {0};
        std::string socketName;
        char* pSocketName = null;
        size_t socketNameLength = 0;
        int flags = 0;
 
-       helloMessage.pid = getpid();
        if (forReverse)
        {
                helloMessage.reverse = 1;
@@ -174,21 +167,6 @@ _IpcClient::MakeConnection(bool forReverse)
        socketNameLength = socketName.size() + 1;
        SysTryReturnResult(NID_IO, socketNameLength < 108, E_INVALID_ARG, "Server name is too long.");
 
-       if (__fdCount == 0)
-       {
-               // Set an appId
-               String appId = _AppInfo::GetApplicationId();
-               int length = (appId.GetLength() + 1) * sizeof(wchar_t);
-               if (length > 255)
-               {
-                       length = 255;
-               }
-
-               SysTryReturnResult(NID_IO, appId.GetLength() > 0, E_SYSTEM, "AppId dose not exist.");
-
-               memcpy(helloMessage.appId, appId.GetPointer(), length);
-       }
-
        client = socket(AF_UNIX, SOCK_STREAM, 0);
        SysTryCatch(NID_IO, client != -1, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to create a socket : %s.", strerror(errno));
 
@@ -302,8 +280,6 @@ _IpcClient::MakeConnection(bool forReverse)
        }
        else
        {
-               ++__fdCount;
-
                ReleaseFd(client);
        }
 
index 2a6a062..168848b 100644 (file)
@@ -136,7 +136,6 @@ private:
        GSource* __pReverseSource;
 
        std::vector <int> __fds;
-       int __fdCount;
        Tizen::Base::Runtime::Mutex* __pFdLock;
        Tizen::Base::String __name;
        _IIpcClientEventListener* __pListener;
index f865270..fced1e5 100644 (file)
@@ -33,6 +33,8 @@
 #include <sys/stat.h>
 #include <sys/un.h>
 
+#include <aul/aul.h>
+
 #include <ipc/ipc_message.h>
 
 #include <FBaseRtMutex.h>
@@ -275,9 +277,7 @@ CATCH:
 
 struct HelloMessage
 {
-       int pid;
-       bool reverse;  // true if the connection is for reverse message
-       char appId[256];
+       int reverse;  // if the connection is for reverse message
 };
 
 gboolean
@@ -290,12 +290,17 @@ _IpcServer::OnConnectionRequest(GIOChannel* source, GIOCondition condition, gpoi
        _ChannelInfo* pChannelInfo = null;
        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");
 
@@ -304,8 +309,9 @@ _IpcServer::OnConnectionRequest(GIOChannel* source, GIOCondition condition, gpoi
        client = accept(server, (struct sockaddr*) &clientAddress, &clientLen);
        SysTryCatch(NID_IO, client != -1, , E_SYSTEM, "[E_SYSTEM] Accept failed.");
 
-       read(client, &helloMessage, sizeof(helloMessage));
-       helloMessage.appId[255] = '\0';
+       readBytes = read(client, &helloMessage, sizeof(helloMessage));
+       SysTryCatch(NID_IO, readBytes >= 0, , E_SYSTEM, "[E_SYSTEM] Failed to receive hello message (%d, %s).",
+                       errno, strerror(errno));
 
        pChannel = g_io_channel_unix_new(client);
        SysTryCatch(NID_IO, pChannel != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
@@ -314,23 +320,32 @@ _IpcServer::OnConnectionRequest(GIOChannel* source, GIOCondition condition, gpoi
        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->appId.Append((wchar_t*) helloMessage.appId);
-               pClientInfo->pReverseChannel = null;
+               pClientInfo->clientId = cr.pid;
+
+               char buffer[256] = {0, };
+               ret = aul_app_get_appid_bypid(cr.pid, buffer, sizeof(buffer));
+               SysTryCatch(NID_IO, ret == AUL_R_OK, delete pClientInfo, E_SYSTEM, "[E_SYSTEM] Failed to get the application ID of pid: %d", ret);
 
-               pIpcServer->__clients[helloMessage.pid] = pClientInfo;
+               pClientInfo->appId = buffer;
+
+               pClientInfo->pReverseChannel = null;
 
+               pIpcServer->__clients[cr.pid] = pClientInfo;
                pIpcServer->__pCurrentClientInfo = pClientInfo;
-               pIpcServer->__pListener->OnIpcClientConnected(*pIpcServer, helloMessage.pid);
+               pIpcServer->__pListener->OnIpcClientConnected(*pIpcServer, cr.pid);
                pIpcServer->__pCurrentClientInfo = null;
        }