Check signal agent's operation success 00/309900/4
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 18 Apr 2024 04:06:13 +0000 (13:06 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Thu, 18 Apr 2024 04:34:53 +0000 (13:34 +0900)
Change-Id: I3997edf0a5b890ae85daa6433848b8d22869dd55
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
installer/pkgmgr_installer_signal_agent.cc
installer/src/control.cc
installer/src/pkgmgr_installer_debug.h

index 38c5c6b..306e129 100644 (file)
@@ -330,6 +330,12 @@ static gboolean __handle_signal(gint fd,
 
   free(data);
   free(type_name);
+
+  int ret = 0;
+  ssize_t send_byte = send(clifd, &ret, sizeof(ret), MSG_NOSIGNAL);
+  if (send_byte < 0)
+    LOGE("send() is failed. fd: %d, errno: %d", fd, errno);
+
   close(clifd);
 
   /* renew timeout */
@@ -386,6 +392,8 @@ int main(int argc, char* argv[]) {
   if (r < 0)
     return -1;
 
+  LOGW("signal agent start");
+
   g_main_loop_run(loop);
 
   __fini();
index e88213b..db2eb23 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "control.hh"
 
+#include <fcntl.h>
 #include <getopt.h>
 #include <sys/socket.h>
 #include <sys/types.h>
@@ -42,6 +43,8 @@ constexpr int OPTVAL_SKIP_CHECK_REFERENCE = 1007;
 constexpr int OPTVAL_RECOVER_DB = 1008;
 constexpr int OPTVAL_RECOVERY_CLEANUP = 1009;
 
+constexpr int AGENT_TIMEOUT = 3000;
+
 constexpr const char short_opts[] = "k:l:i:d:c:m:t:o:r:p:s:b:e:M:y:u:w:D:A:qGS";
 constexpr const struct option long_opts[] = {
   { "session-id", 1, nullptr, 'k' },
@@ -486,6 +489,26 @@ static int __send_signal_to_agent(uid_t uid, void* data, size_t len) {
     return -1;
   }
 
+  int flags = fcntl(fd, F_GETFL, 0);
+  if (fcntl(fd, F_SETFL, (flags & (~SOCK_NONBLOCK))) != 0) {
+    _E("Failed to set flags: %d on fd: %d, errno: %d", flags, fd, errno);
+    close(fd);
+    return 0;
+  }
+
+  struct timeval timeout = {
+      .tv_sec = static_cast<time_t>(AGENT_TIMEOUT / 1000),
+      .tv_usec = static_cast<suseconds_t>((AGENT_TIMEOUT % 1000) * 1000)};
+
+  if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0)
+    _E("setsockopt() is failed. fd: %d, errno: %d", fd, errno);
+
+  int ret;
+  ssize_t recv_byte = recv(fd, &ret, sizeof(ret), 0);
+  if (recv_byte <= 0)
+    _E("recv() is failed. recv_vypte : %d, fd: %d, errno: %d",
+        recv_byte, fd, errno);
+
   close(fd);
 
   return 0;
index a92a883..dcdc876 100644 (file)
 #define _E LOGE
 #endif
 
+#ifndef _W
+#define _W LOGW
+#endif
+
 #ifndef _D
 #define _D LOGD
 #endif