Add functions to get sender pid
authorJunghyun Yeon <jungh.yeon@samsung.com>
Sat, 6 Mar 2021 08:02:18 +0000 (17:02 +0900)
committer연정현/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <jungh.yeon@samsung.com>
Mon, 8 Mar 2021 02:17:24 +0000 (11:17 +0900)
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/socket/abstract_socket.cc
src/common/socket/abstract_socket.hh
src/server/pkg_request.cc
src/server/pkg_request.hh

index 82ac752..e2e2f8f 100644 (file)
@@ -89,6 +89,16 @@ int AbstractSocket::GetFd() { return fd_; }
 
 std::string AbstractSocket::GetPath() { return path_; }
 
+int AbstractSocket::GetPID() {
+  int r;
+  struct ucred cred;
+  socklen_t len;
+
+  r = getsockopt(fd_, SOCK_STREAM, SO_PEERCRED, &cred, &len);
+
+  return cred.pid;
+}
+
 void AbstractSocket::SetOption() {
   int size = 2048;
   int ret = setsockopt(fd_, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
index bbfabb0..1220b86 100644 (file)
@@ -40,6 +40,7 @@ class EXPORT_API AbstractSocket {
 
   int GetFd();
   std::string GetPath();
+  int GetPID();
 
  protected:
   void SetOption();
index 0ae4438..5203d5e 100644 (file)
@@ -34,6 +34,10 @@ unsigned char* PkgRequest::GetData() { return data_; }
 
 int PkgRequest::GetSize() { return data_size_; }
 
+int PkgRequest::GetSenderPID() {
+  return socket_->GetPID();
+}
+
 pkgmgr_common::ReqType PkgRequest::GetRequestType() { return request_type_; }
 
 bool PkgRequest::ReceiveData() {
index 2afca11..2036e54 100644 (file)
@@ -33,6 +33,7 @@ class EXPORT_API PkgRequest {
   ~PkgRequest();
   unsigned char* GetData();
   int GetSize();
+  int GetSenderPID();
   pkgmgr_common::ReqType GetRequestType();
   bool ReceiveData();
   bool SendData(unsigned char* data, int size);