Skip to content

Commit d28ec46

Browse files
committed
clamd: Fix bug reporting memory stats, used by clamdtop
ClamD's STATS API reports process memory stats on systems that provide the `mallinfo()` system call. This feature is used by ClamDTOP to show process memory usage. When we switched to the CMake build system, we neglected to add the check for the `mallinfo()` system call and so broke ClamD memory usage reporting. This commit adds the CMake check for `mallinfo()` and sets HAVE_MALLINFO, if found. Fixes: #706 Jira: CLAM-2742
1 parent 492e505 commit d28ec46

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ include(CheckFTS)
778778
include(CheckUnamePosix)
779779
# Check support for file descriptor passing
780780
include(CheckFDPassing)
781+
# Check support for mallinfo memory stats
782+
include(CheckMallinfo)
781783

782784
# Check if big-endian
783785
include(TestBigEndian)

cmake/CheckMallinfo.c

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <malloc.h>
2+
3+
int main()
4+
{
5+
struct mallinfo mi;
6+
mi = mallinfo();
7+
return 0;
8+
}

cmake/CheckMallinfo.cmake

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Check for mallinfo(3) sys call.
3+
#
4+
5+
GET_FILENAME_COMPONENT(_selfdir_CheckMallinfo
6+
"${CMAKE_CURRENT_LIST_FILE}" PATH)
7+
8+
# Check that the POSIX compliant uname(2) call works properly (HAVE_UNAME_SYSCALL)
9+
try_run(
10+
# Name of variable to store the run result (process exit status; number) in:
11+
test_run_result
12+
# Name of variable to store the compile result (TRUE or FALSE) in:
13+
test_compile_result
14+
# Binary directory:
15+
${CMAKE_CURRENT_BINARY_DIR}
16+
# Source file to be compiled:
17+
${_selfdir_CheckMallinfo}/CheckMallinfo.c
18+
# Where to store the output produced during compilation:
19+
COMPILE_OUTPUT_VARIABLE test_compile_output
20+
# Where to store the output produced by running the compiled executable:
21+
RUN_OUTPUT_VARIABLE test_run_output )
22+
23+
# Did compilation succeed and process return 0 (success)?
24+
if("${test_compile_result}" AND ("${test_run_result}" EQUAL 0))
25+
set(HAVE_MALLINFO 1)
26+
endif()

0 commit comments

Comments
 (0)