From 898bf1edd98f39ede26639343cd39ecfdcf1b9cc Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 17 Jun 2024 13:35:26 +0800 Subject: [PATCH] SunOS: support InitSystem --- CMakeLists.txt | 3 ++- src/common/processing_linux.c | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b9d47776c..c4554bbc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index ac4ee2b9f..bf4160e3c 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -18,7 +18,7 @@ #include #include #endif -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__sun) #include #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";