diff --git a/src/common/FFPlatform.h b/src/common/FFPlatform.h index e174469ad..c714b5dda 100644 --- a/src/common/FFPlatform.h +++ b/src/common/FFPlatform.h @@ -20,6 +20,7 @@ typedef struct FFPlatform FFlist dataDirs; // List of FFstrbuf, trailing slash included FFstrbuf exePath; // The real path of current exe (empty if unavailable) + uint32_t pid; #ifndef _WIN32 uint32_t uid; #else diff --git a/src/common/impl/FFPlatform_unix.c b/src/common/impl/FFPlatform_unix.c index 3ca836fb6..25c3f86a0 100644 --- a/src/common/impl/FFPlatform_unix.c +++ b/src/common/impl/FFPlatform_unix.c @@ -28,15 +28,15 @@ static void getExePath(FFPlatform* platform) if (exePathLen >= 0) exePath[exePathLen] = '\0'; #elif defined(__APPLE__) - int exePathLen = proc_pidpath((int) getpid(), exePath, sizeof(exePath)); + int exePathLen = proc_pidpath(platform->pid, exePath, sizeof(exePath)); #elif defined(__FreeBSD__) || defined(__NetBSD__) size_t exePathLen = sizeof(exePath); if(sysctl( (int[]){CTL_KERN, #ifdef __FreeBSD__ - KERN_PROC, KERN_PROC_PATHNAME, (int) getpid() + KERN_PROC, KERN_PROC_PATHNAME, platform->pid #else - KERN_PROC_ARGS, (int) getpid(), KERN_PROC_PATHNAME + KERN_PROC_ARGS, platform->pid, KERN_PROC_PATHNAME #endif }, 4, exePath, &exePathLen, @@ -226,6 +226,7 @@ static void getSysinfo(FFPlatformSysinfo* info, const struct utsname* uts) void ffPlatformInitImpl(FFPlatform* platform) { + platform->pid = (uint32_t) getpid(); platform->uid = getuid(); struct passwd* pwd = getpwuid(platform->uid); diff --git a/src/common/impl/FFPlatform_windows.c b/src/common/impl/FFPlatform_windows.c index 259491cae..c09cdc277 100644 --- a/src/common/impl/FFPlatform_windows.c +++ b/src/common/impl/FFPlatform_windows.c @@ -307,6 +307,7 @@ static void getSystemArchitectureAndPageSize(FFPlatformSysinfo* info) void ffPlatformInitImpl(FFPlatform* platform) { + platform->pid = (uint32_t) GetCurrentProcessId(); getExePath(platform); getHomeDir(platform); getCacheDir(platform); diff --git a/src/common/impl/netif_apple.c b/src/common/impl/netif_apple.c index 54128ec9c..64b1e99f1 100644 --- a/src/common/impl/netif_apple.c +++ b/src/common/impl/netif_apple.c @@ -72,7 +72,7 @@ bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result) setsockopt(pfRoute, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)); } - int pid = getpid(); + uint32_t pid = instance.state.platform.pid; struct { struct rt_msghdr hdr; @@ -145,7 +145,7 @@ bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result) setsockopt(pfRoute, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)); } - int pid = getpid(); + uint32_t pid = instance.state.platform.pid; struct { struct rt_msghdr hdr; diff --git a/src/common/impl/netif_linux.c b/src/common/impl/netif_linux.c index 03ade7d9d..6e7631e7a 100644 --- a/src/common/impl/netif_linux.c +++ b/src/common/impl/netif_linux.c @@ -19,7 +19,7 @@ bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result) } FF_DEBUG("Created netlink socket: fd=%d", sock_fd); - unsigned pid = (unsigned) getpid(); + uint32_t pid = instance.state.platform.pid; FF_DEBUG("Process PID: %u", pid); // Bind socket @@ -235,7 +235,7 @@ bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result) } FF_DEBUG("Created netlink socket: fd=%d", sock_fd); - unsigned pid = (unsigned) getpid(); + int pid = instance.state.platform.pid; FF_DEBUG("Process PID: %u", pid); // Bind socket diff --git a/src/common/impl/processing_windows.c b/src/common/impl/processing_windows.c index f07344cda..ebfe5d82b 100644 --- a/src/common/impl/processing_windows.c +++ b/src/common/impl/processing_windows.c @@ -53,7 +53,7 @@ const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFProcessHandle* wchar_t pipeName[32]; static unsigned pidCounter = 0; - swprintf(pipeName, ARRAY_SIZE(pipeName), L"\\\\.\\pipe\\FASTFETCH-%u-%u", GetCurrentProcessId(), ++pidCounter); + swprintf(pipeName, ARRAY_SIZE(pipeName), L"\\\\.\\pipe\\FASTFETCH-%u-%u", instance.state.platform.pid, ++pidCounter); FF_AUTO_CLOSE_FD HANDLE hChildPipeRead = CreateNamedPipeW( pipeName, diff --git a/src/modules/title/title.c b/src/modules/title/title.c index d75446e55..4e8f586d4 100644 --- a/src/modules/title/title.c +++ b/src/modules/title/title.c @@ -64,6 +64,7 @@ bool ffPrintTitle(FFTitleOptions* options) FF_FORMAT_ARG(atColored, "at-symbol-colored"), FF_FORMAT_ARG(hostNameColored, "host-name-colored"), FF_FORMAT_ARG(instance.state.platform.fullUserName, "full-user-name"), + FF_FORMAT_ARG(instance.state.platform.pid, "pid"), })); } @@ -132,6 +133,7 @@ bool ffGenerateTitleJsonResult(FF_MAYBE_UNUSED FFTitleOptions* options, yyjson_m yyjson_mut_obj_add_strbuf(doc, obj, "homeDir", &instance.state.platform.homeDir); yyjson_mut_obj_add_strbuf(doc, obj, "exePath", &instance.state.platform.exePath); yyjson_mut_obj_add_strbuf(doc, obj, "userShell", &instance.state.platform.userShell); + yyjson_mut_obj_add_uint(doc, obj, "pid", instance.state.platform.pid); return true; } @@ -175,5 +177,6 @@ FFModuleBaseInfo ffTitleModuleInfo = { {"Host name (colored)", "host-name-colored"}, {"Full user name", "full-user-name"}, {"UID / SID", "user-id"}, + {"Fastfetch PID", "pid"}, })) };