From: Mateusz Moscicki Date: Wed, 19 May 2021 08:15:45 +0000 (+0200) Subject: update-manager: Change the search location for the delta.tar file X-Git-Tag: submit/tizen/20210528.131738^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8652bdb6c89d0cc029116b1fa9af1e50c6cca1df;p=platform%2Fcore%2Fsystem%2Fupdate-control.git update-manager: Change the search location for the delta.tar file update-manager will look for the delta.tar file in the data directory of the application that called the "install" DBus method. If the appid of the caller cannot be determined, the delta.tar file will be searched for in the application data directory that has the value "client" for the key "tizen-fota-manager". Change-Id: Iebc9b5badcbe084d98ee41b03760a5f0951f4697 --- diff --git a/update-manager/common/common-dbus-manager.c b/update-manager/common/common-dbus-manager.c index abed007..eacabe0 100644 --- a/update-manager/common/common-dbus-manager.c +++ b/update-manager/common/common-dbus-manager.c @@ -1,9 +1,42 @@ +#include #include "common.h" #include "../fota/fota-manager.h" #include "update-manager-dbus.h" static guint owner_id; +static pid_t dbus_get_sender_pid(GDBusMethodInvocation *invocation) +{ + const gchar *sender = g_dbus_method_invocation_get_sender(invocation); + GDBusConnection *conn = g_dbus_method_invocation_get_connection(invocation); + if (sender == NULL || conn == NULL) { + _FLOGW("Failed to get invocation data"); + return 0; + } + GError *error = NULL; + GVariant *result = g_dbus_connection_call_sync(conn, + "org.freedesktop.DBus", + "/", + "org.freedesktop.DBus", + "GetConnectionUnixProcessID", + g_variant_new("(s)", sender), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (!result || error) { + _FLOGW("Failed to get sender PID: %s", error ? error->message : ""); + g_error_free(error); + return 0; + } + + pid_t pid; + g_variant_get(result, "(u)", &pid); + g_variant_unref(result); + return pid; +} + gboolean dbus_manager_result(OrgTizenUpdateManager *skeleton, GDBusMethodInvocation *invocation, gpointer user_data) { int ret = 0; @@ -22,7 +55,8 @@ gboolean dbus_manager_install(OrgTizenUpdateManager *skeleton, GDBusMethodInvoca int ret = 0; _FLOGD("Dbus status : install called"); - ret = fota_installer_execute(); + pid_t pid = dbus_get_sender_pid(invocation); + ret = fota_installer_execute(pid); if (ret < 0) _FLOGW("Failed to install delta with fota : %d", ret); org_tizen_update_manager_complete_install(skeleton, invocation, ret); diff --git a/update-manager/fota/fota-installer.c b/update-manager/fota/fota-installer.c index 5635ff0..953bdf6 100644 --- a/update-manager/fota/fota-installer.c +++ b/update-manager/fota/fota-installer.c @@ -1,3 +1,4 @@ +#include #include "../common/common.h" #include "fota-manager.h" @@ -10,8 +11,34 @@ #define FOTA_INSTALL_REBOOT_REASON "fota" +static char *get_sender_or_client_appid(pid_t pid) +{ + char *result = NULL; + if (pid > 0) { + char tmp_appid[PATH_MAX]; + int res = aul_app_get_appid_bypid(pid, tmp_appid, sizeof(tmp_appid)); + if (res == AUL_R_OK) { + result = strdup(tmp_appid); + if (result == NULL) { + _FLOGE("Out of memory"); + return NULL; + } + } else { + _FLOGE("Failed to get sender app id: %d", res); + } + } + + // Fallback to appid retrieval based on application metadata if the + // caller appid cannot be determined + if (result == NULL) { + result = fota_client_info_get_appid(); + if (result == NULL) + _FLOGE("Failed to get client app id"); + } + return result; +} -int fota_installer_execute() +int fota_installer_execute(pid_t sender_pid) { int ret = 0, status = 0, exec_status = 0; char buf[MAX_BUFFER_SIZE] = {0, }; @@ -20,9 +47,8 @@ int fota_installer_execute() pid_t pid; /* 1. Check client have delta.tar */ - appid = fota_client_info_get_appid(); + appid = get_sender_or_client_appid(sender_pid); if (appid == NULL) { - _FLOGE("Failed to get client app id"); status = -1; goto execute_destroy; } diff --git a/update-manager/fota/fota-manager.h b/update-manager/fota/fota-manager.h index 30db703..bad0e8f 100644 --- a/update-manager/fota/fota-manager.h +++ b/update-manager/fota/fota-manager.h @@ -4,6 +4,7 @@ #include #include #include +#include /* Log */ #define FOTA_LOG_TAG "FOTA_MANAGER" @@ -44,7 +45,7 @@ int fota_info_checker_init(void); int fota_info_checker_fini(void); char *fota_info_get_build_string(void); -int fota_installer_execute(void); +int fota_installer_execute(pid_t pid); int fota_result_sender_execute(void); int fota_status_checker_init(void);