diff --git a/src/common/files.c b/src/common/files.c index eb7cbdd..b145fcf 100644 --- a/src/common/files.c +++ b/src/common/files.c @@ -84,6 +84,20 @@ char *lsi_get_steam_dir() return strdup(resolv); } +char *lsi_get_process_name(void) +{ + autofree(char) *realp = NULL; + char *basep = NULL; + + realp = realpath("/proc/self/exe", NULL); + if (!realp) { + return false; + } + + basep = basename(realp); + return strdup(basep); +} + /* * Editor modelines - https://www.wireshark.org/tools/modelines.html * diff --git a/src/common/files.h b/src/common/files.h index 5538795..c575ccd 100644 --- a/src/common/files.h +++ b/src/common/files.h @@ -36,6 +36,11 @@ char *lsi_get_steam_dir(void); */ bool lsi_file_exists(const char *path); +/** + * Determine the basename'd process + */ +char *lsi_get_process_name(void); + /* * Editor modelines - https://www.wireshark.org/tools/modelines.html * diff --git a/src/intercept/main.c b/src/intercept/main.c index 2efebef..faedfe4 100644 --- a/src/intercept/main.c +++ b/src/intercept/main.c @@ -18,14 +18,9 @@ #include #include "../common/common.h" +#include "../common/files.h" #include "nica/util.h" -static inline bool lsi_file_exists(const char *path) -{ - struct stat st = { .st_ino = 0 }; - return (lstat(path, &st) == 0); -} - /** * What's the known process name? */ @@ -128,23 +123,6 @@ static const char *vendor_blacklist[] = { "libssl.so.1.0.0", }; -/** - * Determine the basename'd process - */ -static inline char *get_process_name(void) -{ - autofree(char) *realp = NULL; - char *basep = NULL; - - realp = realpath("/proc/self/exe", NULL); - if (!realp) { - return false; - } - - basep = basename(realp); - return strdup(basep); -} - /** * Determine if we're in a given process set, i.e. the process name matches * the given table @@ -176,7 +154,7 @@ static void check_is_intercept_candidate(void) { autofree(char) *nom = NULL; - nom = get_process_name(); + nom = lsi_get_process_name(); if (!nom) { return; } diff --git a/src/redirect/main.c b/src/redirect/main.c index ef905b0..e5397b9 100644 --- a/src/redirect/main.c +++ b/src/redirect/main.c @@ -59,23 +59,6 @@ typedef struct LsiRedirectTable { */ static LsiRedirectTable lsi_table = { 0 }; -/** - * Determine the basename'd process - */ -static inline char *get_process_name(void) -{ - autofree(char) *realp = NULL; - char *basep = NULL; - - realp = realpath("/proc/self/exe", NULL); - if (!realp) { - return false; - } - - basep = basename(realp); - return strdup(basep); -} - /** * We'll only perform teardown code if the process doesn't `abort()` or `_exit()` */ @@ -150,7 +133,7 @@ __attribute__((constructor)) static void lsi_redirect_init(void) /* Ensure we're open. */ lsi_redirect_init_tables(); - autofree(char) *process_name = get_process_name(); + autofree(char) *process_name = lsi_get_process_name(); if (!process_name) { fprintf(stderr, "Failure to allocate memory! %s\n", strerror(errno));