From 6662a8730a467ba88548e162a851e017d13d3cd2 Mon Sep 17 00:00:00 2001 From: ilho kim Date: Tue, 2 Apr 2024 06:55:29 +0000 Subject: [PATCH] Revert "Use dbus activation for server execution" This reverts commit 1bc4ce4da97baac3a36d585b199ae5f4fc5cfa52. Change-Id: If7d8f5fdc8b3e8d7390b7b41e539912355f6f3d2 --- client/src/connector.cc | 86 ++++++++++++++++++++----------------------------- client/src/connector.hh | 2 +- 2 files changed, 36 insertions(+), 52 deletions(-) diff --git a/client/src/connector.cc b/client/src/connector.cc index af400bd..381fe45 100644 --- a/client/src/connector.cc +++ b/client/src/connector.cc @@ -124,7 +124,7 @@ bool Connector::ConnectForAdmin() { if (conn_admin_listener_.GetState() == ConnectionState::Connected) return true; - if (!activator_.Connect(raw_pc_, "install")) + if (!activator_.Connect()) return false; try { @@ -145,7 +145,7 @@ bool Connector::ConnectForInfo() { if (conn_info_listener_.GetState() == ConnectionState::Connected) return true; - if (!activator_.Connect(raw_pc_, "getsize")) + if (!activator_.Connect()) return false; try { @@ -166,7 +166,7 @@ bool Connector::ConnectForCache() { if (conn_cache_listener_.GetState() == ConnectionState::Connected) return true; - if (!activator_.Connect(raw_pc_, "clearcache")) + if (!activator_.Connect()) return false; try { @@ -187,7 +187,7 @@ bool Connector::ConnectForDelayedResult() { if (conn_delayed_result_listener_.GetState() == ConnectionState::Connected) return true; - if (!activator_.Connect(raw_pc_, "install")) + if (!activator_.Connect()) return false; try { @@ -234,56 +234,40 @@ pkgmgr_client_t* Connector::GetRawPc() { return raw_pc_; } -bool Connector::Activator::Connect(pkgmgr_client_t* pc, std::string method) { - GVariant *result; - int ret = PKGMGR_R_ECOMM; +bool Connector::Activator::Connect() { + if (!Create()) + return false; - ret = pkgmgr_client_connection_send_request(pc, method.c_str(), - g_variant_new("()"), &result); - if (ret != PKGMGR_R_OK) { - _E("request failed: %d", ret); - return false; - } + SetTimeout(60 * 1000); + + int retry_cnt = 3; + do { + int ret = TryConnect(); + if (ret == 0) { + break; + } else if (ret < -1) { + _E("Maybe peer not launched or peer dead. path: %s, fd: %d", + PACKAGE_MANAGER_SOCKET_PATH, fd_); + // If requester is root, don't wait + if (getuid() == 0) + return false; + + usleep(100 * 1000); + --retry_cnt; + } else if (ret < 0) { + _E("Failed to connect to socket: %s, fd: %d", + PACKAGE_MANAGER_SOCKET_PATH, fd_); + return false; + } + } while (retry_cnt > 0); - g_variant_get(result, "(i)", &ret); - g_variant_unref(result); - return ret == PKGMGR_R_OK ? true : false; -} + if (retry_cnt == 0) { + _E("Failed to connect with server"); + return false; + } -//bool Connector::Activator::Connect() { -// if (!Create()) -// return false; -// -// SetTimeout(60 * 1000); -// -// int retry_cnt = 3; -// do { -// int ret = TryConnect(); -// if (ret == 0) { -// break; -// } else if (ret < -1) { -// _E("Maybe peer not launched or peer dead. path: %s, fd: %d", -// PACKAGE_MANAGER_SOCKET_PATH, fd_); -// // If requester is root, don't wait -// if (getuid() == 0) -// return false; -// -// usleep(100 * 1000); -// --retry_cnt; -// } else if (ret < 0) { -// _E("Failed to connect to socket: %s, fd: %d", -// PACKAGE_MANAGER_SOCKET_PATH, fd_); -// return false; -// } -// } while (retry_cnt > 0); -// -// if (retry_cnt == 0) { -// _E("Failed to connect with server"); -// return false; -// } -// -// return ReceiveReady(); -//} + return ReceiveReady(); +} bool Connector::Activator::Create() { if (fd_ != -1) diff --git a/client/src/connector.hh b/client/src/connector.hh index d8f3499..29236b3 100644 --- a/client/src/connector.hh +++ b/client/src/connector.hh @@ -72,7 +72,7 @@ class Connector { public: Activator() : fd_(-1), addr_{} {} - bool Connect(pkgmgr_client_t* pc, std::string method); + bool Connect(); bool Create(); void SetTimeout(int timeout_msec); int TryConnect(); -- 2.7.4