Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Jan 2018 12:25:10 +0000 (UTC)
From:      Mahdi Mokhtari <mmokhi@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r459323 - in head/net-mgmt/netdata: . files
Message-ID:  <201801181225.w0ICPAeK075257@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mmokhi
Date: Thu Jan 18 12:25:10 2018
New Revision: 459323
URL: https://svnweb.freebsd.org/changeset/ports/459323

Log:
  net-mgmt/netdata: Fix wrong PID assumption on FreeBSD.
  The issue merged on upstream but not in release-tree yet
  Also add two other dependencies for run-time.
  
  PR:		224135
  Reported by:	nhoyle@hoyletech.com
  Sponsored by:	Netzkommune GmbH

Added:
  head/net-mgmt/netdata/files/patch-fixes-issue-3276-upstream   (contents, props changed)
Modified:
  head/net-mgmt/netdata/Makefile

Modified: head/net-mgmt/netdata/Makefile
==============================================================================
--- head/net-mgmt/netdata/Makefile	Thu Jan 18 11:16:24 2018	(r459322)
+++ head/net-mgmt/netdata/Makefile	Thu Jan 18 12:25:10 2018	(r459323)
@@ -4,6 +4,7 @@
 PORTNAME=	netdata
 PORTVERSION=	1.9.0
 DISTVERSIONPREFIX=v
+PORTREVISION=	1
 CATEGORIES=	net-mgmt
 
 MAINTAINER=	mmokhi@FreeBSD.org
@@ -13,6 +14,8 @@ LICENSE=	GPLv3
 
 BUILD_DEPENDS=	${LOCALBASE}/include/uuid/uuid.h:misc/e2fsprogs-libuuid
 LIB_DEPENDS=	libuuid.so:misc/e2fsprogs-libuuid
+RUN_DEPENDS=	bash:shells/bash \
+		curl:ftp/curl
 
 USES=		autoreconf pathfix pkgconfig:both python shebangfix
 

Added: head/net-mgmt/netdata/files/patch-fixes-issue-3276-upstream
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/net-mgmt/netdata/files/patch-fixes-issue-3276-upstream	Thu Jan 18 12:25:10 2018	(r459323)
@@ -0,0 +1,295 @@
+--- installer/functions.sh.orig
++++ installer/functions.sh
+@@ -161,6 +161,22 @@ pidof() {
+ 
+ # -----------------------------------------------------------------------------
+ 
++export SYSTEM_CPUS=1
++portable_find_processors() {
++    if [ -f "/proc/cpuinfo" ]
++    then
++        # linux
++        SYSTEM_CPUS=$(grep -c ^processor /proc/cpuinfo)
++    else
++        # freebsd
++        SYSTEM_CPUS=$(sysctl hw.ncpu 2>/dev/null | grep ^hw.ncpu | cut -d ' ' -f 2)
++    fi
++    [ -z "${SYSTEM_CPUS}" -o $(( SYSTEM_CPUS )) -lt 1 ] && SYSTEM_CPUS=1
++}
++portable_find_processors
++
++# -----------------------------------------------------------------------------
++
+ run_ok() {
+     printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
+ }
+--- makeself/functions.sh.orig
++++ makeself/functions.sh
+@@ -8,8 +8,6 @@
+ [ -z "${NETDATA_MAKESELF_PATH}" ] && export NETDATA_MAKESELF_PATH="$(dirname "${0}")/.."
+ [ "${NETDATA_MAKESELF_PATH:0:1}" != "/" ] && export NETDATA_MAKESELF_PATH="$(pwd)/${NETDATA_MAKESELF_PATH}"
+ [ -z "${NETDATA_SOURCE_PATH}" ] && export NETDATA_SOURCE_PATH="${NETDATA_MAKESELF_PATH}/.."
+-[ -z "${PROCESSORS}" ] && export PROCESSORS=$(grep -c ^processor /proc/cpuinfo)
+-[ -z "${PROCESSORS}" -o $((PROCESSORS)) -lt 1 ] && export PROCESSORS=1
+ export NULL=
+ 
+ # make sure the path does not end with /
+@@ -21,14 +19,7 @@ fi
+ # find the parent directory
+ export NETDATA_INSTALL_PARENT="$(dirname "${NETDATA_INSTALL_PATH}")"
+ 
+-
+-# debug
+-echo "ME=${0}"
+-echo "NETDATA_INSTALL_PARENT=${NETDATA_INSTALL_PARENT}"
+-echo "NETDATA_INSTALL_PATH=${NETDATA_INSTALL_PATH}"
+-echo "NETDATA_MAKESELF_PATH=${NETDATA_MAKESELF_PATH}"
+-echo "NETDATA_SOURCE_PATH=${NETDATA_SOURCE_PATH}"
+-echo "PROCESSORS=${PROCESSORS}"
++# -----------------------------------------------------------------------------
+ 
+ # bash strict mode
+ set -euo pipefail
+@@ -58,3 +49,13 @@ fetch() {
+ 
+ # load the functions of the netdata-installer.sh
+ . "${NETDATA_SOURCE_PATH}/installer/functions.sh"
++
++# -----------------------------------------------------------------------------
++
++# debug
++echo "ME=${0}"
++echo "NETDATA_INSTALL_PARENT=${NETDATA_INSTALL_PARENT}"
++echo "NETDATA_INSTALL_PATH=${NETDATA_INSTALL_PATH}"
++echo "NETDATA_MAKESELF_PATH=${NETDATA_MAKESELF_PATH}"
++echo "NETDATA_SOURCE_PATH=${NETDATA_SOURCE_PATH}"
++echo "PROCESSORS=${SYSTEM_CPUS}"
+--- makeself/jobs/50-bash-4.4.install.sh.orig
++++ makeself/jobs/50-bash-4.4.install.sh
+@@ -34,7 +34,7 @@ run ./configure \
+ 		
+ 
+ run make clean
+-run make -j${PROCESSORS}
++run make -j${SYSTEM_CPUS}
+ 
+ cat >examples/loadables/Makefile <<EOF
+ all:
+--- makeself/jobs/50-curl-7.53.1.install.sh.orig
++++ makeself/jobs/50-curl-7.53.1.install.sh
+@@ -24,7 +24,7 @@ run ./configure \
+ run sed -i -e "s/curl_LDFLAGS =/curl_LDFLAGS = -all-static/" src/Makefile
+ 
+ run make clean
+-run make -j${PROCESSORS}
++run make -j${SYSTEM_CPUS}
+ run make install
+ 
+ if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ]
+--- makeself/jobs/50-fping-4.0.install.sh.orig
++++ makeself/jobs/50-fping-4.0.install.sh
+@@ -19,7 +19,7 @@ install:
+ EOF
+ 
+ run make clean
+-run make -j${PROCESSORS}
++run make -j${SYSTEM_CPUS}
+ run make install
+ 
+ if [ ${NETDATA_BUILD_WITH_DEBUG} -eq 0 ]
+--- netdata-installer.sh.orig
++++ netdata-installer.sh
+@@ -63,9 +63,6 @@ umask 002
+ # Be nice on production environments
+ renice 19 $$ >/dev/null 2>/dev/null
+ 
+-processors=$(grep -c ^processor /proc/cpuinfo)
+-[ $(( processors )) -lt 1 ] && processors=1
+-
+ # you can set CFLAGS before running installer
+ CFLAGS="${CFLAGS--O2}"
+ [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
+@@ -495,7 +492,7 @@ progress "Cleanup compilation directory"
+ # -----------------------------------------------------------------------------
+ progress "Compile netdata"
+ 
+-run make -j${processors} || exit 1
++run make -j${SYSTEM_CPUS} || exit 1
+ 
+ 
+ # -----------------------------------------------------------------------------
+--- src/apps_plugin.c.orig
++++ src/apps_plugin.c
+@@ -715,19 +715,35 @@ static inline int managed_log(struct pid_stat *p, uint32_t log, int status) {
+                 p->log_thrown |= log;
+                 switch(log) {
+                     case PID_LOG_IO:
++                        #ifdef __FreeBSD__
++                        error("Cannot fetch process %d I/O info (command '%s')", p->pid, p->comm);
++                        #else
+                         error("Cannot process %s/proc/%d/io (command '%s')", netdata_configured_host_prefix, p->pid, p->comm);
++                        #endif
+                         break;
+ 
+                     case PID_LOG_STATM:
++                        #ifdef __FreeBSD__
++                        error("Cannot fetch process %d memory info (command '%s')", p->pid, p->comm);
++                        #else
+                         error("Cannot process %s/proc/%d/statm (command '%s')", netdata_configured_host_prefix, p->pid, p->comm);
++                        #endif
+                         break;
+ 
+                     case PID_LOG_CMDLINE:
++                        #ifdef __FreeBSD__
++                        error("Cannot fetch process %d command line (command '%s')", p->pid, p->comm);
++                        #else
+                         error("Cannot process %s/proc/%d/cmdline (command '%s')", netdata_configured_host_prefix, p->pid, p->comm);
++                        #endif
+                         break;
+ 
+                     case PID_LOG_FDS:
++                        #ifdef __FreeBSD__
++                        error("Cannot fetch process %d files (command '%s')", p->pid, p->comm);
++                        #else
+                         error("Cannot process entries in %s/proc/%d/fd (command '%s')", netdata_configured_host_prefix, p->pid, p->comm);
++                        #endif
+                         break;
+ 
+                     case PID_LOG_STAT:
+@@ -955,7 +971,7 @@ static inline int read_proc_pid_stat(struct pid_stat *p, void *ptr) {
+     pid_incremental_rate(stat, p->utime,   (kernel_uint_t)proc_info->ki_rusage.ru_utime.tv_sec * 100 + proc_info->ki_rusage.ru_utime.tv_usec / 10000);
+     pid_incremental_rate(stat, p->stime,   (kernel_uint_t)proc_info->ki_rusage.ru_stime.tv_sec * 100 + proc_info->ki_rusage.ru_stime.tv_usec / 10000);
+     pid_incremental_rate(stat, p->cutime,  (kernel_uint_t)proc_info->ki_rusage_ch.ru_utime.tv_sec * 100 + proc_info->ki_rusage_ch.ru_utime.tv_usec / 10000);
+-    pid_incremental_rate(stat, p->cstime,  (kernel_uint_t)proc_info->ki_rusage_ch.ru_stime.tv_sec * 100 + proc_info->ki_rusage_ch.ru_utime.tv_usec / 10000);
++    pid_incremental_rate(stat, p->cstime,  (kernel_uint_t)proc_info->ki_rusage_ch.ru_stime.tv_sec * 100 + proc_info->ki_rusage_ch.ru_stime.tv_usec / 10000);
+ 
+     p->num_threads      = proc_info->ki_numthreads;
+ 
+@@ -2006,8 +2022,8 @@ static int compar_pid(const void *pid1, const void *pid2) {
+ #endif
+ 
+ static inline int collect_data_for_pid(pid_t pid, void *ptr) {
+-    if(unlikely(pid < INIT_PID || pid > pid_max)) {
+-        error("Invalid pid %d read (expected %d to %d). Ignoring process.", pid, INIT_PID, pid_max);
++    if(unlikely(pid < 0 || pid > pid_max)) {
++        error("Invalid pid %d read (expected %d to %d). Ignoring process.", pid, 0, pid_max);
+         return 0;
+     }
+ 
+@@ -2069,28 +2085,46 @@ static int collect_data_for_all_processes(void) {
+ 
+ #ifdef __FreeBSD__
+     int i, procnum;
+-    size_t procbase_size;
+-    static struct kinfo_proc *procbase;
+ 
+-    int mib[3];
++    static size_t procbase_size = 0;
++    static struct kinfo_proc *procbase = NULL;
+ 
+-    mib[0] = CTL_KERN;
+-    mib[1] = KERN_PROC;
+-    mib[2] = KERN_PROC_PROC;
+-    if (unlikely(sysctl(mib, 3, NULL, &procbase_size, NULL, 0))) {
++    size_t new_procbase_size;
++
++    int mib[3] = { CTL_KERN, KERN_PROC, KERN_PROC_PROC };
++    if (unlikely(sysctl(mib, 3, NULL, &new_procbase_size, NULL, 0))) {
+         error("sysctl error: Can't get processes data size");
+         return 0;
+     }
+-    procbase = reallocz(procbase, procbase_size);
+-    if (unlikely(sysctl(mib, 3, procbase, &procbase_size, NULL, 0))) {
++
++    // give it some air for processes that may be started
++    // during this little time.
++    new_procbase_size += 100 * sizeof(struct kinfo_proc);
++
++    // increase the buffer if needed
++    if(new_procbase_size > procbase_size) {
++        procbase_size = new_procbase_size;
++        procbase = reallocz(procbase, procbase_size);
++    }
++
++    // sysctl() gets from new_procbase_size the buffer size
++    // and also returns to it the amount of data filled in
++    new_procbase_size = procbase_size;
++
++    // get the processes from the system
++    if (unlikely(sysctl(mib, 3, procbase, &new_procbase_size, NULL, 0))) {
+         error("sysctl error: Can't get processes data");
+         return 0;
+     }
+-    procnum = procbase_size / sizeof(struct kinfo_proc);
++
++    // based on the amount of data filled in
++    // calculate the number of processes we got
++    procnum = new_procbase_size / sizeof(struct kinfo_proc);
++
+ #endif
+ 
+     if(all_pids_count) {
+-#ifndef __FreeBSD__
++#if (ALL_PIDS_ARE_READ_INSTANTLY == 0)
+         size_t slc = 0;
+ #endif
+         for(p = root_of_pids; p ; p = p->next) {
+@@ -2107,7 +2141,7 @@ static int collect_data_for_all_processes(void) {
+ 
+ #if (ALL_PIDS_ARE_READ_INSTANTLY == 0)
+         if(unlikely(slc != all_pids_count)) {
+-            error("Internal error: I was thinking I had %zu processes in my arrays, but it seems there are more.", all_pids_count);
++            error("Internal error: I was thinking I had %zu processes in my arrays, but it seems there are %zu.", all_pids_count, slc);
+             all_pids_count = slc;
+         }
+ 
+@@ -2130,7 +2164,7 @@ static int collect_data_for_all_processes(void) {
+     }
+ 
+ #ifdef __FreeBSD__
+-    for (i = INIT_PID; i < procnum - INIT_PID; ++i) {
++    for (i = 0 ; i < procnum ; ++i) {
+         pid_t pid = procbase[i].ki_pid;
+         collect_data_for_pid(pid, &procbase[i]);
+     }
+@@ -2258,21 +2292,17 @@ static void apply_apps_groups_targets_inheritance(void) {
+             if(unlikely(!p->sortlist && !p->children_count))
+                 p->sortlist = sortlist++;
+ 
+-            // if this process does not have any children
+-            // and is not already merged
+-            // and has a parent
+-            // and its parent has children
+-            // and the target of this process and its parent is the same, or the parent does not have a target
+-            // and its parent is not init
+-            // then, mark them as merged.
+             if(unlikely(
+-                    !p->children_count
+-                    && !p->merged
+-                    && p->parent
+-                    && p->parent->children_count
++                    !p->children_count            // if this process does not have any children
++                    && !p->merged                 // and is not already merged
++                    && p->parent                  // and has a parent
++                    && p->parent->children_count  // and its parent has children
++                                                  // and the target of this process and its parent is the same,
++                                                  // or the parent does not have a target
+                     && (p->target == p->parent->target || !p->parent->target)
+-                    && p->ppid != INIT_PID
++                    && p->ppid != INIT_PID        // and its parent is not init
+                 )) {
++                // mark it as merged
+                 p->parent->children_count--;
+                 p->merged = 1;
+ 
+@@ -2296,6 +2326,10 @@ static void apply_apps_groups_targets_inheritance(void) {
+     if(all_pids[INIT_PID])
+         all_pids[INIT_PID]->target = apps_groups_default_target;
+ 
++    // pid 0 goes always to default target
++    if(all_pids[0])
++        all_pids[0]->target = apps_groups_default_target;
++
+     // give a default target on all top level processes
+     if(unlikely(debug)) loops++;
+     for(p = root_of_pids; p ; p = p->next) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801181225.w0ICPAeK075257>