allow netdata binaries to be compiled with debugging info
Costa Tsaousis (ktsaou) committed
Sep 16, 2017 at 23:53 UTC
f5a751e82e71eaa8533cda3700face2025c712ce
11 files changed
+106
-16
makeself/Makefile.am
+1
-1
@@ -7,7 +7,7 @@ dist_noinst_SCRIPTS = \
7
build.sh \
8
makeself.sh \
9
makeself-license.txt \
10
- setup-x86_64-static.sh \
10
+ install-alpine-packages.sh \
11
post-installer.sh \
12
jobs/10-prepare-destination.install.sh \
13
jobs/50-curl-7.53.1.install.sh \
makeself/README.md
new
+46
@@ -0,0 +1,46 @@
1
+# netdata static binary build
2
+
3
+To build the static binary 64bit distribution package, run:
4
+
5
+```bash
6
+$ cd /path/to/netdata.git
7
+$ ./makeself/build-x86_64-static.sh
8
+```
9
+
10
+The program will:
11
+
12
+1. setup a new docker container with Alpine Linux
13
+2. install the required alpine packages (the build environment, needed libraries, etc)
14
+3. download and compile third party apps that are packaged with netdata (`bash`, `curl`, etc)
15
+4. compile netdata
16
+
17
+Once finished, a file named `netdata-vX.X.X-gGITHASH-x86_64-DATE-TIME.run` will be created in the current directory. This is the netdata binary package that can be run to install netdata on any other computer.
18
+
19
+---
20
+
21
+## building binaries with debug info
22
+
23
+To build netdata binaries with debugging / tracing information in them, use:
24
+
25
+```bash
26
+$ cd /path/to/netdata.git
27
+$ ./makeself/build-x86_64-static.sh debug
28
+```
29
+
30
+These binaries are not optimized (they are a bit slower), they have certain features disables (like log flood protection), other features enables (like `debug flags`) and are not stripped (the binary files are bigger, since they now include source code tracing information).
31
+
32
+#### debugging netdata binaries
33
+
34
+Once you have installed a binary package with debugging info, you will need to install `valgrind` and run this command to start netdata:
35
+
36
+```bash
37
+PATH="/opt/netdata/bin:${PATH}" valgrind --undef-value-errors=no /opt/netdata/bin/srv/netdata -D
38
+```
39
+
40
+The above command, will run netdata under `valgrind`. While netdata runs under `valgrind` it will be 10x slower and use a lot more memory.
41
+
42
+If netdata crashes, `valgrind` will print a stack trace of the issue. Open a github issue to let us know.
43
+
44
+To stop netdata while it runs under `valgrind`, press Control-C on the console.
45
+
46
+> If you ommit the parameter `--undef-value-errors=no` to valgrind, you will get hundreds of errors about conditional jumps that depend on unitialized values. This is normal. Valgrind has heuristics to prevent it from printing such errors for system libraries, but for the static netdata binary, all the required libraries are built into netdata. So, valgrind cannot appply its heuristics and prints them.
makeself/build-x86_64-static.sh
+8
-6
@@ -1,5 +1,7 @@
1
#!/usr/bin/env sh
2
3
+. $(dirname "$0")/../installer/functions.sh || exit 1
4
+
5
set -e
6
7
DOCKER_CONTAINER_NAME="netdata-package-x86_64-static"
@@ -16,22 +18,22 @@ then
18
#
19
# This command maps the current directory to
20
# /usr/src/netdata.git
19
- # inside the container and runs the script setup-x86_64-static.sh
21
+ # inside the container and runs the script install-alpine-packages.sh
22
# (also inside the container)
23
#
22
- sudo docker run -v $(pwd):/usr/src/netdata.git:rw alpine:3.5 \
23
- /bin/sh /usr/src/netdata.git/makeself/setup-x86_64-static.sh
24
+ run sudo docker run -v $(pwd):/usr/src/netdata.git:rw alpine:3.6 \
25
+ /bin/sh /usr/src/netdata.git/makeself/install-alpine-packages.sh
26
27
# save the changes made permanently
28
id=$(sudo docker ps -l -q)
27
- sudo docker commit ${id} "${DOCKER_CONTAINER_NAME}"
29
+ run sudo docker commit ${id} "${DOCKER_CONTAINER_NAME}"
30
fi
31
32
# Run the build script inside the container
31
-sudo docker run -a stdin -a stdout -a stderr -i -t -v \
33
+run sudo docker run -a stdin -a stdout -a stderr -i -t -v \
34
$(pwd):/usr/src/netdata.git:rw \
35
"${DOCKER_CONTAINER_NAME}" \
34
- /bin/sh /usr/src/netdata.git/makeself/build.sh
36
+ /bin/sh /usr/src/netdata.git/makeself/build.sh "${@}"
37
38
if [ "${USER}" ]
39
then
makeself/build.sh
+23
-1
@@ -1,6 +1,28 @@
1
#!/usr/bin/env sh
2
3
-# First run setup-x86_64-static.sh under alpine linux to install
3
+# -----------------------------------------------------------------------------
4
+# parse command line arguments
5
+
6
+export NETDATA_BUILD_WITH_DEBUG=0
7
+
8
+while [ ! -z "${1}" ]
9
+do
10
+ case "${1}" in
11
+ debug)
12
+ export NETDATA_BUILD_WITH_DEBUG=1
13
+ ;;
14
+
15
+ *)
16
+ ;;
17
+ esac
18
+
19
+ shift
20
+done
21
+
22
+
23
+# -----------------------------------------------------------------------------
24
+
25
+# First run install-alpine-packages.sh under alpine linux to install
26
# the required packages. build-x86_64-static.sh will do this for you
27
# using docker.
28
makeself/functions.sh
+1
@@ -3,6 +3,7 @@
3
# -----------------------------------------------------------------------------
4
5
# allow running the jobs by hand
6
+[ -z "${NETDATA_BUILD_WITH_DEBUG}" ] && export NETDATA_BUILD_WITH_DEBUG=0
7
[ -z "${NETDATA_INSTALL_PATH}" ] && export NETDATA_INSTALL_PATH="${1-/opt/netdata}"
8
[ -z "${NETDATA_MAKESELF_PATH}" ] && export NETDATA_MAKESELF_PATH="$(dirname "${0}")/.."
9
[ "${NETDATA_MAKESELF_PATH:0:1}" != "/" ] && export NETDATA_MAKESELF_PATH="$(pwd)/${NETDATA_MAKESELF_PATH}"
makeself/install-alpine-packages.sh
renamed
makeself/jobs/50-bash-4.4.install.sh
+4
-1
@@ -44,4 +44,7 @@ EOF
44
45
run make install
46
47
-run strip ${NETDATA_INSTALL_PATH}/bin/bash
47
+if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ]
48
+then
49
+ run strip ${NETDATA_INSTALL_PATH}/bin/bash
50
+fi
makeself/jobs/50-curl-7.53.1.install.sh
+4
-1
@@ -27,4 +27,7 @@ run make clean
27
run make -j${PROCESSORS}
28
run make install
29
30
-run strip ${NETDATA_INSTALL_PATH}/bin/curl
30
+if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ]
31
+then
32
+ run strip ${NETDATA_INSTALL_PATH}/bin/curl
33
+fi
makeself/jobs/50-fping-4.0.install.sh
+4
-1
@@ -22,4 +22,7 @@ run make clean
22
run make -j${PROCESSORS}
23
run make install
24
25
-run strip ${NETDATA_INSTALL_PATH}/bin/fping
25
+if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ]
26
+then
27
+ run strip ${NETDATA_INSTALL_PATH}/bin/fping
28
+fi
makeself/jobs/70-netdata-git.install.sh
+11
-4
@@ -4,13 +4,20 @@
4
5
cd "${NETDATA_SOURCE_PATH}" || exit 1
6
7
-export CFLAGS="-O3 -static"
7
+if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ]
8
+then
9
+ export CFLAGS="-static -O3"
10
+else
11
+ export CFLAGS="-static -O1 -ggdb -Wall -Wextra -Wformat-signedness -fstack-protector-all -D_FORTIFY_SOURCE=2 -DNETDATA_INTERNAL_CHECKS=1"
12
+fi
13
14
run ./netdata-installer.sh --install "${NETDATA_INSTALL_PARENT}" \
15
--dont-wait \
16
--dont-start-it \
17
${NULL}
18
14
-run strip ${NETDATA_INSTALL_PATH}/bin/netdata
15
-run strip ${NETDATA_INSTALL_PATH}/usr/libexec/netdata/plugins.d/apps.plugin
16
-
19
+if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ]
20
+then
21
+ run strip ${NETDATA_INSTALL_PATH}/bin/netdata
22
+ run strip ${NETDATA_INSTALL_PATH}/usr/libexec/netdata/plugins.d/apps.plugin
23
+fi
src/signals.c
+4
-1
@@ -39,7 +39,10 @@ static void signal_handler(int signo) {
39
if(signals_waiting[i].action == NETDATA_SIGNAL_FATAL) {
40
char buffer[200 + 1];
41
snprintfz(buffer, 200, "\nSIGNAL HANLDER: received: %s. Oops! This is bad!\n", signals_waiting[i].name);
42
- write(STDERR_FILENO, buffer, strlen(buffer));
42
+ if(write(STDERR_FILENO, buffer, strlen(buffer)) == -1) {
43
+ // nothing to do - we cannot write but there is no way to complaint about it
44
+ ;
45
+ }
46
}
47
48
return;