From 73a1aa413274e9947283406cd5ad672b346df34f Mon Sep 17 00:00:00 2001 From: Pablo Marcos Oltra Date: Sat, 6 Jan 2018 10:27:32 +0100 Subject: [PATCH] Print debug logs when APPIMAGE_CHECKRT_DEBUG is set --- checkrt.c | 13 ++++++++----- checkrt.h | 6 ++++++ exec.c | 10 ++++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/checkrt.c b/checkrt.c index a105f5f..4e8b4ad 100644 --- a/checkrt.c +++ b/checkrt.c @@ -47,6 +47,7 @@ char *optional = NULL; char *optional_ld_preload = NULL; +int debug_flag = 0; void checkrt(char *usr_in_appdir) { @@ -62,6 +63,8 @@ void checkrt(char *usr_in_appdir) char *gcc_bundle_lib = "./" GCCDIR "/libgcc_s.so.1"; const char *format = "tr '\\0' '\\n' < '%s' | grep -e '%s' | tail -n1"; + debug_flag = getenv("APPIMAGE_CHECKRT_DEBUG") ? 1 : 0; + if (access(stdcxx_bundle_lib, F_OK) == 0) { f = popen("ldconfig -p | grep 'libstdc++.so.6 (" LIBC6_ARCH ")' | awk 'NR==1{print $NF}'", "r"); ret = fscanf(f, "%s", stdcxx_sys_lib); (void)ret; @@ -72,8 +75,8 @@ void checkrt(char *usr_in_appdir) SCANLIB(stdcxx_bundle_lib, stdcxx_bundle_sym, "^GLIBCXX_3\\.4"); stdcxx_sys_ver = atoi(stdcxx_sys_sym+12); stdcxx_bundle_ver = atoi(stdcxx_bundle_sym+12); - //printf("%s ==> %s (%d)\n", stdcxx_sys_lib, stdcxx_sys_sym, stdcxx_sys_ver); - //printf("%s ==> %s (%d)\n\n", stdcxx_bundle_lib, stdcxx_bundle_sym, stdcxx_bundle_ver); + DEBUG("%s ==> %s (%d)\n", stdcxx_sys_lib, stdcxx_sys_sym, stdcxx_sys_ver); + DEBUG("%s ==> %s (%d)\n\n", stdcxx_bundle_lib, stdcxx_bundle_sym, stdcxx_bundle_ver); } } @@ -87,8 +90,8 @@ void checkrt(char *usr_in_appdir) SCANLIB(gcc_bundle_lib, gcc_bundle_sym, "^GCC_[0-9]\\.[0-9]"); gcc_sys_ver = atoi(gcc_sys_sym+4) * 100 + atoi(gcc_sys_sym+6) * 10 + atoi(gcc_sys_sym+8); gcc_bundle_ver = atoi(gcc_bundle_sym+4) * 100 + atoi(gcc_bundle_sym+6) * 10 + atoi(gcc_bundle_sym+8); - //printf("%s ==> %s (%d)\n", gcc_sys_lib, gcc_sys_sym, gcc_sys_ver); - //printf("%s ==> %s (%d)\n\n", gcc_bundle_lib, gcc_bundle_sym, gcc_bundle_ver); + DEBUG("%s ==> %s (%d)\n", gcc_sys_lib, gcc_sys_sym, gcc_sys_ver); + DEBUG("%s ==> %s (%d)\n\n", gcc_bundle_lib, gcc_bundle_sym, gcc_bundle_ver); } } @@ -121,6 +124,6 @@ void checkrt(char *usr_in_appdir) sprintf(optional, "%s", ""); } - //printf("optional: %s\noptional_ld_preload: %s\n", optional, optional_ld_preload); + DEBUG("optional: %s\noptional_ld_preload: %s\n", optional, optional_ld_preload); } diff --git a/checkrt.h b/checkrt.h index aafe389..4f8a72a 100644 --- a/checkrt.h +++ b/checkrt.h @@ -1,3 +1,9 @@ extern char *optional; extern char *optional_ld_preload; extern void checkrt(char *usr_in_appdir); +extern int debug_flag; + +#define DEBUG(...) do { \ + if (debug_flag) \ + printf(__VA_ARGS__); \ +} while (0) diff --git a/exec.c b/exec.c index 7632b74..ccf2bd7 100644 --- a/exec.c +++ b/exec.c @@ -42,6 +42,8 @@ variable (e.g. "PATH"): #define _GNU_SOURCE +#include "checkrt.h" + #include #include #include @@ -281,7 +283,7 @@ int execve(const char* filename, char* const argv[], char* const envp[]) { old_execve = dlsym(RTLD_NEXT, "execve"); int ret = old_execve(filename, argv, new_envp); stringlist_free(new_envp); - //printf(">>> custom execve()!\n"); + DEBUG(">>> custom execve()!\n"); return ret; } @@ -290,7 +292,7 @@ int execv(const char* filename, char* const argv[]) { old_execve = dlsym(RTLD_NEXT, "execve"); int ret = old_execve(filename, argv, new_envp); stringlist_free(new_envp); - //printf(">>> custom execv()!\n"); + DEBUG(">>> custom execv()!\n"); return ret; } @@ -300,7 +302,7 @@ int execvpe(const char* filename, char* const argv[], char* const envp[]) { old_execvpe = dlsym(RTLD_NEXT, "execvpe"); int ret = old_execvpe(filename, argv, new_envp); stringlist_free(new_envp); - //printf(">>> custom execvpe()!\n"); + DEBUG(">>> custom execvpe()!\n"); return ret; } @@ -310,6 +312,6 @@ int execvp(const char* filename, char* const argv[]) { old_execvpe = dlsym(RTLD_NEXT, "execvpe"); int ret = old_execvpe(filename, argv, new_envp); stringlist_free(new_envp); - //printf(">>> custom execvp()!\n"); + DEBUG(">>> custom execvp()!\n"); return ret; }