namespace {
-constexpr const char SERVER_PROC_NAME[] = "org.tizen.appfw.pkgmgr";
-constexpr const char PACKAGE_MANAGER_SOCKET_PATH[] = "/run/package-manager";
+constexpr const char SERVER_PROC_NAME[] = "d::org.tizen.appfw.pkgmgr";
static int _is_system_user(void)
{
if (conn_admin_listener_.GetState() == ConnectionState::Connected)
return true;
- if (!activator_.Connect())
- return false;
-
try {
admin_proxy_->Connect(true);
} catch (const pkg_proxy::Exception& e) {
if (conn_info_listener_.GetState() == ConnectionState::Connected)
return true;
- if (!activator_.Connect())
- return false;
-
try {
info_proxy_->Connect(true);
} catch (const pkg_proxy::Exception& e) {
if (conn_cache_listener_.GetState() == ConnectionState::Connected)
return true;
- if (!activator_.Connect())
- return false;
-
try {
cache_proxy_->Connect(true);
} catch (const pkg_proxy::Exception& e) {
if (conn_delayed_result_listener_.GetState() == ConnectionState::Connected)
return true;
- if (!activator_.Connect())
- return false;
-
try {
delayed_result_proxy_->Connect(true);
} catch (const pkg_proxy::Exception& e) {
return raw_pc_;
}
-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();
-}
-
-bool Connector::Activator::Create() {
- if (fd_ != -1)
- return true;
-
- fd_ = ::socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
- if (fd_ < 0) {
- _E("socket() is failed. errno: %d", errno);
- return false;
- }
-
- addr_.sun_family = AF_UNIX;
- snprintf(addr_.sun_path, sizeof(addr_.sun_path), "%s",
- PACKAGE_MANAGER_SOCKET_PATH);
- return true;
-}
-
-void Connector::Activator::SetTimeout(int timeout_msec) {
- if (timeout_msec < 0) {
- _E("Invalid timeout parameter");
- return;
- }
-
- timeval timeout = {
- .tv_sec = static_cast<time_t>(timeout_msec / 1000),
- .tv_usec = static_cast<time_t>(timeout_msec % 1000) * 1000
- };
- if (setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0)
- _E("setsockopt() is failed, fd: %d, errno : %d", fd_, errno);
-}
-
-int Connector::Activator::TryConnect() {
- int ret = connect(fd_, reinterpret_cast<sockaddr*>(&addr_), sizeof(addr_));
- _E("ret = %d", ret);
- if (ret < 0) {
- if (errno != EAGAIN && errno != EINPROGRESS)
- return -2;
- }
-
- return 0;
-}
-
-
-bool Connector::Activator::ReceiveReady() {
- bool is_blocking;
- if (fcntl(fd_, F_GETFL, 0) & O_NONBLOCK)
- is_blocking = false;
- else
- is_blocking = true;
-
- int retry_count = 20;
- size_t len = 1;
- char buffer[2] = {0,};
- while (len) {
- ssize_t bytes = recv(fd_, buffer, len, 0);
- if (bytes == 0) {
- _W("EOF. fd(%d)", fd_);
- return -ECOMM;
- }
-
- if (bytes < 0) {
- if (errno == EINTR || errno == EAGAIN) {
- if (is_blocking && errno == EAGAIN) {
- _E("Timed out. fd(%d)", fd_);
- return -EAGAIN;
- }
-
- if (retry_count > 0) {
- usleep(100 * 1000);
- retry_count--;
- continue;
- }
- }
-
- _E("recv() is failed. fd(%d), errno(%d)", fd_, errno);
- return -ECOMM;
- }
-
- len -= bytes;
- }
-
- _E("Received: %s\n", buffer);
-
- close(fd_);
- fd_ = -1;
-
- return true;
-}
-
} // namespace client
} // namespace pkgmgr