mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Platform: adds pid field and use it
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -307,6 +307,7 @@ static void getSystemArchitectureAndPageSize(FFPlatformSysinfo* info)
|
||||
|
||||
void ffPlatformInitImpl(FFPlatform* platform)
|
||||
{
|
||||
platform->pid = (uint32_t) GetCurrentProcessId();
|
||||
getExePath(platform);
|
||||
getHomeDir(platform);
|
||||
getCacheDir(platform);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"},
|
||||
}))
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user