SunOS: support InitSystem

This commit is contained in:
Carter Li
2024-06-17 13:35:26 +08:00
parent 507caa7b49
commit 898bf1edd9
2 changed files with 28 additions and 2 deletions
+2 -1
View File
@@ -773,7 +773,7 @@ elseif(SunOS)
src/detection/gtk_qt/gtk.c
src/detection/host/host_windows.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_nosupport.c
src/detection/initsystem/initsystem_linux.c
src/detection/libc/libc_nosupport.c
src/detection/lm/lm_nosupport.c
src/detection/loadavg/loadavg_nosupport.c
@@ -1130,6 +1130,7 @@ elseif(SunOS)
PRIVATE "socket"
PRIVATE "kstat"
PRIVATE "pciaccess"
PRIVATE "proc"
)
elseif(ANDROID)
CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC)
+26 -1
View File
@@ -18,7 +18,7 @@
#include <sys/user.h>
#include <sys/sysctl.h>
#endif
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__sun)
#include <libproc.h>
#endif
@@ -113,6 +113,15 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use
return "read(childPipeFd, str, FF_PIPE_BUFSIZ) failed";
}
#ifdef __sun
void freeProcHandle(struct ps_prochandle** phandle)
{
assert(phandle);
if (*phandle)
Pfree(*phandle);
}
#endif
void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, const char** exeName, FFstrbuf* exePath)
{
assert(processName->length > 0);
@@ -335,6 +344,22 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
*tty = -1;
}
#elif defined(__sun)
int err;
__attribute__((__cleanup__(freeProcHandle))) struct ps_prochandle* handle = Pgrab(pid, PGRAB_RDONLY, &err);
if (!handle)
return "Pgrab() failed";
const psinfo_t* proc = Ppsinfo(handle);
if (!proc)
return "Ppsinfo() failed";
ffStrbufSetS(name, proc->pr_fname);
if (ppid)
*ppid = proc->pr_ppid;
if (tty)
*tty = (int) proc->pr_ttydev;
#else
return "Unsupported platform";