#include <tzplatform_config.h>
#include <openssl/sha.h>
#include <openssl/evp.h>
+#include <libmount/libmount.h>
+#include <libisu-internal.h>
#define BID_SNAME ".note.gnu.build-id"
+#define ISU_BUFF_LEN 1024
struct rpm_info {
char *file_path;
return ret;
}
+static char *get_isu_pkg_name_from_path(const char *path)
+{
+ char *p = strstr(path, ISU_RUN_PATH);
+ if (p == NULL) {
+ // File is not under /run/isu
+ return NULL;
+ }
+ p += strlen(ISU_RUN_PATH);
+ if (*p == '/')
+ p++;
+
+ char *c = strchr(p, '/');
+ if (c == NULL) {
+ return strdup(p);
+ } else {
+ size_t len = c - p + 1;
+ char *result = (char*)malloc(len);
+ if (result == NULL) {
+ _E("Memory allocation error: %d %m", errno);
+ return NULL;
+ }
+ strncpy(result, p, len-1);
+ result[len-1] = '\0';
+ return result;
+ }
+}
+
enum Perms {
PERM_READ = 1,
PERM_WRITE = 2,
return result;
}
-void get_and_save_so_info(char *map_path, char *out_path)
+static char* get_isu_info(const char *path, pid_t pid)
+{
+ char *source_path = NULL;
+ int res = is_isu_file(path, pid, &source_path);
+ if (res == ISU_FILE_RES_NOT_SUPPORTED || res == ISU_FILE_RES_IS_NORMAL_FILE) {
+ return NULL;
+ }
+ if (res == ISU_FILE_RES_ERROR) {
+ return strdup("libisu error");
+ }
+
+
+ char *isu_info = NULL;
+
+ isu_pkg_list list = isu_list_init();
+ if (list == NULL) {
+ return strdup("get ISU package info error");
+ }
+
+ char *pkg_name = get_isu_pkg_name_from_path(source_path);
+ free(source_path);
+
+ if (pkg_name == NULL) {
+ return strdup("get ISU package name error");
+ }
+
+ isu_pkg_info info = NULL;
+ while ((info = isu_list_next(list)) != NULL) {
+ char name[ISU_BUFF_LEN];
+ isu_pkg_get_name(info, name, sizeof(name));
+ if (strncmp(name, pkg_name, strlen(pkg_name)) == 0) {
+ char version[ISU_BUFF_LEN];
+ isu_pkg_get_version(info, version, sizeof(version));
+ isu_pkg_info_free(info);
+ if (asprintf(&isu_info, "%s;%s", pkg_name, version) == -1) {
+ _E("Memory allocation error");
+ isu_info = NULL;
+ goto exit;
+ }
+ break;
+ }
+ isu_pkg_info_free(info);
+ }
+exit:
+ free(pkg_name);
+ isu_list_free(list);
+ return isu_info;
+}
+
+void get_and_save_so_info(char *map_path, char *out_path, pid_t pid)
{
FILE *f = fopen(out_path, "w");
if (f == NULL) {
GSList *file_list = get_filepaths(map_path);
GSList *pkgs_not_found = NULL;
+ char relative_root[PATH_MAX];
+ snprintf(relative_root, sizeof(relative_root), "/proc/%d/root/", pid);
rpmts ts = init_rpm();
char modified_file_path[PATH_MAX];
char *build_id = NULL;
+ char proc_root_file_path[PATH_MAX+1];
+ snprintf(proc_root_file_path, sizeof(proc_root_file_path), "%s/%s", relative_root, file_path);
if (is_dotnet_file(file_path)) {
build_id = strdup("");
if (correct_file_path(file_path, modified_file_path, sizeof(modified_file_path)))
file_path = modified_file_path;
- } else if (get_build_id(file_path, &build_id) <= 0 || build_id == NULL) {
+ } else if (get_build_id(proc_root_file_path, &build_id) <= 0 || build_id == NULL) {
continue;
}
} else {
char hash_sum[2*SHA_DIGEST_LENGTH + 1];
- if (!sha1sum(file_path, hash_sum))
+ if (!sha1sum(proc_root_file_path, hash_sum))
snprintf(hash_sum, sizeof(hash_sum), "hash-error");
- int fret = fprintf(f, "%s %s %s %s\n", file_path, build_id, rpm_info, hash_sum);
+ int fret = fprintf(f, "%s %s %s %s", file_path, build_id, rpm_info, hash_sum);
+
+ if (fret) {
+ char *isu_info = get_isu_info(file_path, pid);
+ if (isu_info) {
+ fret = fprintf(f, " ISU:%s", isu_info);
+ free(isu_info);
+ }
+ fprintf(f, "\n");
+ }
+
free(rpm_info);
free(build_id);