Skip to content

Commit

Permalink
Build system cleanup / cosmetics.
Browse files Browse the repository at this point in the history
 * libnDPI submodule update

Signed-off-by: Toni Uhlig <[email protected]>
  • Loading branch information
utoni committed Jun 7, 2021
1 parent 54e0601 commit 5954e46
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ __pycache__

# go related
*.sum

# lockfiles generated by some shell scripts
*.lock
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ script:
- ./build/nDPId-test || test $? -eq 1
- ./build/nDPId -h || test $? -eq 1
# dameon start/stop test
- ./daemon.sh ./build/nDPId ./build/nDPIsrvd
- ./daemon.sh ./build/nDPId ./build/nDPIsrvd
- ./scripts/daemon.sh ./build/nDPId ./build/nDPIsrvd
- ./scripts/daemon.sh ./build/nDPId ./build/nDPIsrvd
26 changes: 7 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,6 @@ project(nDPId C)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
find_package(PkgConfig REQUIRED)

function(initialize_submodule DIRECTORY)
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}/.git)
find_package(Git QUIET REQUIRED)
message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}/.git does not exist. "
"Initializing ${DIRECTORY} submodule ...")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init ${DIRECTORY}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_EXIT_CODE)
if(NOT GIT_EXIT_CODE EQUAL "0")
message(FATAL_ERROR "${GIT_EXECUTABLE} submodule update --init ${DIRECTORY} "
"failed with exit code ${GIT_EXIT_CODE}, please checkout submodules")
endif()
endif()
endfunction(initialize_submodule)

option(ENABLE_SANITIZER "Enable ASAN/LSAN/UBSAN." OFF)
option(ENABLE_SANITIZER_THREAD "Enable TSAN (does not work together with ASAN)." OFF)
option(ENABLE_MEMORY_PROFILING "Enable dynamic memory tracking." OFF)
Expand Down Expand Up @@ -73,17 +58,20 @@ if(ENABLE_SANITIZER_THREAD)
endif()

if(STATIC_LIBNDPI_INSTALLDIR STREQUAL "" AND BUILD_NDPI)
initialize_submodule(libnDPI)
include(ExternalProject)
ExternalProject_Add(
libnDPI
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libnDPI
CONFIGURE_COMMAND env CC=${CMAKE_C_COMPILER} CFLAGS=${CMAKE_C_FLAGS} LDFLAGS=${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/libnDPI/autogen.sh
--prefix=${CMAKE_CURRENT_BINARY_DIR}/libnDPI
--with-only-libndpi
CONFIGURE_COMMAND env CC=${CMAKE_C_COMPILER} CFLAGS=${CMAKE_C_FLAGS} LDFLAGS=${CMAKE_EXE_LINKER_FLAGS}
MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} DEST_INSTALL=${CMAKE_BINARY_DIR}/libnDPI
${CMAKE_CURRENT_SOURCE_DIR}/scripts/get-and-build-libndpi.sh
BUILD_COMMAND make
BUILD_IN_SOURCE 1)

add_custom_target(clean-libnDPI
COMMAND rm -rf ${CMAKE_BINARY_DIR}/libnDPI ${CMAKE_BINARY_DIR}/libnDPI-prefix
)

set(STATIC_LIBNDPI_INSTALLDIR "${CMAKE_BINARY_DIR}/libnDPI")
add_dependencies(nDPId libnDPI)
add_dependencies(nDPId-test libnDPI)
Expand Down
4 changes: 4 additions & 0 deletions nDPIsrvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,10 @@ int main(int argc, char ** argv)

signal(SIGPIPE, SIG_IGN);

signal(SIGINT, SIG_IGN);
signal(SIGTERM, SIG_IGN);
signal(SIGQUIT, SIG_IGN);

epollfd = setup_event_queue();
if (epollfd < 0)
{
Expand Down
4 changes: 1 addition & 3 deletions daemon.sh → scripts/daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ if [ -r "/tmp/nDPId-${NSUFFIX}.pid" -o -r "/tmp/nDPIsrvd-${NSUFFIX}.pid" ]; then
printf '%s\n' "${2} not started .." >&2
fi

sudo rm -f "/tmp/nDPId-${NSUFFIX}.pid"
rm -f "/tmp/nDPIsrvd-${NSUFFIX}.pid"
printf '%s\n' "daemons stopped" >&2
else
set -x
Expand All @@ -40,5 +38,5 @@ else
sudo ${1} -p "/tmp/nDPId-${NSUFFIX}.pid" -c "/tmp/nDPIsrvd-${NSUFFIX}-collector.sock" -d -u "${NUSER}"
set +x
printf '%s\n' "daemons started" >&2
printf '%s\n' "You may now run examples e.g.: ./examples/py-flow-info/flow-info.py --unix /tmp/nDPIsrvd-${NSUFFIX}-distributor.sock"
printf '%s\n' "You may now run examples e.g.: $(realpath --relative-to="$(pwd)" $(dirname "${0}")/../examples/py-flow-info/flow-info.py) --unix /tmp/nDPIsrvd-${NSUFFIX}-distributor.sock"
fi
23 changes: 23 additions & 0 deletions scripts/get-and-build-libndpi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -e
set -x

LOCKFILE="$(realpath "${0}").lock"
touch "${LOCKFILE}"
exec 42< "${LOCKFILE}"
flock -x -n 42 || {
printf '%s\n' "Could not aquire file lock for ${0}. Already running instance?" >&2;
exit 1;
}

cd "$(dirname "${0}")/.."
git submodule update --init ./libnDPI

cd ./libnDPI
DEST_INSTALL="${DEST_INSTALL:-$(realpath ./install)}"
MAKE_PROGRAM="${MAKE_PROGRAM:-make -j4}"
./autogen.sh --prefix="${DEST_INSTALL}" --with-only-libndpi
${MAKE_PROGRAM} install

rm -f "${LOCKFILE}"

0 comments on commit 5954e46

Please sign in to comment.