From 8ae908fe85ef0defa2ac4893fd255e8b4e61cd84 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Thu, 31 Mar 2016 18:39:49 -0700 Subject: [PATCH 01/11] Rework cmake files Rather than do include_directory() on the whole sysdig repo, just do it for driver, libscap, and libsinp. This is a step on the way to building a digwatch package. --- CMakeLists.txt | 108 +++++++++++++++++++++++++++--- userspace/digwatch/CMakeLists.txt | 12 +--- 2 files changed, 102 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3b4e43b..59196317 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,24 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.2) project(digwatch) +if(NOT DEFINED DIGWATCH_VERSION) + set(DIGWATCH_VERSION "0.1.1dev") +endif() + set(DRAIOS_DEBUG_FLAGS "-D_DEBUG") -#set(DRAIOS_FEATURE_FLAGS "-DPPM_ENABLE_SENTINEL") set(CMAKE_C_FLAGS "-Wall -ggdb ${DRAIOS_FEATURE_FLAGS}") set(CMAKE_CXX_FLAGS "-Wall -ggdb --std=c++0x ${DRAIOS_FEATURE_FLAGS}") + set(CMAKE_C_FLAGS_DEBUG "${DRAIOS_DEBUG_FLAGS}") set(CMAKE_CXX_FLAGS_DEBUG "${DRAIOS_DEBUG_FLAGS}") -# Add "-fno-inline -fno-omit-frame-pointer" for perf + set(CMAKE_C_FLAGS_RELEASE "-O3 -fno-strict-aliasing -DNDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "-O3 -fno-strict-aliasing -DNDEBUG") add_definitions(-DPLATFORM_NAME="${CMAKE_SYSTEM_NAME}") +add_definitions(-DK8S_DISABLE_THREAD) add_definitions(-DHAS_CAPTURE) if(CMAKE_BUILD_TYPE STREQUAL "Debug") @@ -23,30 +28,117 @@ else() endif() set(PACKAGE_NAME "draios-digwatch") +set(PROBE_VERSION "${DIGWATCH_VERSION}") +set(PROBE_NAME "sysdig-probe") +set(PROBE_DEVICE_NAME "sysdig") -add_definitions(-DK8S_DISABLE_THREAD) +set(CMD_MAKE make) set(SYSDIG_DIR ${PROJECT_SOURCE_DIR}/../sysdig) -add_subdirectory(${SYSDIG_DIR} ${PROJECT_BINARY_DIR}/sysdig) +include(ExternalProject) -set(LUAJIT_INCLUDE_DIR "${sysdig_BINARY_DIR}/luajit-prefix/src/luajit/src") +set(ZLIB_SRC "${PROJECT_BINARY_DIR}/zlib-prefix/src/zlib") +message(STATUS "Using bundled zlib in '${ZLIB_SRC}'") +set(ZLIB_INCLUDE "${ZLIB_SRC}") +set(ZLIB_LIB "${ZLIB_SRC}/libz.a") +ExternalProject_Add(zlib + URL "http://download.draios.com/dependencies/zlib-1.2.8.tar.gz" + URL_MD5 "44d667c142d7cda120332623eab69f40" + CONFIGURE_COMMAND "./configure" + BUILD_COMMAND ${CMD_MAKE} + BUILD_IN_SOURCE 1 + INSTALL_COMMAND "") +set(JSONCPP_SRC "${SYSDIG_DIR}/userspace/libsinsp/third-party/jsoncpp") +set(JSONCPP_INCLUDE "${JSONCPP_SRC}") +set(JSONCPP_LIB_SRC "${JSONCPP_SRC}/jsoncpp.cpp") + +# we pull this in because libsinsp won't build without it +set(CURSES_BUNDLE_DIR "${PROJECT_BINARY_DIR}/ncurses-prefix/src/ncurses") +set(CURSES_INCLUDE_DIR "${CURSES_BUNDLE_DIR}/include/") +set(CURSES_LIBRARIES "${CURSES_BUNDLE_DIR}/lib/libncurses.a") +message(STATUS "Using bundled ncurses in '${CURSES_BUNDLE_DIR}'") +ExternalProject_Add(ncurses + URL "http://download.draios.com/dependencies/ncurses-6.0-20150725.tgz" + URL_MD5 "32b8913312e738d707ae68da439ca1f4" + CONFIGURE_COMMAND ./configure --without-cxx --without-cxx-binding --without-ada --without-manpages --without-progs --without-tests --with-terminfo-dirs=/etc/terminfo:/lib/terminfo:/usr/share/terminfo + BUILD_COMMAND ${CMD_MAKE} + BUILD_IN_SOURCE 1 + INSTALL_COMMAND "") + + +set(B64_SRC "${PROJECT_BINARY_DIR}/b64-prefix/src/b64") +message(STATUS "Using bundled b64 in '${B64_SRC}'") +set(B64_INCLUDE "${B64_SRC}/include") +set(B64_LIB "${B64_SRC}/src/libb64.a") +ExternalProject_Add(b64 + URL "http://download.draios.com/dependencies/libb64-1.2.src.zip" + URL_MD5 "a609809408327117e2c643bed91b76c5" + CONFIGURE_COMMAND "" + BUILD_COMMAND ${CMD_MAKE} + BUILD_IN_SOURCE 1 + INSTALL_COMMAND "") + +set(OPENSSL_BUNDLE_DIR "${PROJECT_BINARY_DIR}/openssl-prefix/src/openssl") +set(OPENSSL_INSTALL_DIR "${OPENSSL_BUNDLE_DIR}/target") +set(OPENSSL_LIBRARY_SSL "${OPENSSL_INSTALL_DIR}/lib/libssl.a") +set(OPENSSL_LIBRARY_CRYPTO "${OPENSSL_INSTALL_DIR}/lib/libcrypto.a") + +message(STATUS "Using bundled openssl in '${OPENSSL_BUNDLE_DIR}'") + +ExternalProject_Add(openssl + URL "http://download.draios.com/dependencies/openssl-1.0.2d.tar.gz" + URL_MD5 "38dd619b2e77cbac69b99f52a053d25a" + CONFIGURE_COMMAND ./config shared --prefix=${OPENSSL_INSTALL_DIR} + BUILD_COMMAND ${CMD_MAKE} + BUILD_IN_SOURCE 1 + INSTALL_COMMAND ${CMD_MAKE} install) + +set(CURL_SSL_OPTION "--with-ssl=${OPENSSL_INSTALL_DIR}") + + +set(CURL_BUNDLE_DIR "${PROJECT_BINARY_DIR}/curl-prefix/src/curl") +set(CURL_INCLUDE_DIR "${CURL_BUNDLE_DIR}/include/") +set(CURL_LIBRARIES "${CURL_BUNDLE_DIR}/lib/.libs/libcurl.a") message(STATUS "Using bundled curl in '${CURL_BUNDLE_DIR}'") message(STATUS "Using SSL for curl in '${CURL_SSL_OPTION}'") -include(ExternalProject) +ExternalProject_Add(curl + DEPENDS openssl + URL "http://download.draios.com/dependencies/curl-7.45.0.tar.bz2" + URL_MD5 "62c1a352b28558f25ba6209214beadc8" + CONFIGURE_COMMAND ./configure ${CURL_SSL_OPTION} --disable-shared --enable-optimize --disable-curldebug --disable-rt --enable-http --disable-ftp --disable-file --disable-ldap --disable-ldaps --disable-rtsp --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smb --disable-smtp --disable-gopher --disable-sspi --disable-ntlm-wb --disable-tls-srp --without-winssl --without-darwinssl --without-polarssl --without-cyassl --without-nss --without-axtls --without-ca-path --without-ca-bundle --without-libmetalink --without-librtmp --without-winidn --without-libidn --without-nghttp2 --without-libssh2 + BUILD_COMMAND ${CMD_MAKE} + BUILD_IN_SOURCE 1 + INSTALL_COMMAND "") + +set(LUAJIT_SRC "${PROJECT_BINARY_DIR}/luajit-prefix/src/luajit/src") +message(STATUS "Using bundled LuaJIT in '${LUAJIT_SRC}'") +set(LUAJIT_INCLUDE "${LUAJIT_SRC}") +set(LUAJIT_LIB "${LUAJIT_SRC}/libluajit.a") +ExternalProject_Add(luajit + URL "http://download.draios.com/dependencies/LuaJIT-2.0.3.tar.gz" + URL_MD5 "f14e9104be513913810cd59c8c658dc0" + CONFIGURE_COMMAND "" + BUILD_COMMAND ${CMD_MAKE} + BUILD_IN_SOURCE 1 + INSTALL_COMMAND "") ExternalProject_Add(lpeg DEPENDS luajit URL "https://s3.amazonaws.com/download.draios.com/dependencies/lpeg-1.0.0.tar.gz" URL_MD5 "0aec64ccd13996202ad0c099e2877ece" - BUILD_COMMAND LUA_INCLUDE=${LUAJIT_INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/scripts/build-lpeg.sh + BUILD_COMMAND LUA_INCLUDE=${LUAJIT_INCLUDE} ${PROJECT_SOURCE_DIR}/scripts/build-lpeg.sh BUILD_IN_SOURCE 1 CONFIGURE_COMMAND "" INSTALL_COMMAND cp lpeg.so re.lua ${PROJECT_SOURCE_DIR}/userspace/digwatch/lua) +add_subdirectory(${SYSDIG_DIR}/driver ${PROJECT_BINARY_DIR}/driver) +add_subdirectory(${SYSDIG_DIR}/userspace/libscap ${PROJECT_BINARY_DIR}/userspace/libscap) +add_subdirectory(${SYSDIG_DIR}/userspace/libsinsp ${PROJECT_BINARY_DIR}/userspace/libsinsp) + add_subdirectory(userspace/digwatch) diff --git a/userspace/digwatch/CMakeLists.txt b/userspace/digwatch/CMakeLists.txt index f6117511..d2fb7b14 100644 --- a/userspace/digwatch/CMakeLists.txt +++ b/userspace/digwatch/CMakeLists.txt @@ -1,22 +1,14 @@ include_directories(${PROJECT_SOURCE_DIR}/../sysdig/userspace/libsinsp/third-party/jsoncpp) -include_directories("${LUAJIT_INCLUDE_DIR}") - -set(CURL_BUNDLE_DIR "${sysdig_BINARY_DIR}/curl-prefix/src/curl") -set(CURL_INCLUDE_DIR "${CURL_BUNDLE_DIR}/include/") - -if(NOT APPLE) - include_directories("${CURL_INCLUDE_DIR}") -endif() - +include_directories("${LUAJIT_INCLUDE}") include_directories(${PROJECT_SOURCE_DIR}/../sysdig/userspace/libscap) include_directories(${PROJECT_SOURCE_DIR}/../sysdig/userspace/libsinsp) include_directories("${PROJECT_BINARY_DIR}/userspace/digwatch") +include_directories("${CURL_INCLUDE_DIR}") add_executable(digwatch formats.cpp fields.cpp rules.cpp digwatch.cpp) target_link_libraries(digwatch sinsp) - set(DIGWATCH_LUA_MAIN "rule_loader.lua") configure_file(config_digwatch.h.in config_digwatch.h) From 37d0f7d3e00c4544628b97dcb0c1cf39383a43d5 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Thu, 31 Mar 2016 18:54:52 -0700 Subject: [PATCH 02/11] Build .deb, .rpm, and .tgz --- CMakeCPackOptions.cmake | 4 ++++ CMakeLists.txt | 30 ++++++++++++++++++++++++++++++ scripts/description.txt | 3 +++ scripts/rpm/postinstall | 13 +++++++++++++ scripts/rpm/preuninstall | 1 + userspace/digwatch/CMakeLists.txt | 2 ++ 6 files changed, 53 insertions(+) create mode 100644 CMakeCPackOptions.cmake create mode 100644 scripts/description.txt create mode 100755 scripts/rpm/postinstall create mode 100755 scripts/rpm/preuninstall diff --git a/CMakeCPackOptions.cmake b/CMakeCPackOptions.cmake new file mode 100644 index 00000000..91854961 --- /dev/null +++ b/CMakeCPackOptions.cmake @@ -0,0 +1,4 @@ +if(CPACK_GENERATOR MATCHES "TGZ") + set(CPACK_SET_DESTDIR "ON") + set(CPACK_STRIP_FILES "OFF") +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 59196317..47406960 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,10 @@ if(NOT DEFINED DIGWATCH_VERSION) set(DIGWATCH_VERSION "0.1.1dev") endif() +if(NOT DEFINED DIR_ETC) + set(DIR_ETC "${CMAKE_INSTALL_PREFIX}/etc") +endif() + set(DRAIOS_DEBUG_FLAGS "-D_DEBUG") set(CMAKE_C_FLAGS "-Wall -ggdb ${DRAIOS_FEATURE_FLAGS}") @@ -142,3 +146,29 @@ add_subdirectory(${SYSDIG_DIR}/userspace/libsinsp ${PROJECT_BINARY_DIR}/userspac add_subdirectory(userspace/digwatch) + +set(CPACK_PACKAGE_NAME "${PACKAGE_NAME}") +set(CPACK_PACKAGE_VENDOR "Sysdig Inc.") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "digwatch, a system-level activity monitoring tool") +set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/scripts/description.txt") +set(CPACK_PACKAGE_VERSION "${DIGWATCH_VERSION}") +set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_PROCESSOR}") +set(CPACK_PROJECT_CONFIG_FILE "${PROJECT_SOURCE_DIR}/CMakeCPackOptions.cmake") +set(CPACK_STRIP_FILES "ON") + +set(CPACK_GENERATOR DEB) + +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Sysdig ") +set(CPACK_DEBIAN_PACKAGE_SECTION "utils") +set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://www.sysdig.org") +set(CPACK_DEBIAN_PACKAGE_DEPENDS "dkms (>= 2.1.0.0)") +set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/scripts/debian/postinst;${CMAKE_BINARY_DIR}/scripts/debian/prerm") + +set(CPACK_RPM_PACKAGE_LICENSE "GPLv2") +set(CPACK_RPM_PACKAGE_URL "http://www.sysdig.org") +set(CPACK_RPM_PACKAGE_REQUIRES "dkms, gcc, make, kernel-devel, perl") +set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/scripts/rpm/postinstall") +set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/scripts/rpm/preuninstall") +set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /usr/src /usr/share/man /usr/share/man/man8) + +include(CPack) diff --git a/scripts/description.txt b/scripts/description.txt new file mode 100644 index 00000000..c4fc004c --- /dev/null +++ b/scripts/description.txt @@ -0,0 +1,3 @@ +Digwatch instruments your physical and virtual machines at the OS level by installing into the Linux kernel and capturing system calls and other OS events. +Then, using a rule-based configuration, you can specify filters for events of interest that you would like to log or be notified of. + diff --git a/scripts/rpm/postinstall b/scripts/rpm/postinstall new file mode 100755 index 00000000..5ec759d2 --- /dev/null +++ b/scripts/rpm/postinstall @@ -0,0 +1,13 @@ +dkms add -m sysdig -v %{version} --rpm_safe_upgrade +if [ `uname -r | grep -c "BOOT"` -eq 0 ] && [ -e /lib/modules/`uname -r`/build/include ]; then + dkms build -m sysdig -v %{version} + dkms install --force -m sysdig -v %{version} +elif [ `uname -r | grep -c "BOOT"` -gt 0 ]; then + echo -e "" + echo -e "Module build for the currently running kernel was skipped since you" + echo -e "are running a BOOT variant of the kernel." +else + echo -e "" + echo -e "Module build for the currently running kernel was skipped since the" + echo -e "kernel source for this kernel does not seem to be installed." +fi diff --git a/scripts/rpm/preuninstall b/scripts/rpm/preuninstall new file mode 100755 index 00000000..8fc95ce3 --- /dev/null +++ b/scripts/rpm/preuninstall @@ -0,0 +1 @@ +dkms remove -m sysdig -v %{version} --all --rpm_safe_upgrade diff --git a/userspace/digwatch/CMakeLists.txt b/userspace/digwatch/CMakeLists.txt index d2fb7b14..f176c32b 100644 --- a/userspace/digwatch/CMakeLists.txt +++ b/userspace/digwatch/CMakeLists.txt @@ -12,3 +12,5 @@ target_link_libraries(digwatch sinsp) set(DIGWATCH_LUA_MAIN "rule_loader.lua") configure_file(config_digwatch.h.in config_digwatch.h) + +install(TARGETS digwatch DESTINATION bin) From 8546e970f071a403ce65f75284c79301f4a13cab Mon Sep 17 00:00:00 2001 From: Henri DF Date: Thu, 31 Mar 2016 20:29:41 -0700 Subject: [PATCH 03/11] rename rules file --- rules/{base.txt => digwatch.conf} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename rules/{base.txt => digwatch.conf} (100%) diff --git a/rules/base.txt b/rules/digwatch.conf similarity index 100% rename from rules/base.txt rename to rules/digwatch.conf From 0cfb89ffb4f61d2d853803f614756c5bbcb75868 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Thu, 31 Mar 2016 20:47:00 -0700 Subject: [PATCH 04/11] Add digwatch.conf to package, install to /etc --- CMakeLists.txt | 3 ++- rules/CMakeLists.txt | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 rules/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 47406960..0d81153f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ if(NOT DEFINED DIGWATCH_VERSION) endif() if(NOT DEFINED DIR_ETC) - set(DIR_ETC "${CMAKE_INSTALL_PREFIX}/etc") + set(DIR_ETC "/etc") endif() set(DRAIOS_DEBUG_FLAGS "-D_DEBUG") @@ -144,6 +144,7 @@ add_subdirectory(${SYSDIG_DIR}/driver ${PROJECT_BINARY_DIR}/driver) add_subdirectory(${SYSDIG_DIR}/userspace/libscap ${PROJECT_BINARY_DIR}/userspace/libscap) add_subdirectory(${SYSDIG_DIR}/userspace/libsinsp ${PROJECT_BINARY_DIR}/userspace/libsinsp) +add_subdirectory(rules) add_subdirectory(userspace/digwatch) diff --git a/rules/CMakeLists.txt b/rules/CMakeLists.txt new file mode 100644 index 00000000..b1c34ae1 --- /dev/null +++ b/rules/CMakeLists.txt @@ -0,0 +1,3 @@ +install(FILES digwatch.conf + DESTINATION "${DIR_ETC}") + From 171d58c80578923941c4cf5f3effd39d8e6c29e8 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Thu, 31 Mar 2016 20:48:24 -0700 Subject: [PATCH 05/11] Packaging - add debian pre/post scripts - make tgz and rpm (as well as deb) --- CMakeLists.txt | 3 ++- scripts/CMakeLists.txt | 2 ++ scripts/debian/postinst.in | 26 ++++++++++++++++++++++++++ scripts/debian/prerm.in | 13 +++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 scripts/CMakeLists.txt create mode 100755 scripts/debian/postinst.in create mode 100755 scripts/debian/prerm.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d81153f..1e0db62e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,6 +144,7 @@ add_subdirectory(${SYSDIG_DIR}/driver ${PROJECT_BINARY_DIR}/driver) add_subdirectory(${SYSDIG_DIR}/userspace/libscap ${PROJECT_BINARY_DIR}/userspace/libscap) add_subdirectory(${SYSDIG_DIR}/userspace/libsinsp ${PROJECT_BINARY_DIR}/userspace/libsinsp) +add_subdirectory(scripts) add_subdirectory(rules) add_subdirectory(userspace/digwatch) @@ -157,7 +158,7 @@ set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CM set(CPACK_PROJECT_CONFIG_FILE "${PROJECT_SOURCE_DIR}/CMakeCPackOptions.cmake") set(CPACK_STRIP_FILES "ON") -set(CPACK_GENERATOR DEB) +set(CPACK_GENERATOR DEB RPM TGZ) set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Sysdig ") set(CPACK_DEBIAN_PACKAGE_SECTION "utils") diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt new file mode 100644 index 00000000..4af86d1a --- /dev/null +++ b/scripts/CMakeLists.txt @@ -0,0 +1,2 @@ +configure_file(debian/postinst.in debian/postinst) +configure_file(debian/prerm.in debian/prerm) diff --git a/scripts/debian/postinst.in b/scripts/debian/postinst.in new file mode 100755 index 00000000..e187dac1 --- /dev/null +++ b/scripts/debian/postinst.in @@ -0,0 +1,26 @@ +#!/bin/sh +set -e + +DKMS_PACKAGE_NAME="@PACKAGE_NAME@" +DKMS_VERSION="@PROBE_VERSION@" + +postinst_found=0 + +case "$1" in + configure) + for DKMS_POSTINST in /usr/lib/dkms/common.postinst /usr/share/$DKMS_PACKAGE_NAME/postinst; do + if [ -f $DKMS_POSTINST ]; then + $DKMS_POSTINST $DKMS_PACKAGE_NAME $DKMS_VERSION /usr/share/$DKMS_PACKAGE_NAME "" $2 + postinst_found=1 + break + fi + done + if [ "$postinst_found" -eq 0 ]; then + echo "ERROR: DKMS version is too old and $DKMS_PACKAGE_NAME was not" + echo "built with legacy DKMS support." + echo "You must either rebuild $DKMS_PACKAGE_NAME with legacy postinst" + echo "support or upgrade DKMS to a more current version." + exit 1 + fi + ;; +esac diff --git a/scripts/debian/prerm.in b/scripts/debian/prerm.in new file mode 100755 index 00000000..8b841812 --- /dev/null +++ b/scripts/debian/prerm.in @@ -0,0 +1,13 @@ +#!/bin/sh +set -e + +DKMS_PACKAGE_NAME="@PACKAGE_NAME@" +DKMS_VERSION="@PROBE_VERSION@" + +case "$1" in + remove|upgrade|deconfigure) + if [ "$(dkms status -m $DKMS_PACKAGE_NAME -v $DKMS_VERSION)" ]; then + dkms remove -m $DKMS_PACKAGE_NAME -v $DKMS_VERSION --all + fi + ;; +esac From aa337f169ce74700fb42d2ce076a9af9a2425e40 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Thu, 31 Mar 2016 21:11:07 -0700 Subject: [PATCH 06/11] Change package name: draios-digwatch-> digwatch --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e0db62e..ec39d3fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ else() set(KBUILD_FLAGS "${DRAIOS_FEATURE_FLAGS}") endif() -set(PACKAGE_NAME "draios-digwatch") +set(PACKAGE_NAME "digwatch") set(PROBE_VERSION "${DIGWATCH_VERSION}") set(PROBE_NAME "sysdig-probe") set(PROBE_DEVICE_NAME "sysdig") From 39b1f6451064d8c4aeddc00722d15e6192ff43c7 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Thu, 31 Mar 2016 21:18:23 -0700 Subject: [PATCH 07/11] Packaging: Bundle lua files --- userspace/digwatch/CMakeLists.txt | 6 ++++++ userspace/digwatch/config_digwatch.h.in | 3 ++- userspace/digwatch/digwatch.cpp | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/userspace/digwatch/CMakeLists.txt b/userspace/digwatch/CMakeLists.txt index f176c32b..08bc7298 100644 --- a/userspace/digwatch/CMakeLists.txt +++ b/userspace/digwatch/CMakeLists.txt @@ -14,3 +14,9 @@ set(DIGWATCH_LUA_MAIN "rule_loader.lua") configure_file(config_digwatch.h.in config_digwatch.h) install(TARGETS digwatch DESTINATION bin) +install(FILES lua/compiler.lua + DESTINATION share/digwatch/lua) +install(FILES lua/rule_loader.lua + DESTINATION share/digwatch/lua) +install(FILES lua/output.lua + DESTINATION share/digwatch/lua) diff --git a/userspace/digwatch/config_digwatch.h.in b/userspace/digwatch/config_digwatch.h.in index 4b887cd3..9f75ffb1 100644 --- a/userspace/digwatch/config_digwatch.h.in +++ b/userspace/digwatch/config_digwatch.h.in @@ -2,6 +2,7 @@ #define DIGWATCH_VERSION "${DIGWATCH_VERSION}" -#define DIGWATCH_INSTALLATION_DIR "${CMAKE_INSTALL_PREFIX}" +#define DIGWATCH_LUA_DIR "/usr/share/digwatch/lua/" #define DIGWATCH_LUA_MAIN "${DIGWATCH_LUA_MAIN}" + diff --git a/userspace/digwatch/digwatch.cpp b/userspace/digwatch/digwatch.cpp index ab42ad92..b25e4748 100644 --- a/userspace/digwatch/digwatch.cpp +++ b/userspace/digwatch/digwatch.cpp @@ -169,7 +169,7 @@ int digwatch_init(int argc, char **argv) int long_index = 0; string lua_main_filename; string output_name = "stdout"; - string lua_dir = DIGWATCH_INSTALLATION_DIR; + string lua_dir = DIGWATCH_LUA_DIR; lua_State* ls = NULL; static struct option long_options[] = From 8b748d5bcdaecbfbf4d43d471e64e549c43ea285 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Thu, 31 Mar 2016 21:19:55 -0700 Subject: [PATCH 08/11] readme change --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index da9fbd41..2102da42 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,8 @@ as a result, you should have a digwatch executable `build/userspace/digwatch/dig Set the path of the digwatch lua directory in the env var `DIGWATCH_LUA_DIR`: -`export DIGWATCH_LUA_DIR=/sysdig/digwatch/userspace/digwatch/lua/` +`export DIGWATCH_LUA_DIR=/userspace/digwatch/lua/` -(this is just for the manually-built version; the packaged/installed version will not need such an env var). Create a file with some [digwatch rules](Rule-syntax-and-design). For example: From 86e1eeffb2c14c59e744f7773fb8e9f477986195 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Mon, 4 Apr 2016 15:07:16 -0700 Subject: [PATCH 09/11] Statically link in lpeg lua library --- CMakeLists.txt | 3 ++- scripts/build-lpeg.sh | 9 ++++++++- userspace/digwatch/CMakeLists.txt | 3 +++ userspace/digwatch/digwatch.cpp | 2 ++ userspace/digwatch/lpeg.h | 6 ++++++ 5 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 userspace/digwatch/lpeg.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ec39d3fb..3eb5d19b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,6 +129,7 @@ ExternalProject_Add(luajit BUILD_IN_SOURCE 1 INSTALL_COMMAND "") +set (LPEG_SRC "${PROJECT_BINARY_DIR}/lpeg-prefix/src/lpeg") ExternalProject_Add(lpeg DEPENDS luajit URL "https://s3.amazonaws.com/download.draios.com/dependencies/lpeg-1.0.0.tar.gz" @@ -136,7 +137,7 @@ ExternalProject_Add(lpeg BUILD_COMMAND LUA_INCLUDE=${LUAJIT_INCLUDE} ${PROJECT_SOURCE_DIR}/scripts/build-lpeg.sh BUILD_IN_SOURCE 1 CONFIGURE_COMMAND "" - INSTALL_COMMAND cp lpeg.so re.lua ${PROJECT_SOURCE_DIR}/userspace/digwatch/lua) + INSTALL_COMMAND "") diff --git a/scripts/build-lpeg.sh b/scripts/build-lpeg.sh index 8d2037a6..b0c990c0 100755 --- a/scripts/build-lpeg.sh +++ b/scripts/build-lpeg.sh @@ -5,6 +5,13 @@ gcc -O2 -fPIC -I$LUA_INCLUDE -c lpcode.c -o lpcode.o gcc -O2 -fPIC -I$LUA_INCLUDE -c lpprint.c -o lpprint.o gcc -O2 -fPIC -I$LUA_INCLUDE -c lptree.c -o lptree.o gcc -O2 -fPIC -I$LUA_INCLUDE -c lpvm.c -o lpvm.o -gcc -shared -o lpeg.so -L/usr/local/lib lpcap.o lpcode.o lpprint.o lptree.o lpvm.o + + +# For building lpeg.so, which we don't need now that we're statically linking lpeg.a into digwatch +#gcc -shared -o lpeg.so -L/usr/local/lib lpcap.o lpcode.o lpprint.o lptree.o lpvm.o +#gcc -shared -o lpeg.so -L/usr/local/lib lpcap.o lpcode.o lpprint.o lptree.o lpvm.o + +/usr/bin/ar cr lpeg.a lpcap.o lpcode.o lpprint.o lptree.o lpvm.o +/usr/bin/ranlib lpeg.a chmod ug+w re.lua diff --git a/userspace/digwatch/CMakeLists.txt b/userspace/digwatch/CMakeLists.txt index 08bc7298..387bdad2 100644 --- a/userspace/digwatch/CMakeLists.txt +++ b/userspace/digwatch/CMakeLists.txt @@ -5,10 +5,13 @@ include_directories(${PROJECT_SOURCE_DIR}/../sysdig/userspace/libscap) include_directories(${PROJECT_SOURCE_DIR}/../sysdig/userspace/libsinsp) include_directories("${PROJECT_BINARY_DIR}/userspace/digwatch") include_directories("${CURL_INCLUDE_DIR}") +include_directories("${LPEG_SRC}") add_executable(digwatch formats.cpp fields.cpp rules.cpp digwatch.cpp) target_link_libraries(digwatch sinsp) +target_link_libraries(digwatch "${LPEG_SRC}/lpeg.a") + set(DIGWATCH_LUA_MAIN "rule_loader.lua") configure_file(config_digwatch.h.in config_digwatch.h) diff --git a/userspace/digwatch/digwatch.cpp b/userspace/digwatch/digwatch.cpp index b25e4748..a84ee7d2 100644 --- a/userspace/digwatch/digwatch.cpp +++ b/userspace/digwatch/digwatch.cpp @@ -14,6 +14,7 @@ extern "C" { #include "lua.h" #include "lualib.h" #include "lauxlib.h" +#include "lpeg.h" } #include @@ -279,6 +280,7 @@ int digwatch_init(int argc, char **argv) // Initialize Lua interpreter ls = lua_open(); luaL_openlibs(ls); + luaopen_lpeg(ls); add_lua_path(ls, lua_dir); rules = new digwatch_rules(inspector, ls, lua_main_filename); diff --git a/userspace/digwatch/lpeg.h b/userspace/digwatch/lpeg.h new file mode 100644 index 00000000..2a166a94 --- /dev/null +++ b/userspace/digwatch/lpeg.h @@ -0,0 +1,6 @@ +#pragma once + +#include "lua.h" + +int luaopen_lpeg (lua_State *L); + From d96336ccaac4b89b2accc275f6329d31e9d188a2 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Mon, 4 Apr 2016 17:55:05 -0700 Subject: [PATCH 10/11] Packaging: remove driver and add dep on sysdig package --- CMakeLists.txt | 10 +++------- scripts/CMakeLists.txt | 2 -- scripts/debian/postinst.in | 26 -------------------------- scripts/debian/prerm.in | 13 ------------- scripts/rpm/postinstall | 13 ------------- scripts/rpm/preuninstall | 1 - 6 files changed, 3 insertions(+), 62 deletions(-) delete mode 100644 scripts/CMakeLists.txt delete mode 100755 scripts/debian/postinst.in delete mode 100755 scripts/debian/prerm.in delete mode 100755 scripts/rpm/postinstall delete mode 100755 scripts/rpm/preuninstall diff --git a/CMakeLists.txt b/CMakeLists.txt index 3eb5d19b..d4f3d143 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,11 +141,9 @@ ExternalProject_Add(lpeg -add_subdirectory(${SYSDIG_DIR}/driver ${PROJECT_BINARY_DIR}/driver) add_subdirectory(${SYSDIG_DIR}/userspace/libscap ${PROJECT_BINARY_DIR}/userspace/libscap) add_subdirectory(${SYSDIG_DIR}/userspace/libsinsp ${PROJECT_BINARY_DIR}/userspace/libsinsp) -add_subdirectory(scripts) add_subdirectory(rules) add_subdirectory(userspace/digwatch) @@ -163,15 +161,13 @@ set(CPACK_GENERATOR DEB RPM TGZ) set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Sysdig ") set(CPACK_DEBIAN_PACKAGE_SECTION "utils") + set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://www.sysdig.org") -set(CPACK_DEBIAN_PACKAGE_DEPENDS "dkms (>= 2.1.0.0)") -set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/scripts/debian/postinst;${CMAKE_BINARY_DIR}/scripts/debian/prerm") +set(CPACK_DEBIAN_PACKAGE_DEPENDS "sysdig") set(CPACK_RPM_PACKAGE_LICENSE "GPLv2") set(CPACK_RPM_PACKAGE_URL "http://www.sysdig.org") -set(CPACK_RPM_PACKAGE_REQUIRES "dkms, gcc, make, kernel-devel, perl") -set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/scripts/rpm/postinstall") -set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/scripts/rpm/preuninstall") +set(CPACK_RPM_PACKAGE_REQUIRES "sysdig") set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /usr/src /usr/share/man /usr/share/man/man8) include(CPack) diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt deleted file mode 100644 index 4af86d1a..00000000 --- a/scripts/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -configure_file(debian/postinst.in debian/postinst) -configure_file(debian/prerm.in debian/prerm) diff --git a/scripts/debian/postinst.in b/scripts/debian/postinst.in deleted file mode 100755 index e187dac1..00000000 --- a/scripts/debian/postinst.in +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -set -e - -DKMS_PACKAGE_NAME="@PACKAGE_NAME@" -DKMS_VERSION="@PROBE_VERSION@" - -postinst_found=0 - -case "$1" in - configure) - for DKMS_POSTINST in /usr/lib/dkms/common.postinst /usr/share/$DKMS_PACKAGE_NAME/postinst; do - if [ -f $DKMS_POSTINST ]; then - $DKMS_POSTINST $DKMS_PACKAGE_NAME $DKMS_VERSION /usr/share/$DKMS_PACKAGE_NAME "" $2 - postinst_found=1 - break - fi - done - if [ "$postinst_found" -eq 0 ]; then - echo "ERROR: DKMS version is too old and $DKMS_PACKAGE_NAME was not" - echo "built with legacy DKMS support." - echo "You must either rebuild $DKMS_PACKAGE_NAME with legacy postinst" - echo "support or upgrade DKMS to a more current version." - exit 1 - fi - ;; -esac diff --git a/scripts/debian/prerm.in b/scripts/debian/prerm.in deleted file mode 100755 index 8b841812..00000000 --- a/scripts/debian/prerm.in +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -set -e - -DKMS_PACKAGE_NAME="@PACKAGE_NAME@" -DKMS_VERSION="@PROBE_VERSION@" - -case "$1" in - remove|upgrade|deconfigure) - if [ "$(dkms status -m $DKMS_PACKAGE_NAME -v $DKMS_VERSION)" ]; then - dkms remove -m $DKMS_PACKAGE_NAME -v $DKMS_VERSION --all - fi - ;; -esac diff --git a/scripts/rpm/postinstall b/scripts/rpm/postinstall deleted file mode 100755 index 5ec759d2..00000000 --- a/scripts/rpm/postinstall +++ /dev/null @@ -1,13 +0,0 @@ -dkms add -m sysdig -v %{version} --rpm_safe_upgrade -if [ `uname -r | grep -c "BOOT"` -eq 0 ] && [ -e /lib/modules/`uname -r`/build/include ]; then - dkms build -m sysdig -v %{version} - dkms install --force -m sysdig -v %{version} -elif [ `uname -r | grep -c "BOOT"` -gt 0 ]; then - echo -e "" - echo -e "Module build for the currently running kernel was skipped since you" - echo -e "are running a BOOT variant of the kernel." -else - echo -e "" - echo -e "Module build for the currently running kernel was skipped since the" - echo -e "kernel source for this kernel does not seem to be installed." -fi diff --git a/scripts/rpm/preuninstall b/scripts/rpm/preuninstall deleted file mode 100755 index 8fc95ce3..00000000 --- a/scripts/rpm/preuninstall +++ /dev/null @@ -1 +0,0 @@ -dkms remove -m sysdig -v %{version} --all --rpm_safe_upgrade From 77440750e6c367a5e3c54f5cd286a60226e855cb Mon Sep 17 00:00:00 2001 From: Henri DF Date: Mon, 4 Apr 2016 18:39:42 -0700 Subject: [PATCH 11/11] Load probe --- userspace/digwatch/config_digwatch.h.in | 1 + userspace/digwatch/digwatch.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/userspace/digwatch/config_digwatch.h.in b/userspace/digwatch/config_digwatch.h.in index 9f75ffb1..c29ede36 100644 --- a/userspace/digwatch/config_digwatch.h.in +++ b/userspace/digwatch/config_digwatch.h.in @@ -6,3 +6,4 @@ #define DIGWATCH_LUA_MAIN "${DIGWATCH_LUA_MAIN}" +#define PROBE_NAME "${PROBE_NAME}" diff --git a/userspace/digwatch/digwatch.cpp b/userspace/digwatch/digwatch.cpp index a84ee7d2..a995a28d 100644 --- a/userspace/digwatch/digwatch.cpp +++ b/userspace/digwatch/digwatch.cpp @@ -292,7 +292,19 @@ int digwatch_init(int argc, char **argv) rules->load_rules(rules_file); inspector->set_filter(rules->get_filter()); - inspector->open(""); + + try + { + inspector->open(""); + } + catch(sinsp_exception e) + { + if(system("modprobe " PROBE_NAME " > /dev/null 2> /dev/null")) + { + fprintf(stderr, "Unable to load the driver\n"); + } + inspector->open(""); + } do_inspect(inspector, rules,