From 2f17b33f2e2c25c0284133cb4a7007cee794a2e3 Mon Sep 17 00:00:00 2001 From: Martin Rehak Date: Tue, 2 Jun 2026 13:47:17 +0200 Subject: [PATCH 1/6] util/path: handle missing d_type definitions on Solaris Guard DT_REG usage so directory walking code still builds on platforms where dirent does not expose d_type or DT_REG, such as Solaris. --- src/source-pcap-file-directory-helper.c | 2 +- src/util-path.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/source-pcap-file-directory-helper.c b/src/source-pcap-file-directory-helper.c index bd244fbc5640..b2da74441e32 100644 --- a/src/source-pcap-file-directory-helper.c +++ b/src/source-pcap-file-directory-helper.c @@ -304,7 +304,7 @@ TmEcode PcapDirectoryPopulateBuffer(PcapFileDirectoryVars *pv, PendingFile *file_to_add = NULL; while ((dir = readdir(pv->directory)) != NULL) { -#ifndef OS_WIN32 +#if defined(DT_REG) if (dir->d_type != DT_REG) { continue; } diff --git a/src/util-path.c b/src/util-path.c index d7618856e471..072133c04baf 100644 --- a/src/util-path.c +++ b/src/util-path.c @@ -196,7 +196,7 @@ bool SCPathExists(const char *path) */ bool SCIsRegularDirectory(const struct dirent *const dir_entry) { -#ifndef OS_WIN32 +#if !defined(OS_WIN32) && !defined(__sun) if ((dir_entry->d_type == DT_DIR) && (strcmp(dir_entry->d_name, ".") != 0) && (strcmp(dir_entry->d_name, "..") != 0)) { @@ -214,7 +214,7 @@ bool SCIsRegularDirectory(const struct dirent *const dir_entry) */ bool SCIsRegularFile(const struct dirent *const dir_entry) { -#ifndef OS_WIN32 +#if defined(DT_REG) return dir_entry->d_type == DT_REG; #endif return false; From 30bd2c5af60d34ce4e11c259beffb0e738b740c6 Mon Sep 17 00:00:00 2001 From: Martin Rehak Date: Tue, 2 Jun 2026 13:47:34 +0200 Subject: [PATCH 2/6] build/solaris: use __sun and Solaris byteorder helpers Replace uses of the non-standard sun macro with __sun and use Solaris byte swap helpers from . This keeps the Solaris-specific code paths reachable when building with standard-conforming toolchains. --- src/threads.h | 6 ++---- src/tm-threads.c | 6 +++--- src/util-affinity.c | 12 ++++++------ src/util-affinity.h | 2 +- src/util-byte.h | 7 ++++++- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/threads.h b/src/threads.h index 117c4c4a6ab9..15d13b9f324e 100644 --- a/src/threads.h +++ b/src/threads.h @@ -244,7 +244,7 @@ enum { unsigned long _scgetthread_tid = (unsigned long)tpid; \ _scgetthread_tid; \ }) -#elif defined(sun) +#elif defined(__sun) #include #define SCGetThreadIdLong(...) ({ \ thread_t tmpthid = thr_self(); \ @@ -302,9 +302,7 @@ extern thread_local char t_thread_name[THREAD_NAME_LEN + 1]; SCLogDebug("Error setting thread name \"%s\": %s", tname, strerror(errno)); \ }) #else -#define SCSetThreadName(n) ({ \ - strlcpy(t_thread_name, n, sizeof(t_thread_name)); \ -} +#define SCSetThreadName(n) ({ strlcpy(t_thread_name, n, sizeof(t_thread_name)); }) #endif diff --git a/src/tm-threads.c b/src/tm-threads.c index c3ab08d14f53..be2a230eeab4 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -701,7 +701,7 @@ void TmSlotSetFuncAppend(ThreadVars *tv, TmModule *tm, const void *data) } } -#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun +#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined __sun static int SetCPUAffinitySet(cpu_set_t *cs) { #if defined OS_FREEBSD @@ -735,7 +735,7 @@ static int SetCPUAffinitySet(cpu_set_t *cs) */ static int SetCPUAffinity(uint16_t cpuid) { -#if defined __OpenBSD__ || defined sun +#if defined __OpenBSD__ || defined __sun return 0; #else int cpu = (int)cpuid; @@ -871,7 +871,7 @@ TmEcode TmThreadSetupOptions(ThreadVars *tv) SetCPUAffinity(tv->cpu_affinity); } -#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun +#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined __sun if (tv->thread_setup_flags & THREAD_SET_PRIORITY) TmThreadSetPrio(tv); if (tv->thread_setup_flags & THREAD_SET_AFFTYPE) { diff --git a/src/util-affinity.c b/src/util-affinity.c index 806310e3d941..cba5aec1d60a 100644 --- a/src/util-affinity.c +++ b/src/util-affinity.c @@ -65,7 +65,7 @@ ThreadsAffinityType thread_affinity[MAX_CPU_SET] = { int thread_affinity_init_done = 0; -#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun +#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined __sun #ifdef HAVE_HWLOC static hwloc_topology_t topology = NULL; #endif /* HAVE_HWLOC */ @@ -206,7 +206,7 @@ ThreadsAffinityType *GetOrAllocAffinityTypeForIfaceOfName( return parent_affinity; } -#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun +#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined __sun static void AffinitySetupInit(void) { int i, j; @@ -587,7 +587,7 @@ static bool AffinityConfigIsLegacy(void) */ void AffinitySetupLoadFromConfig(void) { -#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun +#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined __sun if (thread_affinity_init_done == 0) { AffinitySetupInit(); AffinityConfigIsLegacy(); @@ -643,7 +643,7 @@ void AffinitySetupLoadFromConfig(void) #endif /* OS_WIN32 and __OpenBSD__ */ } -#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun +#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined __sun #ifdef HAVE_HWLOC static int HwLocDeviceNumaGet(hwloc_topology_t topo, hwloc_obj_t obj) { @@ -1006,7 +1006,7 @@ static bool AutopinEnabled(void) uint16_t AffinityGetNextCPU(ThreadVars *tv, ThreadsAffinityType *taf) { uint16_t ncpu = 0; -#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun +#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined __sun int iface_numa = -1; if (AutopinEnabled()) { #ifdef HAVE_HWLOC @@ -1043,7 +1043,7 @@ uint16_t AffinityGetNextCPU(ThreadVars *tv, ThreadsAffinityType *taf) uint16_t UtilAffinityGetAffinedCPUNum(ThreadsAffinityType *taf) { uint16_t ncpu = 0; -#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun +#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined __sun SCMutexLock(&taf->taf_mutex); for (int i = UtilCpuGetNumProcessorsOnline(); i >= 0; i--) if (CPU_ISSET(i, &taf->cpu_set)) { diff --git a/src/util-affinity.h b/src/util-affinity.h index a44f65e8a176..bcd4c6276337 100644 --- a/src/util-affinity.h +++ b/src/util-affinity.h @@ -75,7 +75,7 @@ typedef struct ThreadsAffinityType_ { struct ThreadsAffinityType_ *parent; // e.g. worker-cpu-set for interfaces SCMutex taf_mutex; -#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined sun +#if !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && !defined __sun cpu_set_t cpu_set; cpu_set_t lowprio_cpu; cpu_set_t medprio_cpu; diff --git a/src/util-byte.h b/src/util-byte.h index 43452094f748..9cbcb7b6bff7 100644 --- a/src/util-byte.h +++ b/src/util-byte.h @@ -45,7 +45,12 @@ #define SCByteSwap16(x) OSSwapInt16(x) #define SCByteSwap32(x) OSSwapInt32(x) #define SCByteSwap64(x) OSSwapInt64(x) -#elif defined(__WIN32) || defined(_WIN32) || defined(sun) +#elif defined(__sun) +#include +#define SCByteSwap16(x) BSWAP_16(x) +#define SCByteSwap32(x) BSWAP_32(x) +#define SCByteSwap64(x) BSWAP_64(x) +#elif defined(__WIN32) || defined(_WIN32) /* Quick & dirty solution, nothing seems to exist for this in Win32 API */ #define SCByteSwap16(x) \ ((((x) & 0xff00) >> 8) \ From 2daad32e46f5286cf8aad08345b831c0dfec1618 Mon Sep 17 00:00:00 2001 From: Martin Rehak Date: Tue, 2 Jun 2026 13:47:34 +0200 Subject: [PATCH 3/6] util/time: avoid tm_gmtoff on Solaris Skip tm_gmtoff and tm_zone initialization on Solaris where those struct tm members are not available. --- src/util-time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util-time.c b/src/util-time.c index ff8b5c654478..9d039fd6ea06 100644 --- a/src/util-time.c +++ b/src/util-time.c @@ -462,7 +462,7 @@ time_t SCMkTimeUtc (struct tm *tp) result += tp->tm_min; result *= 60; result += tp->tm_sec; -#ifndef OS_WIN32 +#if !defined(OS_WIN32) && !defined(__sun) if (tp->tm_gmtoff) result -= tp->tm_gmtoff; #endif @@ -497,7 +497,7 @@ int SCStringPatternToTime (char *string, const char **patterns, int num_patterns tp->tm_hour = tp->tm_min = tp->tm_sec = 0; tp->tm_year = tp->tm_mon = tp->tm_mday = tp->tm_wday = INT_MIN; tp->tm_isdst = -1; -#ifndef OS_WIN32 +#if !defined(OS_WIN32) && !defined(__sun) tp->tm_gmtoff = 0; tp->tm_zone = NULL; #endif From 57b44c533dbe67185f61c1fde7ae6fd0177be4f3 Mon Sep 17 00:00:00 2001 From: Martin Rehak Date: Tue, 2 Jun 2026 13:47:41 +0200 Subject: [PATCH 4/6] util/syslog: guard LOG_FTP for Solaris Only expose the ftp facility when the platform syslog headers define LOG_FTP. --- src/util-syslog.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util-syslog.c b/src/util-syslog.c index 482f206789aa..b69365e1d68a 100644 --- a/src/util-syslog.c +++ b/src/util-syslog.c @@ -28,12 +28,15 @@ #include "util-syslog.h" /* holds the string-enum mapping for the syslog facility in SCLogOPIfaceCtx */ +// clang-format off SCEnumCharMap sc_syslog_facility_map[] = { { "auth", LOG_AUTH }, { "authpriv", LOG_AUTHPRIV }, { "cron", LOG_CRON }, { "daemon", LOG_DAEMON }, +#if defined(LOG_FTP) { "ftp", LOG_FTP }, +#endif { "kern", LOG_KERN }, { "lpr", LOG_LPR }, { "mail", LOG_MAIL }, @@ -52,6 +55,7 @@ SCEnumCharMap sc_syslog_facility_map[] = { { "local7", LOG_LOCAL7 }, { NULL, -1 } }; +// clang-format on /** \brief returns the syslog facility enum map */ SCEnumCharMap *SCSyslogGetFacilityMap(void) From 00569a167b9cce7a79e8108729cbe78aefb68418 Mon Sep 17 00:00:00 2001 From: Martin Rehak Date: Tue, 2 Jun 2026 13:48:01 +0200 Subject: [PATCH 5/6] util/cpu: enable SPARC misalignment emulation at startup Call a SPARC-specific helper during pre-init so the kernel emulates unaligned accesses for this process instead of terminating on alignment faults. This matches the Solaris/SPARC portability fix that motivated the original patch. --- src/suricata.c | 2 ++ src/util-cpu.c | 13 +++++++++++++ src/util-cpu.h | 2 ++ 3 files changed, 17 insertions(+) diff --git a/src/suricata.c b/src/suricata.c index 78b3b34ed076..263959c432a7 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -3089,6 +3089,8 @@ int InitGlobal(void) void SuricataPreInit(const char *progname) { + UtilCpuEnableSparcMisalignEmulation(); + SCInstanceInit(&suricata, progname); if (InitGlobal() != 0) { diff --git a/src/util-cpu.c b/src/util-cpu.c index 1ae49e7abec0..1cb64d4ddca3 100644 --- a/src/util-cpu.c +++ b/src/util-cpu.c @@ -204,3 +204,16 @@ uint64_t UtilCpuGetTicks(void) #endif return val; } + +/** + * \brief Handle memory access miss align on SPARC processors + */ +void UtilCpuEnableSparcMisalignEmulation(void) +{ +/* 'ta 6' tells the kernel to synthesize any unaligned accesses this process + * makes, instead of just signalling an error and terminating the process. + */ +#ifdef __sparc + __asm("ta 6"); +#endif /* __sparc */ +} diff --git a/src/util-cpu.h b/src/util-cpu.h index 8e31c338f2f4..cd2830aaf670 100644 --- a/src/util-cpu.h +++ b/src/util-cpu.h @@ -33,4 +33,6 @@ void UtilCpuPrintSummary(void); uint64_t UtilCpuGetTicks(void); +void UtilCpuEnableSparcMisalignEmulation(void); + #endif /* SURICATA_UTIL_CPU_H */ From a6e7b2dc7afad64c327aa7e7b810d31f34a3b179 Mon Sep 17 00:00:00 2001 From: Martin Rehak Date: Tue, 2 Jun 2026 13:48:07 +0200 Subject: [PATCH 6/6] suricata: guard RLIMIT_NPROC usage Only use RLIMIT_NPROC when the platform exposes that resource limit constant. --- src/suricata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/suricata.c b/src/suricata.c index 263959c432a7..e6165b5f5fbf 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -3225,7 +3225,7 @@ void SuricataPostInit(void) #endif if (limit_nproc) { -#if defined(HAVE_SYS_RESOURCE_H) +#if defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_NPROC) #ifdef linux if (geteuid() == 0) { SCLogWarning("setrlimit has no effect when running as root.");