vnstat-2.9/0000755000000000000000000000000014173313400011375 5ustar rootrootvnstat-2.9/config.sub0000755000000000000000000010535413037475074013406 0ustar rootroot#! /bin/sh # Configuration validation subroutine script. # Copyright 1992-2013 Free Software Foundation, Inc. timestamp='2013-08-10' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that # program. This Exception is an additional permission under section 7 # of the GNU General Public License, version 3 ("GPLv3"). # Please send patches with a ChangeLog entry to config-patches@gnu.org. # # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. # If it is invalid, we print an error message on stderr and exit with code 1. # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: # http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases # that are meaningful with *any* GNU software. # Each package is responsible for reporting which valid configurations # it does not support. The user should be able to distinguish # a failure to support a valid configuration from a meaningless # configuration. # The goal of this file is to map all the various variations of a given # machine specification into a single specification in the form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM # or in some cases, the newer four-part form: # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] CPU-MFR-OPSYS $0 [OPTION] ALIAS Canonicalize a configuration name. Operation modes: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.sub ($timestamp) Copyright 1992-2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try \`$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" exit 1 ;; *local*) # First pass through any local machine types. echo $1 exit ;; * ) break ;; esac done case $# in 0) echo "$me: missing argument$help" >&2 exit 1;; 1) ;; *) echo "$me: too many arguments$help" >&2 exit 1;; esac # Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). # Here we must recognize all the valid KERNEL-OS combinations. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \ linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \ knetbsd*-gnu* | netbsd*-gnu* | \ kopensolaris*-gnu* | \ storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; android-linux) os=-linux-android basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown ;; *) basic_machine=`echo $1 | sed 's/-[^-]*$//'` if [ $basic_machine != $1 ] then os=`echo $1 | sed 's/.*-/-/'` else os=; fi ;; esac ### Let's recognize common machines as not being operating systems so ### that things like config.sub decstation-3100 work. We also ### recognize some manufacturers as not being operating systems, so we ### can provide default operating systems below. case $os in -sun*os*) # Prevent following clause from handling this invalid input. ;; -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ -apple | -axis | -knuth | -cray | -microblaze*) os= basic_machine=$1 ;; -bluegene*) os=-cnk ;; -sim | -cisco | -oki | -wec | -winbond) os= basic_machine=$1 ;; -scout) ;; -wrs) os=-vxworks basic_machine=$1 ;; -chorusos*) os=-chorusos basic_machine=$1 ;; -chorusrdb) os=-chorusrdb basic_machine=$1 ;; -hiux*) os=-hiuxwe2 ;; -sco6) os=-sco5v6 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco5) os=-sco3.2v5 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco4) os=-sco3.2v4 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco3.2.[4-9]*) os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco3.2v[4-9]*) # Don't forget version if it is 3.2v4 or newer. basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco5v6*) # Don't forget version if it is 3.2v4 or newer. basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco*) os=-sco3.2v2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -udk*) basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -isc) os=-isc2.2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -clix*) basic_machine=clipper-intergraph ;; -isc*) basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -lynx*178) os=-lynxos178 ;; -lynx*5) os=-lynxos5 ;; -lynx*) os=-lynxos ;; -ptx*) basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` ;; -windowsnt*) os=`echo $os | sed -e 's/windowsnt/winnt/'` ;; -psos*) os=-psos ;; -mint | -mint[0-9]*) basic_machine=m68k-atari os=-mint ;; esac # Decode aliases for certain CPU-COMPANY combinations. case $basic_machine in # Recognize the basic CPU types without company name. # Some are omitted here because they have special meanings below. 1750a | 580 \ | a29k \ | aarch64 | aarch64_be \ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ | am33_2.0 \ | arc | arceb \ | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \ | avr | avr32 \ | be32 | be64 \ | bfin \ | c4x | c8051 | clipper \ | d10v | d30v | dlx | dsp16xx \ | epiphany \ | fido | fr30 | frv \ | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ | hexagon \ | i370 | i860 | i960 | ia64 \ | ip2k | iq2000 \ | le32 | le64 \ | lm32 \ | m32c | m32r | m32rle | m68000 | m68k | m88k \ | maxq | mb | microblaze | microblazeel | mcore | mep | metag \ | mips | mipsbe | mipseb | mipsel | mipsle \ | mips16 \ | mips64 | mips64el \ | mips64octeon | mips64octeonel \ | mips64orion | mips64orionel \ | mips64r5900 | mips64r5900el \ | mips64vr | mips64vrel \ | mips64vr4100 | mips64vr4100el \ | mips64vr4300 | mips64vr4300el \ | mips64vr5000 | mips64vr5000el \ | mips64vr5900 | mips64vr5900el \ | mipsisa32 | mipsisa32el \ | mipsisa32r2 | mipsisa32r2el \ | mipsisa64 | mipsisa64el \ | mipsisa64r2 | mipsisa64r2el \ | mipsisa64sb1 | mipsisa64sb1el \ | mipsisa64sr71k | mipsisa64sr71kel \ | mipsr5900 | mipsr5900el \ | mipstx39 | mipstx39el \ | mn10200 | mn10300 \ | moxie \ | mt \ | msp430 \ | nds32 | nds32le | nds32be \ | nios | nios2 | nios2eb | nios2el \ | ns16k | ns32k \ | open8 \ | or1k | or32 \ | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle \ | pyramid \ | rl78 | rx \ | score \ | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ | sh64 | sh64le \ | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ | spu \ | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \ | ubicom32 \ | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \ | we32k \ | x86 | xc16x | xstormy16 | xtensa \ | z8k | z80) basic_machine=$basic_machine-unknown ;; c54x) basic_machine=tic54x-unknown ;; c55x) basic_machine=tic55x-unknown ;; c6x) basic_machine=tic6x-unknown ;; m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | picochip) basic_machine=$basic_machine-unknown os=-none ;; m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) ;; ms1) basic_machine=mt-unknown ;; strongarm | thumb | xscale) basic_machine=arm-unknown ;; xgate) basic_machine=$basic_machine-unknown os=-none ;; xscaleeb) basic_machine=armeb-unknown ;; xscaleel) basic_machine=armel-unknown ;; # We use `pc' rather than `unknown' # because (1) that's what they normally are, and # (2) the word "unknown" tends to confuse beginning users. i*86 | x86_64) basic_machine=$basic_machine-pc ;; # Object if more than one company name word. *-*-*) echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 exit 1 ;; # Recognize the basic CPU types with company name. 580-* \ | a29k-* \ | aarch64-* | aarch64_be-* \ | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ | avr-* | avr32-* \ | be32-* | be64-* \ | bfin-* | bs2000-* \ | c[123]* | c30-* | [cjt]90-* | c4x-* \ | c8051-* | clipper-* | craynv-* | cydra-* \ | d10v-* | d30v-* | dlx-* \ | elxsi-* \ | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ | h8300-* | h8500-* \ | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ | hexagon-* \ | i*86-* | i860-* | i960-* | ia64-* \ | ip2k-* | iq2000-* \ | le32-* | le64-* \ | lm32-* \ | m32c-* | m32r-* | m32rle-* \ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \ | microblaze-* | microblazeel-* \ | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ | mips16-* \ | mips64-* | mips64el-* \ | mips64octeon-* | mips64octeonel-* \ | mips64orion-* | mips64orionel-* \ | mips64r5900-* | mips64r5900el-* \ | mips64vr-* | mips64vrel-* \ | mips64vr4100-* | mips64vr4100el-* \ | mips64vr4300-* | mips64vr4300el-* \ | mips64vr5000-* | mips64vr5000el-* \ | mips64vr5900-* | mips64vr5900el-* \ | mipsisa32-* | mipsisa32el-* \ | mipsisa32r2-* | mipsisa32r2el-* \ | mipsisa64-* | mipsisa64el-* \ | mipsisa64r2-* | mipsisa64r2el-* \ | mipsisa64sb1-* | mipsisa64sb1el-* \ | mipsisa64sr71k-* | mipsisa64sr71kel-* \ | mipsr5900-* | mipsr5900el-* \ | mipstx39-* | mipstx39el-* \ | mmix-* \ | mt-* \ | msp430-* \ | nds32-* | nds32le-* | nds32be-* \ | nios-* | nios2-* | nios2eb-* | nios2el-* \ | none-* | np1-* | ns16k-* | ns32k-* \ | open8-* \ | orion-* \ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \ | pyramid-* \ | rl78-* | romp-* | rs6000-* | rx-* \ | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ | sparclite-* \ | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \ | tahoe-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tile*-* \ | tron-* \ | ubicom32-* \ | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \ | vax-* \ | we32k-* \ | x86-* | x86_64-* | xc16x-* | xps100-* \ | xstormy16-* | xtensa*-* \ | ymp-* \ | z8k-* | z80-*) ;; # Recognize the basic CPU types without company name, with glob match. xtensa*) basic_machine=$basic_machine-unknown ;; # Recognize the various machine names and aliases which stand # for a CPU type and a company and sometimes even an OS. 386bsd) basic_machine=i386-unknown os=-bsd ;; 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) basic_machine=m68000-att ;; 3b*) basic_machine=we32k-att ;; a29khif) basic_machine=a29k-amd os=-udi ;; abacus) basic_machine=abacus-unknown ;; adobe68k) basic_machine=m68010-adobe os=-scout ;; alliant | fx80) basic_machine=fx80-alliant ;; altos | altos3068) basic_machine=m68k-altos ;; am29k) basic_machine=a29k-none os=-bsd ;; amd64) basic_machine=x86_64-pc ;; amd64-*) basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` ;; amdahl) basic_machine=580-amdahl os=-sysv ;; amiga | amiga-*) basic_machine=m68k-unknown ;; amigaos | amigados) basic_machine=m68k-unknown os=-amigaos ;; amigaunix | amix) basic_machine=m68k-unknown os=-sysv4 ;; apollo68) basic_machine=m68k-apollo os=-sysv ;; apollo68bsd) basic_machine=m68k-apollo os=-bsd ;; aros) basic_machine=i386-pc os=-aros ;; aux) basic_machine=m68k-apple os=-aux ;; balance) basic_machine=ns32k-sequent os=-dynix ;; blackfin) basic_machine=bfin-unknown os=-linux ;; blackfin-*) basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'` os=-linux ;; bluegene*) basic_machine=powerpc-ibm os=-cnk ;; c54x-*) basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'` ;; c55x-*) basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'` ;; c6x-*) basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'` ;; c90) basic_machine=c90-cray os=-unicos ;; cegcc) basic_machine=arm-unknown os=-cegcc ;; convex-c1) basic_machine=c1-convex os=-bsd ;; convex-c2) basic_machine=c2-convex os=-bsd ;; convex-c32) basic_machine=c32-convex os=-bsd ;; convex-c34) basic_machine=c34-convex os=-bsd ;; convex-c38) basic_machine=c38-convex os=-bsd ;; cray | j90) basic_machine=j90-cray os=-unicos ;; craynv) basic_machine=craynv-cray os=-unicosmp ;; cr16 | cr16-*) basic_machine=cr16-unknown os=-elf ;; crds | unos) basic_machine=m68k-crds ;; crisv32 | crisv32-* | etraxfs*) basic_machine=crisv32-axis ;; cris | cris-* | etrax*) basic_machine=cris-axis ;; crx) basic_machine=crx-unknown os=-elf ;; da30 | da30-*) basic_machine=m68k-da30 ;; decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) basic_machine=mips-dec ;; decsystem10* | dec10*) basic_machine=pdp10-dec os=-tops10 ;; decsystem20* | dec20*) basic_machine=pdp10-dec os=-tops20 ;; delta | 3300 | motorola-3300 | motorola-delta \ | 3300-motorola | delta-motorola) basic_machine=m68k-motorola ;; delta88) basic_machine=m88k-motorola os=-sysv3 ;; dicos) basic_machine=i686-pc os=-dicos ;; djgpp) basic_machine=i586-pc os=-msdosdjgpp ;; dpx20 | dpx20-*) basic_machine=rs6000-bull os=-bosx ;; dpx2* | dpx2*-bull) basic_machine=m68k-bull os=-sysv3 ;; ebmon29k) basic_machine=a29k-amd os=-ebmon ;; elxsi) basic_machine=elxsi-elxsi os=-bsd ;; encore | umax | mmax) basic_machine=ns32k-encore ;; es1800 | OSE68k | ose68k | ose | OSE) basic_machine=m68k-ericsson os=-ose ;; fx2800) basic_machine=i860-alliant ;; genix) basic_machine=ns32k-ns ;; gmicro) basic_machine=tron-gmicro os=-sysv ;; go32) basic_machine=i386-pc os=-go32 ;; h3050r* | hiux*) basic_machine=hppa1.1-hitachi os=-hiuxwe2 ;; h8300hms) basic_machine=h8300-hitachi os=-hms ;; h8300xray) basic_machine=h8300-hitachi os=-xray ;; h8500hms) basic_machine=h8500-hitachi os=-hms ;; harris) basic_machine=m88k-harris os=-sysv3 ;; hp300-*) basic_machine=m68k-hp ;; hp300bsd) basic_machine=m68k-hp os=-bsd ;; hp300hpux) basic_machine=m68k-hp os=-hpux ;; hp3k9[0-9][0-9] | hp9[0-9][0-9]) basic_machine=hppa1.0-hp ;; hp9k2[0-9][0-9] | hp9k31[0-9]) basic_machine=m68000-hp ;; hp9k3[2-9][0-9]) basic_machine=m68k-hp ;; hp9k6[0-9][0-9] | hp6[0-9][0-9]) basic_machine=hppa1.0-hp ;; hp9k7[0-79][0-9] | hp7[0-79][0-9]) basic_machine=hppa1.1-hp ;; hp9k78[0-9] | hp78[0-9]) # FIXME: really hppa2.0-hp basic_machine=hppa1.1-hp ;; hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) # FIXME: really hppa2.0-hp basic_machine=hppa1.1-hp ;; hp9k8[0-9][13679] | hp8[0-9][13679]) basic_machine=hppa1.1-hp ;; hp9k8[0-9][0-9] | hp8[0-9][0-9]) basic_machine=hppa1.0-hp ;; hppa-next) os=-nextstep3 ;; hppaosf) basic_machine=hppa1.1-hp os=-osf ;; hppro) basic_machine=hppa1.1-hp os=-proelf ;; i370-ibm* | ibm*) basic_machine=i370-ibm ;; i*86v32) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv32 ;; i*86v4*) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv4 ;; i*86v) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-sysv ;; i*86sol2) basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-solaris2 ;; i386mach) basic_machine=i386-mach os=-mach ;; i386-vsta | vsta) basic_machine=i386-unknown os=-vsta ;; iris | iris4d) basic_machine=mips-sgi case $os in -irix*) ;; *) os=-irix4 ;; esac ;; isi68 | isi) basic_machine=m68k-isi os=-sysv ;; m68knommu) basic_machine=m68k-unknown os=-linux ;; m68knommu-*) basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'` os=-linux ;; m88k-omron*) basic_machine=m88k-omron ;; magnum | m3230) basic_machine=mips-mips os=-sysv ;; merlin) basic_machine=ns32k-utek os=-sysv ;; microblaze*) basic_machine=microblaze-xilinx ;; mingw64) basic_machine=x86_64-pc os=-mingw64 ;; mingw32) basic_machine=i686-pc os=-mingw32 ;; mingw32ce) basic_machine=arm-unknown os=-mingw32ce ;; miniframe) basic_machine=m68000-convergent ;; *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) basic_machine=m68k-atari os=-mint ;; mips3*-*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` ;; mips3*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown ;; monitor) basic_machine=m68k-rom68k os=-coff ;; morphos) basic_machine=powerpc-unknown os=-morphos ;; msdos) basic_machine=i386-pc os=-msdos ;; ms1-*) basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` ;; msys) basic_machine=i686-pc os=-msys ;; mvs) basic_machine=i370-ibm os=-mvs ;; nacl) basic_machine=le32-unknown os=-nacl ;; ncr3000) basic_machine=i486-ncr os=-sysv4 ;; netbsd386) basic_machine=i386-unknown os=-netbsd ;; netwinder) basic_machine=armv4l-rebel os=-linux ;; news | news700 | news800 | news900) basic_machine=m68k-sony os=-newsos ;; news1000) basic_machine=m68030-sony os=-newsos ;; news-3600 | risc-news) basic_machine=mips-sony os=-newsos ;; necv70) basic_machine=v70-nec os=-sysv ;; next | m*-next ) basic_machine=m68k-next case $os in -nextstep* ) ;; -ns2*) os=-nextstep2 ;; *) os=-nextstep3 ;; esac ;; nh3000) basic_machine=m68k-harris os=-cxux ;; nh[45]000) basic_machine=m88k-harris os=-cxux ;; nindy960) basic_machine=i960-intel os=-nindy ;; mon960) basic_machine=i960-intel os=-mon960 ;; nonstopux) basic_machine=mips-compaq os=-nonstopux ;; np1) basic_machine=np1-gould ;; neo-tandem) basic_machine=neo-tandem ;; nse-tandem) basic_machine=nse-tandem ;; nsr-tandem) basic_machine=nsr-tandem ;; op50n-* | op60c-*) basic_machine=hppa1.1-oki os=-proelf ;; openrisc | openrisc-*) basic_machine=or32-unknown ;; os400) basic_machine=powerpc-ibm os=-os400 ;; OSE68000 | ose68000) basic_machine=m68000-ericsson os=-ose ;; os68k) basic_machine=m68k-none os=-os68k ;; pa-hitachi) basic_machine=hppa1.1-hitachi os=-hiuxwe2 ;; paragon) basic_machine=i860-intel os=-osf ;; parisc) basic_machine=hppa-unknown os=-linux ;; parisc-*) basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'` os=-linux ;; pbd) basic_machine=sparc-tti ;; pbb) basic_machine=m68k-tti ;; pc532 | pc532-*) basic_machine=ns32k-pc532 ;; pc98) basic_machine=i386-pc ;; pc98-*) basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentium | p5 | k5 | k6 | nexgen | viac3) basic_machine=i586-pc ;; pentiumpro | p6 | 6x86 | athlon | athlon_*) basic_machine=i686-pc ;; pentiumii | pentium2 | pentiumiii | pentium3) basic_machine=i686-pc ;; pentium4) basic_machine=i786-pc ;; pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentiumpro-* | p6-* | 6x86-* | athlon-*) basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentium4-*) basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pn) basic_machine=pn-gould ;; power) basic_machine=power-ibm ;; ppc | ppcbe) basic_machine=powerpc-unknown ;; ppc-* | ppcbe-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ppcle | powerpclittle | ppc-le | powerpc-little) basic_machine=powerpcle-unknown ;; ppcle-* | powerpclittle-*) basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ppc64) basic_machine=powerpc64-unknown ;; ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ppc64le | powerpc64little | ppc64-le | powerpc64-little) basic_machine=powerpc64le-unknown ;; ppc64le-* | powerpc64little-*) basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` ;; ps2) basic_machine=i386-ibm ;; pw32) basic_machine=i586-unknown os=-pw32 ;; rdos | rdos64) basic_machine=x86_64-pc os=-rdos ;; rdos32) basic_machine=i386-pc os=-rdos ;; rom68k) basic_machine=m68k-rom68k os=-coff ;; rm[46]00) basic_machine=mips-siemens ;; rtpc | rtpc-*) basic_machine=romp-ibm ;; s390 | s390-*) basic_machine=s390-ibm ;; s390x | s390x-*) basic_machine=s390x-ibm ;; sa29200) basic_machine=a29k-amd os=-udi ;; sb1) basic_machine=mipsisa64sb1-unknown ;; sb1el) basic_machine=mipsisa64sb1el-unknown ;; sde) basic_machine=mipsisa32-sde os=-elf ;; sei) basic_machine=mips-sei os=-seiux ;; sequent) basic_machine=i386-sequent ;; sh) basic_machine=sh-hitachi os=-hms ;; sh5el) basic_machine=sh5le-unknown ;; sh64) basic_machine=sh64-unknown ;; sparclite-wrs | simso-wrs) basic_machine=sparclite-wrs os=-vxworks ;; sps7) basic_machine=m68k-bull os=-sysv2 ;; spur) basic_machine=spur-unknown ;; st2000) basic_machine=m68k-tandem ;; stratus) basic_machine=i860-stratus os=-sysv4 ;; strongarm-* | thumb-*) basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'` ;; sun2) basic_machine=m68000-sun ;; sun2os3) basic_machine=m68000-sun os=-sunos3 ;; sun2os4) basic_machine=m68000-sun os=-sunos4 ;; sun3os3) basic_machine=m68k-sun os=-sunos3 ;; sun3os4) basic_machine=m68k-sun os=-sunos4 ;; sun4os3) basic_machine=sparc-sun os=-sunos3 ;; sun4os4) basic_machine=sparc-sun os=-sunos4 ;; sun4sol2) basic_machine=sparc-sun os=-solaris2 ;; sun3 | sun3-*) basic_machine=m68k-sun ;; sun4) basic_machine=sparc-sun ;; sun386 | sun386i | roadrunner) basic_machine=i386-sun ;; sv1) basic_machine=sv1-cray os=-unicos ;; symmetry) basic_machine=i386-sequent os=-dynix ;; t3e) basic_machine=alphaev5-cray os=-unicos ;; t90) basic_machine=t90-cray os=-unicos ;; tile*) basic_machine=$basic_machine-unknown os=-linux-gnu ;; tx39) basic_machine=mipstx39-unknown ;; tx39el) basic_machine=mipstx39el-unknown ;; toad1) basic_machine=pdp10-xkl os=-tops20 ;; tower | tower-32) basic_machine=m68k-ncr ;; tpf) basic_machine=s390x-ibm os=-tpf ;; udi29k) basic_machine=a29k-amd os=-udi ;; ultra3) basic_machine=a29k-nyu os=-sym1 ;; v810 | necv810) basic_machine=v810-nec os=-none ;; vaxv) basic_machine=vax-dec os=-sysv ;; vms) basic_machine=vax-dec os=-vms ;; vpp*|vx|vx-*) basic_machine=f301-fujitsu ;; vxworks960) basic_machine=i960-wrs os=-vxworks ;; vxworks68) basic_machine=m68k-wrs os=-vxworks ;; vxworks29k) basic_machine=a29k-wrs os=-vxworks ;; w65*) basic_machine=w65-wdc os=-none ;; w89k-*) basic_machine=hppa1.1-winbond os=-proelf ;; xbox) basic_machine=i686-pc os=-mingw32 ;; xps | xps100) basic_machine=xps100-honeywell ;; xscale-* | xscalee[bl]-*) basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'` ;; ymp) basic_machine=ymp-cray os=-unicos ;; z8k-*-coff) basic_machine=z8k-unknown os=-sim ;; z80-*-coff) basic_machine=z80-unknown os=-sim ;; none) basic_machine=none-none os=-none ;; # Here we handle the default manufacturer of certain CPU types. It is in # some cases the only manufacturer, in others, it is the most popular. w89k) basic_machine=hppa1.1-winbond ;; op50n) basic_machine=hppa1.1-oki ;; op60c) basic_machine=hppa1.1-oki ;; romp) basic_machine=romp-ibm ;; mmix) basic_machine=mmix-knuth ;; rs6000) basic_machine=rs6000-ibm ;; vax) basic_machine=vax-dec ;; pdp10) # there are many clones, so DEC is not a safe bet basic_machine=pdp10-unknown ;; pdp11) basic_machine=pdp11-dec ;; we32k) basic_machine=we32k-att ;; sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele) basic_machine=sh-unknown ;; sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) basic_machine=sparc-sun ;; cydra) basic_machine=cydra-cydrome ;; orion) basic_machine=orion-highlevel ;; orion105) basic_machine=clipper-highlevel ;; mac | mpw | mac-mpw) basic_machine=m68k-apple ;; pmac | pmac-mpw) basic_machine=powerpc-apple ;; *-unknown) # Make sure to match an already-canonicalized machine name. ;; *) echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 exit 1 ;; esac # Here we canonicalize certain aliases for manufacturers. case $basic_machine in *-digital*) basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` ;; *-commodore*) basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` ;; *) ;; esac # Decode manufacturer-specific aliases for certain operating systems. if [ x"$os" != x"" ] then case $os in # First match some system type aliases # that might get confused with valid system types. # -solaris* is a basic system type, with this one exception. -auroraux) os=-auroraux ;; -solaris1 | -solaris1.*) os=`echo $os | sed -e 's|solaris1|sunos4|'` ;; -solaris) os=-solaris2 ;; -svr4*) os=-sysv4 ;; -unixware*) os=-sysv4.2uw ;; -gnu/linux*) os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` ;; # First accept the basic system types. # The portable systems comes first. # Each alternative MUST END IN A *, to match a version number. # -sysv* is not here because it comes later, after sysvr4. -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\ | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \ | -sym* | -kopensolaris* | -plan9* \ | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ | -aos* | -aros* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ | -bitrig* | -openbsd* | -solidbsd* \ | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -chorusos* | -chorusrdb* | -cegcc* \ | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \ | -linux-newlib* | -linux-musl* | -linux-uclibc* \ | -uxpv* | -beos* | -mpeix* | -udk* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*) # Remember, each alternative MUST END IN *, to match a version number. ;; -qnx*) case $basic_machine in x86-* | i*86-*) ;; *) os=-nto$os ;; esac ;; -nto-qnx*) ;; -nto*) os=`echo $os | sed -e 's|nto|nto-qnx|'` ;; -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) ;; -mac*) os=`echo $os | sed -e 's|mac|macos|'` ;; -linux-dietlibc) os=-linux-dietlibc ;; -linux*) os=`echo $os | sed -e 's|linux|linux-gnu|'` ;; -sunos5*) os=`echo $os | sed -e 's|sunos5|solaris2|'` ;; -sunos6*) os=`echo $os | sed -e 's|sunos6|solaris3|'` ;; -opened*) os=-openedition ;; -os400*) os=-os400 ;; -wince*) os=-wince ;; -osfrose*) os=-osfrose ;; -osf*) os=-osf ;; -utek*) os=-bsd ;; -dynix*) os=-bsd ;; -acis*) os=-aos ;; -atheos*) os=-atheos ;; -syllable*) os=-syllable ;; -386bsd) os=-bsd ;; -ctix* | -uts*) os=-sysv ;; -nova*) os=-rtmk-nova ;; -ns2 ) os=-nextstep2 ;; -nsk*) os=-nsk ;; # Preserve the version number of sinix5. -sinix5.*) os=`echo $os | sed -e 's|sinix|sysv|'` ;; -sinix*) os=-sysv4 ;; -tpf*) os=-tpf ;; -triton*) os=-sysv3 ;; -oss*) os=-sysv3 ;; -svr4) os=-sysv4 ;; -svr3) os=-sysv3 ;; -sysvr4) os=-sysv4 ;; # This must come after -sysvr4. -sysv*) ;; -ose*) os=-ose ;; -es1800*) os=-ose ;; -xenix) os=-xenix ;; -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) os=-mint ;; -aros*) os=-aros ;; -zvmoe) os=-zvmoe ;; -dicos*) os=-dicos ;; -nacl*) ;; -none) ;; *) # Get rid of the `-' at the beginning of $os. os=`echo $os | sed 's/[^-]*-//'` echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 exit 1 ;; esac else # Here we handle the default operating systems that come with various machines. # The value should be what the vendor currently ships out the door with their # machine or put another way, the most popular os provided with the machine. # Note that if you're going to try to match "-MANUFACTURER" here (say, # "-sun"), then you have to tell the case statement up towards the top # that MANUFACTURER isn't an operating system. Otherwise, code above # will signal an error saying that MANUFACTURER isn't an operating # system, and we'll never get to this point. case $basic_machine in score-*) os=-elf ;; spu-*) os=-elf ;; *-acorn) os=-riscix1.2 ;; arm*-rebel) os=-linux ;; arm*-semi) os=-aout ;; c4x-* | tic4x-*) os=-coff ;; c8051-*) os=-elf ;; hexagon-*) os=-elf ;; tic54x-*) os=-coff ;; tic55x-*) os=-coff ;; tic6x-*) os=-coff ;; # This must come before the *-dec entry. pdp10-*) os=-tops20 ;; pdp11-*) os=-none ;; *-dec | vax-*) os=-ultrix4.2 ;; m68*-apollo) os=-domain ;; i386-sun) os=-sunos4.0.2 ;; m68000-sun) os=-sunos3 ;; m68*-cisco) os=-aout ;; mep-*) os=-elf ;; mips*-cisco) os=-elf ;; mips*-*) os=-elf ;; or1k-*) os=-elf ;; or32-*) os=-coff ;; *-tti) # must be before sparc entry or we get the wrong os. os=-sysv3 ;; sparc-* | *-sun) os=-sunos4.1.1 ;; *-be) os=-beos ;; *-haiku) os=-haiku ;; *-ibm) os=-aix ;; *-knuth) os=-mmixware ;; *-wec) os=-proelf ;; *-winbond) os=-proelf ;; *-oki) os=-proelf ;; *-hp) os=-hpux ;; *-hitachi) os=-hiux ;; i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) os=-sysv ;; *-cbm) os=-amigaos ;; *-dg) os=-dgux ;; *-dolphin) os=-sysv3 ;; m68k-ccur) os=-rtu ;; m88k-omron*) os=-luna ;; *-next ) os=-nextstep ;; *-sequent) os=-ptx ;; *-crds) os=-unos ;; *-ns) os=-genix ;; i370-*) os=-mvs ;; *-next) os=-nextstep3 ;; *-gould) os=-sysv ;; *-highlevel) os=-bsd ;; *-encore) os=-bsd ;; *-sgi) os=-irix ;; *-siemens) os=-sysv4 ;; *-masscomp) os=-rtu ;; f30[01]-fujitsu | f700-fujitsu) os=-uxpv ;; *-rom68k) os=-coff ;; *-*bug) os=-coff ;; *-apple) os=-macos ;; *-atari*) os=-mint ;; *) os=-none ;; esac fi # Here we handle the case where we know the os, and the CPU type, but not the # manufacturer. We pick the logical manufacturer. vendor=unknown case $basic_machine in *-unknown) case $os in -riscix*) vendor=acorn ;; -sunos*) vendor=sun ;; -cnk*|-aix*) vendor=ibm ;; -beos*) vendor=be ;; -hpux*) vendor=hp ;; -mpeix*) vendor=hp ;; -hiux*) vendor=hitachi ;; -unos*) vendor=crds ;; -dgux*) vendor=dg ;; -luna*) vendor=omron ;; -genix*) vendor=ns ;; -mvs* | -opened*) vendor=ibm ;; -os400*) vendor=ibm ;; -ptx*) vendor=sequent ;; -tpf*) vendor=ibm ;; -vxsim* | -vxworks* | -windiss*) vendor=wrs ;; -aux*) vendor=apple ;; -hms*) vendor=hitachi ;; -mpw* | -macos*) vendor=apple ;; -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) vendor=atari ;; -vos*) vendor=stratus ;; esac basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` ;; esac echo $basic_machine$os exit # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: vnstat-2.9/COPYING0000644000000000000000000004325413046366412012451 0ustar rootroot GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. vnstat-2.9/CHANGES0000644000000000000000000006502714173306225012411 0ustar rootroot2.9 / 23-Jan-2022 - Fixed - RescanDatabaseOnSave configuration option wasn't being read from the configuration file resulting in the feature always being enabled - Hourly graph image output using large fonts didn't correctly fade out the x-axis line for hours not having data available - New - Add --alert for producing output and/or specific exit status when configured condition and transfer limit is exceeded, can also be used for "quota remaining" type of queries depending on used parameters - Add configuration option InterfaceMatchMethod which allows configuring the possibility of specifying an interface for database queries by using its alias instead of system provided interface name, enabled by default to support case insensitive matching of the beginning of interface aliases (vnstat and vnstati) - Image output file extension allows selecting the used image file format as long as the used LibGD supports it, PNG is no longer the only option - Add configuration option HourlyGraphMode for changing the output mode of the graph, 0 = 24 hour sliding window (default, as in previous releases), 1 = graph begins from midnight - Add mode parameter for -hg / --hoursgraph options for overriding the HourlyGraphMode configuration option setting from the command line - Add vertical line to image output hourly graph to visualize midnight - Add -t / --timestamp options to daemon for enabling timestamps to prints when the daemon is running in the foreground attached to a terminal - Accept ; as comment character in configuration file in addition to # - Comment out keywords which are using default values with ; character in provided configuration file and --showconfig output 2.8 / 4-Sep-2021 - Fixed - Using a combination of --live and --json wasn't flushing stdout after each line resulting in buffered output if the output was being piped - Image output would fail to show the last line bar graph in list outputs if EstimateStyle was 0, BarColumnShowsRate was 1 and the last line had a higher traffic rate than other lines - Image output didn't correctly horizontally align the "no data available" message in 5 minute graph depending on the width of the image - Image output related configuration warnings could get shown when image output wasn't being used - Warnings of mismatches between image output and data retention configuration didn't provide relevant details for solving the issues - BandwidthDetection was being used for tun interfaces even when the Linux kernel had the information hardcoded to 10 Mbit regardless of the used real interface, interface specific MaxBW will now be used instead or MaxBandwidth as fallback - Configured interface specific MaxBW values were getting overridden by BandwidthDetection when something could be detected - Image output horizontal rx/tx bars often had one pixel too much width in the tx section resulting in slightly wrong ratio getting shown - Top days list wasn't always sorting entries with exactly the same traffic sum using ascending date - 64bitInterfaceCounters with value -2 always assumed 32-bit on Linux systems until a 64-bit value was seen if kernel headers weren't available when binaries were built - New - Add the possibility of specifying an interface without using the -i / --iface options (vnstat and vnstati) - The daemon can discover added interfaces from the database without requiring a restart, configurable with option RescanDatabaseOnSave - Add configuration option UseUTC for using UTC as timezone for database entries instead of following the system timezone configuration - --iflist uses user configured interface specific MaxBW values in the output when available instead of showing only the kernel provided information when detected - Add configuration option AlwaysAddNewInterfaces to expose the daemon --alwaysadd command line option which gains an optional mode parameter - Image output uses LibGD filled arc bug workaround only for LibGD versions that are known to be broken - Image output example cgi (examples/vnstat.cgi) improvements - Automatically lists all monitored interfaces instead of requiring the list to be filled manually, server name in page title comes from hostname command by default - Provides links for most available images to more detailed or longer versions of each image - Allows direct interface specific page access with /interfacename suffix for the cgi if the used httpd supports PATH_INFO - Page auto refresh can be enabled with configurable interval 2.7 / 16-May-2021 - Fixed - Possibility of segmentation fault with image list output when database existed but no data was available - ./configure output could show invalid install paths with some parameter combinations (pull request by Severin Glöckner) - Columns in text hours graph output could get misaligned if the selected system locale used a UTF-8 sequence for the thousands separator instead of a single character - New - Add -5g / --fivegraph options to image output with sizing related parameters for the output of a 5 minute resolution bar graph - Add configuration option SummaryGraph and optional parameter for --hsummary and --vsummary for selecting which graph is shown next to the summary data in the horizontal and vertical summary image outputs - Add --large / --small options and configuration option LargeFonts for controlling the image output font size - Add --scale and configuration option ImageScale for scaling the image output to a given percent - Add configuration option LineSpacingAdjustment for adjusting the line spacing of list format image outputs - Add bar visualizations for traffic estimations in image output - Allow writing image output to a filename starting with - - Add --initdb to daemon for creating a new empty database without having the daemon process staying running, doesn't discard data if a database already exists - Add configuration option BarColumnShowsRate for having the bar column in image list outputs be scaled according to the average rate column values when those values are visible, disabled by default - Add --dbiflist for getting a list of interfaces in the database, both --iflist and --dbiflist also get alternative more parseable outputs - Add configuration option for large font output and make 5 minute resolution graph visible in vnstat.cgi 2.6 / 20-Jan-2020 - Fixed - --json and --xml didn't support having both mode and limit parameters defined at the same time as documented, broken since previous release - Documentation was using a mix of "count" and "limit" for the option of limiting the maximum number of shown entries in queries - Summary image output would segmentation fault when the database existed but didn't yet contain any daily or monthly data for the selected interface - New - Add --limit as an alternative way for controlling the length of outputs 2.5 / 14-Jan-2020 - Fixed - Automatic interface selection wasn't done for --traffic and --live when the Interface configuration setting was left empty - --setalias didn't do anything when used in combination with --add - -l / --live and -tr default to first interface instead of producing an error if a interface merge is requested 2.4 / 18-Aug-2019 - Fixed - Daemon didn't correctly wait when acquiring database lock for data write which could result in unnecessary errors and even process exit if an external database read operation had exactly the same timing as the daemon write operation - Daemon didn't fork() even when requested to with --daemon when started by PID 1 (issue seen at least in Docker containers) - Move vnstatd man page from section 1 to section 8 - New - Add --rename for renaming interfaces already existing the database 2.3 / 10-Jul-2019 - Fixed - Traffic rate wasn't being shown for the last entry of most lists during the first update of the next period (first SaveInterval minutes of each new hour, day, month and year) - Systemd example service file could result in database file write issues if the used systemd version supported ProtectSystem=strict but didn't support StateDirectory (issue seen at least with systemd 232 in Debian 9) - Debian and Red Hat init.d example files had wrong path for the pid file - Interfaces could end up staying marked as 'disabled' in the database even after becoming back active and monitored, only the shown status was wrong without resulting in any data loss - Some image outputs didn't allocate enough height for the image resulting in the last row having less space below it than intended - New - Automatic interface selection when the Interface configuration setting is left empty (new default) - Add configuration option DatabaseWriteAheadLogging to enable SQLite Write-Ahead Logging mode which may provide some disk i/o benefits, see https://www.sqlite.org/wal.html for more details and note that SQLite 3.22.0 or later is required to support read-only operations - Add configuration option DatabaseSynchronous for changing the SQLite setting of the "synchronous" flag, see https://www.sqlite.org/pragma.html#pragma_synchronous for more details - Show warning in log if writing cached data to database is slow - Try database query for up to 5 seconds when database is busy or locked instead of giving up immediately - Continue daemon process execution with data caching if database writes fail due to disk being full 2.2 / 28-Apr-2019 - Fixed - O_CLOEXEC undeclared error when compiling with glibc older than 2.12 - Image output --headertext wasn't being applied to some output types - DefaultDecimals setting wasn't controlling all outputs - Traffic rate for the last entry of the 5 minute resolution list wasn't being correctly calculated - New - Detection of 32-bit / 64-bit kernel interface counters for improving traffic calculations in rollover situations, cfg: 64bitInterfaceCounters - Possibility in queries to merge data from multiple interfaces to one output with interface1+interface2 syntax - Highlight current day in top list when visible - Changes in interface specific detected bandwidth limits are reported in the log - UpdateInterval value is automatically adjusted during daemon startup if found to be too high compared to the value of MaxBandwidth - Notes - Added clarification to the man page that the 'jsonversion' and 'xmlversion' fields in the --json and --xml outputs should be seen as the API version and compared to the previously used version in 3rd party implementations for verifying compatibility - Default value of UpdateInterval is now 20 instead of previous 30 seconds 2.1 / 6-Dec-2018 - Fixed - --oneline could segmentation fault if database had total traffic values set but didn't have any daily or monthly traffic (Arch bug #60588) - No proper error message was produced when querying interface which didn't exist in the database - Several typos and spelling mistakes in documentation - Daemon:waittimesync_does_not_wait_with_new_interfaces test was failing if the system used a time zone with a negative numeric value - Traffic estimate and average rate for ongoing month was not being calculated correctly when MonthRotate had a value greater than 1 - Accuracy of traffic estimate and average rate for the ongoing month could be slightly skewed depending on the used time zone - New - Remove possible PollInterval and UpdateInterval drift over time - Sync SaveInterval to full minutes 2.0 / 21-Oct-2018 - Fixed - Data rate calculations when using SI decimal prefixes - Workaround for filled arcs not drawn correctly with some versions of libgd (libgd/libgd#351) - New - C struct dump database has been replaced with sqlite database, full data import included from legacy databases of versions 1.3 - 1.18 - User configurable data retention durations for all resolutions with following changed defaults: v1.18 v2.0 5 minutes n/a 576 (48 hours) hours 24 96 (4 days) days 30 62 (2 full months) months 12 25 (2 full years) years n/a all top days 10 20 - Option to select units to use SI decimal prefixes using calculations with powers of 1000 (IEC and JEDEC prefixes use powers of 1024) - Yearly and 5 minute resolution statistics - Pebibyte and exbibyte support - Options the configure the length of each list output - Option to limit the length of --json and --xml outputs - Hourly list output replaces the hourly graph when the -h parameter is used - Hourly graph is accessible with -hg / --hoursgraph parameter - Options -b / --begin and -e / --end for specifying query time range - Configuration comes with ISO 8601 date formats as new defaults - Removed - Weekly output - Merge of data from multiple interfaces to one output - --testkernel - --exportdb, use --oneline, --json or --xml instead - --importdb, -u / --update and related options using vnstat command - Old style (default in versions up to 1.7) summary layout in image output 1.18 / 4-Mar-2018 - Fix: Misspellings, compiler warnings and possible error situations (pull requests by Christian Göttsche) - Hardening added to examples/systemd/vnstat.service (pull request by Christian Göttsche) - Add RTC sanity check and sync wait to daemon startup, the possible wait duration can be configured using the TimeSyncWait keyword - Add optional parameter to --oneline output for forcing fields to output in bytes - Add --json support for -l / --live and -tr outputs - Number of decimals used in outputs can be configured using DefaultDecimals and HourlyDecimals - Add section separators for improving readability of the vnstat -h output, configurable using HourlySectionStyle 1.17 / 16-Feb-2017 - Fix: --importdb was creating invalid databases since version 1.15 - Fix: console output was being buffered which resulted in lack of output in at least systemd log - Add cross-compilation detection and improve install-data-hook to not assume that the binaries can be executed in the host system 1.16 / 24-Dec-2016 - Fix: traffic rate calculation, SI decimal prefixes were shown but calculation was done for IEC binary prefixes - Add option for configure to disable image output support even if required library is available, improve library detection (pull request by Rodrigo Rebello) - Add selection between SI decimal prefixes (kbit/s...) (default) and IEC binary prefixes (Kibit/s...) for traffic rate using RateUnitMode keyword in configuration file - Improve database handling resilience - Inherit database file ownership from database directory if UpdateFileOwner configuration option is enabled (default: enabled) when adding new interfaces for monitoring as root. This solves database file ownership mismatches when the daemon is started as a non-root user and an interface gets added for monitoring with a sudo command as root - Improve user guidance in error situations related to the configured default interface 1.15 / 22-Dec-2015 - Fix: XML output had extra commas, broken since previous version - Fix: unintended shared pointer modification in mosecs() sometimes resulted in wrong month name to be shown for the current month - Fix: possible buffer overflow in /proc/net/dev parsing, requires corrupted content in /proc/net/dev or use of address sanitizer (found by Hanno Böck) - Use ANSI escape codes in -l and -tr modes for cursor location manipulation instead of printing backspaces, hide cursor while output is active - Improve database import robustness - Improve support for Asian UTF-8 date strings - Replace hand written Makefiles with Autotools - Add --alwaysadd parameter to daemon for allowing automatic addition of interfaces even if the database directory was populated during startup 1.14 / 26-Apr-2015 - Fix: JSON output syntax during first day of newly created databases (pull request by Stefan Merettig) - Fix: field padding when using UTF-8 locale - Add optional mode parameter to --json and --xml for limiting the output to only selected information 1.13 / 18-Jan-2015 - Fix: getgroup() test in Debian GNU/kFreeBSD (patch by Felix Geyer) - Fix: struct if_data usage after freeifaddrs() call in BSD - Dynamic unit selection in hourly output instead of being fixed to KiB - New options in image output (vnstati) * -nl / --nolegend for hiding the rx/tx legend * --altdate for using alternative date and time text location * --headertext for using custom text string in image header section - Add legend to hourly output image - Add option for content alignment and page background color to vnstat.cgi - Document keyword value ranges in configuration file man page - Import Makefile improvements from OpenBSD (pull requests by Jasper Lievisse Adriaanse) - Automatic interface bandwidth detection, BandwidthDetection in config, default fallback value MaxBandwidth changed from 100 to 1000 - JSON output (--json), vnstat-json.cgi and vnstat-json.php examples provided in the 'examples' directory - Drop support for over 10 year old database formats (versions 1.0 - 1.2) 1.12 / 30-Aug-2014 - Fix: Memory allocation when zero interfaces are available, also lo needed to be missing in order to trigger this leak - Fix: Rebuild total indexing (thanks to William Epp for reporting this) - Fix: Some error situations could leave database file open until the end of command execution - Fix: Live traffic meter occasionally showing higher minimum than average in end statistics (Debian Bug #687812) - Fix: Setting locale when none is specified in config (Debian Bug #606397) - Fix: Cppcheck findings (may fix Debian Bug #692330) - Improve traffic meter output accuracy - Add tests and debug compilation target - Remove use of -D parameter in Makefile install commands in order to improve cross-compilation support - Set CFLAGS in Makefiles only when not already defined - Add support for database import from text file (--importdb) (based on patch by Tilmann Bubeck) - Rename --dumpdb to --exportdb - Add example systemd service file - Add example launchd plist file for OS X - Use ISO YYYY-MM-DD date format timestamps if logfile is used - Improve daemon startup prints - Add parameters for changing daemon process user and group - Add example upstart job configuration file (thanks to Cameron Norman) - Create database, pid and log dirs during daemon startup if necessary - Update ownership of database, log and pid files if needed during daemon startup if started as root and configured to change process user and group - Remove cron update related example files and documentation, the cron update method should be considered as deprecated - --create parameter for database creation 1.11 / 1-Jun-2011 - Fix: Memory allocation was miscalculated when creating interface list from /sys/class/net when /proc/net/dev wasn't available which in turn could crash the daemon - Fix: Daemon database cache could remain empty after a -HUP signal - Fix: Don't make temp directory in vnstat.cgi writable for everyone - Import GNU/kFreeBSD support from Debian (#608963, patch by Mats Erik Andersson) - Remove usage of GNU only '-D' option for install for BSD in Makefile - The daemon now automatically creates databases for available interfaces if no databases are found during startup 1.10 / 2-Jan-2010 - Fix: Buffer overflow was possible in hourly image output when RateUnit=1 and HourlyRate=1 - Fix: Minor memory leak was possible in the handling of HUP signal in daemon - Fix: Graphical elements weren't correctly aligned in summary image when header wasn't visible (-nh) - Fix: --delete didn't work - Possibility to merge statistics from several databases and save the end result to a new database (--mergesaved) - Added validation of database cache in daemon in order to be more robust in case of system memory corruption - Support for --style to -l (live mode) - Alternative print mode to -l (live mode) with optional parameter - Present options and elements in man pages in alphabetical order - Code cleanup 1.9 / 12-Sep-2009 - Fix: TrafficlessDays configuration option was enabled when set to zero when it should have been disabled - Fix: MonthRotate setting was getting ignored for the first month if the database is created when day of month < MonthRotate value - Configurable summary layout in image output (1.7 <> 1.8 layouts) - --oneline, a simple parseable one line output - --transparent for setting image background transparency from the command line - --delete for deleting databases and stopping monitoring, doesn't require restarting the daemon - A database write can be configure to occur after interface status changes - Different database write interval can be configure to be used when all monitored interfaces are offline - Better configurability for the content of outputs, including a narrow output for space limited terminals (OutputStyle and --style) - Code cleanup - New configuration file settings: OutputStyle, SummaryLayout, SummaryRate, SaveOnStatusChange, OfflineSaveInterval 1.8 / 1-Aug-2009 - Fix: OpenBSD print issues (was: ' used for formatting in sprintf) - Fix: Monthly estimate for February during a leap year was wrong - Fix: 'make install' didn't install the config file is $(DESTDIR) was used - Traffic of current and previous months added to summary - Increased accuracy of monthly estimate calculation - Traffic rates can be made visible and the shown unit is configurable as bits or bytes - New summary layout in image output - Image output can have the background color set as transparent - Possibility to merge data from several interfaces to one output with interface1+interface2 syntax - -s / --sync parameter added to daemon - --dbdir and --locale parameters added - Outputs now use system locale by default and formatting of dates follow the locale setting unless configured otherwise - New configuration file settings: ShowRate, RateUnit, TrafficlessDays, HourlyRate, TransparentBg 1.7 / 12-Apr-2009 - Fix: Timezone changes shouldn't cause a flood of errors anymore - Fix: Statvfs used instead of statfs for BSD compatibility (Thanks to Mark Mitchell for pointing this out) - Fix: Makefile didn't properly support LDFLAGS and -lm was misplaced - Fix: MonthRotate value in config wasn't used - Fix: Unreadable configuration file doesn't cause a segmentation fault - Fix: /proc/net/dev parser didn't see the difference between eth10 and eth1 - Fix: Updating a database from two of more processes at the same time was able to sometimes cause data loss - Fix: Estimates are calculated based on last database update - Fix: Each interface update had a possibility of losing 1023 bytes of traffic at most due to improper rounding (Thanks to Michael Berlin for suggesting a suitable correction) - Daemon support as alternative for cron based updates - PNG image output (hourly rate based on patch by Sergio Ammirata) - XML output - BSD support - Diskspace check can be disabled from configuration file - IEC standard prefixes (KiB/MiB/GiB/TiB) - List of available interfaces if wrong of unavailable interface is selected 1.6 / 1-Jan-2008 - Fix: Segmentation fault when environment variable "HOME" wasn't defined, this broke most CGI and PHP scripts that used vnStat - Support for /sys/class/net/* if /proc/net/dev is unavailable - Config file parser redesigned - --config parameter for selecting config file - Consistent exit status for all operations (0 for success, 1 for error) - Improved file locking - Man page restrictions paragraph updated - Minor non-visible fixes and code cleanup 1.5 / 3-Dec-2007 - Fix: compile time warnings solved - Fix: kernel test is now more verbose - Fix: more informative error messages - Fix: possible division by zero for traffic estimates right after midnight - Fix: interface names longer than 6 chars (patch by Jan Schmidle) - Realtime transfer rate mode - Automatic 32bit/64bit counter detection - Config file support - Internal database backups and locking - More visuals in outputs - Adaptive units (kB, MB, GB, TB) - Possibility to sync counters without counting traffic - Maximum bandwidth of interfaces can be set 1.4 / 26-Mar-2004 - Fix: major output problems when compiled with some compilers (thanks to DukePyrolator for reporting this bug and Juha / vlu for testing the patch) - Fix: month rotation if database isn't updated every day - Minor non-visible fixes and code cleanup 1.3 / 8-Mar-2004 - Fix: support for 64bit counters - Fix: 'yesterday' was showing 01.01. with new databases - Fix: free space warning changed from 1% to 1MB - Fix: minor security exploit - A man page has been included - Hourly output with textgraphical view - kBs are visible when traffic is under 1000 MB - Webpage moved to http://humdi.net/vnstat/ - Minor visual updates 1.2 / 7-Oct-2003 - Changed file paths to conform with FHS (http://www.pathname.com/fhs/) /usr/local/bin/vnstat -> /usr/bin/vnstat /var/spool/vnstat -> /var/lib/vnstat - Added FAQ - Included sample scripts for pppd users - Support for 64bit counters in /proc/net/dev (Thanks to Stephan van Hienen for the test account) - Actual date is shown if the previous day in the database isn't yesterday - Weekly and last 7 days traffic can be shown. (Thanks to Derk-Jan Hartman for the suggestion) - Average kB/s meter - --testkernel fixed - Documentation for --dumpdb included in the README 1.1 / 13-Jul-2003 - Support for multiple interfaces - Date checking (update shouldn't be before previous update) - New database structure - Possibility to change date output format - Test tool for faulty kernels - Parseable output - Better support for ppp/dsl users - Free diskspace check - Possibility to change month rotation day (like 25. instead of 1.) - Daily/monthly traffic estimation 22-Nov-2002 - Renamed the cron script file that would be installed to /etc/cron.d from vnstat.cron to vnstat because debian systems didn't execute scripts containing dots (Thanks to frangen / Simo Salminen for this note) 1.0 / 23-Sep-2002 - Initial public release vnstat-2.9/install-sh0000755000000000000000000003325513037475074013427 0ustar rootroot#!/bin/sh # install - install a program, script, or datafile scriptversion=2011-11-20.07; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the # following copyright and license. # # Copyright (C) 1994 X Consortium # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to # deal in the Software without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or # sell copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # Except as contained in this notice, the name of the X Consortium shall not # be used in advertising or otherwise to promote the sale, use or other deal- # ings in this Software without prior written authorization from the X Consor- # tium. # # # FSF changes to this file are in the public domain. # # Calling this script install-sh is preferred over install.sh, to prevent # 'make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. nl=' ' IFS=" "" $nl" # set DOITPROG to echo to test this script # Don't use :- since 4.3BSD and earlier shells don't like it. doit=${DOITPROG-} if test -z "$doit"; then doit_exec=exec else doit_exec=$doit fi # Put in absolute file names if you don't have them in your path; # or use environment vars. chgrpprog=${CHGRPPROG-chgrp} chmodprog=${CHMODPROG-chmod} chownprog=${CHOWNPROG-chown} cmpprog=${CMPPROG-cmp} cpprog=${CPPROG-cp} mkdirprog=${MKDIRPROG-mkdir} mvprog=${MVPROG-mv} rmprog=${RMPROG-rm} stripprog=${STRIPPROG-strip} posix_glob='?' initialize_posix_glob=' test "$posix_glob" != "?" || { if (set -f) 2>/dev/null; then posix_glob= else posix_glob=: fi } ' posix_mkdir= # Desired mode of installed file. mode=0755 chgrpcmd= chmodcmd=$chmodprog chowncmd= mvcmd=$mvprog rmcmd="$rmprog -f" stripcmd= src= dst= dir_arg= dst_arg= copy_on_change=false no_target_directory= usage="\ Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE or: $0 [OPTION]... SRCFILES... DIRECTORY or: $0 [OPTION]... -t DIRECTORY SRCFILES... or: $0 [OPTION]... -d DIRECTORIES... In the 1st form, copy SRCFILE to DSTFILE. In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. In the 4th, create DIRECTORIES. Options: --help display this help and exit. --version display version info and exit. -c (ignored) -C install only if different (preserve the last data modification time) -d create directories instead of installing files. -g GROUP $chgrpprog installed files to GROUP. -m MODE $chmodprog installed files to MODE. -o USER $chownprog installed files to USER. -s $stripprog installed files. -t DIRECTORY install into DIRECTORY. -T report an error if DSTFILE is a directory. Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG " while test $# -ne 0; do case $1 in -c) ;; -C) copy_on_change=true;; -d) dir_arg=true;; -g) chgrpcmd="$chgrpprog $2" shift;; --help) echo "$usage"; exit $?;; -m) mode=$2 case $mode in *' '* | *' '* | *' '* | *'*'* | *'?'* | *'['*) echo "$0: invalid mode: $mode" >&2 exit 1;; esac shift;; -o) chowncmd="$chownprog $2" shift;; -s) stripcmd=$stripprog;; -t) dst_arg=$2 # Protect names problematic for 'test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac shift;; -T) no_target_directory=true;; --version) echo "$0 $scriptversion"; exit $?;; --) shift break;; -*) echo "$0: invalid option: $1" >&2 exit 1;; *) break;; esac shift done if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then # When -d is used, all remaining arguments are directories to create. # When -t is used, the destination is already specified. # Otherwise, the last argument is the destination. Remove it from $@. for arg do if test -n "$dst_arg"; then # $@ is not empty: it contains at least $arg. set fnord "$@" "$dst_arg" shift # fnord fi shift # arg dst_arg=$arg # Protect names problematic for 'test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac done fi if test $# -eq 0; then if test -z "$dir_arg"; then echo "$0: no input file specified." >&2 exit 1 fi # It's OK to call 'install-sh -d' without argument. # This can happen when creating conditional directories. exit 0 fi if test -z "$dir_arg"; then do_exit='(exit $ret); exit $ret' trap "ret=129; $do_exit" 1 trap "ret=130; $do_exit" 2 trap "ret=141; $do_exit" 13 trap "ret=143; $do_exit" 15 # Set umask so as not to create temps with too-generous modes. # However, 'strip' requires both read and write access to temps. case $mode in # Optimize common cases. *644) cp_umask=133;; *755) cp_umask=22;; *[0-7]) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw='% 200' fi cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; *) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw=,u+rw fi cp_umask=$mode$u_plus_rw;; esac fi for src do # Protect names problematic for 'test' and other utilities. case $src in -* | [=\(\)!]) src=./$src;; esac if test -n "$dir_arg"; then dst=$src dstdir=$dst test -d "$dstdir" dstdir_status=$? else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if test ! -f "$src" && test ! -d "$src"; then echo "$0: $src does not exist." >&2 exit 1 fi if test -z "$dst_arg"; then echo "$0: no destination specified." >&2 exit 1 fi dst=$dst_arg # If destination is a directory, append the input filename; won't work # if double slashes aren't ignored. if test -d "$dst"; then if test -n "$no_target_directory"; then echo "$0: $dst_arg: Is a directory" >&2 exit 1 fi dstdir=$dst dst=$dstdir/`basename "$src"` dstdir_status=0 else # Prefer dirname, but fall back on a substitute if dirname fails. dstdir=` (dirname "$dst") 2>/dev/null || expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$dst" : 'X\(//\)[^/]' \| \ X"$dst" : 'X\(//\)$' \| \ X"$dst" : 'X\(/\)' \| . 2>/dev/null || echo X"$dst" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q' ` test -d "$dstdir" dstdir_status=$? fi fi obsolete_mkdir_used=false if test $dstdir_status != 0; then case $posix_mkdir in '') # Create intermediate dirs using mode 755 as modified by the umask. # This is like FreeBSD 'install' as of 1997-10-28. umask=`umask` case $stripcmd.$umask in # Optimize common cases. *[2367][2367]) mkdir_umask=$umask;; .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; *[0-7]) mkdir_umask=`expr $umask + 22 \ - $umask % 100 % 40 + $umask % 20 \ - $umask % 10 % 4 + $umask % 2 `;; *) mkdir_umask=$umask,go-w;; esac # With -d, create the new directory with the user-specified mode. # Otherwise, rely on $mkdir_umask. if test -n "$dir_arg"; then mkdir_mode=-m$mode else mkdir_mode= fi posix_mkdir=false case $umask in *[123567][0-7][0-7]) # POSIX mkdir -p sets u+wx bits regardless of umask, which # is incompatible with FreeBSD 'install' when (umask & 300) != 0. ;; *) tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 if (umask $mkdir_umask && exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 then if test -z "$dir_arg" || { # Check for POSIX incompatibilities with -m. # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or # other-writable bit of parent directory when it shouldn't. # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. ls_ld_tmpdir=`ls -ld "$tmpdir"` case $ls_ld_tmpdir in d????-?r-*) different_mode=700;; d????-?--*) different_mode=755;; *) false;; esac && $mkdirprog -m$different_mode -p -- "$tmpdir" && { ls_ld_tmpdir_1=`ls -ld "$tmpdir"` test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" } } then posix_mkdir=: fi rmdir "$tmpdir/d" "$tmpdir" else # Remove any dirs left behind by ancient mkdir implementations. rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null fi trap '' 0;; esac;; esac if $posix_mkdir && ( umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" ) then : else # The umask is ridiculous, or mkdir does not conform to POSIX, # or it failed possibly due to a race condition. Create the # directory the slow way, step by step, checking for races as we go. case $dstdir in /*) prefix='/';; [-=\(\)!]*) prefix='./';; *) prefix='';; esac eval "$initialize_posix_glob" oIFS=$IFS IFS=/ $posix_glob set -f set fnord $dstdir shift $posix_glob set +f IFS=$oIFS prefixes= for d do test X"$d" = X && continue prefix=$prefix$d if test -d "$prefix"; then prefixes= else if $posix_mkdir; then (umask=$mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break # Don't fail if two instances are running concurrently. test -d "$prefix" || exit 1 else case $prefix in *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; *) qprefix=$prefix;; esac prefixes="$prefixes '$qprefix'" fi fi prefix=$prefix/ done if test -n "$prefixes"; then # Don't fail if two instances are running concurrently. (umask $mkdir_umask && eval "\$doit_exec \$mkdirprog $prefixes") || test -d "$dstdir" || exit 1 obsolete_mkdir_used=true fi fi fi if test -n "$dir_arg"; then { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 else # Make a couple of temp file names in the proper directory. dsttmp=$dstdir/_inst.$$_ rmtmp=$dstdir/_rm.$$_ # Trap to clean up those temp files at exit. trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 # Copy the file name to the temp name. (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && # and set any options; do chmod last to preserve setuid bits. # # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $cpprog $src $dsttmp" command. # { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && # If -C, don't bother to copy if it wouldn't change the file. if $copy_on_change && old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && eval "$initialize_posix_glob" && $posix_glob set -f && set X $old && old=:$2:$4:$5:$6 && set X $new && new=:$2:$4:$5:$6 && $posix_glob set +f && test "$old" = "$new" && $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 then rm -f "$dsttmp" else # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || # The rename failed, perhaps because mv can't rename something else # to itself, or perhaps because mv is so ancient that it does not # support -f. { # Now remove or move aside any old file at destination location. # We try this two ways since rm can't unlink itself on some # systems and the destination file might be busy for other # reasons. In this case, the final cleanup might fail but the new # file should still install successfully. { test ! -f "$dst" || $doit $rmcmd -f "$dst" 2>/dev/null || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } } || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 } } && # Now rename the file to the real destination. $doit $mvcmd "$dsttmp" "$dst" } fi || exit 1 trap '' 0 fi done # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC" # time-stamp-end: "; # UTC" # End: vnstat-2.9/examples/0000755000000000000000000000000014016545662013230 5ustar rootrootvnstat-2.9/examples/vnstat-json.php0000644000000000000000000000162214052261736016225 0ustar rootroot */ /* released under the GNU General Public License */ /* location of vnstat binary */ $vnstat_cmd = "/usr/bin/vnstat"; /* individually accessible interfaces with ?interface=N */ /* for static list, uncomment first line below, update the list and comment out second line */ //$interfaces = array("eth0", "eth1"); $interfaces = explode("\n", trim(shell_exec("$vnstat_cmd --dbiflist 1"))); /* no editing should be needed below this line */ $iface = ""; $getiface = ""; if (isset($_GET['interface']) && ctype_digit($_GET['interface'])) { $getiface = $_GET['interface']; } if (strlen($getiface) > 0 && $getiface >= 0 && $getiface < count($interfaces)) { $iface = " -i ".$interfaces[$getiface]; } header("Content-Type: application/json"); passthru($vnstat_cmd." --json".$iface); ?> vnstat-2.9/examples/vnstat-json.cgi0000755000000000000000000000241514110254342016172 0ustar rootroot#!/usr/bin/perl -w # vnstat-json.cgi -- example cgi for vnStat json output # copyright (c) 2015-2021 Teemu Toivola # released under the GNU General Public License use strict; # location of vnstat binary my $vnstat_cmd = '/usr/bin/vnstat'; # individually accessible interfaces with ?interface=N or /interfacename suffix # for static list, uncomment first line below, update the list and comment out second line #my @interfaces = ('eth0', 'eth1'); my @interfaces = `$vnstat_cmd --dbiflist 1`; ################ my $iface = ""; chomp @interfaces; if (defined $ENV{PATH_INFO}) { my @fields = split(/\//, $ENV{PATH_INFO}); my $interface = $fields[-1]; for my $i (0..$#interfaces) { if ($interfaces[${i}] eq $interface) { $iface = "-i $interface"; last; } } } if (length($iface) == 0 and defined $ENV{QUERY_STRING}) { my $getiface = ""; my @values = split(/&/, $ENV{QUERY_STRING}); foreach my $i (@values) { my ($varname, $varvalue) = split(/=/, $i); if ($varname eq 'interface' && $varvalue =~ /^(\d+)$/) { $getiface = $varvalue; } } if (length($getiface) > 0 && $getiface >= 0 && $getiface <= $#interfaces) { $iface = "-i @interfaces[int($getiface)]"; } } print "Content-Type: application/json\n\n"; exec("$vnstat_cmd --json $iface"); vnstat-2.9/examples/systemd/0000755000000000000000000000000013663516374014725 5ustar rootrootvnstat-2.9/examples/systemd/simple/0000755000000000000000000000000013464124021016175 5ustar rootrootvnstat-2.9/examples/systemd/simple/vnstat.service0000644000000000000000000000044113526333557021114 0ustar rootroot[Unit] Description=vnStat network traffic monitor Documentation=man:vnstatd(8) man:vnstat(1) man:vnstat.conf(5) After=network.target [Service] ExecStart=/usr/sbin/vnstatd -n ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure [Install] WantedBy=multi-user.target Alias=vnstatd.service vnstat-2.9/examples/systemd/vnstat.service0000644000000000000000000000135113663516374017626 0ustar rootroot[Unit] Description=vnStat network traffic monitor Documentation=man:vnstatd(8) man:vnstat(1) man:vnstat.conf(5) After=network.target StartLimitIntervalSec=20 StartLimitBurst=4 [Service] ExecStart=/usr/sbin/vnstatd -n ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure RestartSec=2 # Hardening CapabilityBoundingSet= LockPersonality=yes MemoryDenyWriteExecute=yes NoNewPrivileges=yes PrivateDevices=yes PrivateTmp=yes ProtectClock=yes ProtectControlGroups=yes ProtectHome=yes ProtectKernelLogs=yes ProtectKernelModules=yes ProtectKernelTunables=yes ProtectSystem=strict ReadWritePaths=/var/lib RestrictNamespaces=yes RestrictRealtime=yes RestrictSUIDSGID=yes StateDirectory=vnstat [Install] WantedBy=multi-user.target Alias=vnstatd.service vnstat-2.9/examples/upstart/0000755000000000000000000000000012372464015014725 5ustar rootrootvnstat-2.9/examples/upstart/vnstat.conf0000644000000000000000000000024412372464102017110 0ustar rootrootdescription "vnStat network traffic monitor" start on runlevel [2345] stop on runlevel [016] or deconfiguring-networking or unmounting-filesystem exec vnstatd -n vnstat-2.9/examples/vnstat.cgi0000755000000000000000000002546514110254342015235 0ustar rootroot#!/usr/bin/perl -w # vnstat.cgi -- example cgi for vnStat image output # copyright (c) 2008-2021 Teemu Toivola # # based on mailgraph.cgi # copyright (c) 2000-2007 ETH Zurich # copyright (c) 2000-2007 David Schweikert # released under the GNU General Public License package vnStatCGI; use strict; # server name in page title # fill to set, otherwise "hostname" command output is used my $servername = ''; # temporary directory where to store the images my $tmp_dir = '/tmp/vnstatcgi'; # location of "vnstat" binary my $vnstat_cmd = '/usr/bin/vnstat'; # location of "vnstati" binary my $vnstati_cmd = '/usr/bin/vnstati'; # image cache time in minutes, set 0 to disable my $cachetime = '0'; # shown interfaces, interface specific pages can be accessed directly # by using /interfacename as suffix for the cgi if the httpd supports PATH_INFO # for static list, uncomment and update the list #my @interfaces = ('eth0', 'eth1'); # center images on page instead of left alignment, set 0 to disable my $aligncenter = '1'; # use large fonts, set 1 to enable my $largefonts = '0'; # page background color my $bgcolor = "white"; # page auto refresh interval in seconds, set 0 to disable my $pagerefresh = '0'; # cgi script file name for httpd # fill to override automatic detection my $scriptname = ''; ################ my $VERSION = "1.15"; my $cssbody = "body { background-color: $bgcolor; }"; my $csscommonstyle = < $metarefresh Traffic Statistics for $servername HEADER for my $i (0..$#interfaces) { print "

\"$interfaces[${i}]

\n"; } print <Images generated using vnStat image output.

FOOTER } sub print_single_interface_html { my ($interface) = @_; my @interfaces = @vnStatCGI::interfaces; print "Content-Type: text/html\n\n"; print < $metarefresh Traffic Statistics for $servername - $interfaces[${interface}] HEADER print "\n
\n"; print "\"$interfaces[${interface}]
\n"; print "\"$interfaces[${interface}]
\n"; print "\"$interfaces[${interface}]
\n"; print "
\n"; print "\"$interfaces[${interface}]
\n"; print "\"$interfaces[${interface}]
\n"; print "\"$interfaces[${interface}]
\n"; print "\"$interfaces[${interface}]
\n"; print "
\n"; print <Images generated using vnStat image output.

FOOTER } sub print_single_image_html { my ($image) = @_; my $interface = "-1"; my $content = ""; my @interfaces = @vnStatCGI::interfaces; if ($image =~ /^(\d+)-/) { $interface = $1; } else { show_error("ERROR: invalid query"); } if ($image =~ /^\d+-5/) { $content = "5 Minute"; } elsif ($image =~ /^\d+-h/) { $content = "Hourly"; } elsif ($image =~ /^\d+-d/) { $content = "Daily"; } elsif ($image =~ /^\d+-m/) { $content = "Monthly"; } elsif ($image =~ /^\d+-y/) { $content = "Yearly"; } elsif ($image =~ /^\d+-t/) { $content = "Daily Top"; } else { show_error("ERROR: invalid query type"); } print "Content-Type: text/html\n\n"; print < $metarefresh $content Traffic Statistics for $servername - $interfaces[${interface}] HEADER print "\n
\n"; print "\"$interfaces[${interface}]\n"; print "
\n"; print <Image generated using vnStat image output.

FOOTER } sub send_image { my ($file) = @_; -r $file or do { show_error("ERROR: can't find $file"); }; print "Content-type: image/png\n"; print "Content-length: ".((stat($file))[7])."\n"; print "\n"; open(my $IMG_FILE, "<", $file) or die; my $data; print $data while read($IMG_FILE, $data, 16384)>0; } sub show_error { my ($error_msg) = @_; print "Content-type: text/plain\n\n$error_msg\n"; exit 1; } sub main { if (length($scriptname) == 0) { if (defined $ENV{REQUEST_URI}) { ($scriptname) = split(/\?/, $ENV{REQUEST_URI}); } else { ($scriptname) = $ENV{SCRIPT_NAME} =~ /([^\/]*)$/; } if ($scriptname =~ /\/$/) { $scriptname = ''; } } if (not defined $vnStatCGI::interfaces) { our @interfaces = `$vnstat_cmd --dbiflist 1`; } chomp @vnStatCGI::interfaces; my @interfaces = @vnStatCGI::interfaces; if (length($servername) == 0) { $servername = `hostname`; chomp $servername; } if ($aligncenter != '0') { $cssbody = "html { display: table; width: 100%; }\nbody { background-color: $bgcolor; display: table-cell; text-align: center; vertical-align: middle; }\ntable { margin-left: auto; margin-right: auto; margin-top: 10px; }"; } if ($pagerefresh != '0') { $metarefresh = "\n"; } mkdir $tmp_dir, 0755 unless -d $tmp_dir; my $query = $ENV{QUERY_STRING}; if (defined $query and $query =~ /\S/) { if ($query =~ /^(\d+)-s$/) { my $file = "$tmp_dir/vnstat_$1.png"; graph($interfaces[$1], $file, "-s"); send_image($file); } elsif ($query =~ /^(\d+)-hs$/) { my $file = "$tmp_dir/vnstat_$1_hs.png"; graph($interfaces[$1], $file, "-hs"); send_image($file); } elsif ($query =~ /^(\d+)-hsh$/) { my $file = "$tmp_dir/vnstat_$1_hsh.png"; graph($interfaces[$1], $file, "-hs 0"); send_image($file); } elsif ($query =~ /^(\d+)-hs5$/) { my $file = "$tmp_dir/vnstat_$1_hs5.png"; graph($interfaces[$1], $file, "-hs 1"); send_image($file); } elsif ($query =~ /^(\d+)-vs$/) { my $file = "$tmp_dir/vnstat_$1_vs.png"; graph($interfaces[$1], $file, "-vs"); send_image($file); } elsif ($query =~ /^(\d+)-vsh$/) { my $file = "$tmp_dir/vnstat_$1_vsh.png"; graph($interfaces[$1], $file, "-vs 0"); send_image($file); } elsif ($query =~ /^(\d+)-vs5$/) { my $file = "$tmp_dir/vnstat_$1_vs5.png"; graph($interfaces[$1], $file, "-vs 1"); send_image($file); } elsif ($query =~ /^(\d+)-d$/) { my $file = "$tmp_dir/vnstat_$1_d.png"; graph($interfaces[$1], $file, "-d 30"); send_image($file); } elsif ($query =~ /^(\d+)-d-l$/) { my $file = "$tmp_dir/vnstat_$1_d_l.png"; graph($interfaces[$1], $file, "-d 60"); send_image($file); } elsif ($query =~ /^(\d+)-m$/) { my $file = "$tmp_dir/vnstat_$1_m.png"; graph($interfaces[$1], $file, "-m 12"); send_image($file); } elsif ($query =~ /^(\d+)-m-l$/) { my $file = "$tmp_dir/vnstat_$1_m_l.png"; graph($interfaces[$1], $file, "-m 24"); send_image($file); } elsif ($query =~ /^(\d+)-t$/) { my $file = "$tmp_dir/vnstat_$1_t.png"; graph($interfaces[$1], $file, "-t 10"); send_image($file); } elsif ($query =~ /^(\d+)-t-l$/) { my $file = "$tmp_dir/vnstat_$1_t_l.png"; graph($interfaces[$1], $file, "-t 20"); send_image($file); } elsif ($query =~ /^(\d+)-h$/) { my $file = "$tmp_dir/vnstat_$1_h.png"; graph($interfaces[$1], $file, "-h 48"); send_image($file); } elsif ($query =~ /^(\d+)-hg$/) { my $file = "$tmp_dir/vnstat_$1_hg.png"; graph($interfaces[$1], $file, "-hg"); send_image($file); } elsif ($query =~ /^(\d+)-5$/) { my $file = "$tmp_dir/vnstat_$1_5.png"; graph($interfaces[$1], $file, "-5 60"); send_image($file); } elsif ($query =~ /^(\d+)-5g$/) { my $file = "$tmp_dir/vnstat_$1_5g.png"; if ($largefonts == '1') { graph($interfaces[$1], $file, "-5g 576 300"); } else { graph($interfaces[$1], $file, "-5g 422 250"); } send_image($file); } elsif ($query =~ /^(\d+)-y$/) { my $file = "$tmp_dir/vnstat_$1_y.png"; graph($interfaces[$1], $file, "-y 5"); send_image($file); } elsif ($query =~ /^(\d+)-y-l$/) { my $file = "$tmp_dir/vnstat_$1_y_l.png"; graph($interfaces[$1], $file, "-y 0"); send_image($file); } elsif ($query =~ /^(\d+)-f$/) { print_single_interface_html($1); } elsif ($query =~ /^s-(.+)/) { print_single_image_html($1); } else { show_error("ERROR: invalid argument"); } } else { my $html_shown = 0; if (defined $ENV{PATH_INFO}) { my @fields = split(/\//, $ENV{PATH_INFO}); my $interface = $fields[-1]; for my $i (0..$#interfaces) { if ($interfaces[${i}] eq $interface) { print_single_interface_html($i); $html_shown = 1; last; } } if ($html_shown == 0) { show_error("ERROR: no such interface: $interface"); } } if ($html_shown == 0 and scalar @interfaces == 1) { print_single_interface_html(0); } elsif ($html_shown == 0) { print_interface_list_html(); } } } main(); vnstat-2.9/examples/init.d/0000755000000000000000000000000012352076647014420 5ustar rootrootvnstat-2.9/examples/init.d/redhat/0000755000000000000000000000000012302723260015650 5ustar rootrootvnstat-2.9/examples/init.d/redhat/vnstat0000755000000000000000000000270013467346324017133 0ustar rootroot#! /bin/sh # # chkconfig: 2345 20 50 # description: vnStat - a lightweight network traffic monitor # processname: vnstatd # config: /etc/vnstat.conf ### BEGIN INIT INFO # Provides: vnstat # Required-Start: $local_fs $remote_fs $network # Required-Stop: $local_fs $remote_fs $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: lightweight network traffic monitor ### END INIT INFO VNSTATD_BIN=/usr/sbin/vnstatd [ -x $VNSTATD_BIN ] || exit 0 # Source function library . /etc/rc.d/init.d/functions RETVAL=0 prog=vnstatd pidfile=/var/run/vnstat/vnstat.pid start() { echo -n $"Starting $prog: " if [ -e "$pidfile" ] && [ -e /proc/`cat "$pidfile"` ]; then echo -n $"already running."; success "$prog is already running."; echo return 0 fi daemon $VNSTATD_BIN -d RETVAL=$? echo return $RETVAL } stop() { echo -n $"Shutting down $prog: " killproc $VNSTATD_BIN RETVAL=$? echo rm -f $pidfile return $RETVAL } reload() { echo -n $"Reloading $prog configuration: " killproc $VNSTATD_BIN -HUP RETVAL=$? echo return $RETVAL } case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; try-restart) if [ -f $pidfile ]; then stop start fi ;; force-reload) reload || (stop; start) ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|reload|force-reload|restart|try-restart|status}" RETVAL=3 esac exit $RETVAL vnstat-2.9/examples/init.d/ubuntu/0000755000000000000000000000000012302723260015723 5ustar rootrootvnstat-2.9/examples/init.d/ubuntu/vnstat0000755000000000000000000000505113467346314017207 0ustar rootroot#! /bin/sh ### BEGIN INIT INFO # Provides: vnstat # Required-Start: $local_fs $remote_fs $network # Required-Stop: $local_fs $remote_fs $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: lightweight network traffic monitor ### END INIT INFO PATH=/usr/sbin:/usr/bin:/sbin:/bin DESC="vnStat daemon" NAME=vnstatd DAEMON=/usr/sbin/$NAME DAEMON_ARGS="-d" PIDFILE=/var/run/vnstat/vnstat.pid SCRIPTNAME=/etc/init.d/vnstat # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 # # Function that starts the daemon/service # do_start() { # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ || return 1 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ $DAEMON_ARGS \ || return 2 } # # Function that stops the daemon/service # do_stop() { # Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred start-stop-daemon --stop --quiet --retry=TERM/15/KILL/5 --pidfile $PIDFILE --name $NAME RETVAL="$?" [ "$RETVAL" = 2 ] && return 2 rm -f $PIDFILE return "$RETVAL" } # # Function that sends a SIGHUP to the daemon/service # do_reload() { start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME return 0 } do_status() { # Return # 0 if daemon is stopped # 1 if daemon is running start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ || return 1 } case "$1" in start) echo -n "Starting $DESC: $NAME" do_start case "$?" in 0) echo "." ;; 1) echo " already running." ;; 2) echo " start failed." ; exit 1 ;; esac ;; stop) echo -n "Stopping $DESC: $NAME" do_stop case "$?" in 0) echo "." ;; 1) echo " already stopped." ;; 2) echo " stop failed." ; exit 1 ;; esac ;; status) echo -n "Checking $DESC: " do_status case "$?" in 0) echo "stopped." ; exit 3 ;; 1) echo "running." ;; esac ;; reload|force-reload) echo -n "Reloading $DESC configuration..." do_reload echo "done." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) echo "." ;; 1) echo " old process is still running." ;; *) echo " start failed." ; exit 1 ;; esac ;; *) echo " stop failed." exit 1 ;; esac ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload|status}" >&2 exit 1 ;; esac exit 0 vnstat-2.9/examples/init.d/centos/0000755000000000000000000000000012302723260015674 5ustar rootrootvnstat-2.9/examples/init.d/centos/vnstat0000755000000000000000000000000013467346324026506 1vnstat-2.9/examples/init.d/redhat/vnstatustar rootrootvnstat-2.9/examples/init.d/debian/0000755000000000000000000000000012302723260015623 5ustar rootrootvnstat-2.9/examples/init.d/debian/vnstat0000755000000000000000000000000013467346314026507 1vnstat-2.9/examples/init.d/ubuntu/vnstatustar rootrootvnstat-2.9/examples/launchd/0000755000000000000000000000000012316622471014641 5ustar rootrootvnstat-2.9/examples/launchd/net.humdi.vnstat.plist0000644000000000000000000000116712317002176021127 0ustar rootroot Label net.humdi.vnstat ProgramArguments /usr/local/libexec/vnstatd -n KeepAlive NetworkState RunAtLoad WorkingDirectory / ProcessType Background vnstat-2.9/config.guess0000755000000000000000000013036113037475074013737 0ustar rootroot#! /bin/sh # Attempt to guess a canonical system name. # Copyright 1992-2013 Free Software Foundation, Inc. timestamp='2013-06-10' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that # program. This Exception is an additional permission under section 7 # of the GNU General Public License, version 3 ("GPLv3"). # # Originally written by Per Bothner. # # You can get the latest version of this script from: # http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD # # Please send patches with a ChangeLog entry to config-patches@gnu.org. me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] Output the configuration name of the system \`$me' is run on. Operation modes: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. Copyright 1992-2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try \`$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" >&2 exit 1 ;; * ) break ;; esac done if test $# != 0; then echo "$me: too many arguments$help" >&2 exit 1 fi trap 'exit 1' 1 2 15 # CC_FOR_BUILD -- compiler used by this script. Note that the use of a # compiler to aid in system detection is discouraged as it requires # temporary files to be created and, as you can see below, it is a # headache to deal with in a portable fashion. # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still # use `HOST_CC' if defined, but it is deprecated. # Portable tmp directory creation inspired by the Autoconf team. set_cc_for_build=' trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; : ${TMPDIR=/tmp} ; { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; dummy=$tmp/dummy ; tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; case $CC_FOR_BUILD,$HOST_CC,$CC in ,,) echo "int x;" > $dummy.c ; for c in cc gcc c89 c99 ; do if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then CC_FOR_BUILD="$c"; break ; fi ; done ; if test x"$CC_FOR_BUILD" = x ; then CC_FOR_BUILD=no_compiler_found ; fi ;; ,,*) CC_FOR_BUILD=$CC ;; ,*,*) CC_FOR_BUILD=$HOST_CC ;; esac ; set_cc_for_build= ;' # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 1994-08-24) if (test -f /.attbin/uname) >/dev/null 2>&1 ; then PATH=$PATH:/.attbin ; export PATH fi UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown case "${UNAME_SYSTEM}" in Linux|GNU|GNU/*) # If the system lacks a compiler, then just pick glibc. # We could probably try harder. LIBC=gnu eval $set_cc_for_build cat <<-EOF > $dummy.c #include #if defined(__UCLIBC__) LIBC=uclibc #elif defined(__dietlibc__) LIBC=dietlibc #else LIBC=gnu #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'` ;; esac # Note: order is significant - the case branches are not exclusive. case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in *:NetBSD:*:*) # NetBSD (nbsd) targets should (where applicable) match one or # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently # switched to ELF, *-*-netbsd* would select the old # object file format. This provides both forward # compatibility and a consistent mechanism for selecting the # object file format. # # Note: NetBSD doesn't particularly care about the vendor # portion of the name. We always set it to "unknown". sysctl="sysctl -n hw.machine_arch" UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ /usr/sbin/$sysctl 2>/dev/null || echo unknown)` case "${UNAME_MACHINE_ARCH}" in armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; *) machine=${UNAME_MACHINE_ARCH}-unknown ;; esac # The Operating System including object format, if it has switched # to ELF recently, or will in the future. case "${UNAME_MACHINE_ARCH}" in arm*|i386|m68k|ns32k|sh3*|sparc|vax) eval $set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ELF__ then # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). # Return netbsd for either. FIX? os=netbsd else os=netbsdelf fi ;; *) os=netbsd ;; esac # The OS release # Debian GNU/NetBSD machines have a different userland, and # thus, need a distinct triplet. However, they do not need # kernel version information, so it can be replaced with a # suitable tag, in the style of linux-gnu. case "${UNAME_VERSION}" in Debian*) release='-gnu' ;; *) release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` ;; esac # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. echo "${machine}-${os}${release}" exit ;; *:Bitrig:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE} exit ;; *:OpenBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} exit ;; *:ekkoBSD:*:*) echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} exit ;; *:SolidBSD:*:*) echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} exit ;; macppc:MirBSD:*:*) echo powerpc-unknown-mirbsd${UNAME_RELEASE} exit ;; *:MirBSD:*:*) echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} exit ;; alpha:OSF1:*:*) case $UNAME_RELEASE in *4.0) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` ;; *5.*) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` ;; esac # According to Compaq, /usr/sbin/psrinfo has been available on # OSF/1 and Tru64 systems produced since 1995. I hope that # covers most systems running today. This code pipes the CPU # types through head -n 1, so we only detect the type of CPU 0. ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` case "$ALPHA_CPU_TYPE" in "EV4 (21064)") UNAME_MACHINE="alpha" ;; "EV4.5 (21064)") UNAME_MACHINE="alpha" ;; "LCA4 (21066/21068)") UNAME_MACHINE="alpha" ;; "EV5 (21164)") UNAME_MACHINE="alphaev5" ;; "EV5.6 (21164A)") UNAME_MACHINE="alphaev56" ;; "EV5.6 (21164PC)") UNAME_MACHINE="alphapca56" ;; "EV5.7 (21164PC)") UNAME_MACHINE="alphapca57" ;; "EV6 (21264)") UNAME_MACHINE="alphaev6" ;; "EV6.7 (21264A)") UNAME_MACHINE="alphaev67" ;; "EV6.8CB (21264C)") UNAME_MACHINE="alphaev68" ;; "EV6.8AL (21264B)") UNAME_MACHINE="alphaev68" ;; "EV6.8CX (21264D)") UNAME_MACHINE="alphaev68" ;; "EV6.9A (21264/EV69A)") UNAME_MACHINE="alphaev69" ;; "EV7 (21364)") UNAME_MACHINE="alphaev7" ;; "EV7.9 (21364A)") UNAME_MACHINE="alphaev79" ;; esac # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` # Reset EXIT trap before exiting to avoid spurious non-zero exit code. exitcode=$? trap '' 0 exit $exitcode ;; Alpha\ *:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # Should we change UNAME_MACHINE based on the output of uname instead # of the specific Alpha model? echo alpha-pc-interix exit ;; 21064:Windows_NT:50:3) echo alpha-dec-winnt3.5 exit ;; Amiga*:UNIX_System_V:4.0:*) echo m68k-unknown-sysv4 exit ;; *:[Aa]miga[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-amigaos exit ;; *:[Mm]orph[Oo][Ss]:*:*) echo ${UNAME_MACHINE}-unknown-morphos exit ;; *:OS/390:*:*) echo i370-ibm-openedition exit ;; *:z/VM:*:*) echo s390-ibm-zvmoe exit ;; *:OS400:*:*) echo powerpc-ibm-os400 exit ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} exit ;; arm*:riscos:*:*|arm*:RISCOS:*:*) echo arm-unknown-riscos exit ;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) echo hppa1.1-hitachi-hiuxmpp exit ;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. if test "`(/bin/universe) 2>/dev/null`" = att ; then echo pyramid-pyramid-sysv3 else echo pyramid-pyramid-bsd fi exit ;; NILE*:*:*:dcosx) echo pyramid-pyramid-svr4 exit ;; DRS?6000:unix:4.0:6*) echo sparc-icl-nx6 exit ;; DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) case `/usr/bin/uname -p` in sparc) echo sparc-icl-nx7; exit ;; esac ;; s390x:SunOS:*:*) echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4H:SunOS:5.*:*) echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) echo i386-pc-auroraux${UNAME_RELEASE} exit ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) eval $set_cc_for_build SUN_ARCH="i386" # If there is a compiler, see if it is configured for 64-bit objects. # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. # This test works for both compilers. if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then SUN_ARCH="x86_64" fi fi echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; sun4*:SunOS:*:*) case "`/usr/bin/arch -k`" in Series*|S4*) UNAME_RELEASE=`uname -v` ;; esac # Japanese Language versions have a version number like `4.1.3-JL'. echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` exit ;; sun3*:SunOS:*:*) echo m68k-sun-sunos${UNAME_RELEASE} exit ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 case "`/bin/arch`" in sun3) echo m68k-sun-sunos${UNAME_RELEASE} ;; sun4) echo sparc-sun-sunos${UNAME_RELEASE} ;; esac exit ;; aushp:SunOS:*:*) echo sparc-auspex-sunos${UNAME_RELEASE} exit ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not # "atarist" or "atariste" at least should have a processor # > m68000). The system name ranges from "MiNT" over "FreeMiNT" # to the lowercase version "mint" (or "freemint"). Finally # the system name "TOS" denotes a system which is actually not # MiNT. But MiNT is downward compatible to TOS, so this should # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} exit ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} exit ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) echo m68k-atari-mint${UNAME_RELEASE} exit ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) echo m68k-milan-mint${UNAME_RELEASE} exit ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) echo m68k-hades-mint${UNAME_RELEASE} exit ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) echo m68k-unknown-mint${UNAME_RELEASE} exit ;; m68k:machten:*:*) echo m68k-apple-machten${UNAME_RELEASE} exit ;; powerpc:machten:*:*) echo powerpc-apple-machten${UNAME_RELEASE} exit ;; RISC*:Mach:*:*) echo mips-dec-mach_bsd4.3 exit ;; RISC*:ULTRIX:*:*) echo mips-dec-ultrix${UNAME_RELEASE} exit ;; VAX*:ULTRIX*:*:*) echo vax-dec-ultrix${UNAME_RELEASE} exit ;; 2020:CLIX:*:* | 2430:CLIX:*:*) echo clipper-intergraph-clix${UNAME_RELEASE} exit ;; mips:*:*:UMIPS | mips:*:*:RISCos) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #ifdef __cplusplus #include /* for printf() prototype */ int main (int argc, char *argv[]) { #else int main (argc, argv) int argc; char *argv[]; { #endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_SVR4) printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); #endif #endif exit (-1); } EOF $CC_FOR_BUILD -o $dummy $dummy.c && dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && SYSTEM_NAME=`$dummy $dummyarg` && { echo "$SYSTEM_NAME"; exit; } echo mips-mips-riscos${UNAME_RELEASE} exit ;; Motorola:PowerMAX_OS:*:*) echo powerpc-motorola-powermax exit ;; Motorola:*:4.3:PL8-*) echo powerpc-harris-powermax exit ;; Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) echo powerpc-harris-powermax exit ;; Night_Hawk:Power_UNIX:*:*) echo powerpc-harris-powerunix exit ;; m88k:CX/UX:7*:*) echo m88k-harris-cxux7 exit ;; m88k:*:4*:R4*) echo m88k-motorola-sysv4 exit ;; m88k:*:3*:R3*) echo m88k-motorola-sysv3 exit ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] then if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ [ ${TARGET_BINARY_INTERFACE}x = x ] then echo m88k-dg-dgux${UNAME_RELEASE} else echo m88k-dg-dguxbcs${UNAME_RELEASE} fi else echo i586-dg-dgux${UNAME_RELEASE} fi exit ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) echo m88k-dolphin-sysv3 exit ;; M88*:*:R3*:*) # Delta 88k system running SVR3 echo m88k-motorola-sysv3 exit ;; XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) echo m88k-tektronix-sysv3 exit ;; Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) echo m68k-tektronix-bsd exit ;; *:IRIX*:*:*) echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` exit ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' i*86:AIX:*:*) echo i386-ibm-aix exit ;; ia64:AIX:*:*) if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` else IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} exit ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #include main() { if (!__power_pc()) exit(1); puts("powerpc-ibm-aix3.2.5"); exit(0); } EOF if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` then echo "$SYSTEM_NAME" else echo rs6000-ibm-aix3.2.5 fi elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then echo rs6000-ibm-aix3.2.4 else echo rs6000-ibm-aix3.2 fi exit ;; *:AIX:*:[4567]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc fi if [ -x /usr/bin/oslevel ] ; then IBM_REV=`/usr/bin/oslevel` else IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi echo ${IBM_ARCH}-ibm-aix${IBM_REV} exit ;; *:AIX:*:*) echo rs6000-ibm-aix exit ;; ibmrt:4.4BSD:*|romp-ibm:BSD:*) echo romp-ibm-bsd4.4 exit ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to exit ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) echo rs6000-bull-bosx exit ;; DPX/2?00:B.O.S.:*:*) echo m68k-bull-sysv3 exit ;; 9000/[34]??:4.3bsd:1.*:*) echo m68k-hp-bsd exit ;; hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) echo m68k-hp-bsd4.4 exit ;; 9000/[34678]??:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` case "${UNAME_MACHINE}" in 9000/31? ) HP_ARCH=m68000 ;; 9000/[34]?? ) HP_ARCH=m68k ;; 9000/[678][0-9][0-9]) if [ -x /usr/bin/getconf ]; then sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` case "${sc_cpu_version}" in 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 532) # CPU_PA_RISC2_0 case "${sc_kernel_bits}" in 32) HP_ARCH="hppa2.0n" ;; 64) HP_ARCH="hppa2.0w" ;; '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 esac ;; esac fi if [ "${HP_ARCH}" = "" ]; then eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #define _HPUX_SOURCE #include #include int main () { #if defined(_SC_KERNEL_BITS) long bits = sysconf(_SC_KERNEL_BITS); #endif long cpu = sysconf (_SC_CPU_VERSION); switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0"); break; case CPU_PA_RISC1_1: puts ("hppa1.1"); break; case CPU_PA_RISC2_0: #if defined(_SC_KERNEL_BITS) switch (bits) { case 64: puts ("hppa2.0w"); break; case 32: puts ("hppa2.0n"); break; default: puts ("hppa2.0"); break; } break; #else /* !defined(_SC_KERNEL_BITS) */ puts ("hppa2.0"); break; #endif default: puts ("hppa1.0"); break; } exit (0); } EOF (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac if [ ${HP_ARCH} = "hppa2.0w" ] then eval $set_cc_for_build # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler # generating 64-bit code. GNU and HP use different nomenclature: # # $ CC_FOR_BUILD=cc ./config.guess # => hppa2.0w-hp-hpux11.23 # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess # => hppa64-hp-hpux11.23 if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | grep -q __LP64__ then HP_ARCH="hppa2.0w" else HP_ARCH="hppa64" fi fi echo ${HP_ARCH}-hp-hpux${HPUX_REV} exit ;; ia64:HP-UX:*:*) HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` echo ia64-hp-hpux${HPUX_REV} exit ;; 3050*:HI-UX:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #include int main () { long cpu = sysconf (_SC_CPU_VERSION); /* The order matters, because CPU_IS_HP_MC68K erroneously returns true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct results, however. */ if (CPU_IS_PA_RISC (cpu)) { switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; default: puts ("hppa-hitachi-hiuxwe2"); break; } } else if (CPU_IS_HP_MC68K (cpu)) puts ("m68k-hitachi-hiuxwe2"); else puts ("unknown-hitachi-hiuxwe2"); exit (0); } EOF $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && { echo "$SYSTEM_NAME"; exit; } echo unknown-hitachi-hiuxwe2 exit ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) echo hppa1.1-hp-bsd exit ;; 9000/8??:4.3bsd:*:*) echo hppa1.0-hp-bsd exit ;; *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) echo hppa1.0-hp-mpeix exit ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) echo hppa1.1-hp-osf exit ;; hp8??:OSF1:*:*) echo hppa1.0-hp-osf exit ;; i*86:OSF1:*:*) if [ -x /usr/sbin/sysversion ] ; then echo ${UNAME_MACHINE}-unknown-osf1mk else echo ${UNAME_MACHINE}-unknown-osf1 fi exit ;; parisc*:Lites*:*:*) echo hppa1.1-hp-lites exit ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) echo c1-convex-bsd exit ;; C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi exit ;; C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) echo c34-convex-bsd exit ;; C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) echo c38-convex-bsd exit ;; C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) echo c4-convex-bsd exit ;; CRAY*Y-MP:*:*:*) echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*[A-Z]90:*:*:*) echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ -e 's/\.[^.]*$/.X/' exit ;; CRAY*TS:*:*:*) echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*T3E:*:*:*) echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*SV1:*:*:*) echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; *:UNICOS/mp:*:*) echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; 5000:UNIX_System_V:4.*:*) FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} exit ;; sparc*:BSD/OS:*:*) echo sparc-unknown-bsdi${UNAME_RELEASE} exit ;; *:BSD/OS:*:*) echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} exit ;; *:FreeBSD:*:*) UNAME_PROCESSOR=`/usr/bin/uname -p` case ${UNAME_PROCESSOR} in amd64) echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; *) echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; esac exit ;; i*:CYGWIN*:*) echo ${UNAME_MACHINE}-pc-cygwin exit ;; *:MINGW64*:*) echo ${UNAME_MACHINE}-pc-mingw64 exit ;; *:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 exit ;; i*:MSYS*:*) echo ${UNAME_MACHINE}-pc-msys exit ;; i*:windows32*:*) # uname -m includes "-pc" on this system. echo ${UNAME_MACHINE}-mingw32 exit ;; i*:PW*:*) echo ${UNAME_MACHINE}-pc-pw32 exit ;; *:Interix*:*) case ${UNAME_MACHINE} in x86) echo i586-pc-interix${UNAME_RELEASE} exit ;; authenticamd | genuineintel | EM64T) echo x86_64-unknown-interix${UNAME_RELEASE} exit ;; IA64) echo ia64-unknown-interix${UNAME_RELEASE} exit ;; esac ;; [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) echo i${UNAME_MACHINE}-pc-mks exit ;; 8664:Windows_NT:*) echo x86_64-pc-mks exit ;; i*:Windows_NT*:* | Pentium*:Windows_NT*:*) # How do we know it's Interix rather than the generic POSIX subsystem? # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we # UNAME_MACHINE based on the output of uname instead of i386? echo i586-pc-interix exit ;; i*:UWIN*:*) echo ${UNAME_MACHINE}-pc-uwin exit ;; amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) echo x86_64-unknown-cygwin exit ;; p*:CYGWIN*:*) echo powerpcle-unknown-cygwin exit ;; prep*:SunOS:5.*:*) echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` exit ;; *:GNU:*:*) # the GNU system echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` exit ;; *:GNU/*:*:*) # other systems with GNU libc and userland echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC} exit ;; i*86:Minix:*:*) echo ${UNAME_MACHINE}-pc-minix exit ;; aarch64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; aarch64_be:Linux:*:*) UNAME_MACHINE=aarch64_be echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in EV5) UNAME_MACHINE=alphaev5 ;; EV56) UNAME_MACHINE=alphaev56 ;; PCA56) UNAME_MACHINE=alphapca56 ;; PCA57) UNAME_MACHINE=alphapca56 ;; EV6) UNAME_MACHINE=alphaev6 ;; EV67) UNAME_MACHINE=alphaev67 ;; EV68*) UNAME_MACHINE=alphaev68 ;; esac objdump --private-headers /bin/sh | grep -q ld.so.1 if test "$?" = 0 ; then LIBC="gnulibc1" ; fi echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; arc:Linux:*:* | arceb:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; arm*:Linux:*:*) eval $set_cc_for_build if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_EABI__ then echo ${UNAME_MACHINE}-unknown-linux-${LIBC} else if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi else echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf fi fi exit ;; avr32*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; cris:Linux:*:*) echo ${UNAME_MACHINE}-axis-linux-${LIBC} exit ;; crisv32:Linux:*:*) echo ${UNAME_MACHINE}-axis-linux-${LIBC} exit ;; frv:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; hexagon:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; i*86:Linux:*:*) echo ${UNAME_MACHINE}-pc-linux-${LIBC} exit ;; ia64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; m32r*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; m68*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; mips:Linux:*:* | mips64:Linux:*:*) eval $set_cc_for_build sed 's/^ //' << EOF >$dummy.c #undef CPU #undef ${UNAME_MACHINE} #undef ${UNAME_MACHINE}el #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) CPU=${UNAME_MACHINE}el #else #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) CPU=${UNAME_MACHINE} #else CPU= #endif #endif EOF eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; } ;; or1k:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; or32:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; padre:Linux:*:*) echo sparc-unknown-linux-${LIBC} exit ;; parisc64:Linux:*:* | hppa64:Linux:*:*) echo hppa64-unknown-linux-${LIBC} exit ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in PA7*) echo hppa1.1-unknown-linux-${LIBC} ;; PA8*) echo hppa2.0-unknown-linux-${LIBC} ;; *) echo hppa-unknown-linux-${LIBC} ;; esac exit ;; ppc64:Linux:*:*) echo powerpc64-unknown-linux-${LIBC} exit ;; ppc:Linux:*:*) echo powerpc-unknown-linux-${LIBC} exit ;; ppc64le:Linux:*:*) echo powerpc64le-unknown-linux-${LIBC} exit ;; ppcle:Linux:*:*) echo powerpcle-unknown-linux-${LIBC} exit ;; s390:Linux:*:* | s390x:Linux:*:*) echo ${UNAME_MACHINE}-ibm-linux-${LIBC} exit ;; sh64*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; sh*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; sparc:Linux:*:* | sparc64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; tile*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; vax:Linux:*:*) echo ${UNAME_MACHINE}-dec-linux-${LIBC} exit ;; x86_64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; xtensa*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. # earlier versions are messed up and put the nodename in both # sysname and nodename. echo i386-sequent-sysv4 exit ;; i*86:UNIX_SV:4.2MP:2.*) # Unixware is an offshoot of SVR4, but it has its own version # number series starting with 2... # I am not positive that other SVR4 systems won't match this, # I just have to hope. -- rms. # Use sysv4.2uw... so that sysv4* matches it. echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} exit ;; i*86:OS/2:*:*) # If we were able to find `uname', then EMX Unix compatibility # is probably installed. echo ${UNAME_MACHINE}-pc-os2-emx exit ;; i*86:XTS-300:*:STOP) echo ${UNAME_MACHINE}-unknown-stop exit ;; i*86:atheos:*:*) echo ${UNAME_MACHINE}-unknown-atheos exit ;; i*86:syllable:*:*) echo ${UNAME_MACHINE}-pc-syllable exit ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) echo i386-unknown-lynxos${UNAME_RELEASE} exit ;; i*86:*DOS:*:*) echo ${UNAME_MACHINE}-pc-msdosdjgpp exit ;; i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} else echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} fi exit ;; i*86:*:5:[678]*) # UnixWare 7.x, OpenUNIX and OpenServer 6. case `/bin/uname -X | grep "^Machine"` in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} exit ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ && UNAME_MACHINE=i586 (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ && UNAME_MACHINE=i686 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ && UNAME_MACHINE=i686 echo ${UNAME_MACHINE}-pc-sco$UNAME_REL else echo ${UNAME_MACHINE}-pc-sysv32 fi exit ;; pc:*:*:*) # Left here for compatibility: # uname -m prints for DJGPP always 'pc', but it prints nothing about # the processor, so we play safe by assuming i586. # Note: whatever this is, it MUST be the same as what config.sub # prints for the "djgpp" host, or else GDB configury will decide that # this is a cross-build. echo i586-pc-msdosdjgpp exit ;; Intel:Mach:3*:*) echo i386-pc-mach3 exit ;; paragon:*:*:*) echo i860-intel-osf1 exit ;; i860:*:4.*:*) # i860-SVR4 if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 fi exit ;; mini*:CTIX:SYS*5:*) # "miniframe" echo m68010-convergent-sysv exit ;; mc68k:UNIX:SYSTEM5:3.51m) echo m68k-convergent-sysv exit ;; M680?0:D-NIX:5.3:*) echo m68k-diab-dnix exit ;; M68*:*:R3V[5678]*:*) test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4; exit; } ;; NCR*:*:4.2:* | MPRAS*:*:4.2:*) OS_REL='.3' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) echo m68k-unknown-lynxos${UNAME_RELEASE} exit ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 exit ;; TSUNAMI:LynxOS:2.*:*) echo sparc-unknown-lynxos${UNAME_RELEASE} exit ;; rs6000:LynxOS:2.*:*) echo rs6000-unknown-lynxos${UNAME_RELEASE} exit ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) echo powerpc-unknown-lynxos${UNAME_RELEASE} exit ;; SM[BE]S:UNIX_SV:*:*) echo mips-dde-sysv${UNAME_RELEASE} exit ;; RM*:ReliantUNIX-*:*:*) echo mips-sni-sysv4 exit ;; RM*:SINIX-*:*:*) echo mips-sni-sysv4 exit ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then UNAME_MACHINE=`(uname -p) 2>/dev/null` echo ${UNAME_MACHINE}-sni-sysv4 else echo ns32k-sni-sysv fi exit ;; PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort # says echo i586-unisys-sysv4 exit ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm echo hppa1.1-stratus-sysv4 exit ;; *:*:*:FTX*) # From seanf@swdc.stratus.com. echo i860-stratus-sysv4 exit ;; i*86:VOS:*:*) # From Paul.Green@stratus.com. echo ${UNAME_MACHINE}-stratus-vos exit ;; *:VOS:*:*) # From Paul.Green@stratus.com. echo hppa1.1-stratus-vos exit ;; mc68*:A/UX:*:*) echo m68k-apple-aux${UNAME_RELEASE} exit ;; news*:NEWS-OS:6*:*) echo mips-sony-newsos6 exit ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if [ -d /usr/nec ]; then echo mips-nec-sysv${UNAME_RELEASE} else echo mips-unknown-sysv${UNAME_RELEASE} fi exit ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. echo powerpc-be-beos exit ;; BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. echo powerpc-apple-beos exit ;; BePC:BeOS:*:*) # BeOS running on Intel PC compatible. echo i586-pc-beos exit ;; BePC:Haiku:*:*) # Haiku running on Intel PC compatible. echo i586-pc-haiku exit ;; x86_64:Haiku:*:*) echo x86_64-unknown-haiku exit ;; SX-4:SUPER-UX:*:*) echo sx4-nec-superux${UNAME_RELEASE} exit ;; SX-5:SUPER-UX:*:*) echo sx5-nec-superux${UNAME_RELEASE} exit ;; SX-6:SUPER-UX:*:*) echo sx6-nec-superux${UNAME_RELEASE} exit ;; SX-7:SUPER-UX:*:*) echo sx7-nec-superux${UNAME_RELEASE} exit ;; SX-8:SUPER-UX:*:*) echo sx8-nec-superux${UNAME_RELEASE} exit ;; SX-8R:SUPER-UX:*:*) echo sx8r-nec-superux${UNAME_RELEASE} exit ;; Power*:Rhapsody:*:*) echo powerpc-apple-rhapsody${UNAME_RELEASE} exit ;; *:Rhapsody:*:*) echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} exit ;; *:Darwin:*:*) UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown eval $set_cc_for_build if test "$UNAME_PROCESSOR" = unknown ; then UNAME_PROCESSOR=powerpc fi if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then case $UNAME_PROCESSOR in i386) UNAME_PROCESSOR=x86_64 ;; powerpc) UNAME_PROCESSOR=powerpc64 ;; esac fi fi echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` if test "$UNAME_PROCESSOR" = "x86"; then UNAME_PROCESSOR=i386 UNAME_MACHINE=pc fi echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} exit ;; *:QNX:*:4*) echo i386-pc-qnx exit ;; NEO-?:NONSTOP_KERNEL:*:*) echo neo-tandem-nsk${UNAME_RELEASE} exit ;; NSE-*:NONSTOP_KERNEL:*:*) echo nse-tandem-nsk${UNAME_RELEASE} exit ;; NSR-?:NONSTOP_KERNEL:*:*) echo nsr-tandem-nsk${UNAME_RELEASE} exit ;; *:NonStop-UX:*:*) echo mips-compaq-nonstopux exit ;; BS2000:POSIX*:*:*) echo bs2000-siemens-sysv exit ;; DS/*:UNIX_System_V:*:*) echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} exit ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 # operating systems. if test "$cputype" = "386"; then UNAME_MACHINE=i386 else UNAME_MACHINE="$cputype" fi echo ${UNAME_MACHINE}-unknown-plan9 exit ;; *:TOPS-10:*:*) echo pdp10-unknown-tops10 exit ;; *:TENEX:*:*) echo pdp10-unknown-tenex exit ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) echo pdp10-dec-tops20 exit ;; XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) echo pdp10-xkl-tops20 exit ;; *:TOPS-20:*:*) echo pdp10-unknown-tops20 exit ;; *:ITS:*:*) echo pdp10-unknown-its exit ;; SEI:*:*:SEIUX) echo mips-sei-seiux${UNAME_RELEASE} exit ;; *:DragonFly:*:*) echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` exit ;; *:*VMS:*:*) UNAME_MACHINE=`(uname -p) 2>/dev/null` case "${UNAME_MACHINE}" in A*) echo alpha-dec-vms ; exit ;; I*) echo ia64-dec-vms ; exit ;; V*) echo vax-dec-vms ; exit ;; esac ;; *:XENIX:*:SysV) echo i386-pc-xenix exit ;; i*86:skyos:*:*) echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' exit ;; i*86:rdos:*:*) echo ${UNAME_MACHINE}-pc-rdos exit ;; i*86:AROS:*:*) echo ${UNAME_MACHINE}-pc-aros exit ;; x86_64:VMkernel:*:*) echo ${UNAME_MACHINE}-unknown-esx exit ;; esac eval $set_cc_for_build cat >$dummy.c < # include #endif main () { #if defined (sony) #if defined (MIPSEB) /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, I don't know.... */ printf ("mips-sony-bsd\n"); exit (0); #else #include printf ("m68k-sony-newsos%s\n", #ifdef NEWSOS4 "4" #else "" #endif ); exit (0); #endif #endif #if defined (__arm) && defined (__acorn) && defined (__unix) printf ("arm-acorn-riscix\n"); exit (0); #endif #if defined (hp300) && !defined (hpux) printf ("m68k-hp-bsd\n"); exit (0); #endif #if defined (NeXT) #if !defined (__ARCHITECTURE__) #define __ARCHITECTURE__ "m68k" #endif int version; version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; if (version < 4) printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); else printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); exit (0); #endif #if defined (MULTIMAX) || defined (n16) #if defined (UMAXV) printf ("ns32k-encore-sysv\n"); exit (0); #else #if defined (CMU) printf ("ns32k-encore-mach\n"); exit (0); #else printf ("ns32k-encore-bsd\n"); exit (0); #endif #endif #endif #if defined (__386BSD__) printf ("i386-pc-bsd\n"); exit (0); #endif #if defined (sequent) #if defined (i386) printf ("i386-sequent-dynix\n"); exit (0); #endif #if defined (ns32000) printf ("ns32k-sequent-dynix\n"); exit (0); #endif #endif #if defined (_SEQUENT_) struct utsname un; uname(&un); if (strncmp(un.version, "V2", 2) == 0) { printf ("i386-sequent-ptx2\n"); exit (0); } if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ printf ("i386-sequent-ptx1\n"); exit (0); } printf ("i386-sequent-ptx\n"); exit (0); #endif #if defined (vax) # if !defined (ultrix) # include # if defined (BSD) # if BSD == 43 printf ("vax-dec-bsd4.3\n"); exit (0); # else # if BSD == 199006 printf ("vax-dec-bsd4.3reno\n"); exit (0); # else printf ("vax-dec-bsd\n"); exit (0); # endif # endif # else printf ("vax-dec-bsd\n"); exit (0); # endif # else printf ("vax-dec-ultrix\n"); exit (0); # endif #endif #if defined (alliant) && defined (i860) printf ("i860-alliant-bsd\n"); exit (0); #endif exit (1); } EOF $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && { echo "$SYSTEM_NAME"; exit; } # Apollos put the system type in the environment. test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } # Convex versions that predate uname can use getsysinfo(1) if [ -x /usr/convex/getsysinfo ] then case `getsysinfo -f cpu_type` in c1*) echo c1-convex-bsd exit ;; c2*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi exit ;; c34*) echo c34-convex-bsd exit ;; c38*) echo c38-convex-bsd exit ;; c4*) echo c4-convex-bsd exit ;; esac fi cat >&2 < in order to provide the needed information to handle your system. config.guess timestamp = $timestamp uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` /bin/uname -X = `(/bin/uname -X) 2>/dev/null` hostinfo = `(hostinfo) 2>/dev/null` /bin/universe = `(/bin/universe) 2>/dev/null` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` /bin/arch = `(/bin/arch) 2>/dev/null` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` UNAME_MACHINE = ${UNAME_MACHINE} UNAME_RELEASE = ${UNAME_RELEASE} UNAME_SYSTEM = ${UNAME_SYSTEM} UNAME_VERSION = ${UNAME_VERSION} EOF exit 1 # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: vnstat-2.9/Makefile.in0000644000000000000000000045630614173305712013467 0ustar rootroot# Makefile.in generated by automake 1.16.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2018 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ bin_PROGRAMS = vnstat$(EXEEXT) $(am__EXEEXT_1) sbin_PROGRAMS = vnstatd$(EXEEXT) @HAVE_LIBGD_TRUE@am__append_1 = vnstati @HAVE_CHECK_TRUE@TESTS = check_vnstat$(EXEEXT) @HAVE_CHECK_TRUE@check_PROGRAMS = check_vnstat$(EXEEXT) @HAVE_CHECK_TRUE@@HAVE_LIBGD_TRUE@am__append_2 = -DHAVE_IMAGE @HAVE_CHECK_TRUE@@HAVE_LIBGD_TRUE@am__append_3 = @IMAGELIBS@ @HAVE_CHECK_TRUE@@HAVE_LIBGD_TRUE@am__append_4 = tests/image_tests.c tests/image_tests.h \ @HAVE_CHECK_TRUE@@HAVE_LIBGD_TRUE@ src/image.c src/image.h \ @HAVE_CHECK_TRUE@@HAVE_LIBGD_TRUE@ src/image_support.c src/image_support.h subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ $(am__configure_deps) $(am__DIST_COMMON) am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = @HAVE_LIBGD_TRUE@am__EXEEXT_1 = vnstati$(EXEEXT) am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(sbindir)" \ "$(DESTDIR)$(man1dir)" "$(DESTDIR)$(man5dir)" \ "$(DESTDIR)$(man8dir)" PROGRAMS = $(bin_PROGRAMS) $(sbin_PROGRAMS) am__check_vnstat_SOURCES_DIST = tests/vnstat_tests.c \ tests/vnstat_tests.h tests/common_tests.c tests/common_tests.h \ tests/database_tests.c tests/database_tests.h \ tests/dbsql_tests.c tests/dbsql_tests.h \ tests/datacache_tests.c tests/datacache_tests.h \ tests/config_tests.c tests/config_tests.h tests/ifinfo_tests.c \ tests/ifinfo_tests.h tests/misc_tests.c tests/misc_tests.h \ tests/fs_tests.c tests/fs_tests.h tests/id_tests.c \ tests/id_tests.h tests/iflist_tests.c tests/iflist_tests.h \ tests/cli_tests.c tests/cli_tests.h tests/parseargs_tests.c \ tests/parseargs_tests.h tests/daemon_tests.c \ tests/daemon_tests.h src/cfg.c src/cfg.h src/cfgoutput.c \ src/cfgoutput.h src/common.c src/common.h src/daemon.c \ src/daemon.h src/dbsql.c src/dbsql.h src/dbaccess.c \ src/dbaccess.h src/datacache.c src/datacache.h src/dbshow.c \ src/dbshow.h src/dbjson.c src/dbjson.h src/dbxml.c src/dbxml.h \ src/ibw.c src/ibw.h src/ifinfo.c src/ifinfo.h src/iflist.c \ src/iflist.h src/misc.c src/misc.h src/fs.c src/fs.h src/id.c \ src/id.h src/vnstat_func.c src/vnstat_func.h src/traffic.c \ src/traffic.h tests/image_tests.c tests/image_tests.h \ src/image.c src/image.h src/image_support.c \ src/image_support.h am__dirstamp = $(am__leading_dot)dirstamp @HAVE_CHECK_TRUE@@HAVE_LIBGD_TRUE@am__objects_1 = tests/check_vnstat-image_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@@HAVE_LIBGD_TRUE@ src/check_vnstat-image.$(OBJEXT) \ @HAVE_CHECK_TRUE@@HAVE_LIBGD_TRUE@ src/check_vnstat-image_support.$(OBJEXT) @HAVE_CHECK_TRUE@am_check_vnstat_OBJECTS = \ @HAVE_CHECK_TRUE@ tests/check_vnstat-vnstat_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@ tests/check_vnstat-common_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@ tests/check_vnstat-database_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@ tests/check_vnstat-dbsql_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@ tests/check_vnstat-datacache_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@ tests/check_vnstat-config_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@ tests/check_vnstat-ifinfo_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@ tests/check_vnstat-misc_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@ tests/check_vnstat-fs_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@ tests/check_vnstat-id_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@ tests/check_vnstat-iflist_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@ tests/check_vnstat-cli_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@ tests/check_vnstat-parseargs_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@ tests/check_vnstat-daemon_tests.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-cfg.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-cfgoutput.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-common.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-daemon.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-dbsql.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-dbaccess.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-datacache.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-dbshow.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-dbjson.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-dbxml.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-ibw.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-ifinfo.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-iflist.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-misc.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-fs.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-id.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-vnstat_func.$(OBJEXT) \ @HAVE_CHECK_TRUE@ src/check_vnstat-traffic.$(OBJEXT) \ @HAVE_CHECK_TRUE@ $(am__objects_1) check_vnstat_OBJECTS = $(am_check_vnstat_OBJECTS) am__DEPENDENCIES_1 = @HAVE_CHECK_TRUE@check_vnstat_DEPENDENCIES = $(am__DEPENDENCIES_1) check_vnstat_LINK = $(CCLD) $(check_vnstat_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ am_vnstat_OBJECTS = src/vnstat.$(OBJEXT) src/vnstat_func.$(OBJEXT) \ src/ifinfo.$(OBJEXT) src/iflist.$(OBJEXT) src/dbsql.$(OBJEXT) \ src/dbxml.$(OBJEXT) src/dbjson.$(OBJEXT) src/dbshow.$(OBJEXT) \ src/common.$(OBJEXT) src/misc.$(OBJEXT) src/cfg.$(OBJEXT) \ src/cfgoutput.$(OBJEXT) src/ibw.$(OBJEXT) src/fs.$(OBJEXT) \ src/id.$(OBJEXT) src/traffic.$(OBJEXT) vnstat_OBJECTS = $(am_vnstat_OBJECTS) vnstat_LDADD = $(LDADD) am_vnstatd_OBJECTS = src/vnstatd.$(OBJEXT) src/ifinfo.$(OBJEXT) \ src/iflist.$(OBJEXT) src/dbsql.$(OBJEXT) \ src/dbaccess.$(OBJEXT) src/datacache.$(OBJEXT) \ src/common.$(OBJEXT) src/misc.$(OBJEXT) src/cfg.$(OBJEXT) \ src/ibw.$(OBJEXT) src/fs.$(OBJEXT) src/id.$(OBJEXT) \ src/daemon.$(OBJEXT) vnstatd_OBJECTS = $(am_vnstatd_OBJECTS) vnstatd_LDADD = $(LDADD) am_vnstati_OBJECTS = src/vnstati.$(OBJEXT) src/iflist.$(OBJEXT) \ src/image.$(OBJEXT) src/image_support.$(OBJEXT) \ src/dbsql.$(OBJEXT) src/common.$(OBJEXT) src/misc.$(OBJEXT) \ src/fs.$(OBJEXT) src/id.$(OBJEXT) src/cfg.$(OBJEXT) vnstati_OBJECTS = $(am_vnstati_OBJECTS) vnstati_DEPENDENCIES = AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp am__maybe_remake_depfiles = depfiles am__depfiles_remade = src/$(DEPDIR)/cfg.Po src/$(DEPDIR)/cfgoutput.Po \ src/$(DEPDIR)/check_vnstat-cfg.Po \ src/$(DEPDIR)/check_vnstat-cfgoutput.Po \ src/$(DEPDIR)/check_vnstat-common.Po \ src/$(DEPDIR)/check_vnstat-daemon.Po \ src/$(DEPDIR)/check_vnstat-datacache.Po \ src/$(DEPDIR)/check_vnstat-dbaccess.Po \ src/$(DEPDIR)/check_vnstat-dbjson.Po \ src/$(DEPDIR)/check_vnstat-dbshow.Po \ src/$(DEPDIR)/check_vnstat-dbsql.Po \ src/$(DEPDIR)/check_vnstat-dbxml.Po \ src/$(DEPDIR)/check_vnstat-fs.Po \ src/$(DEPDIR)/check_vnstat-ibw.Po \ src/$(DEPDIR)/check_vnstat-id.Po \ src/$(DEPDIR)/check_vnstat-ifinfo.Po \ src/$(DEPDIR)/check_vnstat-iflist.Po \ src/$(DEPDIR)/check_vnstat-image.Po \ src/$(DEPDIR)/check_vnstat-image_support.Po \ src/$(DEPDIR)/check_vnstat-misc.Po \ src/$(DEPDIR)/check_vnstat-traffic.Po \ src/$(DEPDIR)/check_vnstat-vnstat_func.Po \ src/$(DEPDIR)/common.Po src/$(DEPDIR)/daemon.Po \ src/$(DEPDIR)/datacache.Po src/$(DEPDIR)/dbaccess.Po \ src/$(DEPDIR)/dbjson.Po src/$(DEPDIR)/dbshow.Po \ src/$(DEPDIR)/dbsql.Po src/$(DEPDIR)/dbxml.Po \ src/$(DEPDIR)/fs.Po src/$(DEPDIR)/ibw.Po src/$(DEPDIR)/id.Po \ src/$(DEPDIR)/ifinfo.Po src/$(DEPDIR)/iflist.Po \ src/$(DEPDIR)/image.Po src/$(DEPDIR)/image_support.Po \ src/$(DEPDIR)/misc.Po src/$(DEPDIR)/traffic.Po \ src/$(DEPDIR)/vnstat.Po src/$(DEPDIR)/vnstat_func.Po \ src/$(DEPDIR)/vnstatd.Po src/$(DEPDIR)/vnstati.Po \ tests/$(DEPDIR)/check_vnstat-cli_tests.Po \ tests/$(DEPDIR)/check_vnstat-common_tests.Po \ tests/$(DEPDIR)/check_vnstat-config_tests.Po \ tests/$(DEPDIR)/check_vnstat-daemon_tests.Po \ tests/$(DEPDIR)/check_vnstat-database_tests.Po \ tests/$(DEPDIR)/check_vnstat-datacache_tests.Po \ tests/$(DEPDIR)/check_vnstat-dbsql_tests.Po \ tests/$(DEPDIR)/check_vnstat-fs_tests.Po \ tests/$(DEPDIR)/check_vnstat-id_tests.Po \ tests/$(DEPDIR)/check_vnstat-ifinfo_tests.Po \ tests/$(DEPDIR)/check_vnstat-iflist_tests.Po \ tests/$(DEPDIR)/check_vnstat-image_tests.Po \ tests/$(DEPDIR)/check_vnstat-misc_tests.Po \ tests/$(DEPDIR)/check_vnstat-parseargs_tests.Po \ tests/$(DEPDIR)/check_vnstat-vnstat_tests.Po am__mv = mv -f AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) AM_V_CC = $(am__v_CC_@AM_V@) am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) am__v_CC_0 = @echo " CC " $@; am__v_CC_1 = CCLD = $(CC) LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = SOURCES = $(check_vnstat_SOURCES) $(vnstat_SOURCES) $(vnstatd_SOURCES) \ $(vnstati_SOURCES) DIST_SOURCES = $(am__check_vnstat_SOURCES_DIST) $(vnstat_SOURCES) \ $(vnstatd_SOURCES) $(vnstati_SOURCES) RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ install-data-recursive install-dvi-recursive \ install-exec-recursive install-html-recursive \ install-info-recursive install-pdf-recursive \ install-ps-recursive install-recursive installcheck-recursive \ installdirs-recursive pdf-recursive ps-recursive \ tags-recursive uninstall-recursive am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__uninstall_files_from_dir = { \ test -z "$$files" \ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && rm -f $$files; }; \ } man1dir = $(mandir)/man1 man5dir = $(mandir)/man5 man8dir = $(mandir)/man8 NROFF = nroff MANS = $(dist_man_MANS) RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ distclean-recursive maintainer-clean-recursive am__recursive_targets = \ $(RECURSIVE_TARGETS) \ $(RECURSIVE_CLEAN_TARGETS) \ $(am__extra_recursive_targets) AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ cscope check recheck distdir distdir-am dist dist-all \ distcheck am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` ETAGS = etags CTAGS = ctags CSCOPE = cscope am__tty_colors_dummy = \ mgn= red= grn= lgn= blu= brg= std=; \ am__color_tests=no am__tty_colors = { \ $(am__tty_colors_dummy); \ if test "X$(AM_COLOR_TESTS)" = Xno; then \ am__color_tests=no; \ elif test "X$(AM_COLOR_TESTS)" = Xalways; then \ am__color_tests=yes; \ elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \ am__color_tests=yes; \ fi; \ if test $$am__color_tests = yes; then \ red=''; \ grn=''; \ lgn=''; \ blu=''; \ mgn=''; \ brg=''; \ std=''; \ fi; \ } am__recheck_rx = ^[ ]*:recheck:[ ]* am__global_test_result_rx = ^[ ]*:global-test-result:[ ]* am__copy_in_global_log_rx = ^[ ]*:copy-in-global-log:[ ]* # A command that, given a newline-separated list of test names on the # standard input, print the name of the tests that are to be re-run # upon "make recheck". am__list_recheck_tests = $(AWK) '{ \ recheck = 1; \ while ((rc = (getline line < ($$0 ".trs"))) != 0) \ { \ if (rc < 0) \ { \ if ((getline line2 < ($$0 ".log")) < 0) \ recheck = 0; \ break; \ } \ else if (line ~ /$(am__recheck_rx)[nN][Oo]/) \ { \ recheck = 0; \ break; \ } \ else if (line ~ /$(am__recheck_rx)[yY][eE][sS]/) \ { \ break; \ } \ }; \ if (recheck) \ print $$0; \ close ($$0 ".trs"); \ close ($$0 ".log"); \ }' # A command that, given a newline-separated list of test names on the # standard input, create the global log from their .trs and .log files. am__create_global_log = $(AWK) ' \ function fatal(msg) \ { \ print "fatal: making $@: " msg | "cat >&2"; \ exit 1; \ } \ function rst_section(header) \ { \ print header; \ len = length(header); \ for (i = 1; i <= len; i = i + 1) \ printf "="; \ printf "\n\n"; \ } \ { \ copy_in_global_log = 1; \ global_test_result = "RUN"; \ while ((rc = (getline line < ($$0 ".trs"))) != 0) \ { \ if (rc < 0) \ fatal("failed to read from " $$0 ".trs"); \ if (line ~ /$(am__global_test_result_rx)/) \ { \ sub("$(am__global_test_result_rx)", "", line); \ sub("[ ]*$$", "", line); \ global_test_result = line; \ } \ else if (line ~ /$(am__copy_in_global_log_rx)[nN][oO]/) \ copy_in_global_log = 0; \ }; \ if (copy_in_global_log) \ { \ rst_section(global_test_result ": " $$0); \ while ((rc = (getline line < ($$0 ".log"))) != 0) \ { \ if (rc < 0) \ fatal("failed to read from " $$0 ".log"); \ print line; \ }; \ printf "\n"; \ }; \ close ($$0 ".trs"); \ close ($$0 ".log"); \ }' # Restructured Text title. am__rst_title = { sed 's/.*/ & /;h;s/./=/g;p;x;s/ *$$//;p;g' && echo; } # Solaris 10 'make', and several other traditional 'make' implementations, # pass "-e" to $(SHELL), and POSIX 2008 even requires this. Work around it # by disabling -e (using the XSI extension "set +e") if it's set. am__sh_e_setup = case $$- in *e*) set +e;; esac # Default flags passed to test drivers. am__common_driver_flags = \ --color-tests "$$am__color_tests" \ --enable-hard-errors "$$am__enable_hard_errors" \ --expect-failure "$$am__expect_failure" # To be inserted before the command running the test. Creates the # directory for the log if needed. Stores in $dir the directory # containing $f, in $tst the test, in $log the log. Executes the # developer- defined test setup AM_TESTS_ENVIRONMENT (if any), and # passes TESTS_ENVIRONMENT. Set up options for the wrapper that # will run the test scripts (or their associated LOG_COMPILER, if # thy have one). am__check_pre = \ $(am__sh_e_setup); \ $(am__vpath_adj_setup) $(am__vpath_adj) \ $(am__tty_colors); \ srcdir=$(srcdir); export srcdir; \ case "$@" in \ */*) am__odir=`echo "./$@" | sed 's|/[^/]*$$||'`;; \ *) am__odir=.;; \ esac; \ test "x$$am__odir" = x"." || test -d "$$am__odir" \ || $(MKDIR_P) "$$am__odir" || exit $$?; \ if test -f "./$$f"; then dir=./; \ elif test -f "$$f"; then dir=; \ else dir="$(srcdir)/"; fi; \ tst=$$dir$$f; log='$@'; \ if test -n '$(DISABLE_HARD_ERRORS)'; then \ am__enable_hard_errors=no; \ else \ am__enable_hard_errors=yes; \ fi; \ case " $(XFAIL_TESTS) " in \ *[\ \ ]$$f[\ \ ]* | *[\ \ ]$$dir$$f[\ \ ]*) \ am__expect_failure=yes;; \ *) \ am__expect_failure=no;; \ esac; \ $(AM_TESTS_ENVIRONMENT) $(TESTS_ENVIRONMENT) # A shell command to get the names of the tests scripts with any registered # extension removed (i.e., equivalently, the names of the test logs, with # the '.log' extension removed). The result is saved in the shell variable # '$bases'. This honors runtime overriding of TESTS and TEST_LOGS. Sadly, # we cannot use something simpler, involving e.g., "$(TEST_LOGS:.log=)", # since that might cause problem with VPATH rewrites for suffix-less tests. # See also 'test-harness-vpath-rewrite.sh' and 'test-trs-basic.sh'. am__set_TESTS_bases = \ bases='$(TEST_LOGS)'; \ bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \ bases=`echo $$bases` RECHECK_LOGS = $(TEST_LOGS) TEST_SUITE_LOG = test-suite.log TEST_EXTENSIONS = @EXEEXT@ .test LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver LOG_COMPILE = $(LOG_COMPILER) $(AM_LOG_FLAGS) $(LOG_FLAGS) am__set_b = \ case '$@' in \ */*) \ case '$*' in \ */*) b='$*';; \ *) b=`echo '$@' | sed 's/\.log$$//'`; \ esac;; \ *) \ b='$*';; \ esac am__test_logs1 = $(TESTS:=.log) am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log) TEST_LOGS = $(am__test_logs2:.test.log=.log) TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \ $(TEST_LOG_FLAGS) DIST_SUBDIRS = $(SUBDIRS) am__DIST_COMMON = $(dist_man_MANS) $(srcdir)/Makefile.in \ $(top_srcdir)/src/config.h.in COPYING INSTALL README compile \ config.guess config.sub depcomp install-sh missing test-driver DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) am__remove_distdir = \ if test -d "$(distdir)"; then \ find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \ && rm -rf "$(distdir)" \ || { sleep 5 && rm -rf "$(distdir)"; }; \ else :; fi am__post_remove_distdir = $(am__remove_distdir) am__relativize = \ dir0=`pwd`; \ sed_first='s,^\([^/]*\)/.*$$,\1,'; \ sed_rest='s,^[^/]*/*,,'; \ sed_last='s,^.*/\([^/]*\)$$,\1,'; \ sed_butlast='s,/*[^/]*$$,,'; \ while test -n "$$dir1"; do \ first=`echo "$$dir1" | sed -e "$$sed_first"`; \ if test "$$first" != "."; then \ if test "$$first" = ".."; then \ dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ else \ first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ if test "$$first2" = "$$first"; then \ dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ else \ dir2="../$$dir2"; \ fi; \ dir0="$$dir0"/"$$first"; \ fi; \ fi; \ dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ done; \ reldir="$$dir2" DIST_ARCHIVES = $(distdir).tar.gz GZIP_ENV = --best DIST_TARGETS = dist-gzip distuninstallcheck_listfiles = find . -type f -print am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' distcleancheck_listfiles = find . -type f -print ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CFLAG_EXTRAS = @CFLAG_EXTRAS@ CHECK_CFLAGS = @CHECK_CFLAGS@ CHECK_LIBS = @CHECK_LIBS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ GREP = @GREP@ IMAGELIBS = @IMAGELIBS@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ OBJEXT = @OBJEXT@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_CC = @ac_ct_CC@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ SUBDIRS = . AM_CFLAGS = @CFLAG_EXTRAS@ dist_man_MANS = man/vnstat.1 man/vnstat.conf.5 man/vnstatd.8 man/vnstati.1 EXTRA_DIST = cfg examples UPGRADE CHANGES FAQ INSTALL_BSD UNINSTALL vnstati_LDADD = @IMAGELIBS@ vnstat_SOURCES = src/vnstat.c \ src/vnstat_func.c src/vnstat_func.h \ src/ifinfo.c src/ifinfo.h \ src/iflist.c src/iflist.h \ src/dbsql.c src/dbsql.h \ src/dbxml.c src/dbxml.h \ src/dbjson.c src/dbjson.h \ src/dbshow.c src/dbshow.h \ src/common.c src/common.h \ src/misc.c src/misc.h \ src/cfg.c src/cfg.h \ src/cfgoutput.c src/cfgoutput.h \ src/ibw.c src/ibw.h \ src/fs.c src/fs.h \ src/id.c src/id.h \ src/traffic.c src/traffic.h vnstatd_SOURCES = src/vnstatd.c src/vnstatd.h \ src/ifinfo.c src/ifinfo.h \ src/iflist.c src/iflist.h \ src/dbsql.c src/dbsql.h \ src/dbaccess.c src/dbaccess.h \ src/datacache.c src/datacache.h \ src/common.c src/common.h \ src/misc.c src/misc.h \ src/cfg.c src/cfg.h \ src/ibw.c src/ibw.h \ src/fs.c src/fs.h \ src/id.c src/id.h \ src/daemon.c src/daemon.h vnstati_SOURCES = src/vnstati.c src/vnstati.h \ src/iflist.c src/iflist.h \ src/image.c src/image.h \ src/image_support.c src/image_support.h \ src/dbsql.c src/dbsql.h \ src/common.c src/common.h \ src/misc.c src/misc.h \ src/fs.c src/fs.h \ src/id.c src/id.h \ src/cfg.c src/cfg.h @HAVE_CHECK_TRUE@check_vnstat_CFLAGS = @CFLAG_EXTRAS@ @CHECK_CFLAGS@ \ @HAVE_CHECK_TRUE@ -DPROCNETDEV=\"testdir/proc/dev\" \ @HAVE_CHECK_TRUE@ -DSYSCLASSNET=\"testdir/sysclassnet\" \ @HAVE_CHECK_TRUE@ -DCFGFILE=\"tests/vnstat.conf\" \ @HAVE_CHECK_TRUE@ -DCHECK_VNSTAT -I$(top_srcdir)/src \ @HAVE_CHECK_TRUE@ $(am__append_2) @HAVE_CHECK_TRUE@check_vnstat_LDADD = @CHECK_LIBS@ $(am__append_3) @HAVE_CHECK_TRUE@EXTRA_check_vnstat_DEPENDENCIES = tests/vnstat.conf @HAVE_CHECK_TRUE@check_vnstat_SOURCES = tests/vnstat_tests.c \ @HAVE_CHECK_TRUE@ tests/vnstat_tests.h tests/common_tests.c \ @HAVE_CHECK_TRUE@ tests/common_tests.h tests/database_tests.c \ @HAVE_CHECK_TRUE@ tests/database_tests.h tests/dbsql_tests.c \ @HAVE_CHECK_TRUE@ tests/dbsql_tests.h tests/datacache_tests.c \ @HAVE_CHECK_TRUE@ tests/datacache_tests.h tests/config_tests.c \ @HAVE_CHECK_TRUE@ tests/config_tests.h tests/ifinfo_tests.c \ @HAVE_CHECK_TRUE@ tests/ifinfo_tests.h tests/misc_tests.c \ @HAVE_CHECK_TRUE@ tests/misc_tests.h tests/fs_tests.c \ @HAVE_CHECK_TRUE@ tests/fs_tests.h tests/id_tests.c \ @HAVE_CHECK_TRUE@ tests/id_tests.h tests/iflist_tests.c \ @HAVE_CHECK_TRUE@ tests/iflist_tests.h tests/cli_tests.c \ @HAVE_CHECK_TRUE@ tests/cli_tests.h tests/parseargs_tests.c \ @HAVE_CHECK_TRUE@ tests/parseargs_tests.h tests/daemon_tests.c \ @HAVE_CHECK_TRUE@ tests/daemon_tests.h src/cfg.c src/cfg.h \ @HAVE_CHECK_TRUE@ src/cfgoutput.c src/cfgoutput.h src/common.c \ @HAVE_CHECK_TRUE@ src/common.h src/daemon.c src/daemon.h \ @HAVE_CHECK_TRUE@ src/dbsql.c src/dbsql.h src/dbaccess.c \ @HAVE_CHECK_TRUE@ src/dbaccess.h src/datacache.c \ @HAVE_CHECK_TRUE@ src/datacache.h src/dbshow.c src/dbshow.h \ @HAVE_CHECK_TRUE@ src/dbjson.c src/dbjson.h src/dbxml.c \ @HAVE_CHECK_TRUE@ src/dbxml.h src/ibw.c src/ibw.h src/ifinfo.c \ @HAVE_CHECK_TRUE@ src/ifinfo.h src/iflist.c src/iflist.h \ @HAVE_CHECK_TRUE@ src/misc.c src/misc.h src/fs.c src/fs.h \ @HAVE_CHECK_TRUE@ src/id.c src/id.h src/vnstat_func.c \ @HAVE_CHECK_TRUE@ src/vnstat_func.h src/traffic.c src/traffic.h \ @HAVE_CHECK_TRUE@ $(am__append_4) all: all-recursive .SUFFIXES: .SUFFIXES: .c .log .o .obj .test .test$(EXEEXT) .trs am--refresh: Makefile @: $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \ $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \ && exit 0; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --foreign Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ echo ' $(SHELL) ./config.status'; \ $(SHELL) ./config.status;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) $(SHELL) ./config.status --recheck $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) $(am__cd) $(srcdir) && $(AUTOCONF) $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) $(am__aclocal_m4_deps): src/config.h: src/stamp-h1 @test -f $@ || rm -f src/stamp-h1 @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) src/stamp-h1 src/stamp-h1: $(top_srcdir)/src/config.h.in $(top_builddir)/config.status @rm -f src/stamp-h1 cd $(top_builddir) && $(SHELL) ./config.status src/config.h $(top_srcdir)/src/config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) rm -f src/stamp-h1 touch $@ distclean-hdr: -rm -f src/config.h src/stamp-h1 install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ fi; \ for p in $$list; do echo "$$p $$p"; done | \ sed 's/$(EXEEXT)$$//' | \ while read p p1; do if test -f $$p \ ; then echo "$$p"; echo "$$p"; else :; fi; \ done | \ sed -e 'p;s,.*/,,;n;h' \ -e 's|.*|.|' \ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ sed 'N;N;N;s,\n, ,g' | \ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ if ($$2 == $$4) files[d] = files[d] " " $$1; \ else { print "f", $$3 "/" $$4, $$1; } } \ END { for (d in files) print "f", d, files[d] }' | \ while read type dir files; do \ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ test -z "$$files" || { \ echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ } \ ; done uninstall-binPROGRAMS: @$(NORMAL_UNINSTALL) @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ files=`for p in $$list; do echo "$$p"; done | \ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ -e 's/$$/$(EXEEXT)/' \ `; \ test -n "$$list" || exit 0; \ echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(bindir)" && rm -f $$files clean-binPROGRAMS: -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) installcheck-binPROGRAMS: $(bin_PROGRAMS) bad=0; pid=$$$$; list="$(bin_PROGRAMS)"; for p in $$list; do \ case ' $(AM_INSTALLCHECK_STD_OPTIONS_EXEMPT) ' in \ *" $$p "* | *" $(srcdir)/$$p "*) continue;; \ esac; \ f=`echo "$$p" | \ sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ for opt in --help --version; do \ if "$(DESTDIR)$(bindir)/$$f" $$opt >c$${pid}_.out \ 2>c$${pid}_.err &2; bad=1; fi; \ done; \ done; rm -f c$${pid}_.???; exit $$bad clean-checkPROGRAMS: -test -z "$(check_PROGRAMS)" || rm -f $(check_PROGRAMS) install-sbinPROGRAMS: $(sbin_PROGRAMS) @$(NORMAL_INSTALL) @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(sbindir)'"; \ $(MKDIR_P) "$(DESTDIR)$(sbindir)" || exit 1; \ fi; \ for p in $$list; do echo "$$p $$p"; done | \ sed 's/$(EXEEXT)$$//' | \ while read p p1; do if test -f $$p \ ; then echo "$$p"; echo "$$p"; else :; fi; \ done | \ sed -e 'p;s,.*/,,;n;h' \ -e 's|.*|.|' \ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ sed 'N;N;N;s,\n, ,g' | \ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ if ($$2 == $$4) files[d] = files[d] " " $$1; \ else { print "f", $$3 "/" $$4, $$1; } } \ END { for (d in files) print "f", d, files[d] }' | \ while read type dir files; do \ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ test -z "$$files" || { \ echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(sbindir)$$dir'"; \ $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(sbindir)$$dir" || exit $$?; \ } \ ; done uninstall-sbinPROGRAMS: @$(NORMAL_UNINSTALL) @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ files=`for p in $$list; do echo "$$p"; done | \ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ -e 's/$$/$(EXEEXT)/' \ `; \ test -n "$$list" || exit 0; \ echo " ( cd '$(DESTDIR)$(sbindir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(sbindir)" && rm -f $$files clean-sbinPROGRAMS: -test -z "$(sbin_PROGRAMS)" || rm -f $(sbin_PROGRAMS) installcheck-sbinPROGRAMS: $(sbin_PROGRAMS) bad=0; pid=$$$$; list="$(sbin_PROGRAMS)"; for p in $$list; do \ case ' $(AM_INSTALLCHECK_STD_OPTIONS_EXEMPT) ' in \ *" $$p "* | *" $(srcdir)/$$p "*) continue;; \ esac; \ f=`echo "$$p" | \ sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ for opt in --help --version; do \ if "$(DESTDIR)$(sbindir)/$$f" $$opt >c$${pid}_.out \ 2>c$${pid}_.err &2; bad=1; fi; \ done; \ done; rm -f c$${pid}_.???; exit $$bad tests/$(am__dirstamp): @$(MKDIR_P) tests @: > tests/$(am__dirstamp) tests/$(DEPDIR)/$(am__dirstamp): @$(MKDIR_P) tests/$(DEPDIR) @: > tests/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-vnstat_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-common_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-database_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-dbsql_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-datacache_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-config_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-ifinfo_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-misc_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-fs_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-id_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-iflist_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-cli_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-parseargs_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-daemon_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) src/$(am__dirstamp): @$(MKDIR_P) src @: > src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp): @$(MKDIR_P) src/$(DEPDIR) @: > src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-cfg.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-cfgoutput.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-common.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-daemon.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-dbsql.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-dbaccess.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-datacache.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-dbshow.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-dbjson.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-dbxml.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-ibw.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-ifinfo.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-iflist.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-misc.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-fs.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-id.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-vnstat_func.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-traffic.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) tests/check_vnstat-image_tests.$(OBJEXT): tests/$(am__dirstamp) \ tests/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-image.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/check_vnstat-image_support.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) check_vnstat$(EXEEXT): $(check_vnstat_OBJECTS) $(check_vnstat_DEPENDENCIES) $(EXTRA_check_vnstat_DEPENDENCIES) @rm -f check_vnstat$(EXEEXT) $(AM_V_CCLD)$(check_vnstat_LINK) $(check_vnstat_OBJECTS) $(check_vnstat_LDADD) $(LIBS) src/vnstat.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/vnstat_func.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/ifinfo.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/iflist.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/dbsql.$(OBJEXT): src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/dbxml.$(OBJEXT): src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/dbjson.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/dbshow.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/common.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/misc.$(OBJEXT): src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/cfg.$(OBJEXT): src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/cfgoutput.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/ibw.$(OBJEXT): src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/fs.$(OBJEXT): src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/id.$(OBJEXT): src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/traffic.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) vnstat$(EXEEXT): $(vnstat_OBJECTS) $(vnstat_DEPENDENCIES) $(EXTRA_vnstat_DEPENDENCIES) @rm -f vnstat$(EXEEXT) $(AM_V_CCLD)$(LINK) $(vnstat_OBJECTS) $(vnstat_LDADD) $(LIBS) src/vnstatd.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/dbaccess.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/datacache.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/daemon.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) vnstatd$(EXEEXT): $(vnstatd_OBJECTS) $(vnstatd_DEPENDENCIES) $(EXTRA_vnstatd_DEPENDENCIES) @rm -f vnstatd$(EXEEXT) $(AM_V_CCLD)$(LINK) $(vnstatd_OBJECTS) $(vnstatd_LDADD) $(LIBS) src/vnstati.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/image.$(OBJEXT): src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/image_support.$(OBJEXT): src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) vnstati$(EXEEXT): $(vnstati_OBJECTS) $(vnstati_DEPENDENCIES) $(EXTRA_vnstati_DEPENDENCIES) @rm -f vnstati$(EXEEXT) $(AM_V_CCLD)$(LINK) $(vnstati_OBJECTS) $(vnstati_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) -rm -f src/*.$(OBJEXT) -rm -f tests/*.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/cfg.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/cfgoutput.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-cfg.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-cfgoutput.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-common.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-daemon.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-datacache.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbaccess.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbjson.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbshow.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbsql.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-dbxml.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-fs.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-ibw.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-id.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-ifinfo.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-iflist.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-image.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-image_support.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-misc.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-traffic.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/check_vnstat-vnstat_func.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/common.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/daemon.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/datacache.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dbaccess.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dbjson.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dbshow.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dbsql.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dbxml.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/fs.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/ibw.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/id.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/ifinfo.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/iflist.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/image.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/image_support.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/misc.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/traffic.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/vnstat.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/vnstat_func.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/vnstatd.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/vnstati.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-cli_tests.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-common_tests.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-config_tests.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-daemon_tests.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-database_tests.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-datacache_tests.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-dbsql_tests.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-fs_tests.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-id_tests.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-ifinfo_tests.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-iflist_tests.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-image_tests.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-misc_tests.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-parseargs_tests.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/check_vnstat-vnstat_tests.Po@am__quote@ # am--include-marker $(am__depfiles_remade): @$(MKDIR_P) $(@D) @echo '# dummy' >$@-t && $(am__mv) $@-t $@ am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` tests/check_vnstat-vnstat_tests.o: tests/vnstat_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-vnstat_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-vnstat_tests.Tpo -c -o tests/check_vnstat-vnstat_tests.o `test -f 'tests/vnstat_tests.c' || echo '$(srcdir)/'`tests/vnstat_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-vnstat_tests.Tpo tests/$(DEPDIR)/check_vnstat-vnstat_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/vnstat_tests.c' object='tests/check_vnstat-vnstat_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-vnstat_tests.o `test -f 'tests/vnstat_tests.c' || echo '$(srcdir)/'`tests/vnstat_tests.c tests/check_vnstat-vnstat_tests.obj: tests/vnstat_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-vnstat_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-vnstat_tests.Tpo -c -o tests/check_vnstat-vnstat_tests.obj `if test -f 'tests/vnstat_tests.c'; then $(CYGPATH_W) 'tests/vnstat_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/vnstat_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-vnstat_tests.Tpo tests/$(DEPDIR)/check_vnstat-vnstat_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/vnstat_tests.c' object='tests/check_vnstat-vnstat_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-vnstat_tests.obj `if test -f 'tests/vnstat_tests.c'; then $(CYGPATH_W) 'tests/vnstat_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/vnstat_tests.c'; fi` tests/check_vnstat-common_tests.o: tests/common_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-common_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-common_tests.Tpo -c -o tests/check_vnstat-common_tests.o `test -f 'tests/common_tests.c' || echo '$(srcdir)/'`tests/common_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-common_tests.Tpo tests/$(DEPDIR)/check_vnstat-common_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/common_tests.c' object='tests/check_vnstat-common_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-common_tests.o `test -f 'tests/common_tests.c' || echo '$(srcdir)/'`tests/common_tests.c tests/check_vnstat-common_tests.obj: tests/common_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-common_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-common_tests.Tpo -c -o tests/check_vnstat-common_tests.obj `if test -f 'tests/common_tests.c'; then $(CYGPATH_W) 'tests/common_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/common_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-common_tests.Tpo tests/$(DEPDIR)/check_vnstat-common_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/common_tests.c' object='tests/check_vnstat-common_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-common_tests.obj `if test -f 'tests/common_tests.c'; then $(CYGPATH_W) 'tests/common_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/common_tests.c'; fi` tests/check_vnstat-database_tests.o: tests/database_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-database_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-database_tests.Tpo -c -o tests/check_vnstat-database_tests.o `test -f 'tests/database_tests.c' || echo '$(srcdir)/'`tests/database_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-database_tests.Tpo tests/$(DEPDIR)/check_vnstat-database_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/database_tests.c' object='tests/check_vnstat-database_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-database_tests.o `test -f 'tests/database_tests.c' || echo '$(srcdir)/'`tests/database_tests.c tests/check_vnstat-database_tests.obj: tests/database_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-database_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-database_tests.Tpo -c -o tests/check_vnstat-database_tests.obj `if test -f 'tests/database_tests.c'; then $(CYGPATH_W) 'tests/database_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/database_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-database_tests.Tpo tests/$(DEPDIR)/check_vnstat-database_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/database_tests.c' object='tests/check_vnstat-database_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-database_tests.obj `if test -f 'tests/database_tests.c'; then $(CYGPATH_W) 'tests/database_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/database_tests.c'; fi` tests/check_vnstat-dbsql_tests.o: tests/dbsql_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-dbsql_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-dbsql_tests.Tpo -c -o tests/check_vnstat-dbsql_tests.o `test -f 'tests/dbsql_tests.c' || echo '$(srcdir)/'`tests/dbsql_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-dbsql_tests.Tpo tests/$(DEPDIR)/check_vnstat-dbsql_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/dbsql_tests.c' object='tests/check_vnstat-dbsql_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-dbsql_tests.o `test -f 'tests/dbsql_tests.c' || echo '$(srcdir)/'`tests/dbsql_tests.c tests/check_vnstat-dbsql_tests.obj: tests/dbsql_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-dbsql_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-dbsql_tests.Tpo -c -o tests/check_vnstat-dbsql_tests.obj `if test -f 'tests/dbsql_tests.c'; then $(CYGPATH_W) 'tests/dbsql_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/dbsql_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-dbsql_tests.Tpo tests/$(DEPDIR)/check_vnstat-dbsql_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/dbsql_tests.c' object='tests/check_vnstat-dbsql_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-dbsql_tests.obj `if test -f 'tests/dbsql_tests.c'; then $(CYGPATH_W) 'tests/dbsql_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/dbsql_tests.c'; fi` tests/check_vnstat-datacache_tests.o: tests/datacache_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-datacache_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-datacache_tests.Tpo -c -o tests/check_vnstat-datacache_tests.o `test -f 'tests/datacache_tests.c' || echo '$(srcdir)/'`tests/datacache_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-datacache_tests.Tpo tests/$(DEPDIR)/check_vnstat-datacache_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/datacache_tests.c' object='tests/check_vnstat-datacache_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-datacache_tests.o `test -f 'tests/datacache_tests.c' || echo '$(srcdir)/'`tests/datacache_tests.c tests/check_vnstat-datacache_tests.obj: tests/datacache_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-datacache_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-datacache_tests.Tpo -c -o tests/check_vnstat-datacache_tests.obj `if test -f 'tests/datacache_tests.c'; then $(CYGPATH_W) 'tests/datacache_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/datacache_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-datacache_tests.Tpo tests/$(DEPDIR)/check_vnstat-datacache_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/datacache_tests.c' object='tests/check_vnstat-datacache_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-datacache_tests.obj `if test -f 'tests/datacache_tests.c'; then $(CYGPATH_W) 'tests/datacache_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/datacache_tests.c'; fi` tests/check_vnstat-config_tests.o: tests/config_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-config_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-config_tests.Tpo -c -o tests/check_vnstat-config_tests.o `test -f 'tests/config_tests.c' || echo '$(srcdir)/'`tests/config_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-config_tests.Tpo tests/$(DEPDIR)/check_vnstat-config_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/config_tests.c' object='tests/check_vnstat-config_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-config_tests.o `test -f 'tests/config_tests.c' || echo '$(srcdir)/'`tests/config_tests.c tests/check_vnstat-config_tests.obj: tests/config_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-config_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-config_tests.Tpo -c -o tests/check_vnstat-config_tests.obj `if test -f 'tests/config_tests.c'; then $(CYGPATH_W) 'tests/config_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/config_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-config_tests.Tpo tests/$(DEPDIR)/check_vnstat-config_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/config_tests.c' object='tests/check_vnstat-config_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-config_tests.obj `if test -f 'tests/config_tests.c'; then $(CYGPATH_W) 'tests/config_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/config_tests.c'; fi` tests/check_vnstat-ifinfo_tests.o: tests/ifinfo_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-ifinfo_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-ifinfo_tests.Tpo -c -o tests/check_vnstat-ifinfo_tests.o `test -f 'tests/ifinfo_tests.c' || echo '$(srcdir)/'`tests/ifinfo_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-ifinfo_tests.Tpo tests/$(DEPDIR)/check_vnstat-ifinfo_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/ifinfo_tests.c' object='tests/check_vnstat-ifinfo_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-ifinfo_tests.o `test -f 'tests/ifinfo_tests.c' || echo '$(srcdir)/'`tests/ifinfo_tests.c tests/check_vnstat-ifinfo_tests.obj: tests/ifinfo_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-ifinfo_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-ifinfo_tests.Tpo -c -o tests/check_vnstat-ifinfo_tests.obj `if test -f 'tests/ifinfo_tests.c'; then $(CYGPATH_W) 'tests/ifinfo_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/ifinfo_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-ifinfo_tests.Tpo tests/$(DEPDIR)/check_vnstat-ifinfo_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/ifinfo_tests.c' object='tests/check_vnstat-ifinfo_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-ifinfo_tests.obj `if test -f 'tests/ifinfo_tests.c'; then $(CYGPATH_W) 'tests/ifinfo_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/ifinfo_tests.c'; fi` tests/check_vnstat-misc_tests.o: tests/misc_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-misc_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-misc_tests.Tpo -c -o tests/check_vnstat-misc_tests.o `test -f 'tests/misc_tests.c' || echo '$(srcdir)/'`tests/misc_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-misc_tests.Tpo tests/$(DEPDIR)/check_vnstat-misc_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/misc_tests.c' object='tests/check_vnstat-misc_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-misc_tests.o `test -f 'tests/misc_tests.c' || echo '$(srcdir)/'`tests/misc_tests.c tests/check_vnstat-misc_tests.obj: tests/misc_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-misc_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-misc_tests.Tpo -c -o tests/check_vnstat-misc_tests.obj `if test -f 'tests/misc_tests.c'; then $(CYGPATH_W) 'tests/misc_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/misc_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-misc_tests.Tpo tests/$(DEPDIR)/check_vnstat-misc_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/misc_tests.c' object='tests/check_vnstat-misc_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-misc_tests.obj `if test -f 'tests/misc_tests.c'; then $(CYGPATH_W) 'tests/misc_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/misc_tests.c'; fi` tests/check_vnstat-fs_tests.o: tests/fs_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-fs_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-fs_tests.Tpo -c -o tests/check_vnstat-fs_tests.o `test -f 'tests/fs_tests.c' || echo '$(srcdir)/'`tests/fs_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-fs_tests.Tpo tests/$(DEPDIR)/check_vnstat-fs_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/fs_tests.c' object='tests/check_vnstat-fs_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-fs_tests.o `test -f 'tests/fs_tests.c' || echo '$(srcdir)/'`tests/fs_tests.c tests/check_vnstat-fs_tests.obj: tests/fs_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-fs_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-fs_tests.Tpo -c -o tests/check_vnstat-fs_tests.obj `if test -f 'tests/fs_tests.c'; then $(CYGPATH_W) 'tests/fs_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/fs_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-fs_tests.Tpo tests/$(DEPDIR)/check_vnstat-fs_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/fs_tests.c' object='tests/check_vnstat-fs_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-fs_tests.obj `if test -f 'tests/fs_tests.c'; then $(CYGPATH_W) 'tests/fs_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/fs_tests.c'; fi` tests/check_vnstat-id_tests.o: tests/id_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-id_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-id_tests.Tpo -c -o tests/check_vnstat-id_tests.o `test -f 'tests/id_tests.c' || echo '$(srcdir)/'`tests/id_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-id_tests.Tpo tests/$(DEPDIR)/check_vnstat-id_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/id_tests.c' object='tests/check_vnstat-id_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-id_tests.o `test -f 'tests/id_tests.c' || echo '$(srcdir)/'`tests/id_tests.c tests/check_vnstat-id_tests.obj: tests/id_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-id_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-id_tests.Tpo -c -o tests/check_vnstat-id_tests.obj `if test -f 'tests/id_tests.c'; then $(CYGPATH_W) 'tests/id_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/id_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-id_tests.Tpo tests/$(DEPDIR)/check_vnstat-id_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/id_tests.c' object='tests/check_vnstat-id_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-id_tests.obj `if test -f 'tests/id_tests.c'; then $(CYGPATH_W) 'tests/id_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/id_tests.c'; fi` tests/check_vnstat-iflist_tests.o: tests/iflist_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-iflist_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-iflist_tests.Tpo -c -o tests/check_vnstat-iflist_tests.o `test -f 'tests/iflist_tests.c' || echo '$(srcdir)/'`tests/iflist_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-iflist_tests.Tpo tests/$(DEPDIR)/check_vnstat-iflist_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/iflist_tests.c' object='tests/check_vnstat-iflist_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-iflist_tests.o `test -f 'tests/iflist_tests.c' || echo '$(srcdir)/'`tests/iflist_tests.c tests/check_vnstat-iflist_tests.obj: tests/iflist_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-iflist_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-iflist_tests.Tpo -c -o tests/check_vnstat-iflist_tests.obj `if test -f 'tests/iflist_tests.c'; then $(CYGPATH_W) 'tests/iflist_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/iflist_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-iflist_tests.Tpo tests/$(DEPDIR)/check_vnstat-iflist_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/iflist_tests.c' object='tests/check_vnstat-iflist_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-iflist_tests.obj `if test -f 'tests/iflist_tests.c'; then $(CYGPATH_W) 'tests/iflist_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/iflist_tests.c'; fi` tests/check_vnstat-cli_tests.o: tests/cli_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-cli_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-cli_tests.Tpo -c -o tests/check_vnstat-cli_tests.o `test -f 'tests/cli_tests.c' || echo '$(srcdir)/'`tests/cli_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-cli_tests.Tpo tests/$(DEPDIR)/check_vnstat-cli_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/cli_tests.c' object='tests/check_vnstat-cli_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-cli_tests.o `test -f 'tests/cli_tests.c' || echo '$(srcdir)/'`tests/cli_tests.c tests/check_vnstat-cli_tests.obj: tests/cli_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-cli_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-cli_tests.Tpo -c -o tests/check_vnstat-cli_tests.obj `if test -f 'tests/cli_tests.c'; then $(CYGPATH_W) 'tests/cli_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/cli_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-cli_tests.Tpo tests/$(DEPDIR)/check_vnstat-cli_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/cli_tests.c' object='tests/check_vnstat-cli_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-cli_tests.obj `if test -f 'tests/cli_tests.c'; then $(CYGPATH_W) 'tests/cli_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/cli_tests.c'; fi` tests/check_vnstat-parseargs_tests.o: tests/parseargs_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-parseargs_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-parseargs_tests.Tpo -c -o tests/check_vnstat-parseargs_tests.o `test -f 'tests/parseargs_tests.c' || echo '$(srcdir)/'`tests/parseargs_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-parseargs_tests.Tpo tests/$(DEPDIR)/check_vnstat-parseargs_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/parseargs_tests.c' object='tests/check_vnstat-parseargs_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-parseargs_tests.o `test -f 'tests/parseargs_tests.c' || echo '$(srcdir)/'`tests/parseargs_tests.c tests/check_vnstat-parseargs_tests.obj: tests/parseargs_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-parseargs_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-parseargs_tests.Tpo -c -o tests/check_vnstat-parseargs_tests.obj `if test -f 'tests/parseargs_tests.c'; then $(CYGPATH_W) 'tests/parseargs_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/parseargs_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-parseargs_tests.Tpo tests/$(DEPDIR)/check_vnstat-parseargs_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/parseargs_tests.c' object='tests/check_vnstat-parseargs_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-parseargs_tests.obj `if test -f 'tests/parseargs_tests.c'; then $(CYGPATH_W) 'tests/parseargs_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/parseargs_tests.c'; fi` tests/check_vnstat-daemon_tests.o: tests/daemon_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-daemon_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-daemon_tests.Tpo -c -o tests/check_vnstat-daemon_tests.o `test -f 'tests/daemon_tests.c' || echo '$(srcdir)/'`tests/daemon_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-daemon_tests.Tpo tests/$(DEPDIR)/check_vnstat-daemon_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/daemon_tests.c' object='tests/check_vnstat-daemon_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-daemon_tests.o `test -f 'tests/daemon_tests.c' || echo '$(srcdir)/'`tests/daemon_tests.c tests/check_vnstat-daemon_tests.obj: tests/daemon_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-daemon_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-daemon_tests.Tpo -c -o tests/check_vnstat-daemon_tests.obj `if test -f 'tests/daemon_tests.c'; then $(CYGPATH_W) 'tests/daemon_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/daemon_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-daemon_tests.Tpo tests/$(DEPDIR)/check_vnstat-daemon_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/daemon_tests.c' object='tests/check_vnstat-daemon_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-daemon_tests.obj `if test -f 'tests/daemon_tests.c'; then $(CYGPATH_W) 'tests/daemon_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/daemon_tests.c'; fi` src/check_vnstat-cfg.o: src/cfg.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-cfg.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-cfg.Tpo -c -o src/check_vnstat-cfg.o `test -f 'src/cfg.c' || echo '$(srcdir)/'`src/cfg.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-cfg.Tpo src/$(DEPDIR)/check_vnstat-cfg.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/cfg.c' object='src/check_vnstat-cfg.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-cfg.o `test -f 'src/cfg.c' || echo '$(srcdir)/'`src/cfg.c src/check_vnstat-cfg.obj: src/cfg.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-cfg.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-cfg.Tpo -c -o src/check_vnstat-cfg.obj `if test -f 'src/cfg.c'; then $(CYGPATH_W) 'src/cfg.c'; else $(CYGPATH_W) '$(srcdir)/src/cfg.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-cfg.Tpo src/$(DEPDIR)/check_vnstat-cfg.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/cfg.c' object='src/check_vnstat-cfg.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-cfg.obj `if test -f 'src/cfg.c'; then $(CYGPATH_W) 'src/cfg.c'; else $(CYGPATH_W) '$(srcdir)/src/cfg.c'; fi` src/check_vnstat-cfgoutput.o: src/cfgoutput.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-cfgoutput.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-cfgoutput.Tpo -c -o src/check_vnstat-cfgoutput.o `test -f 'src/cfgoutput.c' || echo '$(srcdir)/'`src/cfgoutput.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-cfgoutput.Tpo src/$(DEPDIR)/check_vnstat-cfgoutput.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/cfgoutput.c' object='src/check_vnstat-cfgoutput.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-cfgoutput.o `test -f 'src/cfgoutput.c' || echo '$(srcdir)/'`src/cfgoutput.c src/check_vnstat-cfgoutput.obj: src/cfgoutput.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-cfgoutput.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-cfgoutput.Tpo -c -o src/check_vnstat-cfgoutput.obj `if test -f 'src/cfgoutput.c'; then $(CYGPATH_W) 'src/cfgoutput.c'; else $(CYGPATH_W) '$(srcdir)/src/cfgoutput.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-cfgoutput.Tpo src/$(DEPDIR)/check_vnstat-cfgoutput.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/cfgoutput.c' object='src/check_vnstat-cfgoutput.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-cfgoutput.obj `if test -f 'src/cfgoutput.c'; then $(CYGPATH_W) 'src/cfgoutput.c'; else $(CYGPATH_W) '$(srcdir)/src/cfgoutput.c'; fi` src/check_vnstat-common.o: src/common.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-common.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-common.Tpo -c -o src/check_vnstat-common.o `test -f 'src/common.c' || echo '$(srcdir)/'`src/common.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-common.Tpo src/$(DEPDIR)/check_vnstat-common.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/common.c' object='src/check_vnstat-common.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-common.o `test -f 'src/common.c' || echo '$(srcdir)/'`src/common.c src/check_vnstat-common.obj: src/common.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-common.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-common.Tpo -c -o src/check_vnstat-common.obj `if test -f 'src/common.c'; then $(CYGPATH_W) 'src/common.c'; else $(CYGPATH_W) '$(srcdir)/src/common.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-common.Tpo src/$(DEPDIR)/check_vnstat-common.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/common.c' object='src/check_vnstat-common.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-common.obj `if test -f 'src/common.c'; then $(CYGPATH_W) 'src/common.c'; else $(CYGPATH_W) '$(srcdir)/src/common.c'; fi` src/check_vnstat-daemon.o: src/daemon.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-daemon.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-daemon.Tpo -c -o src/check_vnstat-daemon.o `test -f 'src/daemon.c' || echo '$(srcdir)/'`src/daemon.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-daemon.Tpo src/$(DEPDIR)/check_vnstat-daemon.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/daemon.c' object='src/check_vnstat-daemon.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-daemon.o `test -f 'src/daemon.c' || echo '$(srcdir)/'`src/daemon.c src/check_vnstat-daemon.obj: src/daemon.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-daemon.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-daemon.Tpo -c -o src/check_vnstat-daemon.obj `if test -f 'src/daemon.c'; then $(CYGPATH_W) 'src/daemon.c'; else $(CYGPATH_W) '$(srcdir)/src/daemon.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-daemon.Tpo src/$(DEPDIR)/check_vnstat-daemon.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/daemon.c' object='src/check_vnstat-daemon.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-daemon.obj `if test -f 'src/daemon.c'; then $(CYGPATH_W) 'src/daemon.c'; else $(CYGPATH_W) '$(srcdir)/src/daemon.c'; fi` src/check_vnstat-dbsql.o: src/dbsql.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbsql.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbsql.Tpo -c -o src/check_vnstat-dbsql.o `test -f 'src/dbsql.c' || echo '$(srcdir)/'`src/dbsql.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbsql.Tpo src/$(DEPDIR)/check_vnstat-dbsql.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbsql.c' object='src/check_vnstat-dbsql.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbsql.o `test -f 'src/dbsql.c' || echo '$(srcdir)/'`src/dbsql.c src/check_vnstat-dbsql.obj: src/dbsql.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbsql.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbsql.Tpo -c -o src/check_vnstat-dbsql.obj `if test -f 'src/dbsql.c'; then $(CYGPATH_W) 'src/dbsql.c'; else $(CYGPATH_W) '$(srcdir)/src/dbsql.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbsql.Tpo src/$(DEPDIR)/check_vnstat-dbsql.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbsql.c' object='src/check_vnstat-dbsql.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbsql.obj `if test -f 'src/dbsql.c'; then $(CYGPATH_W) 'src/dbsql.c'; else $(CYGPATH_W) '$(srcdir)/src/dbsql.c'; fi` src/check_vnstat-dbaccess.o: src/dbaccess.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbaccess.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbaccess.Tpo -c -o src/check_vnstat-dbaccess.o `test -f 'src/dbaccess.c' || echo '$(srcdir)/'`src/dbaccess.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbaccess.Tpo src/$(DEPDIR)/check_vnstat-dbaccess.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbaccess.c' object='src/check_vnstat-dbaccess.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbaccess.o `test -f 'src/dbaccess.c' || echo '$(srcdir)/'`src/dbaccess.c src/check_vnstat-dbaccess.obj: src/dbaccess.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbaccess.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbaccess.Tpo -c -o src/check_vnstat-dbaccess.obj `if test -f 'src/dbaccess.c'; then $(CYGPATH_W) 'src/dbaccess.c'; else $(CYGPATH_W) '$(srcdir)/src/dbaccess.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbaccess.Tpo src/$(DEPDIR)/check_vnstat-dbaccess.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbaccess.c' object='src/check_vnstat-dbaccess.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbaccess.obj `if test -f 'src/dbaccess.c'; then $(CYGPATH_W) 'src/dbaccess.c'; else $(CYGPATH_W) '$(srcdir)/src/dbaccess.c'; fi` src/check_vnstat-datacache.o: src/datacache.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-datacache.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-datacache.Tpo -c -o src/check_vnstat-datacache.o `test -f 'src/datacache.c' || echo '$(srcdir)/'`src/datacache.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-datacache.Tpo src/$(DEPDIR)/check_vnstat-datacache.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/datacache.c' object='src/check_vnstat-datacache.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-datacache.o `test -f 'src/datacache.c' || echo '$(srcdir)/'`src/datacache.c src/check_vnstat-datacache.obj: src/datacache.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-datacache.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-datacache.Tpo -c -o src/check_vnstat-datacache.obj `if test -f 'src/datacache.c'; then $(CYGPATH_W) 'src/datacache.c'; else $(CYGPATH_W) '$(srcdir)/src/datacache.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-datacache.Tpo src/$(DEPDIR)/check_vnstat-datacache.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/datacache.c' object='src/check_vnstat-datacache.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-datacache.obj `if test -f 'src/datacache.c'; then $(CYGPATH_W) 'src/datacache.c'; else $(CYGPATH_W) '$(srcdir)/src/datacache.c'; fi` src/check_vnstat-dbshow.o: src/dbshow.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbshow.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbshow.Tpo -c -o src/check_vnstat-dbshow.o `test -f 'src/dbshow.c' || echo '$(srcdir)/'`src/dbshow.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbshow.Tpo src/$(DEPDIR)/check_vnstat-dbshow.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbshow.c' object='src/check_vnstat-dbshow.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbshow.o `test -f 'src/dbshow.c' || echo '$(srcdir)/'`src/dbshow.c src/check_vnstat-dbshow.obj: src/dbshow.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbshow.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbshow.Tpo -c -o src/check_vnstat-dbshow.obj `if test -f 'src/dbshow.c'; then $(CYGPATH_W) 'src/dbshow.c'; else $(CYGPATH_W) '$(srcdir)/src/dbshow.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbshow.Tpo src/$(DEPDIR)/check_vnstat-dbshow.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbshow.c' object='src/check_vnstat-dbshow.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbshow.obj `if test -f 'src/dbshow.c'; then $(CYGPATH_W) 'src/dbshow.c'; else $(CYGPATH_W) '$(srcdir)/src/dbshow.c'; fi` src/check_vnstat-dbjson.o: src/dbjson.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbjson.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbjson.Tpo -c -o src/check_vnstat-dbjson.o `test -f 'src/dbjson.c' || echo '$(srcdir)/'`src/dbjson.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbjson.Tpo src/$(DEPDIR)/check_vnstat-dbjson.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbjson.c' object='src/check_vnstat-dbjson.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbjson.o `test -f 'src/dbjson.c' || echo '$(srcdir)/'`src/dbjson.c src/check_vnstat-dbjson.obj: src/dbjson.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbjson.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbjson.Tpo -c -o src/check_vnstat-dbjson.obj `if test -f 'src/dbjson.c'; then $(CYGPATH_W) 'src/dbjson.c'; else $(CYGPATH_W) '$(srcdir)/src/dbjson.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbjson.Tpo src/$(DEPDIR)/check_vnstat-dbjson.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbjson.c' object='src/check_vnstat-dbjson.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbjson.obj `if test -f 'src/dbjson.c'; then $(CYGPATH_W) 'src/dbjson.c'; else $(CYGPATH_W) '$(srcdir)/src/dbjson.c'; fi` src/check_vnstat-dbxml.o: src/dbxml.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbxml.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbxml.Tpo -c -o src/check_vnstat-dbxml.o `test -f 'src/dbxml.c' || echo '$(srcdir)/'`src/dbxml.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbxml.Tpo src/$(DEPDIR)/check_vnstat-dbxml.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbxml.c' object='src/check_vnstat-dbxml.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbxml.o `test -f 'src/dbxml.c' || echo '$(srcdir)/'`src/dbxml.c src/check_vnstat-dbxml.obj: src/dbxml.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-dbxml.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-dbxml.Tpo -c -o src/check_vnstat-dbxml.obj `if test -f 'src/dbxml.c'; then $(CYGPATH_W) 'src/dbxml.c'; else $(CYGPATH_W) '$(srcdir)/src/dbxml.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-dbxml.Tpo src/$(DEPDIR)/check_vnstat-dbxml.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/dbxml.c' object='src/check_vnstat-dbxml.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-dbxml.obj `if test -f 'src/dbxml.c'; then $(CYGPATH_W) 'src/dbxml.c'; else $(CYGPATH_W) '$(srcdir)/src/dbxml.c'; fi` src/check_vnstat-ibw.o: src/ibw.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-ibw.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-ibw.Tpo -c -o src/check_vnstat-ibw.o `test -f 'src/ibw.c' || echo '$(srcdir)/'`src/ibw.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-ibw.Tpo src/$(DEPDIR)/check_vnstat-ibw.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/ibw.c' object='src/check_vnstat-ibw.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-ibw.o `test -f 'src/ibw.c' || echo '$(srcdir)/'`src/ibw.c src/check_vnstat-ibw.obj: src/ibw.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-ibw.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-ibw.Tpo -c -o src/check_vnstat-ibw.obj `if test -f 'src/ibw.c'; then $(CYGPATH_W) 'src/ibw.c'; else $(CYGPATH_W) '$(srcdir)/src/ibw.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-ibw.Tpo src/$(DEPDIR)/check_vnstat-ibw.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/ibw.c' object='src/check_vnstat-ibw.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-ibw.obj `if test -f 'src/ibw.c'; then $(CYGPATH_W) 'src/ibw.c'; else $(CYGPATH_W) '$(srcdir)/src/ibw.c'; fi` src/check_vnstat-ifinfo.o: src/ifinfo.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-ifinfo.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-ifinfo.Tpo -c -o src/check_vnstat-ifinfo.o `test -f 'src/ifinfo.c' || echo '$(srcdir)/'`src/ifinfo.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-ifinfo.Tpo src/$(DEPDIR)/check_vnstat-ifinfo.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/ifinfo.c' object='src/check_vnstat-ifinfo.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-ifinfo.o `test -f 'src/ifinfo.c' || echo '$(srcdir)/'`src/ifinfo.c src/check_vnstat-ifinfo.obj: src/ifinfo.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-ifinfo.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-ifinfo.Tpo -c -o src/check_vnstat-ifinfo.obj `if test -f 'src/ifinfo.c'; then $(CYGPATH_W) 'src/ifinfo.c'; else $(CYGPATH_W) '$(srcdir)/src/ifinfo.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-ifinfo.Tpo src/$(DEPDIR)/check_vnstat-ifinfo.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/ifinfo.c' object='src/check_vnstat-ifinfo.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-ifinfo.obj `if test -f 'src/ifinfo.c'; then $(CYGPATH_W) 'src/ifinfo.c'; else $(CYGPATH_W) '$(srcdir)/src/ifinfo.c'; fi` src/check_vnstat-iflist.o: src/iflist.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-iflist.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-iflist.Tpo -c -o src/check_vnstat-iflist.o `test -f 'src/iflist.c' || echo '$(srcdir)/'`src/iflist.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-iflist.Tpo src/$(DEPDIR)/check_vnstat-iflist.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/iflist.c' object='src/check_vnstat-iflist.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-iflist.o `test -f 'src/iflist.c' || echo '$(srcdir)/'`src/iflist.c src/check_vnstat-iflist.obj: src/iflist.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-iflist.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-iflist.Tpo -c -o src/check_vnstat-iflist.obj `if test -f 'src/iflist.c'; then $(CYGPATH_W) 'src/iflist.c'; else $(CYGPATH_W) '$(srcdir)/src/iflist.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-iflist.Tpo src/$(DEPDIR)/check_vnstat-iflist.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/iflist.c' object='src/check_vnstat-iflist.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-iflist.obj `if test -f 'src/iflist.c'; then $(CYGPATH_W) 'src/iflist.c'; else $(CYGPATH_W) '$(srcdir)/src/iflist.c'; fi` src/check_vnstat-misc.o: src/misc.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-misc.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-misc.Tpo -c -o src/check_vnstat-misc.o `test -f 'src/misc.c' || echo '$(srcdir)/'`src/misc.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-misc.Tpo src/$(DEPDIR)/check_vnstat-misc.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/misc.c' object='src/check_vnstat-misc.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-misc.o `test -f 'src/misc.c' || echo '$(srcdir)/'`src/misc.c src/check_vnstat-misc.obj: src/misc.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-misc.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-misc.Tpo -c -o src/check_vnstat-misc.obj `if test -f 'src/misc.c'; then $(CYGPATH_W) 'src/misc.c'; else $(CYGPATH_W) '$(srcdir)/src/misc.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-misc.Tpo src/$(DEPDIR)/check_vnstat-misc.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/misc.c' object='src/check_vnstat-misc.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-misc.obj `if test -f 'src/misc.c'; then $(CYGPATH_W) 'src/misc.c'; else $(CYGPATH_W) '$(srcdir)/src/misc.c'; fi` src/check_vnstat-fs.o: src/fs.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-fs.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-fs.Tpo -c -o src/check_vnstat-fs.o `test -f 'src/fs.c' || echo '$(srcdir)/'`src/fs.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-fs.Tpo src/$(DEPDIR)/check_vnstat-fs.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/fs.c' object='src/check_vnstat-fs.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-fs.o `test -f 'src/fs.c' || echo '$(srcdir)/'`src/fs.c src/check_vnstat-fs.obj: src/fs.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-fs.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-fs.Tpo -c -o src/check_vnstat-fs.obj `if test -f 'src/fs.c'; then $(CYGPATH_W) 'src/fs.c'; else $(CYGPATH_W) '$(srcdir)/src/fs.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-fs.Tpo src/$(DEPDIR)/check_vnstat-fs.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/fs.c' object='src/check_vnstat-fs.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-fs.obj `if test -f 'src/fs.c'; then $(CYGPATH_W) 'src/fs.c'; else $(CYGPATH_W) '$(srcdir)/src/fs.c'; fi` src/check_vnstat-id.o: src/id.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-id.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-id.Tpo -c -o src/check_vnstat-id.o `test -f 'src/id.c' || echo '$(srcdir)/'`src/id.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-id.Tpo src/$(DEPDIR)/check_vnstat-id.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/id.c' object='src/check_vnstat-id.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-id.o `test -f 'src/id.c' || echo '$(srcdir)/'`src/id.c src/check_vnstat-id.obj: src/id.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-id.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-id.Tpo -c -o src/check_vnstat-id.obj `if test -f 'src/id.c'; then $(CYGPATH_W) 'src/id.c'; else $(CYGPATH_W) '$(srcdir)/src/id.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-id.Tpo src/$(DEPDIR)/check_vnstat-id.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/id.c' object='src/check_vnstat-id.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-id.obj `if test -f 'src/id.c'; then $(CYGPATH_W) 'src/id.c'; else $(CYGPATH_W) '$(srcdir)/src/id.c'; fi` src/check_vnstat-vnstat_func.o: src/vnstat_func.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-vnstat_func.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-vnstat_func.Tpo -c -o src/check_vnstat-vnstat_func.o `test -f 'src/vnstat_func.c' || echo '$(srcdir)/'`src/vnstat_func.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-vnstat_func.Tpo src/$(DEPDIR)/check_vnstat-vnstat_func.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/vnstat_func.c' object='src/check_vnstat-vnstat_func.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-vnstat_func.o `test -f 'src/vnstat_func.c' || echo '$(srcdir)/'`src/vnstat_func.c src/check_vnstat-vnstat_func.obj: src/vnstat_func.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-vnstat_func.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-vnstat_func.Tpo -c -o src/check_vnstat-vnstat_func.obj `if test -f 'src/vnstat_func.c'; then $(CYGPATH_W) 'src/vnstat_func.c'; else $(CYGPATH_W) '$(srcdir)/src/vnstat_func.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-vnstat_func.Tpo src/$(DEPDIR)/check_vnstat-vnstat_func.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/vnstat_func.c' object='src/check_vnstat-vnstat_func.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-vnstat_func.obj `if test -f 'src/vnstat_func.c'; then $(CYGPATH_W) 'src/vnstat_func.c'; else $(CYGPATH_W) '$(srcdir)/src/vnstat_func.c'; fi` src/check_vnstat-traffic.o: src/traffic.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-traffic.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-traffic.Tpo -c -o src/check_vnstat-traffic.o `test -f 'src/traffic.c' || echo '$(srcdir)/'`src/traffic.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-traffic.Tpo src/$(DEPDIR)/check_vnstat-traffic.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/traffic.c' object='src/check_vnstat-traffic.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-traffic.o `test -f 'src/traffic.c' || echo '$(srcdir)/'`src/traffic.c src/check_vnstat-traffic.obj: src/traffic.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-traffic.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-traffic.Tpo -c -o src/check_vnstat-traffic.obj `if test -f 'src/traffic.c'; then $(CYGPATH_W) 'src/traffic.c'; else $(CYGPATH_W) '$(srcdir)/src/traffic.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-traffic.Tpo src/$(DEPDIR)/check_vnstat-traffic.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/traffic.c' object='src/check_vnstat-traffic.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-traffic.obj `if test -f 'src/traffic.c'; then $(CYGPATH_W) 'src/traffic.c'; else $(CYGPATH_W) '$(srcdir)/src/traffic.c'; fi` tests/check_vnstat-image_tests.o: tests/image_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-image_tests.o -MD -MP -MF tests/$(DEPDIR)/check_vnstat-image_tests.Tpo -c -o tests/check_vnstat-image_tests.o `test -f 'tests/image_tests.c' || echo '$(srcdir)/'`tests/image_tests.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-image_tests.Tpo tests/$(DEPDIR)/check_vnstat-image_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/image_tests.c' object='tests/check_vnstat-image_tests.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-image_tests.o `test -f 'tests/image_tests.c' || echo '$(srcdir)/'`tests/image_tests.c tests/check_vnstat-image_tests.obj: tests/image_tests.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT tests/check_vnstat-image_tests.obj -MD -MP -MF tests/$(DEPDIR)/check_vnstat-image_tests.Tpo -c -o tests/check_vnstat-image_tests.obj `if test -f 'tests/image_tests.c'; then $(CYGPATH_W) 'tests/image_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/image_tests.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) tests/$(DEPDIR)/check_vnstat-image_tests.Tpo tests/$(DEPDIR)/check_vnstat-image_tests.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tests/image_tests.c' object='tests/check_vnstat-image_tests.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o tests/check_vnstat-image_tests.obj `if test -f 'tests/image_tests.c'; then $(CYGPATH_W) 'tests/image_tests.c'; else $(CYGPATH_W) '$(srcdir)/tests/image_tests.c'; fi` src/check_vnstat-image.o: src/image.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-image.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-image.Tpo -c -o src/check_vnstat-image.o `test -f 'src/image.c' || echo '$(srcdir)/'`src/image.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-image.Tpo src/$(DEPDIR)/check_vnstat-image.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/image.c' object='src/check_vnstat-image.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-image.o `test -f 'src/image.c' || echo '$(srcdir)/'`src/image.c src/check_vnstat-image.obj: src/image.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-image.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-image.Tpo -c -o src/check_vnstat-image.obj `if test -f 'src/image.c'; then $(CYGPATH_W) 'src/image.c'; else $(CYGPATH_W) '$(srcdir)/src/image.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-image.Tpo src/$(DEPDIR)/check_vnstat-image.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/image.c' object='src/check_vnstat-image.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-image.obj `if test -f 'src/image.c'; then $(CYGPATH_W) 'src/image.c'; else $(CYGPATH_W) '$(srcdir)/src/image.c'; fi` src/check_vnstat-image_support.o: src/image_support.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-image_support.o -MD -MP -MF src/$(DEPDIR)/check_vnstat-image_support.Tpo -c -o src/check_vnstat-image_support.o `test -f 'src/image_support.c' || echo '$(srcdir)/'`src/image_support.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-image_support.Tpo src/$(DEPDIR)/check_vnstat-image_support.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/image_support.c' object='src/check_vnstat-image_support.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-image_support.o `test -f 'src/image_support.c' || echo '$(srcdir)/'`src/image_support.c src/check_vnstat-image_support.obj: src/image_support.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -MT src/check_vnstat-image_support.obj -MD -MP -MF src/$(DEPDIR)/check_vnstat-image_support.Tpo -c -o src/check_vnstat-image_support.obj `if test -f 'src/image_support.c'; then $(CYGPATH_W) 'src/image_support.c'; else $(CYGPATH_W) '$(srcdir)/src/image_support.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/check_vnstat-image_support.Tpo src/$(DEPDIR)/check_vnstat-image_support.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/image_support.c' object='src/check_vnstat-image_support.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(check_vnstat_CFLAGS) $(CFLAGS) -c -o src/check_vnstat-image_support.obj `if test -f 'src/image_support.c'; then $(CYGPATH_W) 'src/image_support.c'; else $(CYGPATH_W) '$(srcdir)/src/image_support.c'; fi` install-man1: $(dist_man_MANS) @$(NORMAL_INSTALL) @list1=''; \ list2='$(dist_man_MANS)'; \ test -n "$(man1dir)" \ && test -n "`echo $$list1$$list2`" \ || exit 0; \ echo " $(MKDIR_P) '$(DESTDIR)$(man1dir)'"; \ $(MKDIR_P) "$(DESTDIR)$(man1dir)" || exit 1; \ { for i in $$list1; do echo "$$i"; done; \ if test -n "$$list2"; then \ for i in $$list2; do echo "$$i"; done \ | sed -n '/\.1[a-z]*$$/p'; \ fi; \ } | while read p; do \ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; echo "$$p"; \ done | \ sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \ sed 'N;N;s,\n, ,g' | { \ list=; while read file base inst; do \ if test "$$base" = "$$inst"; then list="$$list $$file"; else \ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man1dir)/$$inst'"; \ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man1dir)/$$inst" || exit $$?; \ fi; \ done; \ for i in $$list; do echo "$$i"; done | $(am__base_list) | \ while read files; do \ test -z "$$files" || { \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man1dir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(man1dir)" || exit $$?; }; \ done; } uninstall-man1: @$(NORMAL_UNINSTALL) @list=''; test -n "$(man1dir)" || exit 0; \ files=`{ for i in $$list; do echo "$$i"; done; \ l2='$(dist_man_MANS)'; for i in $$l2; do echo "$$i"; done | \ sed -n '/\.1[a-z]*$$/p'; \ } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \ dir='$(DESTDIR)$(man1dir)'; $(am__uninstall_files_from_dir) install-man5: $(dist_man_MANS) @$(NORMAL_INSTALL) @list1=''; \ list2='$(dist_man_MANS)'; \ test -n "$(man5dir)" \ && test -n "`echo $$list1$$list2`" \ || exit 0; \ echo " $(MKDIR_P) '$(DESTDIR)$(man5dir)'"; \ $(MKDIR_P) "$(DESTDIR)$(man5dir)" || exit 1; \ { for i in $$list1; do echo "$$i"; done; \ if test -n "$$list2"; then \ for i in $$list2; do echo "$$i"; done \ | sed -n '/\.5[a-z]*$$/p'; \ fi; \ } | while read p; do \ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; echo "$$p"; \ done | \ sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^5][0-9a-z]*$$,5,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \ sed 'N;N;s,\n, ,g' | { \ list=; while read file base inst; do \ if test "$$base" = "$$inst"; then list="$$list $$file"; else \ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man5dir)/$$inst'"; \ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man5dir)/$$inst" || exit $$?; \ fi; \ done; \ for i in $$list; do echo "$$i"; done | $(am__base_list) | \ while read files; do \ test -z "$$files" || { \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man5dir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(man5dir)" || exit $$?; }; \ done; } uninstall-man5: @$(NORMAL_UNINSTALL) @list=''; test -n "$(man5dir)" || exit 0; \ files=`{ for i in $$list; do echo "$$i"; done; \ l2='$(dist_man_MANS)'; for i in $$l2; do echo "$$i"; done | \ sed -n '/\.5[a-z]*$$/p'; \ } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^5][0-9a-z]*$$,5,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \ dir='$(DESTDIR)$(man5dir)'; $(am__uninstall_files_from_dir) install-man8: $(dist_man_MANS) @$(NORMAL_INSTALL) @list1=''; \ list2='$(dist_man_MANS)'; \ test -n "$(man8dir)" \ && test -n "`echo $$list1$$list2`" \ || exit 0; \ echo " $(MKDIR_P) '$(DESTDIR)$(man8dir)'"; \ $(MKDIR_P) "$(DESTDIR)$(man8dir)" || exit 1; \ { for i in $$list1; do echo "$$i"; done; \ if test -n "$$list2"; then \ for i in $$list2; do echo "$$i"; done \ | sed -n '/\.8[a-z]*$$/p'; \ fi; \ } | while read p; do \ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; echo "$$p"; \ done | \ sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \ sed 'N;N;s,\n, ,g' | { \ list=; while read file base inst; do \ if test "$$base" = "$$inst"; then list="$$list $$file"; else \ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man8dir)/$$inst'"; \ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man8dir)/$$inst" || exit $$?; \ fi; \ done; \ for i in $$list; do echo "$$i"; done | $(am__base_list) | \ while read files; do \ test -z "$$files" || { \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man8dir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(man8dir)" || exit $$?; }; \ done; } uninstall-man8: @$(NORMAL_UNINSTALL) @list=''; test -n "$(man8dir)" || exit 0; \ files=`{ for i in $$list; do echo "$$i"; done; \ l2='$(dist_man_MANS)'; for i in $$l2; do echo "$$i"; done | \ sed -n '/\.8[a-z]*$$/p'; \ } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \ dir='$(DESTDIR)$(man8dir)'; $(am__uninstall_files_from_dir) # This directory's subdirectories are mostly independent; you can cd # into them and run 'make' without going through this Makefile. # To change the values of 'make' variables: instead of editing Makefiles, # (1) if the variable is set in 'config.status', edit 'config.status' # (which will cause the Makefiles to be regenerated when you run 'make'); # (2) otherwise, pass the desired values on the 'make' command line. $(am__recursive_targets): @fail=; \ if $(am__make_keepgoing); then \ failcom='fail=yes'; \ else \ failcom='exit 1'; \ fi; \ dot_seen=no; \ target=`echo $@ | sed s/-recursive//`; \ case "$@" in \ distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ *) list='$(SUBDIRS)' ;; \ esac; \ for subdir in $$list; do \ echo "Making $$target in $$subdir"; \ if test "$$subdir" = "."; then \ dot_seen=yes; \ local_target="$$target-am"; \ else \ local_target="$$target"; \ fi; \ ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ || eval $$failcom; \ done; \ if test "$$dot_seen" = "no"; then \ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ fi; test -z "$$fail" ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-recursive TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ include_option=--etags-include; \ empty_fix=.; \ else \ include_option=--include; \ empty_fix=; \ fi; \ list='$(SUBDIRS)'; for subdir in $$list; do \ if test "$$subdir" = .; then :; else \ test ! -f $$subdir/TAGS || \ set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ fi; \ done; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-recursive CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscope: cscope.files test ! -s cscope.files \ || $(CSCOPE) -b -q $(AM_CSCOPEFLAGS) $(CSCOPEFLAGS) -i cscope.files $(CSCOPE_ARGS) clean-cscope: -rm -f cscope.files cscope.files: clean-cscope cscopelist cscopelist: cscopelist-recursive cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -rm -f cscope.out cscope.in.out cscope.po.out cscope.files # Recover from deleted '.trs' file; this should ensure that # "rm -f foo.log; make foo.trs" re-run 'foo.test', and re-create # both 'foo.log' and 'foo.trs'. Break the recipe in two subshells # to avoid problems with "make -n". .log.trs: rm -f $< $@ $(MAKE) $(AM_MAKEFLAGS) $< # Leading 'am--fnord' is there to ensure the list of targets does not # expand to empty, as could happen e.g. with make check TESTS=''. am--fnord $(TEST_LOGS) $(TEST_LOGS:.log=.trs): $(am__force_recheck) am--force-recheck: @: $(TEST_SUITE_LOG): $(TEST_LOGS) @$(am__set_TESTS_bases); \ am__f_ok () { test -f "$$1" && test -r "$$1"; }; \ redo_bases=`for i in $$bases; do \ am__f_ok $$i.trs && am__f_ok $$i.log || echo $$i; \ done`; \ if test -n "$$redo_bases"; then \ redo_logs=`for i in $$redo_bases; do echo $$i.log; done`; \ redo_results=`for i in $$redo_bases; do echo $$i.trs; done`; \ if $(am__make_dryrun); then :; else \ rm -f $$redo_logs && rm -f $$redo_results || exit 1; \ fi; \ fi; \ if test -n "$$am__remaking_logs"; then \ echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \ "recursion detected" >&2; \ elif test -n "$$redo_logs"; then \ am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \ fi; \ if $(am__make_dryrun); then :; else \ st=0; \ errmsg="fatal: making $(TEST_SUITE_LOG): failed to create"; \ for i in $$redo_bases; do \ test -f $$i.trs && test -r $$i.trs \ || { echo "$$errmsg $$i.trs" >&2; st=1; }; \ test -f $$i.log && test -r $$i.log \ || { echo "$$errmsg $$i.log" >&2; st=1; }; \ done; \ test $$st -eq 0 || exit 1; \ fi @$(am__sh_e_setup); $(am__tty_colors); $(am__set_TESTS_bases); \ ws='[ ]'; \ results=`for b in $$bases; do echo $$b.trs; done`; \ test -n "$$results" || results=/dev/null; \ all=` grep "^$$ws*:test-result:" $$results | wc -l`; \ pass=` grep "^$$ws*:test-result:$$ws*PASS" $$results | wc -l`; \ fail=` grep "^$$ws*:test-result:$$ws*FAIL" $$results | wc -l`; \ skip=` grep "^$$ws*:test-result:$$ws*SKIP" $$results | wc -l`; \ xfail=`grep "^$$ws*:test-result:$$ws*XFAIL" $$results | wc -l`; \ xpass=`grep "^$$ws*:test-result:$$ws*XPASS" $$results | wc -l`; \ error=`grep "^$$ws*:test-result:$$ws*ERROR" $$results | wc -l`; \ if test `expr $$fail + $$xpass + $$error` -eq 0; then \ success=true; \ else \ success=false; \ fi; \ br='==================='; br=$$br$$br$$br$$br; \ result_count () \ { \ if test x"$$1" = x"--maybe-color"; then \ maybe_colorize=yes; \ elif test x"$$1" = x"--no-color"; then \ maybe_colorize=no; \ else \ echo "$@: invalid 'result_count' usage" >&2; exit 4; \ fi; \ shift; \ desc=$$1 count=$$2; \ if test $$maybe_colorize = yes && test $$count -gt 0; then \ color_start=$$3 color_end=$$std; \ else \ color_start= color_end=; \ fi; \ echo "$${color_start}# $$desc $$count$${color_end}"; \ }; \ create_testsuite_report () \ { \ result_count $$1 "TOTAL:" $$all "$$brg"; \ result_count $$1 "PASS: " $$pass "$$grn"; \ result_count $$1 "SKIP: " $$skip "$$blu"; \ result_count $$1 "XFAIL:" $$xfail "$$lgn"; \ result_count $$1 "FAIL: " $$fail "$$red"; \ result_count $$1 "XPASS:" $$xpass "$$red"; \ result_count $$1 "ERROR:" $$error "$$mgn"; \ }; \ { \ echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" | \ $(am__rst_title); \ create_testsuite_report --no-color; \ echo; \ echo ".. contents:: :depth: 2"; \ echo; \ for b in $$bases; do echo $$b; done \ | $(am__create_global_log); \ } >$(TEST_SUITE_LOG).tmp || exit 1; \ mv $(TEST_SUITE_LOG).tmp $(TEST_SUITE_LOG); \ if $$success; then \ col="$$grn"; \ else \ col="$$red"; \ test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG); \ fi; \ echo "$${col}$$br$${std}"; \ echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}"; \ echo "$${col}$$br$${std}"; \ create_testsuite_report --maybe-color; \ echo "$$col$$br$$std"; \ if $$success; then :; else \ echo "$${col}See $(subdir)/$(TEST_SUITE_LOG)$${std}"; \ if test -n "$(PACKAGE_BUGREPORT)"; then \ echo "$${col}Please report to $(PACKAGE_BUGREPORT)$${std}"; \ fi; \ echo "$$col$$br$$std"; \ fi; \ $$success || exit 1 check-TESTS: $(check_PROGRAMS) @list='$(RECHECK_LOGS)'; test -z "$$list" || rm -f $$list @list='$(RECHECK_LOGS:.log=.trs)'; test -z "$$list" || rm -f $$list @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) @set +e; $(am__set_TESTS_bases); \ log_list=`for i in $$bases; do echo $$i.log; done`; \ trs_list=`for i in $$bases; do echo $$i.trs; done`; \ log_list=`echo $$log_list`; trs_list=`echo $$trs_list`; \ $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) TEST_LOGS="$$log_list"; \ exit $$?; recheck: all $(check_PROGRAMS) @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) @set +e; $(am__set_TESTS_bases); \ bases=`for i in $$bases; do echo $$i; done \ | $(am__list_recheck_tests)` || exit 1; \ log_list=`for i in $$bases; do echo $$i.log; done`; \ log_list=`echo $$log_list`; \ $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) \ am__force_recheck=am--force-recheck \ TEST_LOGS="$$log_list"; \ exit $$? check_vnstat.log: check_vnstat$(EXEEXT) @p='check_vnstat$(EXEEXT)'; \ b='check_vnstat'; \ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) .test.log: @p='$<'; \ $(am__set_b); \ $(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) @am__EXEEXT_TRUE@.test$(EXEEXT).log: @am__EXEEXT_TRUE@ @p='$<'; \ @am__EXEEXT_TRUE@ $(am__set_b); \ @am__EXEEXT_TRUE@ $(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \ @am__EXEEXT_TRUE@ --log-file $$b.log --trs-file $$b.trs \ @am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \ @am__EXEEXT_TRUE@ "$$tst" $(AM_TESTS_FD_REDIRECT) distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) $(am__remove_distdir) test -d "$(distdir)" || mkdir "$(distdir)" @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ if test "$$subdir" = .; then :; else \ $(am__make_dryrun) \ || test -d "$(distdir)/$$subdir" \ || $(MKDIR_P) "$(distdir)/$$subdir" \ || exit 1; \ dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ $(am__relativize); \ new_distdir=$$reldir; \ dir1=$$subdir; dir2="$(top_distdir)"; \ $(am__relativize); \ new_top_distdir=$$reldir; \ echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ ($(am__cd) $$subdir && \ $(MAKE) $(AM_MAKEFLAGS) \ top_distdir="$$new_top_distdir" \ distdir="$$new_distdir" \ am__remove_distdir=: \ am__skip_length_check=: \ am__skip_mode_fix=: \ distdir) \ || exit 1; \ fi; \ done -test -n "$(am__skip_mode_fix)" \ || find "$(distdir)" -type d ! -perm -755 \ -exec chmod u+rwx,go+rx {} \; -o \ ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ || chmod -R a+r "$(distdir)" dist-gzip: distdir tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz $(am__post_remove_distdir) dist-bzip2: distdir tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2 $(am__post_remove_distdir) dist-lzip: distdir tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz $(am__post_remove_distdir) dist-xz: distdir tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz $(am__post_remove_distdir) dist-tarZ: distdir @echo WARNING: "Support for distribution archives compressed with" \ "legacy program 'compress' is deprecated." >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z $(am__post_remove_distdir) dist-shar: distdir @echo WARNING: "Support for shar distribution archives is" \ "deprecated." >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz $(am__post_remove_distdir) dist-zip: distdir -rm -f $(distdir).zip zip -rq $(distdir).zip $(distdir) $(am__post_remove_distdir) dist dist-all: $(MAKE) $(AM_MAKEFLAGS) $(DIST_TARGETS) am__post_remove_distdir='@:' $(am__post_remove_distdir) # This target untars the dist file and tries a VPATH configuration. Then # it guarantees that the distribution is self-contained by making another # tarfile. distcheck: dist case '$(DIST_ARCHIVES)' in \ *.tar.gz*) \ eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\ *.tar.bz2*) \ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ *.tar.lz*) \ lzip -dc $(distdir).tar.lz | $(am__untar) ;;\ *.tar.xz*) \ xz -dc $(distdir).tar.xz | $(am__untar) ;;\ *.tar.Z*) \ uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ *.shar.gz*) \ eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ *.zip*) \ unzip $(distdir).zip ;;\ esac chmod -R a-w $(distdir) chmod u+w $(distdir) mkdir $(distdir)/_build $(distdir)/_build/sub $(distdir)/_inst chmod a-w $(distdir) test -d $(distdir)/_build || exit 0; \ dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ && am__cwd=`pwd` \ && $(am__cd) $(distdir)/_build/sub \ && ../../configure \ $(AM_DISTCHECK_CONFIGURE_FLAGS) \ $(DISTCHECK_CONFIGURE_FLAGS) \ --srcdir=../.. --prefix="$$dc_install_base" \ && $(MAKE) $(AM_MAKEFLAGS) \ && $(MAKE) $(AM_MAKEFLAGS) dvi \ && $(MAKE) $(AM_MAKEFLAGS) check \ && $(MAKE) $(AM_MAKEFLAGS) install \ && $(MAKE) $(AM_MAKEFLAGS) installcheck \ && $(MAKE) $(AM_MAKEFLAGS) uninstall \ && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \ distuninstallcheck \ && chmod -R a-w "$$dc_install_base" \ && ({ \ (cd ../.. && umask 077 && mkdir "$$dc_destdir") \ && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \ && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \ && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \ distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \ } || { rm -rf "$$dc_destdir"; exit 1; }) \ && rm -rf "$$dc_destdir" \ && $(MAKE) $(AM_MAKEFLAGS) dist \ && rm -rf $(DIST_ARCHIVES) \ && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \ && cd "$$am__cwd" \ || exit 1 $(am__post_remove_distdir) @(echo "$(distdir) archives ready for distribution: "; \ list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' distuninstallcheck: @test -n '$(distuninstallcheck_dir)' || { \ echo 'ERROR: trying to run $@ with an empty' \ '$$(distuninstallcheck_dir)' >&2; \ exit 1; \ }; \ $(am__cd) '$(distuninstallcheck_dir)' || { \ echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \ exit 1; \ }; \ test `$(am__distuninstallcheck_listfiles) | wc -l` -eq 0 \ || { echo "ERROR: files left after uninstall:" ; \ if test -n "$(DESTDIR)"; then \ echo " (check DESTDIR support)"; \ fi ; \ $(distuninstallcheck_listfiles) ; \ exit 1; } >&2 distcleancheck: distclean @if test '$(srcdir)' = . ; then \ echo "ERROR: distcleancheck can only run from a VPATH build" ; \ exit 1 ; \ fi @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \ || { echo "ERROR: files left in build directory after distclean:" ; \ $(distcleancheck_listfiles) ; \ exit 1; } >&2 check-am: all-am $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) $(MAKE) $(AM_MAKEFLAGS) check-TESTS check-local check: check-recursive all-am: Makefile $(PROGRAMS) $(MANS) installdirs: installdirs-recursive installdirs-am: for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(man1dir)" "$(DESTDIR)$(man5dir)" "$(DESTDIR)$(man8dir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-recursive install-exec: install-exec-recursive install-data: install-data-recursive uninstall: uninstall-recursive install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-recursive install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: -test -z "$(TEST_LOGS)" || rm -f $(TEST_LOGS) -test -z "$(TEST_LOGS:.log=.trs)" || rm -f $(TEST_LOGS:.log=.trs) -test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) -rm -f src/$(DEPDIR)/$(am__dirstamp) -rm -f src/$(am__dirstamp) -rm -f tests/$(DEPDIR)/$(am__dirstamp) -rm -f tests/$(am__dirstamp) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." clean: clean-recursive clean-am: clean-binPROGRAMS clean-checkPROGRAMS clean-generic \ clean-local clean-sbinPROGRAMS mostlyclean-am distclean: distclean-recursive -rm -f $(am__CONFIG_DISTCLEAN_FILES) -rm -f src/$(DEPDIR)/cfg.Po -rm -f src/$(DEPDIR)/cfgoutput.Po -rm -f src/$(DEPDIR)/check_vnstat-cfg.Po -rm -f src/$(DEPDIR)/check_vnstat-cfgoutput.Po -rm -f src/$(DEPDIR)/check_vnstat-common.Po -rm -f src/$(DEPDIR)/check_vnstat-daemon.Po -rm -f src/$(DEPDIR)/check_vnstat-datacache.Po -rm -f src/$(DEPDIR)/check_vnstat-dbaccess.Po -rm -f src/$(DEPDIR)/check_vnstat-dbjson.Po -rm -f src/$(DEPDIR)/check_vnstat-dbshow.Po -rm -f src/$(DEPDIR)/check_vnstat-dbsql.Po -rm -f src/$(DEPDIR)/check_vnstat-dbxml.Po -rm -f src/$(DEPDIR)/check_vnstat-fs.Po -rm -f src/$(DEPDIR)/check_vnstat-ibw.Po -rm -f src/$(DEPDIR)/check_vnstat-id.Po -rm -f src/$(DEPDIR)/check_vnstat-ifinfo.Po -rm -f src/$(DEPDIR)/check_vnstat-iflist.Po -rm -f src/$(DEPDIR)/check_vnstat-image.Po -rm -f src/$(DEPDIR)/check_vnstat-image_support.Po -rm -f src/$(DEPDIR)/check_vnstat-misc.Po -rm -f src/$(DEPDIR)/check_vnstat-traffic.Po -rm -f src/$(DEPDIR)/check_vnstat-vnstat_func.Po -rm -f src/$(DEPDIR)/common.Po -rm -f src/$(DEPDIR)/daemon.Po -rm -f src/$(DEPDIR)/datacache.Po -rm -f src/$(DEPDIR)/dbaccess.Po -rm -f src/$(DEPDIR)/dbjson.Po -rm -f src/$(DEPDIR)/dbshow.Po -rm -f src/$(DEPDIR)/dbsql.Po -rm -f src/$(DEPDIR)/dbxml.Po -rm -f src/$(DEPDIR)/fs.Po -rm -f src/$(DEPDIR)/ibw.Po -rm -f src/$(DEPDIR)/id.Po -rm -f src/$(DEPDIR)/ifinfo.Po -rm -f src/$(DEPDIR)/iflist.Po -rm -f src/$(DEPDIR)/image.Po -rm -f src/$(DEPDIR)/image_support.Po -rm -f src/$(DEPDIR)/misc.Po -rm -f src/$(DEPDIR)/traffic.Po -rm -f src/$(DEPDIR)/vnstat.Po -rm -f src/$(DEPDIR)/vnstat_func.Po -rm -f src/$(DEPDIR)/vnstatd.Po -rm -f src/$(DEPDIR)/vnstati.Po -rm -f tests/$(DEPDIR)/check_vnstat-cli_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-common_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-config_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-daemon_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-database_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-datacache_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-dbsql_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-fs_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-id_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-ifinfo_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-iflist_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-image_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-misc_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-parseargs_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-vnstat_tests.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-hdr distclean-tags dvi: dvi-recursive dvi-am: html: html-recursive html-am: info: info-recursive info-am: install-data-am: install-man @$(NORMAL_INSTALL) $(MAKE) $(AM_MAKEFLAGS) install-data-hook install-dvi: install-dvi-recursive install-dvi-am: install-exec-am: install-binPROGRAMS install-sbinPROGRAMS install-html: install-html-recursive install-html-am: install-info: install-info-recursive install-info-am: install-man: install-man1 install-man5 install-man8 install-pdf: install-pdf-recursive install-pdf-am: install-ps: install-ps-recursive install-ps-am: installcheck-am: installcheck-binPROGRAMS installcheck-sbinPROGRAMS maintainer-clean: maintainer-clean-recursive -rm -f $(am__CONFIG_DISTCLEAN_FILES) -rm -rf $(top_srcdir)/autom4te.cache -rm -f src/$(DEPDIR)/cfg.Po -rm -f src/$(DEPDIR)/cfgoutput.Po -rm -f src/$(DEPDIR)/check_vnstat-cfg.Po -rm -f src/$(DEPDIR)/check_vnstat-cfgoutput.Po -rm -f src/$(DEPDIR)/check_vnstat-common.Po -rm -f src/$(DEPDIR)/check_vnstat-daemon.Po -rm -f src/$(DEPDIR)/check_vnstat-datacache.Po -rm -f src/$(DEPDIR)/check_vnstat-dbaccess.Po -rm -f src/$(DEPDIR)/check_vnstat-dbjson.Po -rm -f src/$(DEPDIR)/check_vnstat-dbshow.Po -rm -f src/$(DEPDIR)/check_vnstat-dbsql.Po -rm -f src/$(DEPDIR)/check_vnstat-dbxml.Po -rm -f src/$(DEPDIR)/check_vnstat-fs.Po -rm -f src/$(DEPDIR)/check_vnstat-ibw.Po -rm -f src/$(DEPDIR)/check_vnstat-id.Po -rm -f src/$(DEPDIR)/check_vnstat-ifinfo.Po -rm -f src/$(DEPDIR)/check_vnstat-iflist.Po -rm -f src/$(DEPDIR)/check_vnstat-image.Po -rm -f src/$(DEPDIR)/check_vnstat-image_support.Po -rm -f src/$(DEPDIR)/check_vnstat-misc.Po -rm -f src/$(DEPDIR)/check_vnstat-traffic.Po -rm -f src/$(DEPDIR)/check_vnstat-vnstat_func.Po -rm -f src/$(DEPDIR)/common.Po -rm -f src/$(DEPDIR)/daemon.Po -rm -f src/$(DEPDIR)/datacache.Po -rm -f src/$(DEPDIR)/dbaccess.Po -rm -f src/$(DEPDIR)/dbjson.Po -rm -f src/$(DEPDIR)/dbshow.Po -rm -f src/$(DEPDIR)/dbsql.Po -rm -f src/$(DEPDIR)/dbxml.Po -rm -f src/$(DEPDIR)/fs.Po -rm -f src/$(DEPDIR)/ibw.Po -rm -f src/$(DEPDIR)/id.Po -rm -f src/$(DEPDIR)/ifinfo.Po -rm -f src/$(DEPDIR)/iflist.Po -rm -f src/$(DEPDIR)/image.Po -rm -f src/$(DEPDIR)/image_support.Po -rm -f src/$(DEPDIR)/misc.Po -rm -f src/$(DEPDIR)/traffic.Po -rm -f src/$(DEPDIR)/vnstat.Po -rm -f src/$(DEPDIR)/vnstat_func.Po -rm -f src/$(DEPDIR)/vnstatd.Po -rm -f src/$(DEPDIR)/vnstati.Po -rm -f tests/$(DEPDIR)/check_vnstat-cli_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-common_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-config_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-daemon_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-database_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-datacache_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-dbsql_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-fs_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-id_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-ifinfo_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-iflist_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-image_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-misc_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-parseargs_tests.Po -rm -f tests/$(DEPDIR)/check_vnstat-vnstat_tests.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-recursive mostlyclean-am: mostlyclean-compile mostlyclean-generic pdf: pdf-recursive pdf-am: ps: ps-recursive ps-am: uninstall-am: uninstall-binPROGRAMS uninstall-man \ uninstall-sbinPROGRAMS @$(NORMAL_INSTALL) $(MAKE) $(AM_MAKEFLAGS) uninstall-hook uninstall-man: uninstall-man1 uninstall-man5 uninstall-man8 .MAKE: $(am__recursive_targets) check-am install-am install-data-am \ install-strip uninstall-am .PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ am--depfiles am--refresh check check-TESTS check-am \ check-local clean clean-binPROGRAMS clean-checkPROGRAMS \ clean-cscope clean-generic clean-local clean-sbinPROGRAMS \ cscope cscopelist-am ctags ctags-am dist dist-all dist-bzip2 \ dist-gzip dist-lzip dist-shar dist-tarZ dist-xz dist-zip \ distcheck distclean distclean-compile distclean-generic \ distclean-hdr distclean-tags distcleancheck distdir \ distuninstallcheck dvi dvi-am html html-am info info-am \ install install-am install-binPROGRAMS install-data \ install-data-am install-data-hook install-dvi install-dvi-am \ install-exec install-exec-am install-html install-html-am \ install-info install-info-am install-man install-man1 \ install-man5 install-man8 install-pdf install-pdf-am \ install-ps install-ps-am install-sbinPROGRAMS install-strip \ installcheck installcheck-am installcheck-binPROGRAMS \ installcheck-sbinPROGRAMS installdirs installdirs-am \ maintainer-clean maintainer-clean-generic mostlyclean \ mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \ recheck tags tags-am uninstall uninstall-am \ uninstall-binPROGRAMS uninstall-hook uninstall-man \ uninstall-man1 uninstall-man5 uninstall-man8 \ uninstall-sbinPROGRAMS .PRECIOUS: Makefile INSTALL: cp -a INSTALL.md INSTALL INSTALL_BSD: cp -a INSTALL_BSD.md INSTALL_BSD UPGRADE: cp -a UPGRADE.md UPGRADE UNINSTALL: cp -a UNINSTALL.md UNINSTALL setdebug: CFLAGS='-Wall -Wextra -g' ./configure profile: CFLAGS='-Wall -Wextra -g -fprofile-arcs -ftest-coverage' LDLIBS='-fprofile-arcs -ftest-coverage' ./configure make check lcov -c -d $(PWD) -o coverage.lcov genhtml coverage.lcov --num-spaces 4 -p $(PWD) -o coverage myclean: maintainer-clean mancheck: @echo "Testing man pages for errors and warnings" @for m in $(dist_man_MANS); do \ echo " * $$m"; \ LC_ALL=en_US.UTF-8 MANROFFSEQ='' MANWIDTH=80 man --warnings -E UTF-8 -l -Tutf8 -Z $(srcdir)/$$m >/dev/null; \ done release: distcheck tar zxf $(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz rm -f $(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz fakeroot tar zcf $(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz $(PACKAGE_NAME)-$(PACKAGE_VERSION) rm -fr $(PACKAGE_NAME)-$(PACKAGE_VERSION) ls -l $(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz install-data-hook: install-exec if [ -f $(DESTDIR)$(man1dir)/vnstatd.1 ]; then rm -f $(DESTDIR)$(man1dir)/vnstatd.1; fi $(MKDIR_P) $(DESTDIR)$(sysconfdir) @IS_CROSSCOMPILED_TRUE@ if [ ! -f $(DESTDIR)$(sysconfdir)/vnstat.conf ]; \ @IS_CROSSCOMPILED_TRUE@ then cp -fv $(srcdir)/cfg/vnstat.conf $(DESTDIR)$(sysconfdir)/vnstat.conf; \ @IS_CROSSCOMPILED_TRUE@ fi @IS_CROSSCOMPILED_FALSE@ $(DESTDIR)$(bindir)/vnstat$(EXEEXT) --showconfig >vnstat.conf.new @IS_CROSSCOMPILED_FALSE@ if [ -f $(DESTDIR)$(sysconfdir)/vnstat.conf ]; \ @IS_CROSSCOMPILED_FALSE@ then cp -fv $(DESTDIR)$(sysconfdir)/vnstat.conf vnstat.conf.old; \ @IS_CROSSCOMPILED_FALSE@ fi @IS_CROSSCOMPILED_FALSE@ cp -fv vnstat.conf.new $(DESTDIR)$(sysconfdir)/vnstat.conf @echo @echo "============================================================================" @echo " Note: No service file has been installed for starting the daemon" @echo " automatically. Such setup will need to be created manually" @echo " depending on the used environment. See the included documentation." @echo "============================================================================" @echo uninstall-hook: -rm -f $(DESTDIR)$(sysconfdir)/vnstat.conf -rmdir $(DESTDIR)$(sysconfdir) @echo @echo "==================================================================" @echo " Note: The database directory has been left untouched." @echo " It will need to be removed manually if no longer needed." @echo "==================================================================" @echo clean-local: -rm -fr coverage *.lcov *.gz test*.log test*.xml src/*.gc* tests/*.gc* tests/*.conf *.old *.new *check.png INSTALL INSTALL_BSD UPGRADE UNINSTALL check-local: check-TESTS tail -n 2 test.log tests/vnstat.conf: $(top_srcdir)/cfg/vnstat.conf sed 's/^;//g' $(top_srcdir)/cfg/vnstat.conf >$@ echo "MaxBWethnone 8" >>$@ # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: vnstat-2.9/depcomp0000755000000000000000000005601613037475074013000 0ustar rootroot#! /bin/sh # depcomp - compile a program generating dependencies as side-effects scriptversion=2013-05-30.07; # UTC # Copyright (C) 1999-2013 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # Originally written by Alexandre Oliva . case $1 in '') echo "$0: No command. Try '$0 --help' for more information." 1>&2 exit 1; ;; -h | --h*) cat <<\EOF Usage: depcomp [--help] [--version] PROGRAM [ARGS] Run PROGRAMS ARGS to compile a file, generating dependencies as side-effects. Environment variables: depmode Dependency tracking mode. source Source file read by 'PROGRAMS ARGS'. object Object file output by 'PROGRAMS ARGS'. DEPDIR directory where to store dependencies. depfile Dependency file to output. tmpdepfile Temporary file to use when outputting dependencies. libtool Whether libtool is used (yes/no). Report bugs to . EOF exit $? ;; -v | --v*) echo "depcomp $scriptversion" exit $? ;; esac # Get the directory component of the given path, and save it in the # global variables '$dir'. Note that this directory component will # be either empty or ending with a '/' character. This is deliberate. set_dir_from () { case $1 in */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; *) dir=;; esac } # Get the suffix-stripped basename of the given path, and save it the # global variable '$base'. set_base_from () { base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` } # If no dependency file was actually created by the compiler invocation, # we still have to create a dummy depfile, to avoid errors with the # Makefile "include basename.Plo" scheme. make_dummy_depfile () { echo "#dummy" > "$depfile" } # Factor out some common post-processing of the generated depfile. # Requires the auxiliary global variable '$tmpdepfile' to be set. aix_post_process_depfile () { # If the compiler actually managed to produce a dependency file, # post-process it. if test -f "$tmpdepfile"; then # Each line is of the form 'foo.o: dependency.h'. # Do two passes, one to just change these to # $object: dependency.h # and one to simply output # dependency.h: # which is needed to avoid the deleted-header problem. { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" } > "$depfile" rm -f "$tmpdepfile" else make_dummy_depfile fi } # A tabulation character. tab=' ' # A newline character. nl=' ' # Character ranges might be problematic outside the C locale. # These definitions help. upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ lower=abcdefghijklmnopqrstuvwxyz digits=0123456789 alpha=${upper}${lower} if test -z "$depmode" || test -z "$source" || test -z "$object"; then echo "depcomp: Variables source, object and depmode must be set" 1>&2 exit 1 fi # Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. depfile=${depfile-`echo "$object" | sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} rm -f "$tmpdepfile" # Avoid interferences from the environment. gccflag= dashmflag= # Some modes work just like other modes, but use different flags. We # parameterize here, but still list the modes in the big case below, # to make depend.m4 easier to write. Note that we *cannot* use a case # here, because this file can only contain one case statement. if test "$depmode" = hp; then # HP compiler uses -M and no extra arg. gccflag=-M depmode=gcc fi if test "$depmode" = dashXmstdout; then # This is just like dashmstdout with a different argument. dashmflag=-xM depmode=dashmstdout fi cygpath_u="cygpath -u -f -" if test "$depmode" = msvcmsys; then # This is just like msvisualcpp but w/o cygpath translation. # Just convert the backslash-escaped backslashes to single forward # slashes to satisfy depend.m4 cygpath_u='sed s,\\\\,/,g' depmode=msvisualcpp fi if test "$depmode" = msvc7msys; then # This is just like msvc7 but w/o cygpath translation. # Just convert the backslash-escaped backslashes to single forward # slashes to satisfy depend.m4 cygpath_u='sed s,\\\\,/,g' depmode=msvc7 fi if test "$depmode" = xlc; then # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. gccflag=-qmakedep=gcc,-MF depmode=gcc fi case "$depmode" in gcc3) ## gcc 3 implements dependency tracking that does exactly what ## we want. Yay! Note: for some reason libtool 1.4 doesn't like ## it if -MD -MP comes after the -MF stuff. Hmm. ## Unfortunately, FreeBSD c89 acceptance of flags depends upon ## the command line argument order; so add the flags where they ## appear in depend2.am. Note that the slowdown incurred here ## affects only configure: in makefiles, %FASTDEP% shortcuts this. for arg do case $arg in -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; *) set fnord "$@" "$arg" ;; esac shift # fnord shift # $arg done "$@" stat=$? if test $stat -ne 0; then rm -f "$tmpdepfile" exit $stat fi mv "$tmpdepfile" "$depfile" ;; gcc) ## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. ## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. ## (see the conditional assignment to $gccflag above). ## There are various ways to get dependency output from gcc. Here's ## why we pick this rather obscure method: ## - Don't want to use -MD because we'd like the dependencies to end ## up in a subdir. Having to rename by hand is ugly. ## (We might end up doing this anyway to support other compilers.) ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like ## -MM, not -M (despite what the docs say). Also, it might not be ## supported by the other compilers which use the 'gcc' depmode. ## - Using -M directly means running the compiler twice (even worse ## than renaming). if test -z "$gccflag"; then gccflag=-MD, fi "$@" -Wp,"$gccflag$tmpdepfile" stat=$? if test $stat -ne 0; then rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" echo "$object : \\" > "$depfile" # The second -e expression handles DOS-style file names with drive # letters. sed -e 's/^[^:]*: / /' \ -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" ## This next piece of magic avoids the "deleted header file" problem. ## The problem is that when a header file which appears in a .P file ## is deleted, the dependency causes make to die (because there is ## typically no way to rebuild the header). We avoid this by adding ## dummy dependencies for each header file. Too bad gcc doesn't do ## this for us directly. ## Some versions of gcc put a space before the ':'. On the theory ## that the space means something, we add a space to the output as ## well. hp depmode also adds that space, but also prefixes the VPATH ## to the object. Take care to not repeat it in the output. ## Some versions of the HPUX 10.20 sed can't process this invocation ## correctly. Breaking it into two sed invocations is a workaround. tr ' ' "$nl" < "$tmpdepfile" \ | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; hp) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; sgi) if test "$libtool" = yes; then "$@" "-Wp,-MDupdate,$tmpdepfile" else "$@" -MDupdate "$tmpdepfile" fi stat=$? if test $stat -ne 0; then rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files echo "$object : \\" > "$depfile" # Clip off the initial element (the dependent). Don't try to be # clever and replace this with sed code, as IRIX sed won't handle # lines with more than a fixed number of characters (4096 in # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; # the IRIX cc adds comments like '#:fec' to the end of the # dependency line. tr ' ' "$nl" < "$tmpdepfile" \ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ | tr "$nl" ' ' >> "$depfile" echo >> "$depfile" # The second pass generates a dummy entry for each header file. tr ' ' "$nl" < "$tmpdepfile" \ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ >> "$depfile" else make_dummy_depfile fi rm -f "$tmpdepfile" ;; xlc) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; aix) # The C for AIX Compiler uses -M and outputs the dependencies # in a .u file. In older versions, this file always lives in the # current directory. Also, the AIX compiler puts '$object:' at the # start of each line; $object doesn't have directory information. # Version 6 uses the directory in both cases. set_dir_from "$object" set_base_from "$object" if test "$libtool" = yes; then tmpdepfile1=$dir$base.u tmpdepfile2=$base.u tmpdepfile3=$dir.libs/$base.u "$@" -Wc,-M else tmpdepfile1=$dir$base.u tmpdepfile2=$dir$base.u tmpdepfile3=$dir$base.u "$@" -M fi stat=$? if test $stat -ne 0; then rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" exit $stat fi for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" do test -f "$tmpdepfile" && break done aix_post_process_depfile ;; tcc) # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 # FIXME: That version still under development at the moment of writing. # Make that this statement remains true also for stable, released # versions. # It will wrap lines (doesn't matter whether long or short) with a # trailing '\', as in: # # foo.o : \ # foo.c \ # foo.h \ # # It will put a trailing '\' even on the last line, and will use leading # spaces rather than leading tabs (at least since its commit 0394caf7 # "Emit spaces for -MD"). "$@" -MD -MF "$tmpdepfile" stat=$? if test $stat -ne 0; then rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. # We have to change lines of the first kind to '$object: \'. sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" # And for each line of the second kind, we have to emit a 'dep.h:' # dummy dependency, to avoid the deleted-header problem. sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" rm -f "$tmpdepfile" ;; ## The order of this option in the case statement is important, since the ## shell code in configure will try each of these formats in the order ## listed in this file. A plain '-MD' option would be understood by many ## compilers, so we must ensure this comes after the gcc and icc options. pgcc) # Portland's C compiler understands '-MD'. # Will always output deps to 'file.d' where file is the root name of the # source file under compilation, even if file resides in a subdirectory. # The object file name does not affect the name of the '.d' file. # pgcc 10.2 will output # foo.o: sub/foo.c sub/foo.h # and will wrap long lines using '\' : # foo.o: sub/foo.c ... \ # sub/foo.h ... \ # ... set_dir_from "$object" # Use the source, not the object, to determine the base name, since # that's sadly what pgcc will do too. set_base_from "$source" tmpdepfile=$base.d # For projects that build the same source file twice into different object # files, the pgcc approach of using the *source* file root name can cause # problems in parallel builds. Use a locking strategy to avoid stomping on # the same $tmpdepfile. lockdir=$base.d-lock trap " echo '$0: caught signal, cleaning up...' >&2 rmdir '$lockdir' exit 1 " 1 2 13 15 numtries=100 i=$numtries while test $i -gt 0; do # mkdir is a portable test-and-set. if mkdir "$lockdir" 2>/dev/null; then # This process acquired the lock. "$@" -MD stat=$? # Release the lock. rmdir "$lockdir" break else # If the lock is being held by a different process, wait # until the winning process is done or we timeout. while test -d "$lockdir" && test $i -gt 0; do sleep 1 i=`expr $i - 1` done fi i=`expr $i - 1` done trap - 1 2 13 15 if test $i -le 0; then echo "$0: failed to acquire lock after $numtries attempts" >&2 echo "$0: check lockdir '$lockdir'" >&2 exit 1 fi if test $stat -ne 0; then rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" # Each line is of the form `foo.o: dependent.h', # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. # Do two passes, one to just change these to # `$object: dependent.h' and one to simply `dependent.h:'. sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" # Some versions of the HPUX 10.20 sed can't process this invocation # correctly. Breaking it into two sed invocations is a workaround. sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; hp2) # The "hp" stanza above does not work with aCC (C++) and HP's ia64 # compilers, which have integrated preprocessors. The correct option # to use with these is +Maked; it writes dependencies to a file named # 'foo.d', which lands next to the object file, wherever that # happens to be. # Much of this is similar to the tru64 case; see comments there. set_dir_from "$object" set_base_from "$object" if test "$libtool" = yes; then tmpdepfile1=$dir$base.d tmpdepfile2=$dir.libs/$base.d "$@" -Wc,+Maked else tmpdepfile1=$dir$base.d tmpdepfile2=$dir$base.d "$@" +Maked fi stat=$? if test $stat -ne 0; then rm -f "$tmpdepfile1" "$tmpdepfile2" exit $stat fi for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" do test -f "$tmpdepfile" && break done if test -f "$tmpdepfile"; then sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" # Add 'dependent.h:' lines. sed -ne '2,${ s/^ *// s/ \\*$// s/$/:/ p }' "$tmpdepfile" >> "$depfile" else make_dummy_depfile fi rm -f "$tmpdepfile" "$tmpdepfile2" ;; tru64) # The Tru64 compiler uses -MD to generate dependencies as a side # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put # dependencies in 'foo.d' instead, so we check for that too. # Subdirectories are respected. set_dir_from "$object" set_base_from "$object" if test "$libtool" = yes; then # Libtool generates 2 separate objects for the 2 libraries. These # two compilations output dependencies in $dir.libs/$base.o.d and # in $dir$base.o.d. We have to check for both files, because # one of the two compilations can be disabled. We should prefer # $dir$base.o.d over $dir.libs/$base.o.d because the latter is # automatically cleaned when .libs/ is deleted, while ignoring # the former would cause a distcleancheck panic. tmpdepfile1=$dir$base.o.d # libtool 1.5 tmpdepfile2=$dir.libs/$base.o.d # Likewise. tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 "$@" -Wc,-MD else tmpdepfile1=$dir$base.d tmpdepfile2=$dir$base.d tmpdepfile3=$dir$base.d "$@" -MD fi stat=$? if test $stat -ne 0; then rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" exit $stat fi for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" do test -f "$tmpdepfile" && break done # Same post-processing that is required for AIX mode. aix_post_process_depfile ;; msvc7) if test "$libtool" = yes; then showIncludes=-Wc,-showIncludes else showIncludes=-showIncludes fi "$@" $showIncludes > "$tmpdepfile" stat=$? grep -v '^Note: including file: ' "$tmpdepfile" if test $stat -ne 0; then rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" echo "$object : \\" > "$depfile" # The first sed program below extracts the file names and escapes # backslashes for cygpath. The second sed program outputs the file # name when reading, but also accumulates all include files in the # hold buffer in order to output them again at the end. This only # works with sed implementations that can handle large buffers. sed < "$tmpdepfile" -n ' /^Note: including file: *\(.*\)/ { s//\1/ s/\\/\\\\/g p }' | $cygpath_u | sort -u | sed -n ' s/ /\\ /g s/\(.*\)/'"$tab"'\1 \\/p s/.\(.*\) \\/\1:/ H $ { s/.*/'"$tab"'/ G p }' >> "$depfile" echo >> "$depfile" # make sure the fragment doesn't end with a backslash rm -f "$tmpdepfile" ;; msvc7msys) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; #nosideeffect) # This comment above is used by automake to tell side-effect # dependency tracking mechanisms from slower ones. dashmstdout) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout, regardless of -o. "$@" || exit $? # Remove the call to Libtool. if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi # Remove '-o $object'. IFS=" " for arg do case $arg in -o) shift ;; $object) shift ;; *) set fnord "$@" "$arg" shift # fnord shift # $arg ;; esac done test -z "$dashmflag" && dashmflag=-M # Require at least two characters before searching for ':' # in the target name. This is to cope with DOS-style filenames: # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. "$@" $dashmflag | sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" rm -f "$depfile" cat < "$tmpdepfile" > "$depfile" # Some versions of the HPUX 10.20 sed can't process this sed invocation # correctly. Breaking it into two sed invocations is a workaround. tr ' ' "$nl" < "$tmpdepfile" \ | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; dashXmstdout) # This case only exists to satisfy depend.m4. It is never actually # run, as this mode is specially recognized in the preamble. exit 1 ;; makedepend) "$@" || exit $? # Remove any Libtool call if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi # X makedepend shift cleared=no eat=no for arg do case $cleared in no) set ""; shift cleared=yes ;; esac if test $eat = yes; then eat=no continue fi case "$arg" in -D*|-I*) set fnord "$@" "$arg"; shift ;; # Strip any option that makedepend may not understand. Remove # the object too, otherwise makedepend will parse it as a source file. -arch) eat=yes ;; -*|$object) ;; *) set fnord "$@" "$arg"; shift ;; esac done obj_suffix=`echo "$object" | sed 's/^.*\././'` touch "$tmpdepfile" ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" rm -f "$depfile" # makedepend may prepend the VPATH from the source file name to the object. # No need to regex-escape $object, excess matching of '.' is harmless. sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" # Some versions of the HPUX 10.20 sed can't process the last invocation # correctly. Breaking it into two sed invocations is a workaround. sed '1,2d' "$tmpdepfile" \ | tr ' ' "$nl" \ | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" "$tmpdepfile".bak ;; cpp) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout. "$@" || exit $? # Remove the call to Libtool. if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi # Remove '-o $object'. IFS=" " for arg do case $arg in -o) shift ;; $object) shift ;; *) set fnord "$@" "$arg" shift # fnord shift # $arg ;; esac done "$@" -E \ | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ | sed '$ s: \\$::' > "$tmpdepfile" rm -f "$depfile" echo "$object : \\" > "$depfile" cat < "$tmpdepfile" >> "$depfile" sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; msvisualcpp) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout. "$@" || exit $? # Remove the call to Libtool. if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi IFS=" " for arg do case "$arg" in -o) shift ;; $object) shift ;; "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") set fnord "$@" shift shift ;; *) set fnord "$@" "$arg" shift shift ;; esac done "$@" -E 2>/dev/null | sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" rm -f "$depfile" echo "$object : \\" > "$depfile" sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" echo "$tab" >> "$depfile" sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" rm -f "$tmpdepfile" ;; msvcmsys) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; none) exec "$@" ;; *) echo "Unknown depmode $depmode" 1>&2 exit 1 ;; esac exit 0 # Local Variables: # mode: shell-script # sh-indentation: 2 # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC" # time-stamp-end: "; # UTC" # End: vnstat-2.9/configure0000755000000000000000000064122314173305711013322 0ustar rootroot#! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.69 for vnstat 2.9. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. # # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # Use a proper internal environment variable to ensure we don't fall # into an infinite loop, continuously re-executing ourselves. if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then _as_can_reexec=no; export _as_can_reexec; # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 as_fn_exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi " as_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 test \$(( 1 + 1 )) = 2 || exit 1" if (eval "$as_required") 2>/dev/null; then : as_have_required=yes else as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir/$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi done;; esac as_found=false done $as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes fi; } IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : export CONFIG_SHELL # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi if test x$as_have_required = xno; then : $as_echo "$0: This script requires a shell more modern than all" $as_echo "$0: the shells that I found on your system." if test x${ZSH_VERSION+set} = xset ; then $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: be upgraded to zsh 4.3.4 or later." else $as_echo "$0: Please tell bug-autoconf@gnu.org about your system, $0: including any error possibly output before this $0: message. Then install a modern shell, or manually run $0: the script under such a shell if you do have one." fi exit 1 fi fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) sed -n ' p /[$]LINENO/= ' <$as_myself | sed ' s/[$]LINENO.*/&-/ t lineno b :lineno N :loop s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ t loop s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # If we had to re-execute with $CONFIG_SHELL, we're ensured to have # already done that, so ensure we don't try to do so again and fall # in an infinite loop. This has already happened in practice. _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). . "./$as_me.lineno" # Exit status is that of the last command. exit } ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` # # Initializations. # ac_default_prefix=/usr/local ac_clean_files= ac_config_libobj_dir=. LIBOBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='vnstat' PACKAGE_TARNAME='vnstat' PACKAGE_VERSION='2.9' PACKAGE_STRING='vnstat 2.9' PACKAGE_BUGREPORT='' PACKAGE_URL='' ac_unique_file="src/vnstatd.c" # Factoring default headers for most tests. ac_includes_default="\ #include #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef STDC_HEADERS # include # include #else # ifdef HAVE_STDLIB_H # include # endif #endif #ifdef HAVE_STRING_H # if !defined STDC_HEADERS && defined HAVE_MEMORY_H # include # endif # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif" ac_header_list= ac_func_list= ac_subst_vars='am__EXEEXT_FALSE am__EXEEXT_TRUE LTLIBOBJS LIBOBJS IS_CROSSCOMPILED_FALSE IS_CROSSCOMPILED_TRUE host_os host_vendor host_cpu host build_os build_vendor build_cpu build EGREP GREP CPP HAVE_CHECK_FALSE HAVE_CHECK_TRUE CHECK_LIBS CHECK_CFLAGS PKG_CONFIG_LIBDIR PKG_CONFIG_PATH PKG_CONFIG HAVE_LIBGD_FALSE HAVE_LIBGD_TRUE IMAGELIBS CFLAG_EXTRAS am__fastdepCC_FALSE am__fastdepCC_TRUE CCDEPMODE am__nodep AMDEPBACKSLASH AMDEP_FALSE AMDEP_TRUE am__include DEPDIR OBJEXT EXEEXT ac_ct_CC CPPFLAGS LDFLAGS CFLAGS CC MAINT MAINTAINER_MODE_FALSE MAINTAINER_MODE_TRUE AM_BACKSLASH AM_DEFAULT_VERBOSITY AM_DEFAULT_V AM_V am__untar am__tar AMTAR am__leading_dot SET_MAKE AWK mkdir_p MKDIR_P INSTALL_STRIP_PROGRAM STRIP install_sh MAKEINFO AUTOHEADER AUTOMAKE AUTOCONF ACLOCAL VERSION PACKAGE CYGPATH_W am__isrc INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir runstatedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL am__quote' ac_subst_files='' ac_user_opts=' enable_option_checking enable_silent_rules enable_maintainer_mode enable_dependency_tracking enable_image_output enable_werror enable_extra_paths ' ac_precious_vars='build_alias host_alias target_alias CC CFLAGS LDFLAGS LIBS CPPFLAGS PKG_CONFIG PKG_CONFIG_PATH PKG_CONFIG_LIBDIR CHECK_CFLAGS CHECK_LIBS CPP' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= verbose= x_includes=NONE x_libraries=NONE # Installation directory options. # These are left unexpanded so users can "make install exec_prefix=/foo" # and all the variables that are supposed to be based on exec_prefix # by default will actually change. # Use braces instead of parens because sh, perl, etc. also accept them. # (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' infodir='${datarootdir}/info' htmldir='${docdir}' dvidir='${docdir}' pdfdir='${docdir}' psdir='${docdir}' libdir='${exec_prefix}/lib' localedir='${datarootdir}/locale' mandir='${datarootdir}/man' ac_prev= ac_dashdash= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval $ac_prev=\$ac_option ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file=$ac_optarg ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=*) datadir=$ac_optarg ;; -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ | --dataroo | --dataro | --datar) ac_prev=datarootdir ;; -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) datarootdir=$ac_optarg ;; -disable-* | --disable-*) ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; -docdir | --docdir | --docdi | --doc | --do) ac_prev=docdir ;; -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) docdir=$ac_optarg ;; -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) ac_prev=dvidir ;; -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) dvidir=$ac_optarg ;; -enable-* | --enable-*) ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he | -h) ac_init_help=long ;; -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) ac_init_help=recursive ;; -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) ac_init_help=short ;; -host | --host | --hos | --ho) ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) host_alias=$ac_optarg ;; -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) ac_prev=htmldir ;; -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ | --ht=*) htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir=$ac_optarg ;; -localedir | --localedir | --localedi | --localed | --locale) ac_prev=localedir ;; -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name=$ac_optarg ;; -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) ac_prev=pdfdir ;; -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) pdfdir=$ac_optarg ;; -psdir | --psdir | --psdi | --psd | --ps) ac_prev=psdir ;; -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -runstatedir | --runstatedir | --runstatedi | --runstated \ | --runstate | --runstat | --runsta | --runst | --runs \ | --run | --ru | --r) ac_prev=runstatedir ;; -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ | --run=* | --ru=* | --r=*) runstatedir=$ac_optarg ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; -*) as_fn_error $? "unrecognized option: \`$ac_option' Try \`$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; esac done if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: `$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias host=$host_alias target=$target_alias # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi fi ac_tool_prefix= test -n "$host_alias" && ac_tool_prefix=$host_alias- test "$silent" = yes && exec 6>/dev/null ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. fi # Remove unnecessary trailing slashes from srcdir. # Double slashes in file names in object file debugging info # mess up M-x gdb in Emacs. case $srcdir in */) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; esac for ac_var in $ac_precious_vars; do eval ac_env_${ac_var}_set=\${${ac_var}+set} eval ac_env_${ac_var}_value=\$${ac_var} eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} eval ac_cv_env_${ac_var}_value=\$${ac_var} done # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF \`configure' configures vnstat 2.9 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print \`checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for \`--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or \`..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, \`make install' will install all the files in \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify an installation prefix other than \`$ac_default_prefix' using \`--prefix', for instance \`--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/vnstat] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] _ACEOF cat <<\_ACEOF Program names: --program-prefix=PREFIX prepend PREFIX to installed program names --program-suffix=SUFFIX append SUFFIX to installed program names --program-transform-name=PROGRAM run sed PROGRAM on installed program names System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in short | recursive ) echo "Configuration of vnstat 2.9:";; esac cat <<\_ACEOF Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --enable-silent-rules less verbose build output (undo: "make V=1") --disable-silent-rules verbose build output (undo: "make V=0") --enable-maintainer-mode enable make rules and dependencies not useful (and sometimes confusing) to the casual installer --enable-dependency-tracking do not reject slow dependency extractors --disable-dependency-tracking speeds up one-time build --disable-image-output disable PNG image output --enable-werror add -Werror to CFLAGS --disable-extra-paths do not add extra paths to CFLAGS and LDFLAGS Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory PKG_CONFIG path to pkg-config utility PKG_CONFIG_PATH directories to add to pkg-config's search path PKG_CONFIG_LIBDIR path overriding pkg-config's built-in search path CHECK_CFLAGS C compiler flags for CHECK, overriding pkg-config CHECK_LIBS linker flags for CHECK, overriding pkg-config CPP C preprocessor Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to the package provider. _ACEOF ac_status=$? fi if test "$ac_init_help" = "recursive"; then # If there are subdirs, report their specific --help. for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue test -d "$ac_dir" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || continue ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } # Check for guested configure. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive elif test -f "$ac_srcdir/configure"; then echo && $SHELL "$ac_srcdir/configure" --help=recursive else $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF vnstat configure 2.9 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF exit fi ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## # ac_fn_c_try_compile LINENO # -------------------------- # Try to compile conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest.$ac_objext; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_compile # ac_fn_c_try_link LINENO # ----------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_link () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext conftest$ac_exeext if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || test -x conftest$ac_exeext }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would # interfere with the next link command; also delete a directory that is # left behind by Apple's compiler. We do this before executing the actions. rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_link # ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES # --------------------------------------------- # Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR # accordingly. ac_fn_c_check_decl () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack as_decl_name=`echo $2|sed 's/ *(.*//'` as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'` { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5 $as_echo_n "checking whether $as_decl_name is declared... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { #ifndef $as_decl_name #ifdef __cplusplus (void) $as_decl_use; #else (void) $as_decl_name; #endif #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_decl # ac_fn_c_try_cpp LINENO # ---------------------- # Try to preprocess conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_cpp () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_cpp conftest.$ac_ext" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } > conftest.i && { test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || test ! -s conftest.err }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_cpp # ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists, giving a warning if it cannot be compiled using # the include files in INCLUDES and setting the cache variable VAR # accordingly. ac_fn_c_check_header_mongrel () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if eval \${$3+:} false; then : { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } else # Is the header compilable? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 $as_echo_n "checking $2 usability... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_header_compiler=yes else ac_header_compiler=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 $as_echo "$ac_header_compiler" >&6; } # Is the header present? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 $as_echo_n "checking $2 presence... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include <$2> _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : ac_header_preproc=yes else ac_header_preproc=no fi rm -f conftest.err conftest.i conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 $as_echo "$ac_header_preproc" >&6; } # So? What about this header? case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( yes:no: ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 $as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ;; no:yes:* ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 $as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 $as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 $as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 $as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=\$ac_header_compiler" fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_mongrel # ac_fn_c_try_run LINENO # ---------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. Assumes # that executables *can* be run. ac_fn_c_try_run () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then : ac_retval=0 else $as_echo "$as_me: program exited with status $ac_status" >&5 $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=$ac_status fi rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_run # ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists and can be compiled using the include files in # INCLUDES, setting the cache variable VAR accordingly. ac_fn_c_check_header_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_compile # ac_fn_c_find_intX_t LINENO BITS VAR # ----------------------------------- # Finds a signed integer type with width BITS, setting cache variable VAR # accordingly. ac_fn_c_find_intX_t () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for int$2_t" >&5 $as_echo_n "checking for int$2_t... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=no" # Order is important - never check a type that is potentially smaller # than half of the expected target width. for ac_type in int$2_t 'int' 'long int' \ 'long long int' 'short int' 'signed char'; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default enum { N = $2 / 2 - 1 }; int main () { static int test_array [1 - 2 * !(0 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1))]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default enum { N = $2 / 2 - 1 }; int main () { static int test_array [1 - 2 * !(($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1) < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 2))]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else case $ac_type in #( int$2_t) : eval "$3=yes" ;; #( *) : eval "$3=\$ac_type" ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if eval test \"x\$"$3"\" = x"no"; then : else break fi done fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_find_intX_t # ac_fn_c_check_type LINENO TYPE VAR INCLUDES # ------------------------------------------- # Tests whether TYPE exists after having included INCLUDES, setting cache # variable VAR accordingly. ac_fn_c_check_type () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=no" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { if (sizeof ($2)) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { if (sizeof (($2))) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else eval "$3=yes" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_type # ac_fn_c_find_uintX_t LINENO BITS VAR # ------------------------------------ # Finds an unsigned integer type with width BITS, setting cache variable VAR # accordingly. ac_fn_c_find_uintX_t () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for uint$2_t" >&5 $as_echo_n "checking for uint$2_t... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=no" # Order is important - never check a type that is potentially smaller # than half of the expected target width. for ac_type in uint$2_t 'unsigned int' 'unsigned long int' \ 'unsigned long long int' 'unsigned short int' 'unsigned char'; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int main () { static int test_array [1 - 2 * !((($ac_type) -1 >> ($2 / 2 - 1)) >> ($2 / 2 - 1) == 3)]; test_array [0] = 0; return test_array [0]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : case $ac_type in #( uint$2_t) : eval "$3=yes" ;; #( *) : eval "$3=\$ac_type" ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if eval test \"x\$"$3"\" = x"no"; then : else break fi done fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_find_uintX_t # ac_fn_c_check_func LINENO FUNC VAR # ---------------------------------- # Tests whether FUNC exists, setting the cache variable VAR accordingly ac_fn_c_check_func () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Define $2 to an innocuous variant, in case declares $2. For example, HP-UX 11i declares gettimeofday. */ #define $2 innocuous_$2 /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $2 (); below. Prefer to if __STDC__ is defined, since exists even on freestanding compilers. */ #ifdef __STDC__ # include #else # include #endif #undef $2 /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char $2 (); /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ #if defined __stub_$2 || defined __stub___$2 choke me #endif int main () { return $2 (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_func cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by vnstat $as_me 2.9, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ _ACEOF exec 5>>config.log { cat <<_ASUNAME ## --------- ## ## Platform. ## ## --------- ## hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` /bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` /bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` /usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` /bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` /bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` _ASUNAME as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. $as_echo "PATH: $as_dir" done IFS=$as_save_IFS } >&5 cat >&5 <<_ACEOF ## ----------- ## ## Core tests. ## ## ----------- ## _ACEOF # Keep a trace of the command line. # Strip out --no-create and --no-recursion so they do not pile up. # Strip out --silent because we don't want to record it for future runs. # Also quote any args containing shell meta-characters. # Make two passes to allow for proper duplicate-argument suppression. ac_configure_args= ac_configure_args0= ac_configure_args1= ac_must_keep_next=false for ac_pass in 1 2 do for ac_arg do case $ac_arg in -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then ac_must_keep_next=false # Got value, back to normal. else case $ac_arg in *=* | --config-cache | -C | -disable-* | --disable-* \ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ | -with-* | --with-* | -without-* | --without-* | --x) case "$ac_configure_args0 " in "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; esac ;; -* ) ac_must_keep_next=true ;; esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset ac_configure_args1;} # When interrupted or exit'd, cleanup temporary files, and complete # config.log. We remove comments because anyway the quotes in there # would cause problems or look ugly. # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? # Save into config.log some information that might help in debugging. { echo $as_echo "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ "s/'\''/'\''\\\\'\'''\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) echo $as_echo "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then $as_echo "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then $as_echo "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && $as_echo "$as_me: caught signal $ac_signal" $as_echo "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && exit $exit_status ' 0 for ac_signal in 1 2 13 15; do trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal done ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h $as_echo "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. cat >>confdefs.h <<_ACEOF #define PACKAGE_NAME "$PACKAGE_NAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_TARNAME "$PACKAGE_TARNAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_VERSION "$PACKAGE_VERSION" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_STRING "$PACKAGE_STRING" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_URL "$PACKAGE_URL" _ACEOF # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. ac_site_file1=NONE ac_site_file2=NONE if test -n "$CONFIG_SITE"; then # We do not want a PATH search for config.site. case $CONFIG_SITE in #(( -*) ac_site_file1=./$CONFIG_SITE;; */*) ac_site_file1=$CONFIG_SITE;; *) ac_site_file1=./$CONFIG_SITE;; esac elif test "x$prefix" != xNONE; then ac_site_file1=$prefix/share/config.site ac_site_file2=$prefix/etc/config.site else ac_site_file1=$ac_default_prefix/share/config.site ac_site_file2=$ac_default_prefix/etc/config.site fi for ac_site_file in "$ac_site_file1" "$ac_site_file2" do test "x$ac_site_file" = xNONE && continue if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 $as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 $as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 $as_echo "$as_me: creating cache $cache_file" >&6;} >$cache_file fi as_fn_append ac_header_list " sys/time.h" as_fn_append ac_header_list " unistd.h" as_fn_append ac_func_list " alarm" # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false for ac_var in $ac_precious_vars; do eval ac_old_set=\$ac_cv_env_${ac_var}_set eval ac_new_set=\$ac_env_${ac_var}_set eval ac_old_val=\$ac_cv_env_${ac_var}_value eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 $as_echo "$as_me: former value: \`$ac_old_val'" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu am__api_version='1.16' ac_aux_dir= for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do if test -f "$ac_dir/install-sh"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install-sh -c" break elif test -f "$ac_dir/install.sh"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/install.sh -c" break elif test -f "$ac_dir/shtool"; then ac_aux_dir=$ac_dir ac_install_sh="$ac_aux_dir/shtool install -c" break fi done if test -z "$ac_aux_dir"; then as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5 fi # These three variables are undocumented and unsupported, # and are intended to be withdrawn in a future Autoconf release. # They can cause serious problems if a builder's source tree is in a directory # whose full name contains unusual characters. ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: # SysV /etc/install, /usr/sbin/install # SunOS /usr/etc/install # IRIX /sbin/install # AIX /bin/install # AmigaOS /C/install, which installs bootblocks on floppy discs # AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag # AFS /usr/afsws/bin/install, which mishandles nonexistent args # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # OS/2's system install, which has a completely different semantic # ./install, which can be erroneously created by make from ./install.sh. # Reject install programs that cannot install multiple files. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 $as_echo_n "checking for a BSD-compatible install... " >&6; } if test -z "$INSTALL"; then if ${ac_cv_path_install+:} false; then : $as_echo_n "(cached) " >&6 else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. # Account for people who put trailing slashes in PATH elements. case $as_dir/ in #(( ./ | .// | /[cC]/* | \ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ /usr/ucb/* ) ;; *) # OSF1 and SCO ODT 3.0 have their own names for install. # Don't use installbsd from OSF since it installs stuff as root # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then if test $ac_prog = install && grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. : elif test $ac_prog = install && grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # program-specific install script used by HP pwplus--don't use. : else rm -rf conftest.one conftest.two conftest.dir echo one > conftest.one echo two > conftest.two mkdir conftest.dir if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && test -s conftest.one && test -s conftest.two && test -s conftest.dir/conftest.one && test -s conftest.dir/conftest.two then ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" break 3 fi fi fi done done ;; esac done IFS=$as_save_IFS rm -rf conftest.one conftest.two conftest.dir fi if test "${ac_cv_path_install+set}" = set; then INSTALL=$ac_cv_path_install else # As a last resort, use the slow shell script. Don't cache a # value for INSTALL within a source directory, because that will # break other packages using the cache if that directory is # removed, or if the value is a relative name. INSTALL=$ac_install_sh fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 $as_echo "$INSTALL" >&6; } # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 $as_echo_n "checking whether build environment is sane... " >&6; } # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' ' case `pwd` in *[\\\"\#\$\&\'\`$am_lf]*) as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5;; esac case $srcdir in *[\\\"\#\$\&\'\`$am_lf\ \ ]*) as_fn_error $? "unsafe srcdir value: '$srcdir'" "$LINENO" 5;; esac # Do 'set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( am_has_slept=no for am_try in 1 2; do echo "timestamp, slept: $am_has_slept" > conftest.file set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` if test "$*" = "X"; then # -L didn't work. set X `ls -t "$srcdir/configure" conftest.file` fi if test "$*" != "X $srcdir/configure conftest.file" \ && test "$*" != "X conftest.file $srcdir/configure"; then # If neither matched, then we have a broken ls. This can happen # if, for instance, CONFIG_SHELL is bash and it inherits a # broken ls alias from the environment. This has actually # happened. Such a system could not be considered "sane". as_fn_error $? "ls -t appears to fail. Make sure there is not a broken alias in your environment" "$LINENO" 5 fi if test "$2" = conftest.file || test $am_try -eq 2; then break fi # Just in case. sleep 1 am_has_slept=yes done test "$2" = conftest.file ) then # Ok. : else as_fn_error $? "newly created file is older than distributed files! Check your system clock" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } # If we didn't sleep, we still need to ensure time stamps of config.status and # generated files are strictly newer. am_sleep_pid= if grep 'slept: no' conftest.file >/dev/null 2>&1; then ( sleep 1 ) & am_sleep_pid=$! fi rm -f conftest.file test "$program_prefix" != NONE && program_transform_name="s&^&$program_prefix&;$program_transform_name" # Use a double $ so make ignores it. test "$program_suffix" != NONE && program_transform_name="s&\$&$program_suffix&;$program_transform_name" # Double any \ or $. # By default was `s,x,x', remove it if useless. ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` # Expand $ac_aux_dir to an absolute path. am_aux_dir=`cd "$ac_aux_dir" && pwd` if test x"${MISSING+set}" != xset; then case $am_aux_dir in *\ * | *\ *) MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; *) MISSING="\${SHELL} $am_aux_dir/missing" ;; esac fi # Use eval to expand $SHELL if eval "$MISSING --is-lightweight"; then am_missing_run="$MISSING " else am_missing_run= { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 $as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;} fi if test x"${install_sh+set}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; *) install_sh="\${SHELL} $am_aux_dir/install-sh" esac fi # Installed binaries are usually stripped using 'strip' when the user # run "make install-strip". However 'strip' might not be the right # tool to use in cross-compilation environments, therefore Automake # will honor the 'STRIP' environment variable to overrule this program. if test "$cross_compiling" != no; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. set dummy ${ac_tool_prefix}strip; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_STRIP+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$STRIP"; then ac_cv_prog_STRIP="$STRIP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi STRIP=$ac_cv_prog_STRIP if test -n "$STRIP"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 $as_echo "$STRIP" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_STRIP"; then ac_ct_STRIP=$STRIP # Extract the first word of "strip", so it can be a program name with args. set dummy strip; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_STRIP+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_STRIP"; then ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_STRIP="strip" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP if test -n "$ac_ct_STRIP"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 $as_echo "$ac_ct_STRIP" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_STRIP" = x; then STRIP=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac STRIP=$ac_ct_STRIP fi else STRIP="$ac_cv_prog_STRIP" fi fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 $as_echo_n "checking for a thread-safe mkdir -p... " >&6; } if test -z "$MKDIR_P"; then if ${ac_cv_path_mkdir+:} false; then : $as_echo_n "(cached) " >&6 else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in mkdir gmkdir; do for ac_exec_ext in '' $ac_executable_extensions; do as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( 'mkdir (GNU coreutils) '* | \ 'mkdir (coreutils) '* | \ 'mkdir (fileutils) '4.1*) ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext break 3;; esac done done done IFS=$as_save_IFS fi test -d ./--version && rmdir ./--version if test "${ac_cv_path_mkdir+set}" = set; then MKDIR_P="$ac_cv_path_mkdir -p" else # As a last resort, use the slow shell script. Don't cache a # value for MKDIR_P within a source directory, because that will # break other packages using the cache if that directory is # removed, or if the value is a relative name. MKDIR_P="$ac_install_sh -d" fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 $as_echo "$MKDIR_P" >&6; } for ac_prog in gawk mawk nawk awk do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_AWK+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$AWK"; then ac_cv_prog_AWK="$AWK" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_AWK="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi AWK=$ac_cv_prog_AWK if test -n "$AWK"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 $as_echo "$AWK" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$AWK" && break done { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 $as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } set x ${MAKE-make} ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : $as_echo_n "(cached) " >&6 else cat >conftest.make <<\_ACEOF SHELL = /bin/sh all: @echo '@@@%%%=$(MAKE)=@@@%%%' _ACEOF # GNU make sometimes prints "make[1]: Entering ...", which would confuse us. case `${MAKE-make} -f conftest.make 2>/dev/null` in *@@@%%%=?*=@@@%%%*) eval ac_cv_prog_make_${ac_make}_set=yes;; *) eval ac_cv_prog_make_${ac_make}_set=no;; esac rm -f conftest.make fi if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } SET_MAKE= else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi rm -rf .tst 2>/dev/null mkdir .tst 2>/dev/null if test -d .tst; then am__leading_dot=. else am__leading_dot=_ fi rmdir .tst 2>/dev/null # Check whether --enable-silent-rules was given. if test "${enable_silent_rules+set}" = set; then : enableval=$enable_silent_rules; fi case $enable_silent_rules in # ((( yes) AM_DEFAULT_VERBOSITY=0;; no) AM_DEFAULT_VERBOSITY=1;; *) AM_DEFAULT_VERBOSITY=1;; esac am_make=${MAKE-make} { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5 $as_echo_n "checking whether $am_make supports nested variables... " >&6; } if ${am_cv_make_support_nested_variables+:} false; then : $as_echo_n "(cached) " >&6 else if $as_echo 'TRUE=$(BAR$(V)) BAR0=false BAR1=true V=1 am__doit: @$(TRUE) .PHONY: am__doit' | $am_make -f - >/dev/null 2>&1; then am_cv_make_support_nested_variables=yes else am_cv_make_support_nested_variables=no fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5 $as_echo "$am_cv_make_support_nested_variables" >&6; } if test $am_cv_make_support_nested_variables = yes; then AM_V='$(V)' AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' else AM_V=$AM_DEFAULT_VERBOSITY AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY fi AM_BACKSLASH='\' if test "`cd $srcdir && pwd`" != "`pwd`"; then # Use -I$(srcdir) only when $(srcdir) != ., so that make's output # is not polluted with repeated "-I." am__isrc=' -I$(srcdir)' # test to see if srcdir already configured if test -f $srcdir/config.status; then as_fn_error $? "source directory already configured; run \"make distclean\" there first" "$LINENO" 5 fi fi # test whether we have cygpath if test -z "$CYGPATH_W"; then if (cygpath --version) >/dev/null 2>/dev/null; then CYGPATH_W='cygpath -w' else CYGPATH_W=echo fi fi # Define the identity of the package. PACKAGE='vnstat' VERSION='2.9' cat >>confdefs.h <<_ACEOF #define PACKAGE "$PACKAGE" _ACEOF cat >>confdefs.h <<_ACEOF #define VERSION "$VERSION" _ACEOF # Some tools Automake needs. ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"} AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"} AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"} AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"} MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} # For better backward compatibility. To be removed once Automake 1.9.x # dies out for good. For more background, see: # # mkdir_p='$(MKDIR_P)' # We need awk for the "check" target (and possibly the TAP driver). The # system "awk" is bad on some platforms. # Always define AMTAR for backward compatibility. Yes, it's still used # in the wild :-( We should find a proper way to deprecate it ... AMTAR='$${TAR-tar}' # We'll loop over all known methods to create a tar archive until one works. _am_tools='gnutar pax cpio none' am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -' # POSIX will say in a future version that running "rm -f" with no argument # is OK; and we want to be able to make that assumption in our Makefile # recipes. So use an aggressive probe to check that the usage we want is # actually supported "in the wild" to an acceptable degree. # See automake bug#10828. # To make any issue more visible, cause the running configure to be aborted # by default if the 'rm' program in use doesn't match our expectations; the # user can still override this though. if rm -f && rm -fr && rm -rf; then : OK; else cat >&2 <<'END' Oops! Your 'rm' program seems unable to run without file operands specified on the command line, even when the '-f' option is present. This is contrary to the behaviour of most rm programs out there, and not conforming with the upcoming POSIX standard: Please tell bug-automake@gnu.org about your system, including the value of your $PATH and any error possibly output before this message. This can help us improve future automake versions. END if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then echo 'Configuration will proceed anyway, since you have set the' >&2 echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2 echo >&2 else cat >&2 <<'END' Aborting the configuration process, to ensure you take notice of the issue. You can download and install GNU coreutils to get an 'rm' implementation that behaves properly: . If you want to complete the configuration process using your problematic 'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM to "yes", and re-run configure. END as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5 fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 $as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; } # Check whether --enable-maintainer-mode was given. if test "${enable_maintainer_mode+set}" = set; then : enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval else USE_MAINTAINER_MODE=no fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5 $as_echo "$USE_MAINTAINER_MODE" >&6; } if test $USE_MAINTAINER_MODE = yes; then MAINTAINER_MODE_TRUE= MAINTAINER_MODE_FALSE='#' else MAINTAINER_MODE_TRUE='#' MAINTAINER_MODE_FALSE= fi MAINT=$MAINTAINER_MODE_TRUE ac_config_headers="$ac_config_headers src/config.h" # Checks for programs. ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. set dummy ${ac_tool_prefix}gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_CC"; then ac_ct_CC=$CC # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi else CC="$ac_cv_prog_CC" fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. set dummy ${ac_tool_prefix}cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi fi if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else ac_prog_rejected=no as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue fi ac_cv_prog_CC="cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift if test $# != 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" fi fi fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then for ac_prog in cl.exe do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$CC" && break done fi if test -z "$CC"; then ac_ct_CC=$CC for ac_prog in cl.exe do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$ac_ct_CC" && break done if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi fi fi test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See \`config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 $as_echo_n "checking whether the C compiler works... " >&6; } ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" ac_rmfiles= for ac_file in $ac_files do case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; * ) ac_rmfiles="$ac_rmfiles $ac_file";; esac done rm -f $ac_rmfiles if { { ac_try="$ac_link_default" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. # So ignore a value of `no', otherwise this would lead to `EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, # so that the user can short-circuit this test for compilers unknown to # Autoconf. for ac_file in $ac_files '' do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; [ab].out ) # We found the default executable, but exeext='' is most # certainly right. break;; *.* ) if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi # We set ac_cv_exeext here because the later test for it is not # safe: cross compilers may not add the suffix if given an `-o' # argument, so we may need to know it at that point already. # Even if this section looks crufty: it has the advantage of # actually working. break;; * ) break;; esac done test "$ac_cv_exeext" = no && ac_cv_exeext= else ac_file='' fi if test -z "$ac_file"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables See \`config.log' for more details" "$LINENO" 5; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 $as_echo_n "checking for C compiler default output file name... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 $as_echo "$ac_file" >&6; } ac_exeext=$ac_cv_exeext rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 $as_echo_n "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # If both `conftest.exe' and `conftest' are `present' (well, observable) # catch `conftest.exe'. For instance with Cygwin, `ls conftest' will # work properly (i.e., refer to `conftest.exe'), while it won't with # `rm'. for ac_file in conftest.exe conftest conftest.*; do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` break;; * ) break;; esac done else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest conftest$ac_cv_exeext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 $as_echo "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext ac_exeext=$EXEEXT cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF ac_clean_files="$ac_clean_files conftest.out" # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 $as_echo_n "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then cross_compiling=no else if test "$cross_compiling" = maybe; then cross_compiling=yes else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run C compiled programs. If you meant to cross compile, use \`--host'. See \`config.log' for more details" "$LINENO" 5; } fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 $as_echo "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 $as_echo_n "checking for suffix of object files... " >&6; } if ${ac_cv_objext+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF rm -f conftest.o conftest.obj if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : for ac_file in conftest.o conftest.obj conftest.*; do test -f "$ac_file" || continue; case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` break;; esac done else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 $as_echo "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; } if ${ac_cv_c_compiler_gnu+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_compiler_gnu=yes else ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 $as_echo "$ac_cv_c_compiler_gnu" >&6; } if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 $as_echo_n "checking whether $CC accepts -g... " >&6; } if ${ac_cv_prog_cc_g+:} false; then : $as_echo_n "(cached) " >&6 else ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes else CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 $as_echo "$ac_cv_prog_cc_g" >&6; } if test "$ac_test_CFLAGS" = set; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" else CFLAGS="-g" fi else if test "$GCC" = yes; then CFLAGS="-O2" else CFLAGS= fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 $as_echo_n "checking for $CC option to accept ISO C89... " >&6; } if ${ac_cv_prog_cc_c89+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include struct stat; /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); static char *e (p, i) char **p; int i; { return p[i]; } static char *f (char * (*g) (char **, int), char **p, ...) { char *s; va_list v; va_start (v,p); s = g (p, va_arg (v,int)); va_end (v); return s; } /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has function prototypes and stuff, but not '\xHH' hex character constants. These don't provoke an error unfortunately, instead are silently treated as 'x'. The following induces an error, until -std is added to get proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an array size at least. It's necessary to write '\x00'==0 to get something that's true only with -std. */ int osf4_cc_array ['\x00' == 0 ? 1 : -1]; /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters inside strings and character constants. */ #define FOO(x) 'x' int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; int test (int i, double x); struct s1 {int (*f) (int a);}; struct s2 {int (*f) (double a);}; int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); int argc; char **argv; int main () { return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; ; return 0; } _ACEOF for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_c89=$ac_arg fi rm -f core conftest.err conftest.$ac_objext test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC fi # AC_CACHE_VAL case "x$ac_cv_prog_cc_c89" in x) { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 $as_echo "none needed" >&6; } ;; xno) { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 $as_echo "unsupported" >&6; } ;; *) CC="$CC $ac_cv_prog_cc_c89" { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 $as_echo "$ac_cv_prog_cc_c89" >&6; } ;; esac if test "x$ac_cv_prog_cc_c89" != xno; then : fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 $as_echo_n "checking whether $CC understands -c and -o together... " >&6; } if ${am_cv_prog_cc_c_o+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF # Make sure it works both with $CC and with simple cc. # Following AC_PROG_CC_C_O, we do the test twice because some # compilers refuse to overwrite an existing .o file with -o, # though they will create one. am_cv_prog_cc_c_o=yes for am_i in 1 2; do if { echo "$as_me:$LINENO: $CC -c conftest.$ac_ext -o conftest2.$ac_objext" >&5 ($CC -c conftest.$ac_ext -o conftest2.$ac_objext) >&5 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } \ && test -f conftest2.$ac_objext; then : OK else am_cv_prog_cc_c_o=no break fi done rm -f core conftest* unset am_i fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 $as_echo "$am_cv_prog_cc_c_o" >&6; } if test "$am_cv_prog_cc_c_o" != yes; then # Losing compiler, so override with the script. # FIXME: It is wrong to rewrite CC. # But if we don't then we get into trouble of one sort or another. # A longer-term fix would be to have automake use am__CC in this case, # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" CC="$am_aux_dir/compile $CC" fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu DEPDIR="${am__leading_dot}deps" ac_config_commands="$ac_config_commands depfiles" { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} supports the include directive" >&5 $as_echo_n "checking whether ${MAKE-make} supports the include directive... " >&6; } cat > confinc.mk << 'END' am__doit: @echo this is the am__doit target >confinc.out .PHONY: am__doit END am__include="#" am__quote= # BSD make does it like this. echo '.include "confinc.mk" # ignored' > confmf.BSD # Other make implementations (GNU, Solaris 10, AIX) do it like this. echo 'include confinc.mk # ignored' > confmf.GNU _am_result=no for s in GNU BSD; do { echo "$as_me:$LINENO: ${MAKE-make} -f confmf.$s && cat confinc.out" >&5 (${MAKE-make} -f confmf.$s && cat confinc.out) >&5 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } case $?:`cat confinc.out 2>/dev/null` in #( '0:this is the am__doit target') : case $s in #( BSD) : am__include='.include' am__quote='"' ;; #( *) : am__include='include' am__quote='' ;; esac ;; #( *) : ;; esac if test "$am__include" != "#"; then _am_result="yes ($s style)" break fi done rm -f confinc.* confmf.* { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${_am_result}" >&5 $as_echo "${_am_result}" >&6; } # Check whether --enable-dependency-tracking was given. if test "${enable_dependency_tracking+set}" = set; then : enableval=$enable_dependency_tracking; fi if test "x$enable_dependency_tracking" != xno; then am_depcomp="$ac_aux_dir/depcomp" AMDEPBACKSLASH='\' am__nodep='_no' fi if test "x$enable_dependency_tracking" != xno; then AMDEP_TRUE= AMDEP_FALSE='#' else AMDEP_TRUE='#' AMDEP_FALSE= fi depcc="$CC" am_compiler_list= { $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 $as_echo_n "checking dependency style of $depcc... " >&6; } if ${am_cv_CC_dependencies_compiler_type+:} false; then : $as_echo_n "(cached) " >&6 else if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up # making a dummy file named 'D' -- because '-MD' means "put the output # in D". rm -rf conftest.dir mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're # using a relative directory. cp "$am_depcomp" conftest.dir cd conftest.dir # We will build objects and dependencies in a subdirectory because # it helps to detect inapplicable dependency modes. For instance # both Tru64's cc and ICC support -MD to output dependencies as a # side effect of compilation, but ICC will put the dependencies in # the current directory while Tru64 will put them in the object # directory. mkdir sub am_cv_CC_dependencies_compiler_type=none if test "$am_compiler_list" = ""; then am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` fi am__universal=false case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac for depmode in $am_compiler_list; do # Setup a source with many dependencies, because some compilers # like to wrap large dependency lists on column 80 (with \), and # we should not choose a depcomp mode which is confused by this. # # We need to recreate these files for each test, as the compiler may # overwrite some of them when testing with obscure command lines. # This happens at least with the AIX C compiler. : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with # Solaris 10 /bin/sh. echo '/* dummy */' > sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf # We check with '-c' and '-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly # handle '-M -o', and we need to detect this. Also, some Intel # versions had trouble with output in subdirs. am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in gcc) # This depmode causes a compiler race in universal mode. test "$am__universal" = false || continue ;; nosideeffect) # After this tag, mechanisms are not by side-effect, so they'll # only be used when explicitly requested. if test "x$enable_dependency_tracking" = xyes; then continue else break fi ;; msvc7 | msvc7msys | msvisualcpp | msvcmsys) # This compiler won't grok '-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} am__minus_obj= ;; none) break ;; esac if depmode=$depmode \ source=sub/conftest.c object=$am__obj \ depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ >/dev/null 2>conftest.err && grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && grep $am__obj sub/conftest.Po > /dev/null 2>&1 && ${MAKE-make} -s -f confmf > /dev/null 2>&1; then # icc doesn't choke on unknown options, it will just issue warnings # or remarks (even with -Werror). So we grep stderr for any message # that says an option was ignored or not supported. # When given -MP, icc 7.0 and 7.1 complain thusly: # icc: Command line warning: ignoring option '-M'; no argument required # The diagnosis changed in icc 8.0: # icc: Command line remark: option '-MP' not supported if (grep 'ignoring option' conftest.err || grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else am_cv_CC_dependencies_compiler_type=$depmode break fi fi done cd .. rm -rf conftest.dir else am_cv_CC_dependencies_compiler_type=none fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 $as_echo "$am_cv_CC_dependencies_compiler_type" >&6; } CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type if test "x$enable_dependency_tracking" != xno \ && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then am__fastdepCC_TRUE= am__fastdepCC_FALSE='#' else am__fastdepCC_TRUE='#' am__fastdepCC_FALSE= fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 $as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } set x ${MAKE-make} ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : $as_echo_n "(cached) " >&6 else cat >conftest.make <<\_ACEOF SHELL = /bin/sh all: @echo '@@@%%%=$(MAKE)=@@@%%%' _ACEOF # GNU make sometimes prints "make[1]: Entering ...", which would confuse us. case `${MAKE-make} -f conftest.make 2>/dev/null` in *@@@%%%=?*=@@@%%%*) eval ac_cv_prog_make_${ac_make}_set=yes;; *) eval ac_cv_prog_make_${ac_make}_set=no;; esac rm -f conftest.make fi if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } SET_MAKE= else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi # Extra options # Check whether --enable-image-output was given. if test "${enable_image_output+set}" = set; then : enableval=$enable_image_output; fi CFLAG_EXTRAS="" # Check whether --enable-werror was given. if test "${enable_werror+set}" = set; then : enableval=$enable_werror; CFLAG_EXTRAS="-Werror" fi # Check whether --enable-extra-paths was given. if test "${enable_extra_paths+set}" = set; then : enableval=$enable_extra_paths; else CFLAGS="$CFLAGS -I/usr/local/include" LDFLAGS="$LDFLAGS -L/usr/local/lib" fi # Checks for libraries. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pow in -lm" >&5 $as_echo_n "checking for pow in -lm... " >&6; } if ${ac_cv_lib_m_pow+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lm $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char pow (); int main () { return pow (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_m_pow=yes else ac_cv_lib_m_pow=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_pow" >&5 $as_echo "$ac_cv_lib_m_pow" >&6; } if test "x$ac_cv_lib_m_pow" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBM 1 _ACEOF LIBS="-lm $LIBS" else as_fn_error $? "could not find required math library" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_prepare_v2 in -lsqlite3" >&5 $as_echo_n "checking for sqlite3_prepare_v2 in -lsqlite3... " >&6; } if ${ac_cv_lib_sqlite3_sqlite3_prepare_v2+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lsqlite3 $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char sqlite3_prepare_v2 (); int main () { return sqlite3_prepare_v2 (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_sqlite3_sqlite3_prepare_v2=yes else ac_cv_lib_sqlite3_sqlite3_prepare_v2=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_sqlite3_sqlite3_prepare_v2" >&5 $as_echo "$ac_cv_lib_sqlite3_sqlite3_prepare_v2" >&6; } if test "x$ac_cv_lib_sqlite3_sqlite3_prepare_v2" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBSQLITE3 1 _ACEOF LIBS="-lsqlite3 $LIBS" else as_fn_error $? "could not find required sqlite3 library" "$LINENO" 5 fi if test "x$enable_image_output" != "xno"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gdImagePng in -lgd" >&5 $as_echo_n "checking for gdImagePng in -lgd... " >&6; } if ${ac_cv_lib_gd_gdImagePng+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lgd $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char gdImagePng (); int main () { return gdImagePng (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_gd_gdImagePng=yes else ac_cv_lib_gd_gdImagePng=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gd_gdImagePng" >&5 $as_echo "$ac_cv_lib_gd_gdImagePng" >&6; } if test "x$ac_cv_lib_gd_gdImagePng" = xyes; then : IMAGELIBS=-lgd fi ac_fn_c_check_decl "$LINENO" "GD_NEAREST_NEIGHBOUR" "ac_cv_have_decl_GD_NEAREST_NEIGHBOUR" "#include " if test "x$ac_cv_have_decl_GD_NEAREST_NEIGHBOUR" = xyes; then : ac_have_decl=1 else ac_have_decl=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_GD_NEAREST_NEIGHBOUR $ac_have_decl _ACEOF ac_fn_c_check_decl "$LINENO" "gdImageFile" "ac_cv_have_decl_gdImageFile" "#include " if test "x$ac_cv_have_decl_gdImageFile" = xyes; then : ac_have_decl=1 else ac_have_decl=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_GDIMAGEFILE $ac_have_decl _ACEOF fi if test "$IMAGELIBS" = "-lgd"; then HAVE_LIBGD_TRUE= HAVE_LIBGD_FALSE='#' else HAVE_LIBGD_TRUE='#' HAVE_LIBGD_FALSE= fi if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args. set dummy ${ac_tool_prefix}pkg-config; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_path_PKG_CONFIG+:} false; then : $as_echo_n "(cached) " >&6 else case $PKG_CONFIG in [\\/]* | ?:[\\/]*) ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi PKG_CONFIG=$ac_cv_path_PKG_CONFIG if test -n "$PKG_CONFIG"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5 $as_echo "$PKG_CONFIG" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_path_PKG_CONFIG"; then ac_pt_PKG_CONFIG=$PKG_CONFIG # Extract the first word of "pkg-config", so it can be a program name with args. set dummy pkg-config; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_path_ac_pt_PKG_CONFIG+:} false; then : $as_echo_n "(cached) " >&6 else case $ac_pt_PKG_CONFIG in [\\/]* | ?:[\\/]*) ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path. ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS ;; esac fi ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG if test -n "$ac_pt_PKG_CONFIG"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_PKG_CONFIG" >&5 $as_echo "$ac_pt_PKG_CONFIG" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_pt_PKG_CONFIG" = x; then PKG_CONFIG="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac PKG_CONFIG=$ac_pt_PKG_CONFIG fi else PKG_CONFIG="$ac_cv_path_PKG_CONFIG" fi fi if test -n "$PKG_CONFIG"; then _pkg_min_version=0.9.0 { $as_echo "$as_me:${as_lineno-$LINENO}: checking pkg-config is at least version $_pkg_min_version" >&5 $as_echo_n "checking pkg-config is at least version $_pkg_min_version... " >&6; } if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } PKG_CONFIG="" fi fi pkg_failed=no { $as_echo "$as_me:${as_lineno-$LINENO}: checking for CHECK" >&5 $as_echo_n "checking for CHECK... " >&6; } if test -n "$CHECK_CFLAGS"; then pkg_cv_CHECK_CFLAGS="$CHECK_CFLAGS" elif test -n "$PKG_CONFIG"; then if test -n "$PKG_CONFIG" && \ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"check >= 0.9.6\""; } >&5 ($PKG_CONFIG --exists --print-errors "check >= 0.9.6") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then pkg_cv_CHECK_CFLAGS=`$PKG_CONFIG --cflags "check >= 0.9.6" 2>/dev/null` test "x$?" != "x0" && pkg_failed=yes else pkg_failed=yes fi else pkg_failed=untried fi if test -n "$CHECK_LIBS"; then pkg_cv_CHECK_LIBS="$CHECK_LIBS" elif test -n "$PKG_CONFIG"; then if test -n "$PKG_CONFIG" && \ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"check >= 0.9.6\""; } >&5 ($PKG_CONFIG --exists --print-errors "check >= 0.9.6") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then pkg_cv_CHECK_LIBS=`$PKG_CONFIG --libs "check >= 0.9.6" 2>/dev/null` test "x$?" != "x0" && pkg_failed=yes else pkg_failed=yes fi else pkg_failed=untried fi if test $pkg_failed = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then _pkg_short_errors_supported=yes else _pkg_short_errors_supported=no fi if test $_pkg_short_errors_supported = yes; then CHECK_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "check >= 0.9.6" 2>&1` else CHECK_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "check >= 0.9.6" 2>&1` fi # Put the nasty error message in config.log where it belongs echo "$CHECK_PKG_ERRORS" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: testcases can not be execute without check installed" >&5 $as_echo "$as_me: testcases can not be execute without check installed" >&6;} elif test $pkg_failed = untried; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: testcases can not be execute without check installed" >&5 $as_echo "$as_me: testcases can not be execute without check installed" >&6;} else CHECK_CFLAGS=$pkg_cv_CHECK_CFLAGS CHECK_LIBS=$pkg_cv_CHECK_LIBS { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi if test "$CHECK_LIBS"; then HAVE_CHECK_TRUE= HAVE_CHECK_FALSE='#' else HAVE_CHECK_TRUE='#' HAVE_CHECK_FALSE= fi # Checks for header files. ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 $as_echo_n "checking how to run the C preprocessor... " >&6; } # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= fi if test -z "$CPP"; then if ${ac_cv_prog_CPP+:} false; then : $as_echo_n "(cached) " >&6 else # Double quotes because CPP needs to be expanded for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" do ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : break fi done ac_cv_prog_CPP=$CPP fi CPP=$ac_cv_prog_CPP else ac_cv_prog_CPP=$CPP fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 $as_echo "$CPP" >&6; } ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "C preprocessor \"$CPP\" fails sanity check See \`config.log' for more details" "$LINENO" 5; } fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 $as_echo_n "checking for grep that handles long lines and -e... " >&6; } if ${ac_cv_path_GREP+:} false; then : $as_echo_n "(cached) " >&6 else if test -z "$GREP"; then ac_path_GREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_GREP" || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in *GNU*) ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'GREP' >> "conftest.nl" "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_GREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_GREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_GREP"; then as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_GREP=$GREP fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 $as_echo "$ac_cv_path_GREP" >&6; } GREP="$ac_cv_path_GREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 $as_echo_n "checking for egrep... " >&6; } if ${ac_cv_path_EGREP+:} false; then : $as_echo_n "(cached) " >&6 else if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 then ac_cv_path_EGREP="$GREP -E" else if test -z "$EGREP"; then ac_path_EGREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_EGREP" || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in *GNU*) ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'EGREP' >> "conftest.nl" "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_EGREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_EGREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_EGREP"; then as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_EGREP=$EGREP fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 $as_echo "$ac_cv_path_EGREP" >&6; } EGREP="$ac_cv_path_EGREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 $as_echo_n "checking for ANSI C header files... " >&6; } if ${ac_cv_header_stdc+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_header_stdc=yes else ac_cv_header_stdc=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "memchr" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "free" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. if test "$cross_compiling" = yes; then : : else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #if ((' ' & 0x0FF) == 0x020) # define ISLOWER(c) ('a' <= (c) && (c) <= 'z') # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) #else # define ISLOWER(c) \ (('a' <= (c) && (c) <= 'i') \ || ('j' <= (c) && (c) <= 'r') \ || ('s' <= (c) && (c) <= 'z')) # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) #endif #define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) int main () { int i; for (i = 0; i < 256; i++) if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) return 2; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : else ac_cv_header_stdc=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 $as_echo "$ac_cv_header_stdc" >&6; } if test $ac_cv_header_stdc = yes; then $as_echo "#define STDC_HEADERS 1" >>confdefs.h fi # On IRIX 5.3, sys/types and inttypes.h are conflicting. for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ inttypes.h stdint.h unistd.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default " if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done for ac_header in fcntl.h inttypes.h locale.h stdint.h stdlib.h string.h sys/file.h sys/mount.h sys/param.h sys/socket.h sys/statvfs.h sys/time.h syslog.h unistd.h wchar.h linux/rtnetlink.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done # Check if being cross-compiled # Make sure we can run config.sub. $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 $as_echo_n "checking build system type... " >&6; } if ${ac_cv_build+:} false; then : $as_echo_n "(cached) " >&6 else ac_build_alias=$build_alias test "x$ac_build_alias" = x && ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` test "x$ac_build_alias" = x && as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 $as_echo "$ac_cv_build" >&6; } case $ac_cv_build in *-*-*) ;; *) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; esac build=$ac_cv_build ac_save_IFS=$IFS; IFS='-' set x $ac_cv_build shift build_cpu=$1 build_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: build_os=$* IFS=$ac_save_IFS case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 $as_echo_n "checking host system type... " >&6; } if ${ac_cv_host+:} false; then : $as_echo_n "(cached) " >&6 else if test "x$host_alias" = x; then ac_cv_host=$ac_cv_build else ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 $as_echo "$ac_cv_host" >&6; } case $ac_cv_host in *-*-*) ;; *) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; esac host=$ac_cv_host ac_save_IFS=$IFS; IFS='-' set x $ac_cv_host shift host_cpu=$1 host_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: host_os=$* IFS=$ac_save_IFS case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac if test "$host" != "$build"; then IS_CROSSCOMPILED_TRUE= IS_CROSSCOMPILED_FALSE='#' else IS_CROSSCOMPILED_TRUE='#' IS_CROSSCOMPILED_FALSE= fi # Check if 64-bit interface counters are used in Linux ac_fn_c_check_decl "$LINENO" "IFLA_STATS64" "ac_cv_have_decl_IFLA_STATS64" "#include " if test "x$ac_cv_have_decl_IFLA_STATS64" = xyes; then : ac_have_decl=1 else ac_have_decl=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_IFLA_STATS64 $ac_have_decl _ACEOF # Check if O_CLOEXEC can be used ac_fn_c_check_decl "$LINENO" "O_CLOEXEC" "ac_cv_have_decl_O_CLOEXEC" "#include " if test "x$ac_cv_have_decl_O_CLOEXEC" = xyes; then : ac_have_decl=1 else ac_have_decl=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_O_CLOEXEC $ac_have_decl _ACEOF # Check availability and level of SQLite WAL mode support ac_fn_c_check_decl "$LINENO" "SQLITE_CHECKPOINT_RESTART" "ac_cv_have_decl_SQLITE_CHECKPOINT_RESTART" "#include " if test "x$ac_cv_have_decl_SQLITE_CHECKPOINT_RESTART" = xyes; then : ac_have_decl=1 else ac_have_decl=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_SQLITE_CHECKPOINT_RESTART $ac_have_decl _ACEOF ac_fn_c_check_decl "$LINENO" "SQLITE_CHECKPOINT_TRUNCATE" "ac_cv_have_decl_SQLITE_CHECKPOINT_TRUNCATE" "#include " if test "x$ac_cv_have_decl_SQLITE_CHECKPOINT_TRUNCATE" = xyes; then : ac_have_decl=1 else ac_have_decl=0 fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_SQLITE_CHECKPOINT_TRUNCATE $ac_have_decl _ACEOF # Checks for typedefs, structures, and compiler characteristics. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for uid_t in sys/types.h" >&5 $as_echo_n "checking for uid_t in sys/types.h... " >&6; } if ${ac_cv_type_uid_t+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "uid_t" >/dev/null 2>&1; then : ac_cv_type_uid_t=yes else ac_cv_type_uid_t=no fi rm -f conftest* fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_uid_t" >&5 $as_echo "$ac_cv_type_uid_t" >&6; } if test $ac_cv_type_uid_t = no; then $as_echo "#define uid_t int" >>confdefs.h $as_echo "#define gid_t int" >>confdefs.h fi ac_fn_c_find_intX_t "$LINENO" "32" "ac_cv_c_int32_t" case $ac_cv_c_int32_t in #( no|yes) ;; #( *) cat >>confdefs.h <<_ACEOF #define int32_t $ac_cv_c_int32_t _ACEOF ;; esac ac_fn_c_check_type "$LINENO" "mode_t" "ac_cv_type_mode_t" "$ac_includes_default" if test "x$ac_cv_type_mode_t" = xyes; then : else cat >>confdefs.h <<_ACEOF #define mode_t int _ACEOF fi ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default" if test "x$ac_cv_type_size_t" = xyes; then : else cat >>confdefs.h <<_ACEOF #define size_t unsigned int _ACEOF fi ac_fn_c_find_uintX_t "$LINENO" "32" "ac_cv_c_uint32_t" case $ac_cv_c_uint32_t in #( no|yes) ;; #( *) $as_echo "#define _UINT32_T 1" >>confdefs.h cat >>confdefs.h <<_ACEOF #define uint32_t $ac_cv_c_uint32_t _ACEOF ;; esac ac_fn_c_find_uintX_t "$LINENO" "64" "ac_cv_c_uint64_t" case $ac_cv_c_uint64_t in #( no|yes) ;; #( *) $as_echo "#define _UINT64_T 1" >>confdefs.h cat >>confdefs.h <<_ACEOF #define uint64_t $ac_cv_c_uint64_t _ACEOF ;; esac # Checks for library functions. for ac_header in unistd.h do : ac_fn_c_check_header_mongrel "$LINENO" "unistd.h" "ac_cv_header_unistd_h" "$ac_includes_default" if test "x$ac_cv_header_unistd_h" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_UNISTD_H 1 _ACEOF fi done { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working chown" >&5 $as_echo_n "checking for working chown... " >&6; } if ${ac_cv_func_chown_works+:} false; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : ac_cv_func_chown_works=no else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default #include int main () { char *f = "conftest.chown"; struct stat before, after; if (creat (f, 0600) < 0) return 1; if (stat (f, &before) < 0) return 1; if (chown (f, (uid_t) -1, (gid_t) -1) == -1) return 1; if (stat (f, &after) < 0) return 1; return ! (before.st_uid == after.st_uid && before.st_gid == after.st_gid); ; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_func_chown_works=yes else ac_cv_func_chown_works=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi rm -f conftest.chown fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_chown_works" >&5 $as_echo "$ac_cv_func_chown_works" >&6; } if test $ac_cv_func_chown_works = yes; then $as_echo "#define HAVE_CHOWN 1" >>confdefs.h fi ac_fn_c_check_type "$LINENO" "pid_t" "ac_cv_type_pid_t" "$ac_includes_default" if test "x$ac_cv_type_pid_t" = xyes; then : else cat >>confdefs.h <<_ACEOF #define pid_t int _ACEOF fi for ac_header in vfork.h do : ac_fn_c_check_header_mongrel "$LINENO" "vfork.h" "ac_cv_header_vfork_h" "$ac_includes_default" if test "x$ac_cv_header_vfork_h" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_VFORK_H 1 _ACEOF fi done for ac_func in fork vfork do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi done if test "x$ac_cv_func_fork" = xyes; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working fork" >&5 $as_echo_n "checking for working fork... " >&6; } if ${ac_cv_func_fork_works+:} false; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : ac_cv_func_fork_works=cross else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int main () { /* By Ruediger Kuhlmann. */ return fork () < 0; ; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_func_fork_works=yes else ac_cv_func_fork_works=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_fork_works" >&5 $as_echo "$ac_cv_func_fork_works" >&6; } else ac_cv_func_fork_works=$ac_cv_func_fork fi if test "x$ac_cv_func_fork_works" = xcross; then case $host in *-*-amigaos* | *-*-msdosdjgpp*) # Override, as these systems have only a dummy fork() stub ac_cv_func_fork_works=no ;; *) ac_cv_func_fork_works=yes ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: result $ac_cv_func_fork_works guessed because of cross compilation" >&5 $as_echo "$as_me: WARNING: result $ac_cv_func_fork_works guessed because of cross compilation" >&2;} fi ac_cv_func_vfork_works=$ac_cv_func_vfork if test "x$ac_cv_func_vfork" = xyes; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working vfork" >&5 $as_echo_n "checking for working vfork... " >&6; } if ${ac_cv_func_vfork_works+:} false; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : ac_cv_func_vfork_works=cross else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Thanks to Paul Eggert for this test. */ $ac_includes_default #include #ifdef HAVE_VFORK_H # include #endif /* On some sparc systems, changes by the child to local and incoming argument registers are propagated back to the parent. The compiler is told about this with #include , but some compilers (e.g. gcc -O) don't grok . Test for this by using a static variable whose address is put into a register that is clobbered by the vfork. */ static void #ifdef __cplusplus sparc_address_test (int arg) # else sparc_address_test (arg) int arg; #endif { static pid_t child; if (!child) { child = vfork (); if (child < 0) { perror ("vfork"); _exit(2); } if (!child) { arg = getpid(); write(-1, "", 0); _exit (arg); } } } int main () { pid_t parent = getpid (); pid_t child; sparc_address_test (0); child = vfork (); if (child == 0) { /* Here is another test for sparc vfork register problems. This test uses lots of local variables, at least as many local variables as main has allocated so far including compiler temporaries. 4 locals are enough for gcc 1.40.3 on a Solaris 4.1.3 sparc, but we use 8 to be safe. A buggy compiler should reuse the register of parent for one of the local variables, since it will think that parent can't possibly be used any more in this routine. Assigning to the local variable will thus munge parent in the parent process. */ pid_t p = getpid(), p1 = getpid(), p2 = getpid(), p3 = getpid(), p4 = getpid(), p5 = getpid(), p6 = getpid(), p7 = getpid(); /* Convince the compiler that p..p7 are live; otherwise, it might use the same hardware register for all 8 local variables. */ if (p != p1 || p != p2 || p != p3 || p != p4 || p != p5 || p != p6 || p != p7) _exit(1); /* On some systems (e.g. IRIX 3.3), vfork doesn't separate parent from child file descriptors. If the child closes a descriptor before it execs or exits, this munges the parent's descriptor as well. Test for this by closing stdout in the child. */ _exit(close(fileno(stdout)) != 0); } else { int status; struct stat st; while (wait(&status) != child) ; return ( /* Was there some problem with vforking? */ child < 0 /* Did the child fail? (This shouldn't happen.) */ || status /* Did the vfork/compiler bug occur? */ || parent != getpid() /* Did the file descriptor bug occur? */ || fstat(fileno(stdout), &st) != 0 ); } } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_func_vfork_works=yes else ac_cv_func_vfork_works=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_vfork_works" >&5 $as_echo "$ac_cv_func_vfork_works" >&6; } fi; if test "x$ac_cv_func_fork_works" = xcross; then ac_cv_func_vfork_works=$ac_cv_func_vfork { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: result $ac_cv_func_vfork_works guessed because of cross compilation" >&5 $as_echo "$as_me: WARNING: result $ac_cv_func_vfork_works guessed because of cross compilation" >&2;} fi if test "x$ac_cv_func_vfork_works" = xyes; then $as_echo "#define HAVE_WORKING_VFORK 1" >>confdefs.h else $as_echo "#define vfork fork" >>confdefs.h fi if test "x$ac_cv_func_fork_works" = xyes; then $as_echo "#define HAVE_WORKING_FORK 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether time.h and sys/time.h may both be included" >&5 $as_echo_n "checking whether time.h and sys/time.h may both be included... " >&6; } if ${ac_cv_header_time+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include int main () { if ((struct tm *) 0) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_header_time=yes else ac_cv_header_time=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_time" >&5 $as_echo "$ac_cv_header_time" >&6; } if test $ac_cv_header_time = yes; then $as_echo "#define TIME_WITH_SYS_TIME 1" >>confdefs.h fi for ac_header in $ac_header_list do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default " if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done for ac_func in $ac_func_list do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi done { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working mktime" >&5 $as_echo_n "checking for working mktime... " >&6; } if ${ac_cv_func_working_mktime+:} false; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : ac_cv_func_working_mktime=no else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Test program from Paul Eggert and Tony Leneis. */ #ifdef TIME_WITH_SYS_TIME # include # include #else # ifdef HAVE_SYS_TIME_H # include # else # include # endif #endif #include #include #ifdef HAVE_UNISTD_H # include #endif #ifndef HAVE_ALARM # define alarm(X) /* empty */ #endif /* Work around redefinition to rpl_putenv by other config tests. */ #undef putenv static time_t time_t_max; static time_t time_t_min; /* Values we'll use to set the TZ environment variable. */ static const char *tz_strings[] = { (const char *) 0, "TZ=GMT0", "TZ=JST-9", "TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00" }; #define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0])) /* Return 0 if mktime fails to convert a date in the spring-forward gap. Based on a problem report from Andreas Jaeger. */ static int spring_forward_gap () { /* glibc (up to about 1998-10-07) failed this test. */ struct tm tm; /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0" instead of "TZ=America/Vancouver" in order to detect the bug even on systems that don't support the Olson extension, or don't have the full zoneinfo tables installed. */ putenv ((char*) "TZ=PST8PDT,M4.1.0,M10.5.0"); tm.tm_year = 98; tm.tm_mon = 3; tm.tm_mday = 5; tm.tm_hour = 2; tm.tm_min = 0; tm.tm_sec = 0; tm.tm_isdst = -1; return mktime (&tm) != (time_t) -1; } static int mktime_test1 (time_t now) { struct tm *lt; return ! (lt = localtime (&now)) || mktime (lt) == now; } static int mktime_test (time_t now) { return (mktime_test1 (now) && mktime_test1 ((time_t) (time_t_max - now)) && mktime_test1 ((time_t) (time_t_min + now))); } static int irix_6_4_bug () { /* Based on code from Ariel Faigon. */ struct tm tm; tm.tm_year = 96; tm.tm_mon = 3; tm.tm_mday = 0; tm.tm_hour = 0; tm.tm_min = 0; tm.tm_sec = 0; tm.tm_isdst = -1; mktime (&tm); return tm.tm_mon == 2 && tm.tm_mday == 31; } static int bigtime_test (int j) { struct tm tm; time_t now; tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j; now = mktime (&tm); if (now != (time_t) -1) { struct tm *lt = localtime (&now); if (! (lt && lt->tm_year == tm.tm_year && lt->tm_mon == tm.tm_mon && lt->tm_mday == tm.tm_mday && lt->tm_hour == tm.tm_hour && lt->tm_min == tm.tm_min && lt->tm_sec == tm.tm_sec && lt->tm_yday == tm.tm_yday && lt->tm_wday == tm.tm_wday && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst) == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst)))) return 0; } return 1; } static int year_2050_test () { /* The correct answer for 2050-02-01 00:00:00 in Pacific time, ignoring leap seconds. */ unsigned long int answer = 2527315200UL; struct tm tm; time_t t; tm.tm_year = 2050 - 1900; tm.tm_mon = 2 - 1; tm.tm_mday = 1; tm.tm_hour = tm.tm_min = tm.tm_sec = 0; tm.tm_isdst = -1; /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0" instead of "TZ=America/Vancouver" in order to detect the bug even on systems that don't support the Olson extension, or don't have the full zoneinfo tables installed. */ putenv ((char*) "TZ=PST8PDT,M4.1.0,M10.5.0"); t = mktime (&tm); /* Check that the result is either a failure, or close enough to the correct answer that we can assume the discrepancy is due to leap seconds. */ return (t == (time_t) -1 || (0 < t && answer - 120 <= t && t <= answer + 120)); } int main () { time_t t, delta; int i, j; /* This test makes some buggy mktime implementations loop. Give up after 60 seconds; a mktime slower than that isn't worth using anyway. */ alarm (60); for (;;) { t = (time_t_max << 1) + 1; if (t <= time_t_max) break; time_t_max = t; } time_t_min = - ((time_t) ~ (time_t) 0 == (time_t) -1) - time_t_max; delta = time_t_max / 997; /* a suitable prime number */ for (i = 0; i < N_STRINGS; i++) { if (tz_strings[i]) putenv ((char*) tz_strings[i]); for (t = 0; t <= time_t_max - delta; t += delta) if (! mktime_test (t)) return 1; if (! (mktime_test ((time_t) 1) && mktime_test ((time_t) (60 * 60)) && mktime_test ((time_t) (60 * 60 * 24)))) return 1; for (j = 1; ; j <<= 1) if (! bigtime_test (j)) return 1; else if (INT_MAX / 2 < j) break; if (! bigtime_test (INT_MAX)) return 1; } return ! (irix_6_4_bug () && spring_forward_gap () && year_2050_test ()); } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_func_working_mktime=yes else ac_cv_func_working_mktime=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_working_mktime" >&5 $as_echo "$ac_cv_func_working_mktime" >&6; } if test $ac_cv_func_working_mktime = no; then case " $LIBOBJS " in *" mktime.$ac_objext "* ) ;; *) LIBOBJS="$LIBOBJS mktime.$ac_objext" ;; esac fi for ac_func in dup2 localtime_r memset mkdir pow rmdir setlocale strcasecmp strchr strdup strerror strncasecmp strstr strtol strtoul strtoull tzset mbstowcs wcswidth do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi done ac_config_files="$ac_config_files Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure # scripts and configure runs, see configure's option --config-cache. # It is not useful on other systems. If it contains results you don't # want to keep, you may remove or edit it. # # config.status only pays attention to the cache file if you give it # the --recheck option to rerun configure. # # `ac_cv_env_foo' variables (set or unset) will be overridden when # loading this file, other *unset* `ac_cv_foo' will be assigned the # following values. _ACEOF # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. ( for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space=' '; set) 2>&1` in #( *${as_nl}ac_space=\ *) # `set' does not quote correctly, so add quotes: double-quote # substitution turns \\\\ into \\, and sed turns \\ into \. sed -n \ "s/'/'\\\\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" ;; #( *) # `set' quotes correctly as required by POSIX, so do not add quotes. sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) | sed ' /^ac_cv_env_/b end t clear :clear s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ t end s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ :end' >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then if test "x$cache_file" != "x/dev/null"; then { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 $as_echo "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then cat confcache >"$cache_file" else case $cache_file in #( */* | ?:*) mv -f confcache "$cache_file"$$ && mv -f "$cache_file"$$ "$cache_file" ;; #( *) mv -f confcache "$cache_file" ;; esac fi fi else { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' DEFS=-DHAVE_CONFIG_H ac_libobjs= ac_ltlibobjs= U= for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue # 1. Remove the extension, and $U if already installed. ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' ac_i=`$as_echo "$ac_i" | sed "$ac_script"` # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR # will be set to the directory where LIBOBJS objects are built. as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' done LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs { $as_echo "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 $as_echo_n "checking that generated files are newer than configure... " >&6; } if test -n "$am_sleep_pid"; then # Hide warnings about reused PIDs. wait $am_sleep_pid 2>/dev/null fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: done" >&5 $as_echo "done" >&6; } if test -n "$EXEEXT"; then am__EXEEXT_TRUE= am__EXEEXT_FALSE='#' else am__EXEEXT_TRUE='#' am__EXEEXT_FALSE= fi if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then as_fn_error $? "conditional \"AMDEP\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then as_fn_error $? "conditional \"am__fastdepCC\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_LIBGD_TRUE}" && test -z "${HAVE_LIBGD_FALSE}"; then as_fn_error $? "conditional \"HAVE_LIBGD\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_CHECK_TRUE}" && test -z "${HAVE_CHECK_FALSE}"; then as_fn_error $? "conditional \"HAVE_CHECK\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${IS_CROSSCOMPILED_TRUE}" && test -z "${IS_CROSSCOMPILED_FALSE}"; then as_fn_error $? "conditional \"IS_CROSSCOMPILED\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi : "${CONFIG_STATUS=./config.status}" ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 $as_echo "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL # Generated by $as_me. # Run this file to recreate the current configuration. # Compiler output produced by configure, useful for debugging # configure, is in config.log if it exists. debug=false ac_cs_recheck=false ac_cs_silent=false SHELL=\${CONFIG_SHELL-$SHELL} export SHELL _ASEOF cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" exec 6>&1 ## ----------------------------------- ## ## Main body of $CONFIG_STATUS script. ## ## ----------------------------------- ## _ASEOF test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" This file was extended by vnstat $as_me 2.9, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS CONFIG_LINKS = $CONFIG_LINKS CONFIG_COMMANDS = $CONFIG_COMMANDS $ $0 $@ on `(hostname || uname -n) 2>/dev/null | sed 1q` " _ACEOF case $ac_config_files in *" "*) set x $ac_config_files; shift; ac_config_files=$*;; esac case $ac_config_headers in *" "*) set x $ac_config_headers; shift; ac_config_headers=$*;; esac cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # Files that config.status was made for. config_files="$ac_config_files" config_headers="$ac_config_headers" config_commands="$ac_config_commands" _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 ac_cs_usage="\ \`$as_me' instantiates files and other configuration actions from templates according to the current configuration. Unless the files and actions are specified as TAGs, all are instantiated by default. Usage: $0 [OPTION]... [TAG]... -h, --help print this help, then exit -V, --version print version number and configuration settings, then exit --config print configuration, then exit -q, --quiet, --silent do not print progress messages -d, --debug don't remove temporary files --recheck update $as_me by reconfiguring in the same conditions --file=FILE[:TEMPLATE] instantiate the configuration file FILE --header=FILE[:TEMPLATE] instantiate the configuration header FILE Configuration files: $config_files Configuration headers: $config_headers Configuration commands: $config_commands Report bugs to the package provider." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ vnstat config.status 2.9 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" Copyright (C) 2012 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." ac_pwd='$ac_pwd' srcdir='$srcdir' INSTALL='$INSTALL' MKDIR_P='$MKDIR_P' AWK='$AWK' test -n "\$AWK" || AWK=awk _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # The default lists apply if the user does not specify any file. ac_need_defaults=: while test $# != 0 do case $1 in --*=?*) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` ac_shift=: ;; --*=) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg= ac_shift=: ;; *) ac_option=$1 ac_optarg=$2 ac_shift=shift ;; esac case $ac_option in # Handling of the options. -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) ac_cs_recheck=: ;; --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) $as_echo "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) $as_echo "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --file | --fil | --fi | --f ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" ac_need_defaults=false;; --header | --heade | --head | --hea ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; esac as_fn_append CONFIG_HEADERS " '$ac_optarg'" ac_need_defaults=false;; --he | --h) # Conflict between --help and --header as_fn_error $? "ambiguous option: \`$1' Try \`$0 --help' for more information.";; --help | --hel | -h ) $as_echo "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; # This is an error. -*) as_fn_error $? "unrecognized option: \`$1' Try \`$0 --help' for more information." ;; *) as_fn_append ac_config_targets " $1" ac_need_defaults=false ;; esac shift done ac_configure_extra_args= if $ac_cs_silent; then exec 6>/dev/null ac_configure_extra_args="$ac_configure_extra_args --silent" fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" fi _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 exec 5>>config.log { echo sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX $as_echo "$ac_log" } >&5 _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # # INIT-COMMANDS # AMDEP_TRUE="$AMDEP_TRUE" MAKE="${MAKE-make}" _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Handling of arguments. for ac_config_target in $ac_config_targets do case $ac_config_target in "src/config.h") CONFIG_HEADERS="$CONFIG_HEADERS src/config.h" ;; "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac done # If the user did not use the arguments to specify the items to instantiate, # then the envvar interface is used. Set only those that are not. # We use the long form for the default assignment because of an extremely # bizarre bug on SunOS 4.1.3. if $ac_need_defaults; then test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands fi # Have a temporary directory for convenience. Make it in the build tree # simply because there is no reason against having it here, and in addition, # creating and moving files from /tmp can sometimes cause problems. # Hook for its removal unless debugging. # Note that there is a small window in which the directory will not be cleaned: # after its creation but before its name has been assigned to `$tmp'. $debug || { tmp= ac_tmp= trap 'exit_status=$? : "${ac_tmp:=$tmp}" { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status ' 0 trap 'as_fn_exit 1' 1 2 13 15 } # Create a (secure) tmp directory for tmp files. { tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && test -d "$tmp" } || { tmp=./conf$$-$RANDOM (umask 077 && mkdir "$tmp") } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 ac_tmp=$tmp # Set up the scripts for CONFIG_FILES section. # No need to generate them if there are no CONFIG_FILES. # This happens for instance with `./config.status config.h'. if test -n "$CONFIG_FILES"; then ac_cr=`echo X | tr X '\015'` # On cygwin, bash can eat \r inside `` if the user requested igncr. # But we know of no other shell where ac_cr would be empty at this # point, so we can use a bashism as a fallback. if test "x$ac_cr" = x; then eval ac_cr=\$\'\\r\' fi ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then ac_cs_awk_cr='\\r' else ac_cs_awk_cr=$ac_cr fi echo 'BEGIN {' >"$ac_tmp/subs1.awk" && _ACEOF { echo "cat >conf$$subs.awk <<_ACEOF" && echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && echo "_ACEOF" } >conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` ac_delim='%!_!# ' for ac_last_try in false false false false false :; do . ./conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` if test $ac_delim_n = $ac_delim_num; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done rm -f conf$$subs.sh cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && _ACEOF sed -n ' h s/^/S["/; s/!.*/"]=/ p g s/^[^!]*!// :repl t repl s/'"$ac_delim"'$// t delim :nl h s/\(.\{148\}\)..*/\1/ t more1 s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ p n b repl :more1 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t nl :delim h s/\(.\{148\}\)..*/\1/ t more2 s/["\\]/\\&/g; s/^/"/; s/$/"/ p b :more2 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t delim ' >$CONFIG_STATUS || ac_write_fail=1 rm -f conf$$subs.awk cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACAWK cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && for (key in S) S_is_set[key] = 1 FS = "" } { line = $ 0 nfields = split(line, field, "@") substed = 0 len = length(field[1]) for (i = 2; i < nfields; i++) { key = field[i] keylen = length(key) if (S_is_set[key]) { value = S[key] line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) len += length(value) + length(field[++i]) substed = 1 } else len += 1 + keylen } print line } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" else cat fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 _ACEOF # VPATH may cause trouble with some makes, so we remove sole $(srcdir), # ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and # trailing colons and then remove the whole line if VPATH becomes empty # (actually we leave an empty line to preserve line numbers). if test "x$srcdir" = x.; then ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ h s/// s/^/:/ s/[ ]*$/:/ s/:\$(srcdir):/:/g s/:\${srcdir}:/:/g s/:@srcdir@:/:/g s/^:*// s/:*$// x s/\(=[ ]*\).*/\1/ G s/\n// s/^[^=]*=[ ]*$// }' fi cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 fi # test -n "$CONFIG_FILES" # Set up the scripts for CONFIG_HEADERS section. # No need to generate them if there are no CONFIG_HEADERS. # This happens for instance with `./config.status Makefile'. if test -n "$CONFIG_HEADERS"; then cat >"$ac_tmp/defines.awk" <<\_ACAWK || BEGIN { _ACEOF # Transform confdefs.h into an awk script `defines.awk', embedded as # here-document in config.status, that substitutes the proper values into # config.h.in to produce config.h. # Create a delimiter string that does not exist in confdefs.h, to ease # handling of long lines. ac_delim='%!_!# ' for ac_last_try in false false :; do ac_tt=`sed -n "/$ac_delim/p" confdefs.h` if test -z "$ac_tt"; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done # For the awk script, D is an array of macro values keyed by name, # likewise P contains macro parameters if any. Preserve backslash # newline sequences. ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* sed -n ' s/.\{148\}/&'"$ac_delim"'/g t rset :rset s/^[ ]*#[ ]*define[ ][ ]*/ / t def d :def s/\\$// t bsnl s/["\\]/\\&/g s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ D["\1"]=" \3"/p s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p d :bsnl s/["\\]/\\&/g s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ D["\1"]=" \3\\\\\\n"\\/p t cont s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p t cont d :cont n s/.\{148\}/&'"$ac_delim"'/g t clear :clear s/\\$// t bsnlc s/["\\]/\\&/g; s/^/"/; s/$/"/p d :bsnlc s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p b cont ' >$CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 for (key in D) D_is_set[key] = 1 FS = "" } /^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ { line = \$ 0 split(line, arg, " ") if (arg[1] == "#") { defundef = arg[2] mac1 = arg[3] } else { defundef = substr(arg[1], 2) mac1 = arg[2] } split(mac1, mac2, "(") #) macro = mac2[1] prefix = substr(line, 1, index(line, defundef) - 1) if (D_is_set[macro]) { # Preserve the white space surrounding the "#". print prefix "define", macro P[macro] D[macro] next } else { # Replace #undef with comments. This is necessary, for example, # in the case of _POSIX_SOURCE, which is predefined and required # on some systems where configure will not decide to define it. if (defundef == "undef") { print "/*", prefix defundef, macro, "*/" next } } } { print } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 as_fn_error $? "could not setup config headers machinery" "$LINENO" 5 fi # test -n "$CONFIG_HEADERS" eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS :C $CONFIG_COMMANDS" shift for ac_tag do case $ac_tag in :[FHLC]) ac_mode=$ac_tag; continue;; esac case $ac_mode$ac_tag in :[FHL]*:*);; :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; :[FH]-) ac_tag=-:-;; :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; esac ac_save_IFS=$IFS IFS=: set x $ac_tag IFS=$ac_save_IFS shift ac_file=$1 shift case $ac_mode in :L) ac_source=$1;; :[FH]) ac_file_inputs= for ac_f do case $ac_f in -) ac_f="$ac_tmp/stdin";; *) # Look for the file first in the build tree, then in the source tree # (if the path is not absolute). The absolute path cannot be DOS-style, # because $ac_f cannot contain `:'. test -f "$ac_f" || case $ac_f in [\\/$]*) false;; *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; esac || as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; esac case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done # Let's still pretend it is `configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ configure_input='Generated from '` $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 $as_echo "$as_me: creating $ac_file" >&6;} fi # Neutralize special characters interpreted by sed in replacement strings. case $configure_input in #( *\&* | *\|* | *\\* ) ac_sed_conf_input=`$as_echo "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac case $ac_tag in *:-:* | *:-) cat >"$ac_tmp/stdin" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac ;; esac ac_dir=`$as_dirname -- "$ac_file" || $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$ac_file" : 'X\(//\)[^/]' \| \ X"$ac_file" : 'X\(//\)$' \| \ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` as_dir="$ac_dir"; as_fn_mkdir_p ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix case $ac_mode in :F) # # CONFIG_FILE # case $INSTALL in [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; esac ac_MKDIR_P=$MKDIR_P case $MKDIR_P in [\\/$]* | ?:[\\/]* ) ;; */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;; esac _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # If the template does not know about datarootdir, expand it. # FIXME: This hack should be removed a few years after 2.60. ac_datarootdir_hack=; ac_datarootdir_seen= ac_sed_dataroot=' /datarootdir/ { p q } /@datadir@/p /@docdir@/p /@infodir@/p /@localedir@/p /@mandir@/p' case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in *datarootdir*) ac_datarootdir_seen=yes;; *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 $as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_datarootdir_hack=' s&@datadir@&$datadir&g s&@docdir@&$docdir&g s&@infodir@&$infodir&g s&@localedir@&$localedir&g s&@mandir@&$mandir&g s&\\\${datarootdir}&$datarootdir&g' ;; esac _ACEOF # Neutralize VPATH when `$srcdir' = `.'. # Shell code in configure.ac might set extrasub. # FIXME: do we really want to maintain this feature? cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_sed_extra="$ac_vpsub $extrasub _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 :t /@[a-zA-Z_][a-zA-Z_0-9]*@/!b s|@configure_input@|$ac_sed_conf_input|;t t s&@top_builddir@&$ac_top_builddir_sub&;t t s&@top_build_prefix@&$ac_top_build_prefix&;t t s&@srcdir@&$ac_srcdir&;t t s&@abs_srcdir@&$ac_abs_srcdir&;t t s&@top_srcdir@&$ac_top_srcdir&;t t s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t s&@builddir@&$ac_builddir&;t t s&@abs_builddir@&$ac_abs_builddir&;t t s&@abs_top_builddir@&$ac_abs_top_builddir&;t t s&@INSTALL@&$ac_INSTALL&;t t s&@MKDIR_P@&$ac_MKDIR_P&;t t $ac_datarootdir_hack " eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ "$ac_tmp/out"`; test -z "$ac_out"; } && { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&5 $as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&2;} rm -f "$ac_tmp/stdin" case $ac_file in -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; esac \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; :H) # # CONFIG_HEADER # if test x"$ac_file" != x-; then { $as_echo "/* $configure_input */" \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" } >"$ac_tmp/config.h" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 $as_echo "$as_me: $ac_file is unchanged" >&6;} else rm -f "$ac_file" mv "$ac_tmp/config.h" "$ac_file" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 fi else $as_echo "/* $configure_input */" \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ || as_fn_error $? "could not create -" "$LINENO" 5 fi # Compute "$ac_file"'s index in $config_headers. _am_arg="$ac_file" _am_stamp_count=1 for _am_header in $config_headers :; do case $_am_header in $_am_arg | $_am_arg:* ) break ;; * ) _am_stamp_count=`expr $_am_stamp_count + 1` ;; esac done echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" || $as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$_am_arg" : 'X\(//\)[^/]' \| \ X"$_am_arg" : 'X\(//\)$' \| \ X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$_am_arg" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'`/stamp-h$_am_stamp_count ;; :C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 $as_echo "$as_me: executing $ac_file commands" >&6;} ;; esac case $ac_file$ac_mode in "depfiles":C) test x"$AMDEP_TRUE" != x"" || { # Older Autoconf quotes --file arguments for eval, but not when files # are listed without --file. Let's play safe and only enable the eval # if we detect the quoting. # TODO: see whether this extra hack can be removed once we start # requiring Autoconf 2.70 or later. case $CONFIG_FILES in #( *\'*) : eval set x "$CONFIG_FILES" ;; #( *) : set x $CONFIG_FILES ;; #( *) : ;; esac shift # Used to flag and report bootstrapping failures. am_rc=0 for am_mf do # Strip MF so we end up with the name of the file. am_mf=`$as_echo "$am_mf" | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile which includes # dependency-tracking related rules and includes. # Grep'ing the whole file directly is not great: AIX grep has a line # limit of 2048, but all sed's we know have understand at least 4000. sed -n 's,^am--depfiles:.*,X,p' "$am_mf" | grep X >/dev/null 2>&1 \ || continue am_dirpart=`$as_dirname -- "$am_mf" || $as_expr X"$am_mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$am_mf" : 'X\(//\)[^/]' \| \ X"$am_mf" : 'X\(//\)$' \| \ X"$am_mf" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$am_mf" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` am_filepart=`$as_basename -- "$am_mf" || $as_expr X/"$am_mf" : '.*/\([^/][^/]*\)/*$' \| \ X"$am_mf" : 'X\(//\)$' \| \ X"$am_mf" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$am_mf" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` { echo "$as_me:$LINENO: cd "$am_dirpart" \ && sed -e '/# am--include-marker/d' "$am_filepart" \ | $MAKE -f - am--depfiles" >&5 (cd "$am_dirpart" \ && sed -e '/# am--include-marker/d' "$am_filepart" \ | $MAKE -f - am--depfiles) >&5 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } || am_rc=$? done if test $am_rc -ne 0; then { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "Something went wrong bootstrapping makefile fragments for automatic dependency tracking. Try re-running configure with the '--disable-dependency-tracking' option to at least be able to build the package (albeit without support for automatic dependency tracking). See \`config.log' for more details" "$LINENO" 5; } fi { am_dirpart=; unset am_dirpart;} { am_filepart=; unset am_filepart;} { am_mf=; unset am_mf;} { am_rc=; unset am_rc;} rm -f conftest-deps.mk } ;; esac done # for ac_tag as_fn_exit 0 _ACEOF ac_clean_files=$ac_clean_files_save test $ac_write_fail = 0 || as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 # configure is writing to config.log, and then calls config.status. # config.status does its own redirection, appending to config.log. # Unfortunately, on DOS this fails, as config.log is still kept open # by configure, so config.status won't be able to write to it; its # output is simply discarded. So we exec the FD to /dev/null, # effectively closing config.log, so it can be properly (re)opened and # appended to by config.status. When coming back to configure, we # need to make the FD available again. if test "$no_create" != yes; then ac_cs_success=: ac_config_status_args= test "$silent" = yes && ac_config_status_args="$ac_config_status_args --quiet" exec 5>/dev/null $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false exec 5>>config.log # Use ||, not &&, to avoid exiting from the if with $? = 1, which # would make configure fail if this is the last instruction. $ac_cs_success || as_fn_exit 1 fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi # Resolve install paths for output. msg_bindir=$bindir while expr match "${msg_bindir}" '^.*\$.*$' 1>/dev/null; do msg_bindir="$(eval echo ${msg_bindir})" done msg_sbindir=$sbindir while expr match "${msg_sbindir}" '^.*\$.*$' 1>/dev/null; do msg_sbindir="$(eval echo ${msg_sbindir})" done msg_sysconfdir=$sysconfdir while expr match "${msg_sysconfdir}" '^.*\$.*$' 1>/dev/null; do msg_sysconfdir="$(eval echo ${msg_sysconfdir})" done # Output configuration. { $as_echo "$as_me:${as_lineno-$LINENO}: " >&5 $as_echo "$as_me: " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: ============================================== " >&5 $as_echo "$as_me: ============================================== " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: " >&5 $as_echo "$as_me: " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: host: $host " >&5 $as_echo "$as_me: host: $host " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: build: $build " >&5 $as_echo "$as_me: build: $build " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: " >&5 $as_echo "$as_me: " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: prefix: $prefix " >&5 $as_echo "$as_me: prefix: $prefix " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: exec_prefix: $exec_prefix " >&5 $as_echo "$as_me: exec_prefix: $exec_prefix " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: bindir: $bindir " >&5 $as_echo "$as_me: bindir: $bindir " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: sbindir: $sbindir " >&5 $as_echo "$as_me: sbindir: $sbindir " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: sysconfdir: $sysconfdir " >&5 $as_echo "$as_me: sysconfdir: $sysconfdir " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: " >&5 $as_echo "$as_me: " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: Install paths " >&5 $as_echo "$as_me: Install paths " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: " >&5 $as_echo "$as_me: " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: vnstat: $msg_bindir/vnstat " >&5 $as_echo "$as_me: vnstat: $msg_bindir/vnstat " >&6;} if test -z "$HAVE_LIBGD_TRUE"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: vnstati: $msg_bindir/vnstati " >&5 $as_echo "$as_me: vnstati: $msg_bindir/vnstati " >&6;} fi { $as_echo "$as_me:${as_lineno-$LINENO}: vnstatd: $msg_sbindir/vnstatd " >&5 $as_echo "$as_me: vnstatd: $msg_sbindir/vnstatd " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: config: $msg_sysconfdir/vnstat.conf " >&5 $as_echo "$as_me: config: $msg_sysconfdir/vnstat.conf " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: " >&5 $as_echo "$as_me: " >&6;} if test -z "$HAVE_CHECK_TRUE"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: Tests: available " >&5 $as_echo "$as_me: Tests: available " >&6;} else { $as_echo "$as_me:${as_lineno-$LINENO}: Tests: unavailable " >&5 $as_echo "$as_me: Tests: unavailable " >&6;} fi if test -z "$HAVE_LIBGD_TRUE"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: Image output: enabled " >&5 $as_echo "$as_me: Image output: enabled " >&6;} else { $as_echo "$as_me:${as_lineno-$LINENO}: Image output: disabled " >&5 $as_echo "$as_me: Image output: disabled " >&6;} fi { $as_echo "$as_me:${as_lineno-$LINENO}: " >&5 $as_echo "$as_me: " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: ============================================== " >&5 $as_echo "$as_me: ============================================== " >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: " >&5 $as_echo "$as_me: " >&6;} vnstat-2.9/tests/0000755000000000000000000000000014173313377012554 5ustar rootrootvnstat-2.9/tests/daemon_tests.c0000644000000000000000000011540014106536055015402 0ustar rootroot#include "common.h" #include "vnstat_tests.h" #include "daemon_tests.h" #include "dbaccess.h" #include "datacache.h" #include "dbsql.h" #include "ifinfo.h" #include "cfg.h" #include "ibw.h" #include "fs.h" #include "daemon.h" START_TEST(debugtimestamp_does_not_exit) { suppress_output(); debugtimestamp(); } END_TEST START_TEST(initdstate_does_not_crash) { DSTATE s; initdstate(&s); } END_TEST START_TEST(addinterfaces_does_nothing_with_no_files) { DSTATE s; initdstate(&s); suppress_output(); ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(addinterfaces(&s), 0); } END_TEST START_TEST(addinterfaces_adds_interfaces) { int ret; DSTATE s; initdstate(&s); suppress_output(); ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(clean_testdbdir(), 1); fake_proc_net_dev("w", "ethone", 1, 2, 3, 4); fake_proc_net_dev("a", "lo0", 0, 0, 0, 0); fake_proc_net_dev("a", "ethtwo", 5, 6, 7, 8); fake_proc_net_dev("a", "sit0", 0, 0, 0, 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = (int)addinterfaces(&s); ck_assert_int_eq(ret, 2); ck_assert_int_eq(db_getinterfacecountbyname("ethone"), 1); ck_assert_int_eq(db_getinterfacecountbyname("ethtwo"), 1); ck_assert_int_eq(check_dbfile_exists("ethone", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".ethone", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists("ethtwo", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".ethtwo", sizeof(DATA)), 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(addinterfaces_adds_only_new_interfaces) { int ret; DSTATE s; initdstate(&s); suppress_output(); ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(clean_testdbdir(), 1); fake_proc_net_dev("w", "ethone", 1, 2, 3, 4); fake_proc_net_dev("a", "lo0", 0, 0, 0, 0); fake_proc_net_dev("a", "ethtwo", 5, 6, 7, 8); fake_proc_net_dev("a", "sit0", 0, 0, 0, 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = (int)addinterfaces(&s); ck_assert_int_eq(ret, 2); ck_assert_int_eq(db_getinterfacecountbyname("ethone"), 1); ck_assert_int_eq(db_getinterfacecountbyname("ethtwo"), 1); ck_assert_int_eq(db_getinterfacecountbyname("eththree"), 0); ck_assert_int_eq(db_getinterfacecountbyname("lo0"), 0); ck_assert_int_eq(db_getinterfacecountbyname("sit0"), 0); /* legacy database files should not get created */ ck_assert_int_eq(check_dbfile_exists("ethone", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".ethone", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists("ethtwo", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".ethtwo", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists("eththree", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".eththree", sizeof(DATA)), 0); fake_proc_net_dev("a", "eththree", 9, 10, 11, 12); ret = (int)addinterfaces(&s); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_getinterfacecountbyname("ethone"), 1); ck_assert_int_eq(db_getinterfacecountbyname("ethtwo"), 1); ck_assert_int_eq(db_getinterfacecountbyname("eththree"), 1); ck_assert_int_eq(db_getinterfacecountbyname("lo0"), 0); ck_assert_int_eq(db_getinterfacecountbyname("sit0"), 0); /* legacy database files should still not get created */ ck_assert_int_eq(check_dbfile_exists("ethone", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".ethone", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists("ethtwo", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".ethtwo", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists("eththree", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".eththree", sizeof(DATA)), 0); ck_assert_int_eq(datacache_count(&s.dcache), 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(addinterfaces_adds_to_cache_when_running) { int ret; DSTATE s; initdstate(&s); suppress_output(); ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(clean_testdbdir(), 1); fake_proc_net_dev("w", "ethone", 1, 2, 3, 4); fake_proc_net_dev("a", "ethtwo", 5, 6, 7, 8); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datacache_count(&s.dcache), 0); s.running = 1; ret = (int)addinterfaces(&s); ck_assert_int_eq(ret, 2); ck_assert_int_eq(datacache_count(&s.dcache), 2); ck_assert_int_eq(db_getinterfacecountbyname("ethone"), 1); ck_assert_int_eq(db_getinterfacecountbyname("ethtwo"), 1); ck_assert_int_eq(db_getinterfacecountbyname("eththree"), 0); ck_assert_int_eq(db_getinterfacecountbyname("lo0"), 0); ck_assert_int_eq(db_getinterfacecountbyname("sit0"), 0); ck_assert_int_eq(check_dbfile_exists("ethone", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".ethone", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists("ethtwo", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".ethtwo", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists("eththree", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".eththree", sizeof(DATA)), 0); fake_proc_net_dev("a", "eththree", 9, 10, 11, 12); ret = (int)addinterfaces(&s); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datacache_count(&s.dcache), 3); ck_assert_int_eq(db_getinterfacecountbyname("ethone"), 1); ck_assert_int_eq(db_getinterfacecountbyname("ethtwo"), 1); ck_assert_int_eq(db_getinterfacecountbyname("eththree"), 1); ck_assert_int_eq(db_getinterfacecountbyname("lo0"), 0); ck_assert_int_eq(db_getinterfacecountbyname("sit0"), 0); ck_assert_int_eq(check_dbfile_exists("ethone", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".ethone", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists("ethtwo", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".ethtwo", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists("eththree", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".eththree", sizeof(DATA)), 0); ret = db_close(); ck_assert_int_eq(ret, 1); datacache_clear(&s.dcache); } END_TEST START_TEST(preparedatabase_exits_with_no_database_dir) { DSTATE s; initdstate(&s); suppress_output(); ck_assert_int_eq(remove_directory(TESTDIR), 1); preparedatabase(&s); } END_TEST START_TEST(preparedatabase_exits_with_no_database) { DSTATE s; initdstate(&s); suppress_output(); strncpy_nt(cfg.dbdir, TESTDBDIR, 512); ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(clean_testdbdir(), 1); preparedatabase(&s); } END_TEST START_TEST(preparedatabase_exits_with_no_database_and_noadd) { DSTATE s; initdstate(&s); s.noadd = 1; suppress_output(); strncpy_nt(cfg.dbdir, TESTDBDIR, 512); ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(clean_testdbdir(), 1); preparedatabase(&s); } END_TEST START_TEST(preparedatabase_with_no_database_creates_database) { int ret; DSTATE s; initdstate(&s); suppress_output(); strncpy_nt(cfg.dbdir, TESTDBDIR, 512); ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(clean_testdbdir(), 1); fake_proc_net_dev("w", "ethone", 1, 2, 3, 4); fake_proc_net_dev("a", "lo0", 0, 0, 0, 0); fake_proc_net_dev("a", "ethtwo", 5, 6, 7, 8); fake_proc_net_dev("a", "sit0", 0, 0, 0, 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); preparedatabase(&s); ck_assert_int_eq(db_getinterfacecountbyname("ethone"), 1); ck_assert_int_eq(db_getinterfacecountbyname("ethtwo"), 1); ck_assert_int_eq(check_dbfile_exists("ethone", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".ethone", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists("ethtwo", sizeof(DATA)), 0); ck_assert_int_eq(check_dbfile_exists(".ethtwo", sizeof(DATA)), 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(setsignaltraps_does_not_exit) { intsignal = 1; setsignaltraps(); ck_assert_int_eq(intsignal, 0); } END_TEST START_TEST(filldatabaselist_exits_with_no_database_dir) { DSTATE s; initdstate(&s); disable_logprints(); strncpy_nt(cfg.dbdir, TESTDBDIR, 512); ck_assert_int_eq(remove_directory(TESTDIR), 1); filldatabaselist(&s); } END_TEST START_TEST(filldatabaselist_does_not_exit_with_empty_database_dir) { int ret; DSTATE s; initdstate(&s); disable_logprints(); s.sync = 1; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); filldatabaselist(&s); ck_assert_int_eq(s.dbifcount, 0); ck_assert_int_eq(s.sync, 0); ck_assert_int_eq(s.updateinterval, 120); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(filldatabaselist_adds_databases) { int ret; DSTATE s; initdstate(&s); disable_logprints(); strncpy_nt(cfg.dbdir, TESTDBDIR, 512); strncpy_nt(cfg.dbdir, TESTDBDIR, 512); s.sync = 1; ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(create_zerosize_dbfile("name1"), 1); ck_assert_int_eq(create_zerosize_dbfile("name2"), 1); ck_assert_int_eq(check_dbfile_exists("name1", 0), 1); ck_assert_int_eq(check_dbfile_exists(".name1", 0), 0); ck_assert_int_eq(check_dbfile_exists("name2", 0), 1); ck_assert_int_eq(check_dbfile_exists(".name2", 0), 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); filldatabaselist(&s); /* filldatabaselist() doesn't import legacy dbs */ ck_assert_int_eq(datacache_count(&s.dcache), 2); ck_assert_int_eq(datacache_activecount(&s.dcache), 2); ck_assert_int_eq(check_dbfile_exists("name1", 0), 1); ck_assert_int_eq(check_dbfile_exists(".name1", 0), 0); ck_assert_int_eq(check_dbfile_exists("name2", 0), 1); ck_assert_int_eq(check_dbfile_exists(".name2", 0), 0); ck_assert_int_eq(s.dbifcount, 2); ck_assert_int_eq(s.sync, 0); ck_assert_int_eq(s.updateinterval, 0); ck_assert_int_eq(intsignal, 42); ret = db_close(); ck_assert_int_eq(ret, 1); datacache_clear(&s.dcache); } END_TEST START_TEST(adjustsaveinterval_with_empty_cache) { DSTATE s; initdstate(&s); s.saveinterval = 0; ck_assert_int_eq(datacache_activecount(&s.dcache), 0); adjustsaveinterval(&s); ck_assert_int_eq(s.saveinterval, cfg.offsaveinterval * 60); } END_TEST START_TEST(adjustsaveinterval_with_filled_cache) { int ret; DSTATE s; initdstate(&s); s.saveinterval = 0; ret = datacache_add(&s.dcache, "name1", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datacache_activecount(&s.dcache), 1); adjustsaveinterval(&s); ck_assert_int_eq(s.saveinterval, cfg.saveinterval * 60); datacache_clear(&s.dcache); } END_TEST START_TEST(checkdbsaveneed_has_no_need) { DSTATE s; initdstate(&s); s.dodbsave = 2; s.current = 10; s.prevdbsave = 0; s.saveinterval = 30; s.forcesave = 0; checkdbsaveneed(&s); ck_assert_int_eq(s.dodbsave, 0); ck_assert_int_ne(s.prevdbsave, s.current); } END_TEST START_TEST(checkdbsaveneed_is_forced) { DSTATE s; initdstate(&s); s.dodbsave = 2; s.current = 125; s.prevdbsave = 110; s.saveinterval = 30; s.forcesave = 1; checkdbsaveneed(&s); ck_assert_int_eq(s.dodbsave, 1); ck_assert_int_eq(s.prevdbsave, 120); ck_assert_int_eq(s.forcesave, 0); } END_TEST START_TEST(checkdbsaveneed_needs) { DSTATE s; initdstate(&s); s.dodbsave = 2; s.current = 65; s.prevdbsave = 5; s.saveinterval = 30; s.forcesave = 0; checkdbsaveneed(&s); ck_assert_int_eq(s.dodbsave, 1); ck_assert_int_eq(s.prevdbsave, 60); ck_assert_int_eq(s.forcesave, 0); } END_TEST START_TEST(processdatacache_empty_does_nothing) { DSTATE s; initdstate(&s); processdatacache(&s); } END_TEST START_TEST(processdatacache_can_process_things) { int ret; DSTATE s; initdstate(&s); suppress_output(); ck_assert_int_eq(remove_directory(TESTDIR), 1); debug = 1; s.iflisthash = 42; s.bootdetected = 1; s.dodbsave = 1; s.cleanuphour = getcurrenthour() + 1; s.dbifcount = 3; ck_assert_int_eq(datacache_count(&s.dcache), 0); ret = datacache_add(&s.dcache, "ethnotindb", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&s.dcache, "ethonlyindb", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&s.dcache, "ethexisting", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datacache_count(&s.dcache), 3); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethonlyindb"); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethexisting"); ck_assert_int_eq(ret, 1); fake_proc_net_dev("w", "ethexisting", 10, 20, 30, 40); processdatacache(&s); ck_assert_int_eq(s.iflisthash, 0); ck_assert_int_eq(s.bootdetected, 0); ck_assert_int_eq(s.dodbsave, 0); ck_assert_int_eq(datacache_count(&s.dcache), 1); ret = db_close(); ck_assert_int_eq(ret, 1); datacache_clear(&s.dcache); } END_TEST START_TEST(handleintsignals_handles_no_signal) { DSTATE s; initdstate(&s); s.running = 1; s.dbifcount = 1; intsignal = 0; handleintsignals(&s); ck_assert_int_eq(intsignal, 0); ck_assert_int_eq(s.running, 1); ck_assert_int_eq(s.dbifcount, 1); } END_TEST START_TEST(handleintsignals_handles_42) { DSTATE s; initdstate(&s); s.running = 1; s.dbifcount = 1; intsignal = 42; handleintsignals(&s); ck_assert_int_eq(intsignal, 0); ck_assert_int_eq(s.running, 1); ck_assert_int_eq(s.dbifcount, 1); } END_TEST START_TEST(handleintsignals_handles_unknown_signal) { DSTATE s; initdstate(&s); s.running = 1; s.dbifcount = 1; disable_logprints(); intsignal = 43; handleintsignals(&s); ck_assert_int_eq(intsignal, 0); ck_assert_int_eq(s.running, 1); ck_assert_int_eq(s.dbifcount, 1); } END_TEST START_TEST(handleintsignals_handles_sigterm) { DSTATE s; initdstate(&s); s.running = 1; s.dbifcount = 1; disable_logprints(); intsignal = SIGTERM; handleintsignals(&s); ck_assert_int_eq(intsignal, 0); ck_assert_int_eq(s.running, 0); ck_assert_int_eq(s.dbifcount, 1); } END_TEST START_TEST(handleintsignals_handles_sigint) { DSTATE s; initdstate(&s); s.running = 1; s.dbifcount = 1; disable_logprints(); s.running = 1; intsignal = SIGINT; handleintsignals(&s); ck_assert_int_eq(intsignal, 0); ck_assert_int_eq(s.running, 0); ck_assert_int_eq(s.dbifcount, 1); } END_TEST START_TEST(handleintsignals_handles_sighup) { int ret; DSTATE s; initdstate(&s); s.running = 1; s.dbifcount = 1; disable_logprints(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); filldatabaselist(&s); disable_logprints(); s.running = 1; intsignal = SIGHUP; strncpy_nt(cfg.dbdir, TESTDBDIR, 512); handleintsignals(&s); ck_assert_int_eq(intsignal, 0); ck_assert_int_eq(s.running, 1); ck_assert_int_eq(s.dbifcount, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(preparedirs_with_no_dir) { char logdir[500], piddir[500]; DSTATE s; initdstate(&s); cfg.uselogging = 1; s.rundaemon = 1; strncpy_nt(cfg.dbdir, TESTDBDIR, 512); snprintf(logdir, 500, "%s/log/vnstat", TESTDIR); snprintf(piddir, 500, "%s/pid/vnstat", TESTDIR); snprintf(cfg.logfile, 512, "%s/vnstat.log", logdir); snprintf(cfg.pidfile, 512, "%s/vnstat.pid", piddir); ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(direxists(TESTDBDIR), 0); ck_assert_int_eq(direxists(logdir), 0); ck_assert_int_eq(direxists(piddir), 0); preparedirs(&s); ck_assert_int_eq(direxists(TESTDBDIR), 1); ck_assert_int_eq(direxists(logdir), 1); ck_assert_int_eq(direxists(piddir), 1); } END_TEST START_TEST(preparedirs_with_dir) { char logdir[500], piddir[500]; DSTATE s; initdstate(&s); cfg.uselogging = 1; s.rundaemon = 1; strncpy_nt(cfg.dbdir, TESTDBDIR, 512); snprintf(logdir, 500, "%s/log/vnstat", TESTDIR); snprintf(piddir, 500, "%s/pid/vnstat", TESTDIR); snprintf(cfg.logfile, 512, "%s/vnstat.log", logdir); snprintf(cfg.pidfile, 512, "%s/vnstat.pid", piddir); ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(direxists(TESTDBDIR), 0); ck_assert_int_eq(mkpath(TESTDBDIR, 0775), 1); ck_assert_int_eq(direxists(TESTDBDIR), 1); ck_assert_int_eq(direxists(logdir), 0); ck_assert_int_eq(direxists(piddir), 0); preparedirs(&s); ck_assert_int_eq(direxists(TESTDBDIR), 1); ck_assert_int_eq(direxists(logdir), 1); ck_assert_int_eq(direxists(piddir), 1); } END_TEST START_TEST(interfacechangecheck_with_no_interfaces) { DSTATE s; initdstate(&s); ck_assert_int_eq(remove_directory(TESTDIR), 1); interfacechangecheck(&s); ck_assert_int_eq(s.iflisthash, 0); ck_assert_int_eq(s.forcesave, 0); } END_TEST START_TEST(interfacechangecheck_with_empty_cache) { DSTATE s; initdstate(&s); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "ethsomething", 1, 2, 3, 4); fake_proc_net_dev("a", "ethelse", 5, 6, 7, 8); interfacechangecheck(&s); ck_assert_int_ne(s.iflisthash, 0); ck_assert_int_eq(s.forcesave, 0); } END_TEST START_TEST(interfacechangecheck_with_no_changes_in_iflist) { DSTATE s; uint32_t ifhash; char *ifacelist; initdstate(&s); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "ethsomething", 1, 2, 3, 4); fake_proc_net_dev("a", "ethelse", 5, 6, 7, 8); ck_assert_int_ne(getifliststring(&ifacelist, 0), 0); ifhash = simplehash(ifacelist, (int)strlen(ifacelist)); s.iflisthash = ifhash; interfacechangecheck(&s); ck_assert_int_eq(s.iflisthash, ifhash); ck_assert_int_eq(s.forcesave, 0); free(ifacelist); } END_TEST START_TEST(interfacechangecheck_with_filled_cache) { int ret; DSTATE s; datacache *iterator; initdstate(&s); disable_logprints(); ck_assert_int_eq(remove_directory(TESTDIR), 1); s.iflisthash = 123; ck_assert_int_eq(datacache_count(&s.dcache), 0); ret = datacache_add(&s.dcache, "ethbasic", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&s.dcache, "ethactive", 0); ck_assert_int_eq(ret, 1); /* cache data needs to appear filled during this test */ iterator = s.dcache; while (iterator != NULL) { iterator->filled = 1; iterator = iterator->next; } ck_assert_int_eq(datacache_count(&s.dcache), 2); ck_assert_int_eq(datacache_activecount(&s.dcache), 2); fake_proc_net_dev("w", "ethbasic", 1, 2, 3, 4); interfacechangecheck(&s); ck_assert_int_ne(s.iflisthash, 0); ck_assert_int_eq(s.forcesave, 1); ck_assert_int_eq(datacache_count(&s.dcache), 2); ck_assert_int_eq(datacache_activecount(&s.dcache), 1); datacache_clear(&s.dcache); } END_TEST START_TEST(simplehash_with_empty_strings) { ck_assert_int_eq(simplehash(NULL, 10), 0); ck_assert_int_eq(simplehash("empty", 0), 0); } END_TEST START_TEST(simplehash_with_simple_strings) { ck_assert_int_eq(simplehash("0", 1), 49); ck_assert_int_eq(simplehash("1", 1), 50); ck_assert_int_eq(simplehash("12", 2), 101); } END_TEST START_TEST(initcachevalues_does_not_init_without_database) { int ret; DSTATE s; initdstate(&s); disable_logprints(); ret = datacache_add(&s.dcache, "eth0", 0); ck_assert_int_eq(ret, 1); ret = initcachevalues(&s, &s.dcache); ck_assert_int_eq(ret, 0); datacache_clear(&s.dcache); } END_TEST START_TEST(initcachevalues_does_init) { int ret; DSTATE s; initdstate(&s); disable_logprints(); ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(clean_testdbdir(), 1); strncpy_nt(cfg.dbdir, TESTDBDIR, 512); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_setcounters("eth0", 1, 2); ck_assert_int_eq(ret, 1); ret = datacache_add(&s.dcache, "eth0", 0); ck_assert_int_eq(ret, 1); ret = initcachevalues(&s, &s.dcache); ck_assert_int_eq(ret, 1); ck_assert_int_eq(s.dcache->currx, 1); ck_assert_int_eq(s.dcache->curtx, 2); ck_assert_int_ne(s.dcache->updated, 0); ret = db_close(); ck_assert_int_eq(ret, 1); datacache_clear(&s.dcache); } END_TEST START_TEST(getcurrenthour_returns_something_realistic) { int ret; ret = getcurrenthour(); ck_assert_int_ge(ret, 0); ck_assert_int_le(ret, 23); } END_TEST START_TEST(waittimesync_does_not_wait_unless_configured_to_do_so) { int ret; DSTATE s; initdstate(&s); disable_logprints(); cfg.timesyncwait = 0; ret = waittimesync(&s); ck_assert_int_eq(ret, 0); } END_TEST START_TEST(waittimesync_does_not_wait_with_no_interfaces) { int ret; DSTATE s; initdstate(&s); suppress_output(); debug = 1; ret = waittimesync(&s); ck_assert_int_eq(ret, 0); ck_assert_int_eq(s.prevdbsave, 0); } END_TEST START_TEST(waittimesync_does_not_wait_with_new_interfaces) { int ret; DSTATE s; initdstate(&s); suppress_output(); debug = 1; cfg.timesyncwait = 60; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); /* 'updated' needs to be slightly adjusted in order to be sure to never trigger an error */ ret = db_exec("update interface set updated=datetime('now', '-2 seconds', 'localtime') where id=1;"); ck_assert_int_eq(ret, 1); filldatabaselist(&s); s.prevdbsave = 0; ret = waittimesync(&s); ck_assert_int_eq(ret, 0); ck_assert_int_ne(s.prevdbsave, 0); ret = db_close(); ck_assert_int_eq(ret, 1); datacache_clear(&s.dcache); } END_TEST START_TEST(waittimesync_knows_when_to_wait) { int ret; DSTATE s; initdstate(&s); suppress_output(); debug = 1; cfg.timesyncwait = 60; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_exec("update interface set updated=datetime('now', '+7 days', 'localtime') where id=1;"); ck_assert_int_eq(ret, 1); filldatabaselist(&s); s.prevdbsave = 0; ret = waittimesync(&s); ck_assert_int_eq(ret, 1); s.prevdbsave = time(NULL) - 100; ret = waittimesync(&s); ck_assert_int_eq(ret, 0); ret = db_close(); ck_assert_int_eq(ret, 1); datacache_clear(&s.dcache); } END_TEST START_TEST(waittimesync_knows_when_to_give_up) { int ret; DSTATE s; initdstate(&s); suppress_output(); debug = 1; cfg.timesyncwait = 60; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_exec("update interface set updated=datetime('now', '+7 days', 'localtime') where id=1;"); ck_assert_int_eq(ret, 1); filldatabaselist(&s); s.prevdbsave = 0; ret = waittimesync(&s); ck_assert_int_eq(ret, 1); s.prevdbupdate -= 5000; ret = waittimesync(&s); ck_assert_int_eq(ret, 0); ret = db_close(); ck_assert_int_eq(ret, 1); datacache_clear(&s.dcache); } END_TEST START_TEST(detectboot_sets_btime_if_missing_from_database) { int ret; DSTATE s; char *buffer; initdstate(&s); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_exec("delete from info where name='btime';"); ck_assert_int_eq(ret, 1); buffer = db_getinfo("btime"); ck_assert_int_eq((int)strlen(buffer), 0); ck_assert_int_eq(s.bootdetected, 0); detectboot(&s); ck_assert_int_eq(s.bootdetected, 0); buffer = db_getinfo("btime"); ck_assert_int_ne((int)strlen(buffer), 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(detectboot_sets_btime_for_new_database) { int ret; DSTATE s; char *buffer; char temp[64]; initdstate(&s); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); buffer = db_getinfo("btime"); ck_assert_int_ne((int)strlen(buffer), 0); strncpy_nt(temp, buffer, 64); ck_assert_str_eq(buffer, temp); ck_assert_int_eq(s.bootdetected, 0); detectboot(&s); ck_assert_int_eq(s.bootdetected, 0); buffer = db_getinfo("btime"); ck_assert_int_ne((int)strlen(buffer), 0); ck_assert_str_ne(buffer, temp); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(detectboot_can_detect_boot) { int ret; DSTATE s; char *buffer; char temp[64]; initdstate(&s); suppress_output(); debug = 1; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); db_setinfo("btime", "1", 1); buffer = db_getinfo("btime"); ck_assert_int_ne((int)strlen(buffer), 0); strncpy_nt(temp, buffer, 64); ck_assert_str_eq(buffer, temp); ck_assert_int_eq(s.bootdetected, 0); detectboot(&s); ck_assert_int_eq(s.bootdetected, 1); buffer = db_getinfo("btime"); ck_assert_int_ne((int)strlen(buffer), 0); ck_assert_str_ne(buffer, temp); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(handledatabaseerror_exits_on_fatal_error) { DSTATE s; initdstate(&s); disable_logprints(); db_errcode = SQLITE_ERROR; handledatabaseerror(&s); } END_TEST START_TEST(handledatabaseerror_does_not_exit_if_limit_is_not_exceeded) { int i; DSTATE s; initdstate(&s); disable_logprints(); ck_assert_int_eq(s.dbretrycount, 0); db_errcode = SQLITE_BUSY; handledatabaseerror(&s); ck_assert_int_eq(s.dbretrycount, 1); for (i = 1; i < DBRETRYLIMIT; i++) { handledatabaseerror(&s); } ck_assert_int_eq(s.dbretrycount, DBRETRYLIMIT); } END_TEST START_TEST(handledatabaseerror_exits_if_limit_is_exceeded) { int i; DSTATE s; initdstate(&s); disable_logprints(); ck_assert_int_eq(s.dbretrycount, 0); db_errcode = SQLITE_BUSY; handledatabaseerror(&s); ck_assert_int_eq(s.dbretrycount, 1); for (i = 1; i < DBRETRYLIMIT + 1; i++) { handledatabaseerror(&s); } } END_TEST START_TEST(cleanremovedinterfaces_allows_interfaces_to_be_removed) { int ret; DSTATE s; initdstate(&s); disable_logprints(); ck_assert_int_eq(datacache_count(&s.dcache), 0); ret = datacache_add(&s.dcache, "ethnotindb1", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&s.dcache, "ethindb1", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&s.dcache, "ethnotindb2", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&s.dcache, "ethindb2", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&s.dcache, "ethindb3", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&s.dcache, "ethnotindb3", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&s.dcache, "ethnotindb4", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datacache_count(&s.dcache), 7); s.dbifcount = 7; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethindb1"); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethindb2"); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethindb3"); ck_assert_int_eq(ret, 1); cleanremovedinterfaces(&s); ck_assert_int_eq(s.dbifcount, 3); ck_assert_int_eq(datacache_count(&s.dcache), 3); ret = db_close(); ck_assert_int_eq(ret, 1); datacache_clear(&s.dcache); } END_TEST START_TEST(processifinfo_syncs_when_needed) { int ret; DSTATE s; initdstate(&s); ifinfo.rx = 11; ifinfo.tx = 22; ck_assert_int_eq(datacache_count(&s.dcache), 0); ret = datacache_add(&s.dcache, "ethsomething", 1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(s.dcache->syncneeded, 1); ck_assert_int_eq(s.dcache->currx, 0); ck_assert_int_eq(s.dcache->curtx, 0); ret = processifinfo(&s, &s.dcache); ck_assert_int_eq(ret, 1); ck_assert_int_eq(s.dcache->syncneeded, 0); ck_assert_int_eq(s.dcache->currx, 11); ck_assert_int_eq(s.dcache->curtx, 22); datacache_clear(&s.dcache); } END_TEST START_TEST(processifinfo_skips_update_if_timestamps_make_no_sense) { int ret; DSTATE s; initdstate(&s); ifinfo.rx = 11; ifinfo.tx = 22; ifinfo.timestamp = 250; ck_assert_int_eq(datacache_count(&s.dcache), 0); ret = datacache_add(&s.dcache, "ethsomething", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(s.dcache->syncneeded, 0); ck_assert_int_eq(s.dcache->currx, 0); ck_assert_int_eq(s.dcache->curtx, 0); s.dcache->updated = 300; ret = processifinfo(&s, &s.dcache); ck_assert_int_eq(ret, 0); ck_assert_int_eq(s.dcache->syncneeded, 0); ck_assert_int_eq(s.dcache->currx, 0); ck_assert_int_eq(s.dcache->curtx, 0); datacache_clear(&s.dcache); } END_TEST START_TEST(processifinfo_exits_if_timestamps_really_make_no_sense) { int ret; DSTATE s; initdstate(&s); disable_logprints(); ifinfo.rx = 11; ifinfo.tx = 22; ifinfo.timestamp = 250; ck_assert_int_eq(datacache_count(&s.dcache), 0); ret = datacache_add(&s.dcache, "ethsomething", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(s.dcache->syncneeded, 0); ck_assert_int_eq(s.dcache->currx, 0); ck_assert_int_eq(s.dcache->curtx, 0); s.dcache->updated = 100000; processifinfo(&s, &s.dcache); } END_TEST START_TEST(processifinfo_syncs_if_timestamps_match) { int ret; DSTATE s; initdstate(&s); ifinfo.rx = 11; ifinfo.tx = 22; ifinfo.timestamp = 250; ck_assert_int_eq(datacache_count(&s.dcache), 0); ret = datacache_add(&s.dcache, "ethsomething", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(s.dcache->syncneeded, 0); ck_assert_int_eq(s.dcache->currx, 0); ck_assert_int_eq(s.dcache->curtx, 0); s.dcache->updated = 250; ret = processifinfo(&s, &s.dcache); ck_assert_int_eq(ret, 1); ck_assert_int_eq(s.dcache->syncneeded, 0); ck_assert_int_eq(s.dcache->currx, 11); ck_assert_int_eq(s.dcache->curtx, 22); ck_assert_ptr_eq(s.dcache->log, NULL); datacache_clear(&s.dcache); } END_TEST START_TEST(processifinfo_adds_traffic) { int ret; DSTATE s; initdstate(&s); suppress_output(); debug = 1; ifinfo.rx = 11; ifinfo.tx = 22; ifinfo.timestamp = 250; ck_assert_int_eq(datacache_count(&s.dcache), 0); ret = datacache_add(&s.dcache, "ethsomething", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(s.dcache->syncneeded, 0); ck_assert_int_eq(s.dcache->currx, 0); ck_assert_int_eq(s.dcache->curtx, 0); s.dcache->updated = 200; ret = ibwadd("ethsomething", 1000); ck_assert_int_eq(ret, 1); ret = processifinfo(&s, &s.dcache); ck_assert_int_eq(ret, 1); ck_assert_int_eq(s.dcache->syncneeded, 0); ck_assert_int_eq(s.dcache->currx, 11); ck_assert_int_eq(s.dcache->curtx, 22); ck_assert_ptr_ne(s.dcache->log, NULL); datacache_clear(&s.dcache); } END_TEST START_TEST(processifinfo_does_not_add_traffic_when_over_limit) { int ret; DSTATE s; initdstate(&s); suppress_output(); debug = 1; ifinfo.rx = 1111111; ifinfo.tx = 2222222; ifinfo.timestamp = 250; cfg.trafficlessentries = 0; ck_assert_int_eq(datacache_count(&s.dcache), 0); ret = datacache_add(&s.dcache, "ethsomething", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(s.dcache->syncneeded, 0); ck_assert_int_eq(s.dcache->currx, 0); ck_assert_int_eq(s.dcache->curtx, 0); s.dcache->updated = 249; ret = ibwadd("ethsomething", 1); ck_assert_int_eq(ret, 1); ret = processifinfo(&s, &s.dcache); ck_assert_int_eq(ret, 1); ck_assert_int_eq(s.dcache->syncneeded, 0); ck_assert_int_eq(s.dcache->currx, 1111111); ck_assert_int_eq(s.dcache->curtx, 2222222); ck_assert_ptr_eq(s.dcache->log, NULL); datacache_clear(&s.dcache); } END_TEST START_TEST(processifinfo_adds_zero_traffic_when_over_limit) { int ret; DSTATE s; initdstate(&s); suppress_output(); debug = 1; ifinfo.rx = 1111111; ifinfo.tx = 2222222; ifinfo.timestamp = 250; cfg.trafficlessentries = 1; ck_assert_int_eq(datacache_count(&s.dcache), 0); ret = datacache_add(&s.dcache, "ethsomething", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(s.dcache->syncneeded, 0); ck_assert_int_eq(s.dcache->currx, 0); ck_assert_int_eq(s.dcache->curtx, 0); s.dcache->updated = 249; ret = ibwadd("ethsomething", 1); ck_assert_int_eq(ret, 1); ret = processifinfo(&s, &s.dcache); ck_assert_int_eq(ret, 1); ck_assert_int_eq(s.dcache->syncneeded, 0); ck_assert_int_eq(s.dcache->currx, 1111111); ck_assert_int_eq(s.dcache->curtx, 2222222); ck_assert_ptr_ne(s.dcache->log, NULL); ck_assert_int_eq(s.dcache->log->rx, 0); ck_assert_int_eq(s.dcache->log->tx, 0); datacache_clear(&s.dcache); } END_TEST START_TEST(datacache_status_can_handle_nothing) { datacache *dcache; disable_logprints(); dcache = NULL; datacache_status(&dcache); } END_TEST START_TEST(datacache_status_can_show_limits) { int ret; datacache *dcache; disable_logprints(); dcache = NULL; ret = datacache_add(&dcache, "ethdefault", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&dcache, "ethslow", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&dcache, "ethfast", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&dcache, "ethnolimit", 0); ck_assert_int_eq(ret, 1); ret = ibwadd("ethslow", 1); ck_assert_int_eq(ret, 1); ret = ibwadd("ethfast", 1000); ck_assert_int_eq(ret, 1); ret = ibwadd("ethnolimit", 0); ck_assert_int_eq(ret, 1); datacache_status(&dcache); datacache_clear(&dcache); } END_TEST START_TEST(datacache_status_has_no_issues_with_large_number_of_interfaces) { int i, ret; char buffer[8]; datacache *dcache; disable_logprints(); dcache = NULL; for (i = 0; i < 100; i++) { snprintf(buffer, 8, "eth%d", i); ret = datacache_add(&dcache, buffer, 0); ck_assert_int_eq(ret, 1); ret = ibwadd(buffer, (uint32_t)i); ck_assert_int_eq(ret, 1); } datacache_status(&dcache); datacache_clear(&dcache); } END_TEST START_TEST(rescandatabaseforinterfaces_does_nothing_if_database_has_no_interfaces) { int ret; DSTATE s; initdstate(&s); ck_assert_int_eq(datacache_count(&s.dcache), 0); ck_assert_int_eq(s.dbifcount, 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_getinterfacecount(), 0); rescandatabaseforinterfaces(&s); ck_assert_int_eq(datacache_count(&s.dcache), 0); ck_assert_int_eq(s.dbifcount, 0); ck_assert_int_eq(db_getinterfacecount(), 0); ret = db_close(); ck_assert_int_eq(ret, 1); datacache_clear(&s.dcache); } END_TEST START_TEST(rescandatabaseforinterfaces_does_nothing_if_interface_lists_are_the_same) { int ret; DSTATE s; initdstate(&s); ck_assert_int_eq(datacache_count(&s.dcache), 0); ret = datacache_add(&s.dcache, "ethtwo", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&s.dcache, "eththree", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&s.dcache, "ethone", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datacache_count(&s.dcache), 3); s.dbifcount = 3; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_getinterfacecount(), 0); ret = db_addinterface("ethtwo"); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethone"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eththree"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_getinterfacecount(), 3); rescandatabaseforinterfaces(&s); ck_assert_int_eq(datacache_count(&s.dcache), 3); ck_assert_int_eq(s.dbifcount, 3); ck_assert_int_eq(db_getinterfacecount(), 3); ret = db_close(); ck_assert_int_eq(ret, 1); datacache_clear(&s.dcache); } END_TEST START_TEST(rescandatabaseforinterfaces_adds_missing_interfaces_to_update_list) { int ret; DSTATE s; initdstate(&s); disable_logprints(); ck_assert_int_eq(datacache_count(&s.dcache), 0); ret = datacache_add(&s.dcache, "ethone", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&s.dcache, "ethfour", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datacache_count(&s.dcache), 2); s.dbifcount = 2; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_getinterfacecount(), 0); ret = db_addinterface("ethtwo"); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethone"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eththree"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_getinterfacecount(), 3); rescandatabaseforinterfaces(&s); ck_assert_int_eq(datacache_count(&s.dcache), 4); ck_assert_int_eq(s.dbifcount, 4); ck_assert_int_eq(db_getinterfacecount(), 3); ret = db_close(); ck_assert_int_eq(ret, 1); datacache_clear(&s.dcache); } END_TEST void add_daemon_tests(Suite *s) { TCase *tc_daemon = tcase_create("Daemon"); tcase_add_checked_fixture(tc_daemon, setup, teardown); tcase_add_unchecked_fixture(tc_daemon, setup, teardown); tcase_add_test(tc_daemon, debugtimestamp_does_not_exit); tcase_add_test(tc_daemon, initdstate_does_not_crash); tcase_add_test(tc_daemon, addinterfaces_does_nothing_with_no_files); tcase_add_test(tc_daemon, addinterfaces_adds_interfaces); tcase_add_test(tc_daemon, addinterfaces_adds_only_new_interfaces); tcase_add_test(tc_daemon, addinterfaces_adds_to_cache_when_running); tcase_add_exit_test(tc_daemon, preparedatabase_exits_with_no_database_dir, 1); tcase_add_exit_test(tc_daemon, preparedatabase_exits_with_no_database, 1); tcase_add_exit_test(tc_daemon, preparedatabase_exits_with_no_database_and_noadd, 1); tcase_add_test(tc_daemon, preparedatabase_with_no_database_creates_database); tcase_add_test(tc_daemon, setsignaltraps_does_not_exit); tcase_add_exit_test(tc_daemon, filldatabaselist_exits_with_no_database_dir, 1); tcase_add_test(tc_daemon, filldatabaselist_does_not_exit_with_empty_database_dir); tcase_add_test(tc_daemon, filldatabaselist_adds_databases); tcase_add_test(tc_daemon, adjustsaveinterval_with_empty_cache); tcase_add_test(tc_daemon, adjustsaveinterval_with_filled_cache); tcase_add_test(tc_daemon, checkdbsaveneed_has_no_need); tcase_add_test(tc_daemon, checkdbsaveneed_is_forced); tcase_add_test(tc_daemon, checkdbsaveneed_needs); tcase_add_test(tc_daemon, processdatacache_empty_does_nothing); tcase_add_test(tc_daemon, processdatacache_can_process_things); tcase_add_test(tc_daemon, handleintsignals_handles_no_signal); tcase_add_test(tc_daemon, handleintsignals_handles_42); tcase_add_test(tc_daemon, handleintsignals_handles_unknown_signal); tcase_add_test(tc_daemon, handleintsignals_handles_sigterm); tcase_add_test(tc_daemon, handleintsignals_handles_sigint); tcase_add_test(tc_daemon, handleintsignals_handles_sighup); tcase_add_test(tc_daemon, preparedirs_with_no_dir); tcase_add_test(tc_daemon, preparedirs_with_dir); tcase_add_test(tc_daemon, interfacechangecheck_with_no_interfaces); tcase_add_test(tc_daemon, interfacechangecheck_with_empty_cache); tcase_add_test(tc_daemon, interfacechangecheck_with_no_changes_in_iflist); tcase_add_test(tc_daemon, interfacechangecheck_with_filled_cache); tcase_add_test(tc_daemon, simplehash_with_empty_strings); tcase_add_test(tc_daemon, simplehash_with_simple_strings); tcase_add_test(tc_daemon, initcachevalues_does_not_init_without_database); tcase_add_test(tc_daemon, initcachevalues_does_init); tcase_add_test(tc_daemon, getcurrenthour_returns_something_realistic); tcase_add_test(tc_daemon, waittimesync_does_not_wait_unless_configured_to_do_so); tcase_add_test(tc_daemon, waittimesync_does_not_wait_with_no_interfaces); tcase_add_test(tc_daemon, waittimesync_does_not_wait_with_new_interfaces); tcase_add_test(tc_daemon, waittimesync_knows_when_to_wait); tcase_add_test(tc_daemon, waittimesync_knows_when_to_give_up); tcase_add_test(tc_daemon, detectboot_sets_btime_if_missing_from_database); tcase_add_test(tc_daemon, detectboot_sets_btime_for_new_database); tcase_add_test(tc_daemon, detectboot_can_detect_boot); tcase_add_exit_test(tc_daemon, handledatabaseerror_exits_on_fatal_error, 1); tcase_add_test(tc_daemon, handledatabaseerror_does_not_exit_if_limit_is_not_exceeded); tcase_add_exit_test(tc_daemon, handledatabaseerror_exits_if_limit_is_exceeded, 1); tcase_add_test(tc_daemon, cleanremovedinterfaces_allows_interfaces_to_be_removed); tcase_add_test(tc_daemon, processifinfo_syncs_when_needed); tcase_add_test(tc_daemon, processifinfo_skips_update_if_timestamps_make_no_sense); tcase_add_exit_test(tc_daemon, processifinfo_exits_if_timestamps_really_make_no_sense, 1); tcase_add_test(tc_daemon, processifinfo_syncs_if_timestamps_match); tcase_add_test(tc_daemon, processifinfo_adds_traffic); tcase_add_test(tc_daemon, processifinfo_does_not_add_traffic_when_over_limit); tcase_add_test(tc_daemon, processifinfo_adds_zero_traffic_when_over_limit); tcase_add_test(tc_daemon, datacache_status_can_handle_nothing); tcase_add_test(tc_daemon, datacache_status_can_show_limits); tcase_add_test(tc_daemon, datacache_status_has_no_issues_with_large_number_of_interfaces); tcase_add_test(tc_daemon, rescandatabaseforinterfaces_does_nothing_if_database_has_no_interfaces); tcase_add_test(tc_daemon, rescandatabaseforinterfaces_does_nothing_if_interface_lists_are_the_same); tcase_add_test(tc_daemon, rescandatabaseforinterfaces_adds_missing_interfaces_to_update_list); suite_add_tcase(s, tc_daemon); } vnstat-2.9/tests/id_tests.h0000644000000000000000000000011413510474665014541 0ustar rootroot#ifndef ID_TESTS_H #define ID_TESTS_H void add_id_tests(Suite *s); #endif vnstat-2.9/tests/ifinfo_tests.c0000644000000000000000000002372214077634752015430 0ustar rootroot#include "common.h" #include "vnstat_tests.h" #include "ifinfo_tests.h" #include "ifinfo.h" #include "dbaccess.h" #include "misc.h" #include "cfg.h" #include "ibw.h" START_TEST(getifliststring_no_source) { char *ifacelist; linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(getifliststring(&ifacelist, 0), 0); ck_assert_str_eq(ifacelist, ""); free(ifacelist); } END_TEST START_TEST(getifliststring_proc_one_interface) { char *ifacelist; linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "ethunusual", 0, 0, 0, 0); ck_assert_int_eq(getifliststring(&ifacelist, 1), 1); ck_assert_str_eq(ifacelist, "ethunusual "); free(ifacelist); } END_TEST START_TEST(getifliststring_proc_one_interface_with_speed) { char *ifacelist; linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "ethunusual", 0, 0, 0, 0); fake_sys_class_net("ethunusual", 0, 0, 0, 0, 10); ck_assert_int_eq(getifliststring(&ifacelist, 1), 1); ck_assert_str_eq(ifacelist, "ethunusual (10 Mbit) "); free(ifacelist); } END_TEST START_TEST(getifliststring_proc_multiple_interfaces) { char *ifacelist; linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "random", 0, 0, 0, 0); fake_proc_net_dev("a", "interfaces", 0, 0, 0, 0); fake_proc_net_dev("a", "having", 0, 0, 0, 0); fake_proc_net_dev("a", "fun", 0, 0, 0, 0); fake_proc_net_dev("a", "i", 0, 0, 0, 0); ck_assert_int_eq(getifliststring(&ifacelist, 0), 1); ck_assert_str_eq(ifacelist, "random interfaces having fun i "); free(ifacelist); } END_TEST START_TEST(getifliststring_proc_multiple_interfaces_validating) { char *ifacelist; linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "random", 0, 0, 0, 0); fake_proc_net_dev("a", "interfaces", 0, 0, 0, 0); fake_proc_net_dev("a", "having", 0, 0, 0, 0); fake_proc_net_dev("a", "sit0", 0, 0, 0, 0); fake_proc_net_dev("a", "fun", 0, 0, 0, 0); fake_proc_net_dev("a", "lo0", 0, 0, 0, 0); fake_proc_net_dev("a", "eth0:0", 0, 0, 0, 0); fake_proc_net_dev("a", "i", 0, 0, 0, 0); ck_assert_int_eq(getifliststring(&ifacelist, 0), 1); ck_assert_str_eq(ifacelist, "random interfaces having fun eth0 i "); free(ifacelist); } END_TEST START_TEST(getifliststring_proc_long_interface_names) { char *ifacelist; linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "random", 0, 0, 0, 0); fake_proc_net_dev("a", "interfaces", 0, 0, 0, 0); fake_proc_net_dev("a", "having", 0, 0, 0, 0); fake_proc_net_dev("a", "toomuchfun", 0, 0, 0, 0); fake_proc_net_dev("a", "longinterfaceislong", 0, 0, 0, 0); fake_proc_net_dev("a", "longestinterfaceislongerthanshouldbeexpectedanywhereinanormallyfunctioningenvironment", 0, 0, 0, 0); fake_proc_net_dev("a", "a", 0, 0, 0, 0); ck_assert_int_eq(getifliststring(&ifacelist, 0), 1); ck_assert_str_eq(ifacelist, "random interfaces having toomuchfun longinterfaceislong a "); free(ifacelist); } END_TEST START_TEST(getifliststring_sysclassnet_one_interface) { char *ifacelist; linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_sys_class_net("ethunusual", 0, 0, 0, 0, 0); ck_assert_int_eq(getifliststring(&ifacelist, 1), 1); ck_assert_str_eq(ifacelist, "ethunusual "); free(ifacelist); } END_TEST START_TEST(getifliststring_sysclassnet_one_interface_with_speed) { char *ifacelist; linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_sys_class_net("ethunusual", 0, 0, 0, 0, 10); ck_assert_int_eq(getifliststring(&ifacelist, 1), 1); ck_assert_str_eq(ifacelist, "ethunusual (10 Mbit) "); free(ifacelist); } END_TEST START_TEST(getifliststring_sysclassnet_multiple_interfaces) { char *ifacelist; linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_sys_class_net("random", 0, 0, 0, 0, 0); fake_sys_class_net("interfaces", 0, 0, 0, 0, 0); fake_sys_class_net("having", 0, 0, 0, 0, 0); fake_sys_class_net("fun", 0, 0, 0, 0, 0); fake_sys_class_net("i", 0, 0, 0, 0, 0); ck_assert_int_eq(getifliststring(&ifacelist, 0), 1); ck_assert_int_eq(strlen(ifacelist), 31); free(ifacelist); } END_TEST START_TEST(getifliststring_sysclassnet_multiple_interfaces_validating) { char *ifacelist; linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_sys_class_net("lo", 0, 0, 0, 0, 0); fake_sys_class_net("random", 0, 0, 0, 0, 0); fake_sys_class_net("lo0", 0, 0, 0, 0, 0); fake_sys_class_net("interfaces", 0, 0, 0, 0, 0); fake_sys_class_net("having", 0, 0, 0, 0, 0); fake_sys_class_net("fun", 0, 0, 0, 0, 0); fake_sys_class_net("sit0", 0, 0, 0, 0, 0); fake_sys_class_net("eth0:0", 0, 0, 0, 0, 0); fake_sys_class_net("i", 0, 0, 0, 0, 0); ck_assert_int_eq(getifliststring(&ifacelist, 0), 1); ck_assert_int_eq(strlen(ifacelist), 31); free(ifacelist); } END_TEST START_TEST(getifliststring_sysclassnet_long_interface_names) { char *ifacelist; linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_sys_class_net("random", 0, 0, 0, 0, 0); fake_sys_class_net("interfaces", 0, 0, 0, 0, 0); fake_sys_class_net("having", 0, 0, 0, 0, 0); fake_sys_class_net("toomuchfun", 0, 0, 0, 0, 0); fake_sys_class_net("longinterfaceislong", 0, 0, 0, 0, 0); fake_sys_class_net("longestinterfaceislongerthanshouldbeexpectedanywhereinanormallyfunctioningenvironment", 0, 0, 0, 0, 0); fake_sys_class_net("a", 0, 0, 0, 0, 0); ck_assert_int_eq(getifliststring(&ifacelist, 0), 1); ck_assert_int_eq(strlen(ifacelist), 58); free(ifacelist); } END_TEST START_TEST(readproc_no_file) { linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(readproc("ethunusual"), 0); } END_TEST START_TEST(readproc_not_found) { linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "ethwrong", 10, 20, 30, 40); ck_assert_int_eq(readproc("ethunusual"), 0); } END_TEST START_TEST(readproc_success) { linuxonly; noexit = 0; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "ethwrong", 10, 20, 30, 40); fake_proc_net_dev("a", "ethunusual", 1, 2, 3, 4); ck_assert_int_eq(readproc("ethunusual"), 1); ck_assert_str_eq(ifinfo.name, "ethunusual"); ck_assert_int_eq(ifinfo.filled, 1); ck_assert_int_eq(ifinfo.rx, 1); ck_assert_int_eq(ifinfo.tx, 2); ck_assert_int_eq(ifinfo.rxp, 3); ck_assert_int_eq(ifinfo.txp, 4); } END_TEST START_TEST(readsysclassnet_not_found) { linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_sys_class_net("ethwrong", 10, 20, 30, 40, 50); ck_assert_int_eq(readsysclassnet("ethunusual"), 0); } END_TEST START_TEST(readsysclassnet_success) { linuxonly; noexit = 0; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_sys_class_net("ethwrong", 10, 20, 30, 40, 50); fake_sys_class_net("ethunusual", 1, 2, 3, 4, 5); ck_assert_int_eq(readsysclassnet("ethunusual"), 1); ck_assert_str_eq(ifinfo.name, "ethunusual"); ck_assert_int_eq(ifinfo.filled, 1); ck_assert_int_eq(ifinfo.rx, 1); ck_assert_int_eq(ifinfo.tx, 2); ck_assert_int_eq(ifinfo.rxp, 3); ck_assert_int_eq(ifinfo.txp, 4); } END_TEST START_TEST(getifinfo_not_found) { linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "ethwrong", 10, 20, 30, 40); suppress_output(); ck_assert_int_eq(getifinfo("ethunusual"), 0); } END_TEST START_TEST(getifinfo_success) { linuxonly; noexit = 0; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "ethwrong", 10, 20, 30, 40); fake_proc_net_dev("a", "ethunusual", 1, 2, 3, 4); suppress_output(); ck_assert_int_eq(getifinfo("ethunusual"), 1); ck_assert_str_eq(ifinfo.name, "ethunusual"); ck_assert_int_eq(ifinfo.filled, 1); ck_assert_int_eq(ifinfo.rx, 1); ck_assert_int_eq(ifinfo.tx, 2); ck_assert_int_eq(ifinfo.rxp, 3); ck_assert_int_eq(ifinfo.txp, 4); } END_TEST START_TEST(isifavailable_knows_interface_availability) { linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "eth0", 10, 20, 30, 40); fake_proc_net_dev("a", "eth1", 1, 2, 3, 4); suppress_output(); ck_assert_int_eq(isifavailable("eth0"), 1); ck_assert_int_eq(isifavailable("eth1"), 1); ck_assert_int_eq(isifavailable("eth2"), 0); } END_TEST START_TEST(istun_knows_what_a_tun_interface_looks_like) { linuxonly; ck_assert_int_eq(istun("eth0"), 0); ck_assert_int_eq(istun("not_tun0"), 0); ck_assert_int_eq(istun("tun"), 0); ck_assert_int_eq(istun("tuna"), 0); ck_assert_int_eq(istun("tun0"), 1); ck_assert_int_eq(istun("tun1"), 1); ck_assert_int_eq(istun("tun12"), 1); ck_assert_int_eq(istun("tun123"), 1); ck_assert_int_eq(istun("tun1234"), 1); } END_TEST void add_ifinfo_tests(Suite *s) { TCase *tc_ifinfo = tcase_create("Ifinfo"); tcase_add_checked_fixture(tc_ifinfo, setup, teardown); tcase_add_unchecked_fixture(tc_ifinfo, setup, teardown); tcase_add_test(tc_ifinfo, getifliststring_no_source); tcase_add_test(tc_ifinfo, getifliststring_proc_one_interface); tcase_add_test(tc_ifinfo, getifliststring_proc_one_interface_with_speed); tcase_add_test(tc_ifinfo, getifliststring_proc_multiple_interfaces); tcase_add_test(tc_ifinfo, getifliststring_proc_multiple_interfaces_validating); tcase_add_test(tc_ifinfo, getifliststring_proc_long_interface_names); tcase_add_test(tc_ifinfo, getifliststring_sysclassnet_one_interface); tcase_add_test(tc_ifinfo, getifliststring_sysclassnet_one_interface_with_speed); tcase_add_test(tc_ifinfo, getifliststring_sysclassnet_multiple_interfaces); tcase_add_test(tc_ifinfo, getifliststring_sysclassnet_multiple_interfaces_validating); tcase_add_test(tc_ifinfo, getifliststring_sysclassnet_long_interface_names); tcase_add_test(tc_ifinfo, readproc_no_file); tcase_add_test(tc_ifinfo, readproc_not_found); tcase_add_test(tc_ifinfo, readproc_success); tcase_add_test(tc_ifinfo, readsysclassnet_not_found); tcase_add_test(tc_ifinfo, readsysclassnet_success); tcase_add_test(tc_ifinfo, getifinfo_not_found); tcase_add_test(tc_ifinfo, getifinfo_success); tcase_add_test(tc_ifinfo, isifavailable_knows_interface_availability); tcase_add_test(tc_ifinfo, istun_knows_what_a_tun_interface_looks_like); suite_add_tcase(s, tc_ifinfo); } vnstat-2.9/tests/image_tests.c0000644000000000000000000007275614100253055015227 0ustar rootroot#include "common.h" #include "vnstat_tests.h" #include "image_tests.h" #include "dbsql.h" #include "cfg.h" #include "image.h" #include "image_support.h" START_TEST(initimagecontent_does_not_crash) { IMAGECONTENT ic; initimagecontent(&ic); } END_TEST START_TEST(imageinit_does_not_crash) { IMAGECONTENT ic; imageinit(&ic, 2, 2); gdImageDestroy(ic.im); } END_TEST START_TEST(layoutinit_does_not_crash) { IMAGECONTENT ic; initimagecontent(&ic); imageinit(&ic, 640, 480); ic.interface.updated = time(NULL); layoutinit(&ic, "testing 123", 640, 480); gdImageDestroy(ic.im); } END_TEST START_TEST(getimagevalue_zeropadding) { ck_assert_str_eq(getimagevalue(0, 0, 0), "--"); ck_assert_str_eq(getimagevalue(0, 2, 0), "--"); ck_assert_str_eq(getimagevalue(0, 3, 0), " --"); ck_assert_str_eq(getimagevalue(0, 0, 1), "--"); ck_assert_str_eq(getimagevalue(0, 2, 1), "--"); ck_assert_str_eq(getimagevalue(0, 3, 1), " --"); } END_TEST START_TEST(getimagevalue_normal) { ck_assert_str_eq(getimagevalue(1, 0, 0), "1"); ck_assert_str_eq(getimagevalue(2, 0, 0), "2"); ck_assert_str_eq(getimagevalue(1000, 0, 0), "1"); ck_assert_str_eq(getimagevalue(1024, 0, 0), "1"); ck_assert_str_eq(getimagevalue(2000, 0, 0), "2"); ck_assert_str_eq(getimagevalue(2345, 0, 0), "2"); ck_assert_str_eq(getimagevalue(123000, 0, 0), "120"); ck_assert_str_eq(getimagevalue(1024000, 0, 0), "1"); ck_assert_str_eq(getimagevalue(1048576, 0, 0), "1"); ck_assert_str_eq(getimagevalue(1048576000, 0, 0), "1"); ck_assert_str_eq(getimagevalue(1073741824, 0, 0), "1"); ck_assert_str_eq(getimagevalue(1073741824000ULL, 0, 0), "1"); ck_assert_str_eq(getimagevalue(1099511627776ULL, 0, 0), "1"); } END_TEST START_TEST(getimagevalue_rate_1024) { cfg.rateunit = 0; cfg.rateunitmode = 0; ck_assert_str_eq(getimagevalue(1, 0, 1), "1"); ck_assert_str_eq(getimagevalue(2, 0, 1), "2"); ck_assert_str_eq(getimagevalue(1000, 0, 1), "1"); ck_assert_str_eq(getimagevalue(2000, 0, 1), "2"); ck_assert_str_eq(getimagevalue(1024000, 0, 1), "1"); ck_assert_str_eq(getimagevalue(1048576000, 0, 1), "1"); ck_assert_str_eq(getimagevalue(1073741824000ULL, 0, 1), "1"); } END_TEST START_TEST(getimagevalue_rate_1000) { cfg.rateunit = 1; cfg.rateunitmode = 1; ck_assert_str_eq(getimagevalue(1, 0, 1), "1"); ck_assert_str_eq(getimagevalue(2, 0, 1), "2"); ck_assert_str_eq(getimagevalue(1000, 0, 1), "1"); ck_assert_str_eq(getimagevalue(2000, 0, 1), "2"); ck_assert_str_eq(getimagevalue(1000000, 0, 1), "1"); ck_assert_str_eq(getimagevalue(1000000000, 0, 1), "1"); ck_assert_str_eq(getimagevalue(1000000000000ULL, 0, 1), "1"); } END_TEST START_TEST(getimagescale_zero) { cfg.rateunit = 0; ck_assert_str_eq(getimagescale(0, 0), "--"); ck_assert_str_eq(getimagescale(0, 1), "--"); } END_TEST START_TEST(getimagescale_normal) { cfg.rateunit = 0; ck_assert_str_eq(getimagescale(1, 0), "B"); ck_assert_str_eq(getimagescale(2, 0), "B"); ck_assert_str_eq(getimagescale(10, 0), "B"); ck_assert_str_eq(getimagescale(100, 0), "B"); ck_assert_str_eq(getimagescale(1000, 0), "KiB"); ck_assert_str_eq(getimagescale(1024, 0), "KiB"); ck_assert_str_eq(getimagescale(1030, 0), "KiB"); ck_assert_str_eq(getimagescale(1024000, 0), "MiB"); ck_assert_str_eq(getimagescale(1048576000, 0), "GiB"); ck_assert_str_eq(getimagescale(1073741824000ULL, 0), "TiB"); } END_TEST START_TEST(getimagescale_rate) { cfg.rateunit = 0; ck_assert_str_eq(getimagescale(1, 1), "B/s"); ck_assert_str_eq(getimagescale(2, 1), "B/s"); ck_assert_str_eq(getimagescale(10, 1), "B/s"); ck_assert_str_eq(getimagescale(100, 1), "B/s"); ck_assert_str_eq(getimagescale(1000, 1), "KiB/s"); ck_assert_str_eq(getimagescale(1024, 1), "KiB/s"); ck_assert_str_eq(getimagescale(1030, 1), "KiB/s"); ck_assert_str_eq(getimagescale(1024000, 1), "MiB/s"); ck_assert_str_eq(getimagescale(1048576000, 1), "GiB/s"); ck_assert_str_eq(getimagescale(1073741824000ULL, 1), "TiB/s"); } END_TEST START_TEST(getscale_zero) { ck_assert_int_eq(getscale(0, 0), 1); } END_TEST START_TEST(getscale_nonzero_1024) { cfg.rateunit = 0; cfg.rateunitmode = 0; ck_assert_int_eq(getscale(1, 0), 1); ck_assert_int_eq(getscale(2, 0), 1); ck_assert_int_eq(getscale(10, 0), 2); ck_assert_int_eq(getscale(20, 0), 5); ck_assert_int_eq(getscale(50, 0), 20); ck_assert_int_eq(getscale(1000, 0), 300); ck_assert_int_eq(getscale(1023, 0), 300); ck_assert_int_eq(getscale(1024, 0), 1024); ck_assert_int_eq(getscale(1025, 0), 1024); ck_assert_int_eq(getscale(1026, 0), 1024); ck_assert_int_eq(getscale(1500, 0), 1024); ck_assert_int_eq(getscale(2047, 0), 1024); ck_assert_int_eq(getscale(2048, 0), 1024); ck_assert_int_eq(getscale(2049, 0), 1024); ck_assert_int_eq(getscale(8191, 0), 1024); ck_assert_int_eq(getscale(8192, 0), 2048); ck_assert_int_eq(getscale(8193, 0), 2048); ck_assert_int_eq(getscale(20000, 0), 4096); ck_assert_int_eq(getscale(1, 1), 1); ck_assert_int_eq(getscale(2, 1), 1); ck_assert_int_eq(getscale(10, 1), 2); ck_assert_int_eq(getscale(20, 1), 5); ck_assert_int_eq(getscale(50, 1), 20); ck_assert_int_eq(getscale(1000, 1), 300); ck_assert_int_eq(getscale(1023, 1), 300); ck_assert_int_eq(getscale(1024, 1), 1024); ck_assert_int_eq(getscale(1025, 1), 1024); ck_assert_int_eq(getscale(1026, 1), 1024); ck_assert_int_eq(getscale(1500, 1), 1024); ck_assert_int_eq(getscale(2047, 1), 1024); ck_assert_int_eq(getscale(2048, 1), 1024); ck_assert_int_eq(getscale(2049, 1), 1024); ck_assert_int_eq(getscale(8191, 1), 1024); ck_assert_int_eq(getscale(8192, 1), 2048); ck_assert_int_eq(getscale(8193, 1), 2048); ck_assert_int_eq(getscale(20000, 1), 4096); ck_assert_int_eq(getscale(720000, 1), 204800); } END_TEST START_TEST(getscale_nonzero_1000) { cfg.rateunit = 1; cfg.rateunitmode = 1; ck_assert_int_eq(getscale(1, 0), 1); ck_assert_int_eq(getscale(2, 0), 1); ck_assert_int_eq(getscale(10, 0), 2); ck_assert_int_eq(getscale(20, 0), 5); ck_assert_int_eq(getscale(50, 0), 20); ck_assert_int_eq(getscale(1000, 0), 300); ck_assert_int_eq(getscale(1023, 0), 300); ck_assert_int_eq(getscale(1024, 0), 1024); ck_assert_int_eq(getscale(1025, 0), 1024); ck_assert_int_eq(getscale(1026, 0), 1024); ck_assert_int_eq(getscale(1500, 0), 1024); ck_assert_int_eq(getscale(2047, 0), 1024); ck_assert_int_eq(getscale(2048, 0), 1024); ck_assert_int_eq(getscale(2049, 0), 1024); ck_assert_int_eq(getscale(8191, 0), 1024); ck_assert_int_eq(getscale(8192, 0), 2048); ck_assert_int_eq(getscale(8193, 0), 2048); ck_assert_int_eq(getscale(20000, 0), 4096); ck_assert_int_eq(getscale(1, 1), 1); ck_assert_int_eq(getscale(2, 1), 1); ck_assert_int_eq(getscale(10, 1), 2); ck_assert_int_eq(getscale(20, 1), 5); ck_assert_int_eq(getscale(50, 1), 20); ck_assert_int_eq(getscale(1000, 1), 1000); ck_assert_int_eq(getscale(1023, 1), 1000); ck_assert_int_eq(getscale(1024, 1), 1000); ck_assert_int_eq(getscale(1025, 1), 1000); ck_assert_int_eq(getscale(1026, 1), 1000); ck_assert_int_eq(getscale(1500, 1), 1000); ck_assert_int_eq(getscale(2047, 1), 1000); ck_assert_int_eq(getscale(2048, 1), 1000); ck_assert_int_eq(getscale(2049, 1), 1000); ck_assert_int_eq(getscale(8191, 1), 2000); ck_assert_int_eq(getscale(8192, 1), 2000); ck_assert_int_eq(getscale(8193, 1), 2000); ck_assert_int_eq(getscale(20000, 1), 5000); } END_TEST /* this function needs to match the logic used in image.c drawhours() */ /* in order to test the right thing */ char *hourly_imagescale_logic(const uint64_t max, const int rate) { // int i, prev = 0; int step = 0, s, extray = 0; uint64_t scaleunit; scaleunit = getscale(max, rate); s = (int)lrint(((double)scaleunit / (double)max) * (124 + extray)); if (s == 0) { s = 1; } while (s * step < SCALEMINPIXELS) { step++; } /* for (i = step; i * s <= (124 + extray + 4); i = i + step) { prev = i * s; } */ /* debug for times when things don't appear to make sense */ /*printf("\nrate: %d\n", rate); printf("lines: %d\n", i-1); printf("max: %"PRIu64"\n", max); printf("scaleunit: %"PRIu64"\n", scaleunit); printf("old 2.0: %"PRIu64" (i: %d, step: %d)\n", scaleunit * (i - step), i, step); printf("old 2.6: %"PRIu64" (i: %d, step: %d)\n", scaleunit * i, i, step); printf("now: %"PRIu64" (i: %d, step: %d)\n", scaleunit * step, i, step); fflush(stdout);*/ return getimagescale(scaleunit * (unsigned int)step, rate); } START_TEST(hourly_imagescaling_normal) { char *unittext; cfg.unitmode = 0; cfg.rateunit = 1; cfg.rateunitmode = 1; unittext = hourly_imagescale_logic(1, 0); ck_assert_str_eq(unittext, "B"); unittext = hourly_imagescale_logic(100, 0); ck_assert_str_eq(unittext, "B"); unittext = hourly_imagescale_logic(981, 0); ck_assert_str_eq(unittext, "B"); unittext = hourly_imagescale_logic(1000, 0); ck_assert_str_eq(unittext, "B"); unittext = hourly_imagescale_logic(1024, 0); ck_assert_str_eq(unittext, "KiB"); unittext = hourly_imagescale_logic(2000, 0); ck_assert_str_eq(unittext, "KiB"); unittext = hourly_imagescale_logic(1000000, 0); ck_assert_str_eq(unittext, "KiB"); unittext = hourly_imagescale_logic(1024000, 0); ck_assert_str_eq(unittext, "KiB"); unittext = hourly_imagescale_logic(1300000, 0); ck_assert_str_eq(unittext, "MiB"); unittext = hourly_imagescale_logic(2000000, 0); ck_assert_str_eq(unittext, "MiB"); unittext = hourly_imagescale_logic(1000000000, 0); ck_assert_str_eq(unittext, "MiB"); unittext = hourly_imagescale_logic(2000000000, 0); ck_assert_str_eq(unittext, "GiB"); unittext = hourly_imagescale_logic(2000000000000ULL, 0); ck_assert_str_eq(unittext, "TiB"); } END_TEST START_TEST(hourly_imagescaling_rate_1024) { char *unittext; cfg.unitmode = 0; cfg.rateunit = 0; cfg.rateunitmode = 0; unittext = hourly_imagescale_logic(1, 1); ck_assert_str_eq(unittext, "B/s"); unittext = hourly_imagescale_logic(100, 1); ck_assert_str_eq(unittext, "B/s"); unittext = hourly_imagescale_logic(981, 1); ck_assert_str_eq(unittext, "B/s"); unittext = hourly_imagescale_logic(1000, 1); ck_assert_str_eq(unittext, "B/s"); unittext = hourly_imagescale_logic(1024, 1); ck_assert_str_eq(unittext, "KiB/s"); unittext = hourly_imagescale_logic(2000, 1); ck_assert_str_eq(unittext, "KiB/s"); unittext = hourly_imagescale_logic(1000000, 1); ck_assert_str_eq(unittext, "KiB/s"); unittext = hourly_imagescale_logic(1024000, 1); ck_assert_str_eq(unittext, "KiB/s"); unittext = hourly_imagescale_logic(1300000, 1); ck_assert_str_eq(unittext, "MiB/s"); unittext = hourly_imagescale_logic(2000000, 1); ck_assert_str_eq(unittext, "MiB/s"); unittext = hourly_imagescale_logic(1000000000, 1); ck_assert_str_eq(unittext, "MiB/s"); unittext = hourly_imagescale_logic(2000000000, 1); ck_assert_str_eq(unittext, "GiB/s"); unittext = hourly_imagescale_logic(2000000000000ULL, 1); ck_assert_str_eq(unittext, "TiB/s"); } END_TEST START_TEST(hourly_imagescaling_rate_1000) { char *unittext; cfg.unitmode = 0; cfg.rateunit = 1; cfg.rateunitmode = 1; unittext = hourly_imagescale_logic(1, 1); ck_assert_str_eq(unittext, "bit/s"); unittext = hourly_imagescale_logic(100, 1); ck_assert_str_eq(unittext, "bit/s"); unittext = hourly_imagescale_logic(981, 1); ck_assert_str_eq(unittext, "bit/s"); unittext = hourly_imagescale_logic(1000, 1); ck_assert_str_eq(unittext, "kbit/s"); unittext = hourly_imagescale_logic(1024, 1); ck_assert_str_eq(unittext, "kbit/s"); unittext = hourly_imagescale_logic(2000, 1); ck_assert_str_eq(unittext, "kbit/s"); unittext = hourly_imagescale_logic(1000000, 1); ck_assert_str_eq(unittext, "Mbit/s"); unittext = hourly_imagescale_logic(1024000, 1); ck_assert_str_eq(unittext, "Mbit/s"); unittext = hourly_imagescale_logic(1300000, 1); ck_assert_str_eq(unittext, "Mbit/s"); unittext = hourly_imagescale_logic(2000000, 1); ck_assert_str_eq(unittext, "Mbit/s"); unittext = hourly_imagescale_logic(1000000000, 1); ck_assert_str_eq(unittext, "Gbit/s"); unittext = hourly_imagescale_logic(2000000000, 1); ck_assert_str_eq(unittext, "Gbit/s"); unittext = hourly_imagescale_logic(2000000000000ULL, 1); ck_assert_str_eq(unittext, "Tbit/s"); } END_TEST START_TEST(libgd_output_comparison) { int ret, x, y; IMAGECONTENT ic; FILE *pngout; x = 1060; y = 420; initimagecontent(&ic); imageinit(&ic, x, y); ic.interface.updated = (time_t)get_timestamp(2001, 2, 3, 4, 5); layoutinit(&ic, "vnstati libgd output comparison", x, y); pngout = fopen("vnstati_libgd_comparison_check.png", "w"); ck_assert_ptr_ne(pngout, NULL); drawlegend(&ic, 40, 30, 0); drawlegend(&ic, 240, 30, 1); /* line 1 */ x = 40; y = 80; gdImageStringUp(ic.im, gdFontGetSmall(), 1, y + 105, (unsigned char *)"libgd bug workaround", ic.ctext); drawdonut_libgd_bug_workaround(&ic, x, y, (float)0, (float)0, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)50, (float)50, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"0/0 - 50/50", ic.ctext); x += 130; drawdonut_libgd_bug_workaround(&ic, x, y, (float)100, (float)0, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)0, (float)100, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"100/0 - 0/100", ic.ctext); x += 130; drawdonut_libgd_bug_workaround(&ic, x, y, (float)60, (float)40, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)40, (float)60, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"60/40 - 40/60", ic.ctext); x += 130; drawdonut_libgd_bug_workaround(&ic, x, y, (float)75, (float)25, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)25, (float)75, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"75/25 - 25/75", ic.ctext); x += 130; drawdonut_libgd_bug_workaround(&ic, x, y, (float)90, (float)10, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)10, (float)90, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"90/10 - 10/90", ic.ctext); x += 130; drawdonut_libgd_bug_workaround(&ic, x, y, (float)95, (float)5, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)5, (float)95, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"95/5 - 5/95", ic.ctext); x += 130; drawdonut_libgd_bug_workaround(&ic, x, y, (float)99, (float)1, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)1, (float)99, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"99/1 - 1/99", ic.ctext); x += 130; drawdonut_libgd_bug_workaround(&ic, x, y, (float)99.9, (float)0.1, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)0.1, (float)99.9, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"99.9/0.1 - 0.1/99.9", ic.ctext); /* line 2 */ x = 40; y = 160; drawdonut_libgd_bug_workaround(&ic, x, y, (float)0, (float)0, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)25, (float)25, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"0/0 - 25/25", ic.ctext); x += 130; drawdonut_libgd_bug_workaround(&ic, x, y, (float)50, (float)0, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)0, (float)50, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"50/0 - 0/50", ic.ctext); x += 130; drawdonut_libgd_bug_workaround(&ic, x, y, (float)40, (float)30, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)30, (float)40, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"40/30 - 30/40", ic.ctext); x += 130; drawdonut_libgd_bug_workaround(&ic, x, y, (float)30, (float)20, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)20, (float)30, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"30/20 - 20/30", ic.ctext); x += 130; drawdonut_libgd_bug_workaround(&ic, x, y, (float)20, (float)10, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)10, (float)20, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"20/10 - 10/20", ic.ctext); x += 130; drawdonut_libgd_bug_workaround(&ic, x, y, (float)15, (float)5, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)5, (float)15, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"15/5 - 5/15", ic.ctext); x += 130; drawdonut_libgd_bug_workaround(&ic, x, y, (float)10, (float)1, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)1, (float)10, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"10/1 - 1/10", ic.ctext); x += 130; drawdonut_libgd_bug_workaround(&ic, x, y, (float)1, (float)0.1, 49, 15); drawdonut_libgd_bug_workaround(&ic, x + 55, y, (float)0.1, (float)1, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"1.0/0.1 - 0.1/1.0", ic.ctext); /* line 3 */ x = 40; y = 270; gdImageStringUp(ic.im, gdFontGetSmall(), 1, y + 105, (unsigned char *)"libgd native", ic.ctext); drawdonut_libgd_native(&ic, x, y, (float)0, (float)0, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)50, (float)50, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"0/0 - 50/50", ic.ctext); x += 130; drawdonut_libgd_native(&ic, x, y, (float)100, (float)0, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)0, (float)100, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"100/0 - 0/100", ic.ctext); x += 130; drawdonut_libgd_native(&ic, x, y, (float)60, (float)40, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)40, (float)60, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"60/40 - 40/60", ic.ctext); x += 130; drawdonut_libgd_native(&ic, x, y, (float)75, (float)25, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)25, (float)75, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"75/25 - 25/75", ic.ctext); x += 130; drawdonut_libgd_native(&ic, x, y, (float)90, (float)10, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)10, (float)90, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"90/10 - 10/90", ic.ctext); x += 130; drawdonut_libgd_native(&ic, x, y, (float)95, (float)5, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)5, (float)95, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"95/5 - 5/95", ic.ctext); x += 130; drawdonut_libgd_native(&ic, x, y, (float)99, (float)1, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)1, (float)99, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"99/1 - 1/99", ic.ctext); x += 130; drawdonut_libgd_native(&ic, x, y, (float)99.9, (float)0.1, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)0.1, (float)99.9, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"99.9/0.1 - 0.1/99.9", ic.ctext); /* line 4 */ x = 40; y = 350; drawdonut_libgd_native(&ic, x, y, (float)0, (float)0, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)25, (float)25, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"0/0 - 25/25", ic.ctext); x += 130; drawdonut_libgd_native(&ic, x, y, (float)50, (float)0, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)0, (float)50, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"50/0 - 0/50", ic.ctext); x += 130; drawdonut_libgd_native(&ic, x, y, (float)40, (float)30, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)30, (float)40, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"40/30 - 30/40", ic.ctext); x += 130; drawdonut_libgd_native(&ic, x, y, (float)30, (float)20, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)20, (float)30, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"30/20 - 20/30", ic.ctext); x += 130; drawdonut_libgd_native(&ic, x, y, (float)20, (float)10, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)10, (float)20, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"20/10 - 10/20", ic.ctext); x += 130; drawdonut_libgd_native(&ic, x, y, (float)15, (float)5, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)5, (float)15, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"15/5 - 5/15", ic.ctext); x += 130; drawdonut_libgd_native(&ic, x, y, (float)10, (float)1, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)1, (float)10, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"10/1 - 1/10", ic.ctext); x += 130; drawdonut_libgd_native(&ic, x, y, (float)1, (float)0.1, 49, 15); drawdonut_libgd_native(&ic, x + 55, y, (float)0.1, (float)1, 49, 15); gdImageString(ic.im, gdFontGetSmall(), x - 20, y + 30, (unsigned char *)"1.0/0.1 - 0.1/1.0", ic.ctext); gdImagePng(ic.im, pngout); ret = fclose(pngout); ck_assert_int_eq(ret, 0); gdImageDestroy(ic.im); } END_TEST START_TEST(element_output_check) { int ret, x, y, i; float f; char buffer[6]; IMAGECONTENT ic; FILE *pngout; x = 1500; y = 900; initimagecontent(&ic); imageinit(&ic, x, y); ic.interface.updated = (time_t)get_timestamp(2012, 3, 4, 5, 6); layoutinit(&ic, "donut with 0.2% input steps and other elements", x, y); pngout = fopen("vnstati_element_check.png", "w"); ck_assert_ptr_ne(pngout, NULL); x = 40; y = 70; gdImageStringUp(ic.im, gdFontGetSmall(), 1, y + 15, (unsigned char *)"50.0%", ic.ctext); for (f = 50.0; f >= 0; f -= (float)0.2) { drawdonut(&ic, x, y, f, f, 49, 15); x += 55; if (x > 1000) { x = 40; y += 60; snprintf(buffer, 6, "%3.1f%%", (double)f - 0.2); gdImageStringUp(ic.im, gdFontGetSmall(), 1, y + 15, (unsigned char *)buffer, ic.ctext); } } gdImageString(ic.im, gdFontGetGiant(), 1020, 40, (unsigned char *)"Giant - The quick brown fox jumps over the lazy dog", ic.ctext); gdImageString(ic.im, gdFontGetLarge(), 1020, 60, (unsigned char *)"Large - The quick brown fox jumps over the lazy dog", ic.ctext); gdImageString(ic.im, gdFontGetMediumBold(), 1020, 80, (unsigned char *)"MediumBold - The quick brown fox jumps over the lazy dog", ic.ctext); gdImageString(ic.im, gdFontGetSmall(), 1020, 100, (unsigned char *)"Small - The quick brown fox jumps over the lazy dog", ic.ctext); gdImageString(ic.im, gdFontGetTiny(), 1020, 120, (unsigned char *)"Tiny - The quick brown fox jumps over the lazy dog", ic.ctext); drawlegend(&ic, 1130, 140, 0); drawlegend(&ic, 1330, 140, 1); drawbar(&ic, 1050, 160, 100, 50, 50, 100, 0); drawbar(&ic, 1050, 180, 100, 25, 75, 100, 0); drawbar(&ic, 1050, 200, 100, 75, 25, 100, 0); drawbar(&ic, 1050, 220, 100, 0, 100, 100, 0); drawbar(&ic, 1050, 240, 100, 100, 0, 100, 0); drawbar(&ic, 1050, 260, 100, 1, 99, 100, 0); drawbar(&ic, 1050, 280, 100, 2, 98, 100, 0); drawbar(&ic, 1050, 300, 100, 99, 1, 100, 0); drawbar(&ic, 1050, 320, 100, 98, 2, 100, 0); drawbar(&ic, 1200, 160, 100, 1, 0, 100, 0); drawbar(&ic, 1200, 180, 100, 2, 0, 100, 0); drawbar(&ic, 1200, 200, 100, 3, 0, 100, 0); drawbar(&ic, 1200, 220, 100, 0, 1, 100, 0); drawbar(&ic, 1200, 240, 100, 0, 2, 100, 0); drawbar(&ic, 1200, 260, 100, 0, 3, 100, 0); drawbar(&ic, 1200, 280, 100, 25, 25, 100, 0); drawbar(&ic, 1200, 300, 100, 10, 30, 100, 0); drawbar(&ic, 1200, 320, 100, 30, 10, 100, 0); gdImageLine(ic.im, 1040, 360, 1260, 360, ic.ctext); gdImageLine(ic.im, 1040, 760, 1260, 760, ic.ctext); gdImageLine(ic.im, 1250, 350, 1250, 770, ic.ctext); drawarrowup(&ic, 1250, 350); drawarrowright(&ic, 1260, 360); drawpoles(&ic, 1050, 360, 400, 50, 50, 100); drawpoles(&ic, 1070, 360, 400, 25, 75, 100); drawpoles(&ic, 1090, 360, 400, 75, 25, 100); drawpoles(&ic, 1110, 360, 400, 0, 100, 100); drawpoles(&ic, 1130, 360, 400, 100, 0, 100); drawpoles(&ic, 1150, 360, 400, 50, 50, 130); drawpoles(&ic, 1170, 360, 400, 25, 75, 130); drawpoles(&ic, 1190, 360, 400, 75, 25, 130); drawpoles(&ic, 1210, 360, 400, 0, 100, 130); drawpoles(&ic, 1230, 360, 400, 100, 0, 130); gdImageLine(ic.im, 1040, 870, 1160, 870, ic.ctext); gdImageLine(ic.im, 1040, 820, 1160, 820, ic.ctext); gdImageLine(ic.im, 1040, 770, 1160, 770, ic.ctext); for (i = 0; i < 100; i++) { drawpole(&ic, 1050 + i, 819, i % 50, 1, ic.crx); drawpole(&ic, 1050 + i, 821, i % 50, 2, ic.ctx); } gdImageString(ic.im, gdFontGetMediumBold(), 1280, 400, (unsigned char *)"Color: ctext", ic.ctext); gdImageString(ic.im, gdFontGetMediumBold(), 1280, 420, (unsigned char *)"Color: cedge", ic.cedge); gdImageString(ic.im, gdFontGetMediumBold(), 1280, 440, (unsigned char *)"Color: cheader", ic.cheader); gdImageString(ic.im, gdFontGetMediumBold(), 1280, 460, (unsigned char *)"Color: cheadertitle", ic.cheadertitle); gdImageString(ic.im, gdFontGetMediumBold(), 1280, 480, (unsigned char *)"Color: cheaderdate", ic.cheaderdate); gdImageString(ic.im, gdFontGetMediumBold(), 1280, 500, (unsigned char *)"Color: cline", ic.cline); gdImageString(ic.im, gdFontGetMediumBold(), 1280, 520, (unsigned char *)"Color: clinel", ic.clinel); gdImageString(ic.im, gdFontGetMediumBold(), 1280, 540, (unsigned char *)"Color: cbackground", ic.cbackground); gdImageString(ic.im, gdFontGetMediumBold(), 1280, 560, (unsigned char *)"Color: cvnstat", ic.cvnstat); gdImageString(ic.im, gdFontGetMediumBold(), 1280, 580, (unsigned char *)"Color: cbgoffset", ic.cbgoffset); gdImageString(ic.im, gdFontGetMediumBold(), 1280, 600, (unsigned char *)"Color: crx", ic.crx); gdImageString(ic.im, gdFontGetMediumBold(), 1280, 620, (unsigned char *)"Color: crxd", ic.crxd); gdImageString(ic.im, gdFontGetMediumBold(), 1280, 640, (unsigned char *)"Color: ctx", ic.ctx); gdImageString(ic.im, gdFontGetMediumBold(), 1280, 660, (unsigned char *)"Color: ctxd", ic.ctxd); gdImagePng(ic.im, pngout); ret = fclose(pngout); ck_assert_int_eq(ret, 0); gdImageDestroy(ic.im); } END_TEST START_TEST(hextorgb_can_convert) { debug = 1; int rgb[3]; suppress_output(); rgb[0] = 1; rgb[1] = 2; rgb[2] = 3; hextorgb("000000", rgb); ck_assert_int_eq(rgb[0], 0); ck_assert_int_eq(rgb[1], 0); ck_assert_int_eq(rgb[2], 0); rgb[0] = 1; rgb[1] = 2; rgb[2] = 3; hextorgb("#000000", rgb); ck_assert_int_eq(rgb[0], 0); ck_assert_int_eq(rgb[1], 0); ck_assert_int_eq(rgb[2], 0); rgb[0] = 1; rgb[1] = 2; rgb[2] = 3; hextorgb("FFFFFF", rgb); ck_assert_int_eq(rgb[0], 255); ck_assert_int_eq(rgb[1], 255); ck_assert_int_eq(rgb[2], 255); rgb[0] = 1; rgb[1] = 2; rgb[2] = 3; hextorgb("#FFFFFF", rgb); ck_assert_int_eq(rgb[0], 255); ck_assert_int_eq(rgb[1], 255); ck_assert_int_eq(rgb[2], 255); rgb[0] = 1; rgb[1] = 2; rgb[2] = 3; hextorgb("ABCABBA", rgb); ck_assert_int_eq(rgb[0], 171); ck_assert_int_eq(rgb[1], 202); ck_assert_int_eq(rgb[2], 187); rgb[0] = 1; rgb[1] = 2; rgb[2] = 3; hextorgb("#ABCABBA", rgb); ck_assert_int_eq(rgb[0], 171); ck_assert_int_eq(rgb[1], 202); ck_assert_int_eq(rgb[2], 187); } END_TEST START_TEST(modcolor_mods_colors) { debug = 1; int rgb[3]; suppress_output(); rgb[0] = 10; rgb[1] = 20; rgb[2] = 30; modcolor(rgb, 10, 0); ck_assert_int_eq(rgb[0], 20); ck_assert_int_eq(rgb[1], 30); ck_assert_int_eq(rgb[2], 40); rgb[0] = 10; rgb[1] = 20; rgb[2] = 30; modcolor(rgb, -10, 0); ck_assert_int_eq(rgb[0], 0); ck_assert_int_eq(rgb[1], 10); ck_assert_int_eq(rgb[2], 20); rgb[0] = 10; rgb[1] = 20; rgb[2] = 30; modcolor(rgb, -20, 0); ck_assert_int_eq(rgb[0], 0); ck_assert_int_eq(rgb[1], 0); ck_assert_int_eq(rgb[2], 10); rgb[0] = 10; rgb[1] = 20; rgb[2] = 30; modcolor(rgb, -30, 0); ck_assert_int_eq(rgb[0], 40); ck_assert_int_eq(rgb[1], 50); ck_assert_int_eq(rgb[2], 60); rgb[0] = 10; rgb[1] = 20; rgb[2] = 30; modcolor(rgb, -30, 1); ck_assert_int_eq(rgb[0], 0); ck_assert_int_eq(rgb[1], 0); ck_assert_int_eq(rgb[2], 0); rgb[0] = 10; rgb[1] = 250; rgb[2] = 30; modcolor(rgb, 30, 0); ck_assert_int_eq(rgb[0], 40); ck_assert_int_eq(rgb[1], 255); ck_assert_int_eq(rgb[2], 60); rgb[0] = 10; rgb[1] = 250; rgb[2] = 30; modcolor(rgb, 30, 1); ck_assert_int_eq(rgb[0], 40); ck_assert_int_eq(rgb[1], 255); ck_assert_int_eq(rgb[2], 60); rgb[0] = 10; rgb[1] = 250; rgb[2] = 251; modcolor(rgb, 30, 0); ck_assert_int_eq(rgb[0], 0); ck_assert_int_eq(rgb[1], 220); ck_assert_int_eq(rgb[2], 221); rgb[0] = 10; rgb[1] = 250; rgb[2] = 251; modcolor(rgb, 30, 1); ck_assert_int_eq(rgb[0], 40); ck_assert_int_eq(rgb[1], 255); ck_assert_int_eq(rgb[2], 255); rgb[0] = 10; rgb[1] = 20; rgb[2] = 251; modcolor(rgb, -30, 0); ck_assert_int_eq(rgb[0], 40); ck_assert_int_eq(rgb[1], 50); ck_assert_int_eq(rgb[2], 255); } END_TEST void add_image_tests(Suite *s) { TCase *tc_image = tcase_create("Image"); tcase_add_checked_fixture(tc_image, setup, teardown); tcase_add_unchecked_fixture(tc_image, setup, teardown); tcase_set_timeout(tc_image, 10); tcase_add_test(tc_image, initimagecontent_does_not_crash); tcase_add_test(tc_image, imageinit_does_not_crash); tcase_add_test(tc_image, layoutinit_does_not_crash); tcase_add_test(tc_image, getimagevalue_zeropadding); tcase_add_test(tc_image, getimagevalue_normal); tcase_add_test(tc_image, getimagevalue_rate_1024); tcase_add_test(tc_image, getimagevalue_rate_1000); tcase_add_test(tc_image, getimagescale_zero); tcase_add_test(tc_image, getimagescale_normal); tcase_add_test(tc_image, getimagescale_rate); tcase_add_test(tc_image, getscale_zero); tcase_add_test(tc_image, getscale_nonzero_1024); tcase_add_test(tc_image, getscale_nonzero_1000); tcase_add_test(tc_image, hourly_imagescaling_normal); tcase_add_test(tc_image, hourly_imagescaling_rate_1024); tcase_add_test(tc_image, hourly_imagescaling_rate_1000); tcase_add_test(tc_image, libgd_output_comparison); tcase_add_test(tc_image, element_output_check); tcase_add_test(tc_image, hextorgb_can_convert); tcase_add_test(tc_image, modcolor_mods_colors); suite_add_tcase(s, tc_image); } vnstat-2.9/tests/vnstat_tests.h0000644000000000000000000000406214164605663015472 0ustar rootroot#ifndef VNSTAT_TESTS_H #define VNSTAT_TESTS_H #include extern int output_suppressed; Suite *test_suite(void); void verify_fork_status(void); void setup(void); void teardown(void); void suppress_output(void); void restore_output(void); int pipe_output(void); void disable_logprints(void); int clean_testdbdir(void); int create_testdir(void); int create_directory(const char *directory); int remove_directory(const char *directory); int create_zerosize_dbfile(const char *iface); int check_dbfile_exists(const char *iface, const int minsize); int fake_proc_net_dev(const char *mode, const char *iface, const int rx, const int tx, const int rxp, const int txp); int fake_sys_class_net(const char *iface, const int rx, const int tx, const int rxp, const int txp, const int speed); uint64_t get_timestamp(const int year, const int month, const int day, const int hour, const int minute); #ifndef TESTDIR #define TESTDIR "testdir" #endif #define TESTDBDIR TESTDIR"/database" #define TESTPROCDIR TESTDIR"/proc" #define TESTSYSCLASSNETDIR TESTDIR"/sysclassnet" #if !defined(CFGFILE) #define CFGFILE "tests/vnstat.conf" #endif #if !defined(__linux__) #define linuxonly return #else #define linuxonly #endif #if !defined(__linux__) #define linuxonly_exit exit(1) #else #define linuxonly_exit #endif /* for compatibility with older check framework versions */ #ifndef ck_assert_int_ge #define ck_assert_int_ge(X, Y) _ck_assert_int(X, >=, Y) #endif #ifndef ck_assert_int_gt #define ck_assert_int_gt(X, Y) _ck_assert_int(X, >, Y) #endif #ifndef ck_assert_int_le #define ck_assert_int_le(X, Y) _ck_assert_int(X, <=, Y) #endif #ifndef ck_assert_int_lt #define ck_assert_int_lt(X, Y) _ck_assert_int(X, <, Y) #endif #ifndef _ck_assert_ptr #define _ck_assert_ptr(X, OP, Y) do { \ void* _ck_x = (X); \ void* _ck_y = (Y); \ ck_assert_msg(_ck_x OP _ck_y, "Assertion '"#X#OP#Y"' failed: "#X"==%p, "#Y"==%p", _ck_x, _ck_y); \ } while (0) #define ck_assert_ptr_eq(X, Y) _ck_assert_ptr(X, ==, Y) #define ck_assert_ptr_ne(X, Y) _ck_assert_ptr(X, !=, Y) #endif #endif vnstat-2.9/tests/id_tests.c0000644000000000000000000000507113510474660014536 0ustar rootroot#include "common.h" #include "vnstat_tests.h" #include "id_tests.h" #include "id.h" START_TEST(getuser_root_string) { ck_assert_int_eq((int)getuser("root"), 0); } END_TEST START_TEST(getuser_root_numeric) { ck_assert_int_eq((int)getuser("0"), 0); } END_TEST START_TEST(getuser_no_such_user_string) { suppress_output(); getuser("reallynosuchuser"); } END_TEST START_TEST(getuser_no_such_user_numeric) { suppress_output(); getuser("99999999"); } END_TEST START_TEST(getgroup_root_string) { #if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__) ck_assert_int_eq((int)getgroup("root"), 0); #else ck_assert_int_eq((int)getgroup("wheel"), 0); #endif } END_TEST START_TEST(getgroup_root_numeric) { ck_assert_int_eq((int)getgroup("0"), 0); } END_TEST START_TEST(getgroup_no_such_user_string) { suppress_output(); getgroup("reallynosuchgroup"); } END_TEST START_TEST(getgroup_no_such_user_numeric) { suppress_output(); getgroup("99999999"); } END_TEST START_TEST(setuser_with_empty_user) { suppress_output(); setuser(""); } END_TEST START_TEST(setuser_with_current_user) { char temp[16]; struct passwd *pw; pw = getpwuid(getuid()); if (pw != NULL) { suppress_output(); snprintf(temp, 16, "%d", getuser("")); setuser(temp); } else { printf("Note: skipping test setuser_with_current_user due to non-existing user\n"); } } END_TEST START_TEST(setgroup_with_empty_group) { suppress_output(); setgroup(""); } END_TEST START_TEST(setgroup_with_current_group) { char temp[16]; struct group *gr; gr = getgrgid(getgid()); if (gr != NULL) { suppress_output(); snprintf(temp, 16, "%d", getgroup("")); setgroup(temp); } else { printf("Note: skipping test setgroup_with_current_group due to non-existing group\n"); } } END_TEST void add_id_tests(Suite *s) { TCase *tc_id = tcase_create("ID"); tcase_add_checked_fixture(tc_id, setup, teardown); tcase_add_unchecked_fixture(tc_id, setup, teardown); tcase_add_test(tc_id, getuser_root_string); tcase_add_test(tc_id, getuser_root_numeric); tcase_add_exit_test(tc_id, getuser_no_such_user_string, 1); tcase_add_exit_test(tc_id, getuser_no_such_user_numeric, 1); tcase_add_test(tc_id, getgroup_root_string); tcase_add_test(tc_id, getgroup_root_numeric); tcase_add_exit_test(tc_id, getgroup_no_such_user_string, 1); tcase_add_exit_test(tc_id, getgroup_no_such_user_numeric, 1); tcase_add_test(tc_id, setuser_with_empty_user); tcase_add_test(tc_id, setuser_with_current_user); tcase_add_test(tc_id, setgroup_with_empty_group); tcase_add_test(tc_id, setgroup_with_current_group); suite_add_tcase(s, tc_id); } vnstat-2.9/tests/dbsql_tests.c0000644000000000000000000022526414163656634015267 0ustar rootroot#include "common.h" #include "vnstat_tests.h" #include "dbsql_tests.h" #include "dbsql.h" #include "misc.h" #include "cfg.h" START_TEST(db_close_does_no_harm_when_db_is_already_closed) { int ret; ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_open_rw_can_create_database_if_file_does_not_exist) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_open_ro_cannot_create_a_database) { int ret; suppress_output(); ret = db_open_ro(); ck_assert_int_eq(ret, 0); } END_TEST START_TEST(db_getinfo_fails_with_no_open_db) { suppress_output(); ck_assert_int_eq(strlen(db_getinfo("foofoo")), 0); } END_TEST START_TEST(db_getinfo_fails_with_nonexisting_name) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_str_eq(db_getinfo("broken_name"), ""); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getinfo_can_get_dbversion) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_str_eq(db_getinfo("dbversion"), SQLDBVERSION); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setinfo_fails_with_no_open_db) { suppress_output(); ck_assert_int_eq(db_setinfo("foo", "bar", 0), 0); ck_assert_int_eq(db_setinfo("foo", "bar", 1), 0); } END_TEST START_TEST(db_setinfo_can_set_infos) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_setinfo("foo", "bar", 1), 1); ck_assert_str_eq(db_getinfo("foo"), "bar"); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setinfo_can_update_infos) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_setinfo("foo", "bar", 1), 1); ck_assert_str_eq(db_getinfo("foo"), "bar"); ck_assert_int_eq(db_setinfo("foo", "qux", 0), 1); ck_assert_str_eq(db_getinfo("foo"), "qux"); ck_assert_int_eq(db_setinfo("foo", "quux", 1), 1); ck_assert_str_eq(db_getinfo("foo"), "quux"); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setinfo_can_not_update_nonexisting_name) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_setinfo("foo", "bar", 1), 1); ck_assert_str_eq(db_getinfo("foo"), "bar"); ck_assert_int_eq(db_setinfo("bar", "qux", 0), 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_addtraffic_with_no_traffic_does_nothing) { suppress_output(); ck_assert_int_eq(db_addtraffic("eth0", 0, 0), 0); } END_TEST START_TEST(db_addtraffic_can_add_traffic_and_interfaces) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_addtraffic("eth0", 0, 0), 1); ck_assert_int_eq(db_addtraffic("eth0", 12, 34), 1); ck_assert_int_eq(db_addtraffic("eth1", 56, 78), 1); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_addtraffic_can_add_traffic_and_interfaces_utc) { int ret; cfg.useutc = 1; validatecfg(CT_Daemon); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_addtraffic("eth0", 0, 0), 1); ck_assert_int_eq(db_addtraffic("eth0", 12, 34), 1); ck_assert_int_eq(db_addtraffic("eth1", 56, 78), 1); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_addtraffic_dated_does_not_touch_updated_time) { int ret; interfaceinfo info; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addtraffic("eth0", 1, 1); ck_assert_int_eq(ret, 1); ret = db_getinterfaceinfo("eth0", &info); ck_assert_int_eq(ret, 1); ck_assert_int_eq(info.rxtotal, 1); ck_assert_int_eq(info.txtotal, 1); ck_assert_int_gt(info.updated, 1000); ck_assert_int_lt(info.updated, 2100000000); ret = db_addtraffic_dated("eth0", 1, 1, 1000); ck_assert_int_eq(ret, 1); ret = db_getinterfaceinfo("eth0", &info); ck_assert_int_eq(ret, 1); ck_assert_int_eq(info.rxtotal, 2); ck_assert_int_eq(info.txtotal, 2); ck_assert_int_gt(info.updated, 1000); ck_assert_int_lt(info.updated, 2100000000); ret = db_addtraffic_dated("eth0", 1, 1, 2100000000); ck_assert_int_eq(ret, 1); ret = db_getinterfaceinfo("eth0", &info); ck_assert_int_eq(ret, 1); ck_assert_int_eq(info.rxtotal, 3); ck_assert_int_eq(info.txtotal, 3); ck_assert_int_lt(info.updated, 2100000000); ret = db_addtraffic_dated("eth0", 1, 1, 1000); ck_assert_int_eq(ret, 1); ret = db_getinterfaceinfo("eth0", &info); ck_assert_int_eq(ret, 1); ck_assert_int_eq(info.rxtotal, 4); ck_assert_int_eq(info.txtotal, 4); ck_assert_int_lt(info.updated, 2100000000); ret = db_addtraffic("eth0", 1, 1); ck_assert_int_eq(ret, 1); ret = db_getinterfaceinfo("eth0", &info); ck_assert_int_eq(ret, 1); ck_assert_int_eq(info.rxtotal, 5); ck_assert_int_eq(info.txtotal, 5); ck_assert_int_gt(info.updated, 1000); ck_assert_int_lt(info.updated, 2100000000); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setactive_fails_with_no_open_db) { suppress_output(); ck_assert_int_eq(db_setactive("eth0", 0), 0); ck_assert_int_eq(db_setactive("eth0", 1), 0); } END_TEST START_TEST(db_setactive_fails_if_interface_does_not_exist_in_database) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_setactive("eth0", 0), 0); ck_assert_int_eq(db_setactive("eth0", 1), 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setactive_can_change_interface_activity_status) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_addtraffic("eth0", 0, 0), 1); ck_assert_int_eq(db_setactive("eth0", 0), 1); ck_assert_int_eq(db_setactive("eth0", 1), 1); ck_assert_int_eq(db_addtraffic("eth0", 12, 34), 1); ck_assert_int_eq(db_setactive("eth0", 0), 1); ck_assert_int_eq(db_setactive("eth0", 1), 1); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setalias_fails_with_no_open_db) { suppress_output(); ck_assert_int_eq(db_setalias("eth0", "The Internet"), 0); } END_TEST START_TEST(db_setalias_fails_if_interface_does_not_exist_in_database) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_setalias("eth0", "The Internet"), 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setalias_can_change_interface_alias) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_addtraffic("eth0", 0, 0), 1); ck_assert_int_eq(db_setalias("eth0", "The Internet"), 1); ck_assert_int_eq(db_addtraffic("eth0", 12, 34), 1); ck_assert_int_eq(db_setalias("eth0", "The Internet"), 1); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setupdated_fails_with_no_open_db) { suppress_output(); ck_assert_int_eq(db_setupdated("eth0", 123456), 0); } END_TEST START_TEST(db_setupdated_fails_if_interface_does_not_exist_in_database) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_setupdated("eth0", 123456), 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setupdated_can_change_updated) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_addtraffic("eth0", 12, 34), 1); ck_assert_int_eq(db_setupdated("eth0", 123456), 1); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_addinterface_fails_with_no_open_db) { int ret; suppress_output(); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 0); } END_TEST START_TEST(db_addinterface_can_add_interfaces) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_addinterface_can_not_add_same_interface_twice) { int ret; suppress_output(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 0); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_removeinterface_knows_if_interface_exists) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_removeinterface("eth0"); ck_assert_int_eq(ret, 0); ret = db_removeinterface("nothing"); ck_assert_int_eq(ret, 0); ret = db_removeinterface(""); ck_assert_int_eq(ret, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_removeinterface_can_remove_interfaces) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth2"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_getinterfacecount(), 3); ck_assert_int_eq(db_getinterfacecountbyname("eth0"), 1); ck_assert_int_eq(db_getinterfacecountbyname("eth1"), 1); ck_assert_int_eq(db_getinterfacecountbyname("eth2"), 1); ck_assert_int_eq(db_getinterfacecountbyname("eth3"), 0); ret = db_removeinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_removeinterface("nothing"); ck_assert_int_eq(ret, 0); ret = db_removeinterface(""); ck_assert_int_eq(ret, 0); ck_assert_int_eq(db_getinterfacecount(), 2); ck_assert_int_eq(db_getinterfacecountbyname("eth0"), 1); ck_assert_int_eq(db_getinterfacecountbyname("eth1"), 0); ck_assert_int_eq(db_getinterfacecountbyname("eth2"), 1); ck_assert_int_eq(db_getinterfacecountbyname("eth3"), 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_renameinterface_knows_if_interface_exists) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_renameinterface("eth0", "eth1"); ck_assert_int_eq(ret, 0); ret = db_renameinterface("nothing", "something"); ck_assert_int_eq(ret, 0); ret = db_renameinterface("", ""); ck_assert_int_eq(ret, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_renameinterface_can_rename_interfaces) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth2"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_getinterfacecount(), 3); ck_assert_int_eq(db_getinterfacecountbyname("eth0"), 1); ck_assert_int_eq(db_getinterfacecountbyname("eth1"), 1); ck_assert_int_eq(db_getinterfacecountbyname("eth2"), 1); ck_assert_int_eq(db_getinterfacecountbyname("eth3"), 0); suppress_output(); ret = db_renameinterface("eth0", "eth1"); ck_assert_int_eq(ret, 0); ret = db_renameinterface("eth2", "eth3"); ck_assert_int_eq(ret, 1); ret = db_renameinterface("eth1", "eth2"); ck_assert_int_eq(ret, 1); ret = db_renameinterface("eth0", ""); ck_assert_int_eq(ret, 0); ret = db_renameinterface("eth0", "eth1"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_getinterfacecount(), 3); ck_assert_int_eq(db_getinterfacecountbyname("eth0"), 0); ck_assert_int_eq(db_getinterfacecountbyname("eth1"), 1); ck_assert_int_eq(db_getinterfacecountbyname("eth2"), 1); ck_assert_int_eq(db_getinterfacecountbyname("eth3"), 1); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getinterfacecount_counts_interfaces) { int ret; suppress_output(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecount(); ck_assert_int_eq(ret, 0); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecount(); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 0); ret = (int)db_getinterfacecount(); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecount(); ck_assert_int_eq(ret, 2); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getinterfacecountbyname_counts_interfaces) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth3"); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecountbyname("foo"); ck_assert_int_eq(ret, 0); ret = (int)db_getinterfacecountbyname("eth0"); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecountbyname("eth1"); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecountbyname("eth2"); ck_assert_int_eq(ret, 0); ret = (int)db_getinterfacecountbyname(""); ck_assert_int_eq(ret, 3); ret = (int)db_getinterfacecountbyname("eth0+eth1"); ck_assert_int_eq(ret, 2); ret = (int)db_getinterfacecountbyname("eth0+eth1+eth3"); ck_assert_int_eq(ret, 3); ret = (int)db_getinterfacecountbyname("eth0+eth1+eth2"); ck_assert_int_eq(ret, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getcounters_with_no_interface) { int ret; uint64_t rx, tx; rx = tx = 1; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_getcounters("eth0", &rx, &tx); ck_assert_int_eq(ret, 0); ck_assert_int_eq(rx, 0); ck_assert_int_eq(tx, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setcounters_with_no_interface) { int ret; uint64_t rx, tx; rx = tx = 1; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_setcounters("eth0", 2, 2); ck_assert_int_eq(ret, 0); ret = db_getcounters("eth0", &rx, &tx); ck_assert_int_eq(ret, 0); ck_assert_int_eq(rx, 0); ck_assert_int_eq(tx, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_interface_info_manipulation) { int ret; uint64_t rx, tx, c; interfaceinfo info; rx = tx = 1; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_getcounters("eth0", &rx, &tx); ck_assert_int_eq(ret, 1); ck_assert_int_eq(rx, 0); ck_assert_int_eq(tx, 0); ret = db_setcounters("eth0", 2, 2); ck_assert_int_eq(ret, 1); ret = db_getcounters("eth0", &rx, &tx); ck_assert_int_eq(ret, 1); ck_assert_int_eq(rx, 2); ck_assert_int_eq(tx, 2); ret = db_settotal("eth1", 42, 24); ck_assert_int_eq(ret, 1); c = (uint64_t)time(NULL) - 100; ret = db_setcreation("eth1", (time_t)c); ret = db_getinterfaceinfo("eth0", &info); ck_assert_int_eq(ret, 1); ck_assert_int_eq(info.active, 1); ck_assert_int_eq(info.rxcounter, 2); ck_assert_int_eq(info.txcounter, 2); ck_assert_int_eq(info.rxtotal, 0); ck_assert_int_eq(info.txtotal, 0); ck_assert_int_ne(info.created, 0); ck_assert_int_eq(db_setactive("eth1", 0), 1); ck_assert_int_eq(db_setupdated("eth1", 0), 1); ret = db_getinterfaceinfo("eth1", &info); ck_assert_int_eq(ret, 1); ck_assert_int_eq(info.active, 0); ck_assert_int_eq(info.rxcounter, 0); ck_assert_int_eq(info.txcounter, 0); ck_assert_int_eq(info.rxtotal, 42); ck_assert_int_eq(info.txtotal, 24); ck_assert_int_eq((uint64_t)info.created, c); ck_assert_int_eq((uint64_t)info.updated, 0); ck_assert_int_eq(db_setupdated("eth1", 123456), 1); ret = db_getinterfaceinfo("eth1", &info); ck_assert_int_eq(ret, 1); ck_assert_int_eq(info.active, 0); ck_assert_int_eq(info.rxcounter, 0); ck_assert_int_eq(info.txcounter, 0); ck_assert_int_eq(info.rxtotal, 42); ck_assert_int_eq(info.txtotal, 24); ck_assert_int_eq((uint64_t)info.created, c); ck_assert_int_eq((uint64_t)info.updated, 123456); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getiflist_lists_interfaces) { int ret; iflist *dbifl = NULL, *dbifl_i = NULL; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("a"); ck_assert_int_eq(ret, 1); ret = db_addinterface("b"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_getiflist(&dbifl); ck_assert_int_eq(ret, 4); dbifl_i = dbifl; ret = db_close(); ck_assert_int_eq(ret, 1); ck_assert_str_eq(dbifl_i->interface, "a"); ck_assert_ptr_ne(dbifl_i->next, NULL); dbifl_i = dbifl_i->next; ck_assert_str_eq(dbifl_i->interface, "b"); ck_assert_ptr_ne(dbifl_i->next, NULL); dbifl_i = dbifl_i->next; ck_assert_str_eq(dbifl_i->interface, "eth0"); ck_assert_ptr_ne(dbifl_i->next, NULL); dbifl_i = dbifl_i->next; ck_assert_str_eq(dbifl_i->interface, "eth1"); ck_assert_ptr_eq(dbifl_i->next, NULL); iflistfree(&dbifl); ck_assert_ptr_eq(dbifl, NULL); } END_TEST START_TEST(db_maintenance_does_not_fault) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_vacuum(); ck_assert_int_eq(ret, 1); ret = db_removeoldentries(); ck_assert_int_eq(ret, 1); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_data_can_be_inserted) { int ret; interfaceinfo info; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_insertdata("foo", "eth0", 1, 2, 3); ck_assert_int_eq(ret, 0); ret = db_insertdata("hour", "eth1", 1, 2, 3); ck_assert_int_eq(ret, 0); ret = db_insertdata("hour", "eth0", 1, 2, 3); ck_assert_int_eq(ret, 1); ret = db_insertdata("day", "eth0", 1, 2, 3); ck_assert_int_eq(ret, 1); ret = db_insertdata("month", "eth0", 1, 2, 3); ck_assert_int_eq(ret, 1); ret = db_insertdata("year", "eth0", 1, 2, 3); ck_assert_int_eq(ret, 1); ret = db_insertdata("top", "eth0", 1, 2, 3); ck_assert_int_eq(ret, 1); /* verify that totals don't get changed */ ret = db_getinterfaceinfo("eth0", &info); ck_assert_int_eq(ret, 1); ck_assert_int_eq(info.active, 1); ck_assert_int_eq(info.rxcounter, 0); ck_assert_int_eq(info.txcounter, 0); ck_assert_int_eq(info.rxtotal, 0); ck_assert_int_eq(info.txtotal, 0); ck_assert_int_ne(info.created, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_data_can_be_retrieved) { int ret; dbdatalist *datalist = NULL, *datalist_iterator = NULL; dbdatalistinfo datainfo; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_insertdata("hour", "eth0", 1, 2, 3); ck_assert_int_eq(ret, 1); ret = db_insertdata("hour", "eth0", 10, 20, 10000); ck_assert_int_eq(ret, 1); ret = db_getdata(&datalist, &datainfo, "eth0", "hour", 2); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 2); ck_assert_int_eq(datainfo.minrx, 1); ck_assert_int_eq(datainfo.maxrx, 10); ck_assert_int_eq(datainfo.sumrx, 11); ck_assert_int_eq(datainfo.mintx, 2); ck_assert_int_eq(datainfo.maxtx, 20); ck_assert_int_eq(datainfo.sumtx, 22); /* db_insertdata rounds the timestamps to full hours */ ck_assert_int_eq((int)datainfo.maxtime, 7200); ck_assert_int_eq((int)datainfo.mintime, 0); datalist_iterator = datalist; ck_assert_int_eq(datalist_iterator->rx, 1); ck_assert_int_eq(datalist_iterator->tx, 2); ck_assert_int_eq(datalist_iterator->timestamp, 0); datalist_iterator = datalist_iterator->next; ck_assert_int_eq(datalist_iterator->rx, 10); ck_assert_int_eq(datalist_iterator->tx, 20); ck_assert_int_eq(datalist_iterator->timestamp, 7200); dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_data_can_be_inserted_utc) { int ret; interfaceinfo info; cfg.useutc = 1; validatecfg(CT_Daemon); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_insertdata("foo", "eth0", 1, 2, 3); ck_assert_int_eq(ret, 0); ret = db_insertdata("hour", "eth1", 1, 2, 3); ck_assert_int_eq(ret, 0); ret = db_insertdata("hour", "eth0", 1, 2, 3); ck_assert_int_eq(ret, 1); ret = db_insertdata("day", "eth0", 1, 2, 3); ck_assert_int_eq(ret, 1); ret = db_insertdata("month", "eth0", 1, 2, 3); ck_assert_int_eq(ret, 1); ret = db_insertdata("year", "eth0", 1, 2, 3); ck_assert_int_eq(ret, 1); ret = db_insertdata("top", "eth0", 1, 2, 3); ck_assert_int_eq(ret, 1); /* verify that totals don't get changed */ ret = db_getinterfaceinfo("eth0", &info); ck_assert_int_eq(ret, 1); ck_assert_int_eq(info.active, 1); ck_assert_int_eq(info.rxcounter, 0); ck_assert_int_eq(info.txcounter, 0); ck_assert_int_eq(info.rxtotal, 0); ck_assert_int_eq(info.txtotal, 0); ck_assert_int_ne(info.created, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_data_can_be_retrieved_utc) { int ret; dbdatalist *datalist = NULL, *datalist_iterator = NULL; dbdatalistinfo datainfo; cfg.useutc = 1; validatecfg(CT_Daemon); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_insertdata("hour", "eth0", 1, 2, 3); ck_assert_int_eq(ret, 1); ret = db_insertdata("hour", "eth0", 10, 20, 10000); ck_assert_int_eq(ret, 1); ret = db_getdata(&datalist, &datainfo, "eth0", "hour", 2); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 2); ck_assert_int_eq(datainfo.minrx, 1); ck_assert_int_eq(datainfo.maxrx, 10); ck_assert_int_eq(datainfo.sumrx, 11); ck_assert_int_eq(datainfo.mintx, 2); ck_assert_int_eq(datainfo.maxtx, 20); ck_assert_int_eq(datainfo.sumtx, 22); /* db_insertdata rounds the timestamps to full hours */ ck_assert_int_eq((int)datainfo.maxtime, 7200); ck_assert_int_eq((int)datainfo.mintime, 0); datalist_iterator = datalist; ck_assert_int_eq(datalist_iterator->rx, 1); ck_assert_int_eq(datalist_iterator->tx, 2); ck_assert_int_eq(datalist_iterator->timestamp, 0); datalist_iterator = datalist_iterator->next; ck_assert_int_eq(datalist_iterator->rx, 10); ck_assert_int_eq(datalist_iterator->tx, 20); ck_assert_int_eq(datalist_iterator->timestamp, 7200); dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_fatal_errors_get_detected) { ck_assert_int_eq(db_iserrcodefatal(SQLITE_OK), 0); ck_assert_int_eq(db_iserrcodefatal(SQLITE_FULL), 0); ck_assert_int_eq(db_iserrcodefatal(SQLITE_IOERR), 0); ck_assert_int_eq(db_iserrcodefatal(SQLITE_LOCKED), 0); ck_assert_int_eq(db_iserrcodefatal(SQLITE_BUSY), 0); ck_assert_int_eq(db_iserrcodefatal(SQLITE_ERROR), 1); ck_assert_int_eq(db_iserrcodefatal(SQLITE_ABORT), 1); ck_assert_int_eq(db_iserrcodefatal(SQLITE_EMPTY), 1); ck_assert_int_eq(db_iserrcodefatal(SQLITE_READONLY), 1); } END_TEST START_TEST(db_validate_with_valid_version) { int ret; suppress_output(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_validate(0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_errcode, 0); ret = db_validate(1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(db_errcode, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_validate_with_no_version) { int ret; suppress_output(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_exec("delete from info where name='dbversion';"); ck_assert_int_eq(ret, 1); ret = db_validate(0); ck_assert_int_eq(ret, 0); ck_assert_int_eq(db_errcode, 0); ret = db_validate(1); ck_assert_int_eq(ret, 0); ck_assert_int_eq(db_errcode, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_validate_with_low_version) { int ret; suppress_output(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_exec("update info set value='-1' where name='dbversion';"); ck_assert_int_eq(ret, 1); ret = db_validate(0); ck_assert_int_eq(ret, 0); ck_assert_int_eq(db_errcode, 0); ret = db_validate(1); ck_assert_int_eq(ret, 0); ck_assert_int_eq(db_errcode, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_validate_with_high_version) { int ret; suppress_output(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_exec("update info set value='100' where name='dbversion';"); ck_assert_int_eq(ret, 1); ret = db_validate(0); ck_assert_int_eq(ret, 0); ck_assert_int_eq(db_errcode, 0); ret = db_validate(1); ck_assert_int_eq(ret, 0); ck_assert_int_eq(db_errcode, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST void range_test_month_setup(void) { int ret, i; cfg.monthrotate = 2; /* this should have no effect */ ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethtest"); ck_assert_int_eq(ret, 1); for (i = 1; i <= 6; i++) { ret = db_insertdata("month", "ethtest", 1, 2, get_timestamp(2000, i, 1, 0, 0)); ck_assert_int_eq(ret, 1); } } START_TEST(db_getdata_range_can_get_months_without_range_defined) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_month_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "", ""); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 6); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-01-01"); break; case 5: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-06-01"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_months_with_range_matching_existing_data) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_month_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "2000-01-01", "2000-06-01"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 6); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-01-01"); break; case 5: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-06-01"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_months_with_range_past_existing_data) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_month_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "1999-01-01", "2000-08-01"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 6); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-01-01"); break; case 5: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-06-01"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_months_with_range_limiting_begin_and_end) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_month_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "2000-02-01", "2000-04-01"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 3); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-02-01"); break; case 2: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-04-01"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_months_with_range_limiting_begin) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_month_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "2000-03-01", ""); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 4); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-03-01"); break; case 3: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-06-01"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_months_with_range_limiting_begin_with_limit) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_month_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 3, "2000-03-01", ""); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 3); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-03-01"); break; case 2: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-05-01"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_months_with_range_limiting_end) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_month_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "", "2000-04-01"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 4); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-01-01"); break; case 3: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-04-01"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_months_with_range_limiting_end_with_limit) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_month_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 3, "", "2000-04-01"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 3); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-02-01"); break; case 2: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-04-01"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_months_with_range_on_same_month) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_month_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "2000-04-01", "2000-04-01"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 1); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-04-01"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_months_with_range_past_first_day_of_month) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_month_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 3, "2000-02-02", "2000-05-06"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 3); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-03-01"); break; case 2: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-05-01"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST void range_test_hour_setup(void) { int ret, i, j; cfg.monthrotate = 2; /* this should have no effect */ ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethtest"); ck_assert_int_eq(ret, 1); for (j = 2; j < 5; j++) { for (i = 0; i < 24; i++) { ret = db_insertdata("hour", "ethtest", 1, 2, get_timestamp(2002, 2, j, i, 0)); ck_assert_int_eq(ret, 1); } } } START_TEST(db_getdata_range_can_get_hours_without_range_defined) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_hour_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "", ""); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 72); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-02 00:00"); break; case 71: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-04 23:00"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_hours_with_range_matching_existing_data) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_hour_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "2002-02-02 00:00", "2002-02-04 23:00"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 72); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-02 00:00"); break; case 71: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-04 23:00"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_hours_with_range_past_existing_data) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_hour_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "2002-01-01 15:00", "2002-02-04 23:30"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 72); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-02 00:00"); break; case 71: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-04 23:00"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_hours_with_range_limiting_begin_and_end) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_hour_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "2002-02-02 20:00", "2002-02-03 17:00"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 22); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-02 20:00"); break; case 21: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-03 17:00"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_hours_with_range_limiting_begin) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_hour_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "2002-02-02 20:00", ""); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 52); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-02 20:00"); break; case 51: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-04 23:00"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_hours_with_range_limiting_begin_with_limit) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_hour_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 11, "2002-02-02 20:00", ""); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 11); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-02 20:00"); break; case 10: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-03 06:00"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_hours_with_range_limiting_end) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_hour_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "", "2002-02-02 20:00"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 21); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-02 00:00"); break; case 20: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-02 20:00"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_hours_with_range_limiting_end_with_limit) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_hour_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 5, "", "2002-02-02 20:00"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 5); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-02 16:00"); break; case 4: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-02 20:00"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_can_get_hours_with_range_on_same_hour) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; range_test_hour_setup(); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "2002-02-02 20:00", "2002-02-02 20:00"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 1); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2002-02-02 20:00"); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "2002-02-02 20:15", "2002-02-02 20:45"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getdata_range_with_merged_interfaces) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; cfg.monthrotate = 1; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethtest"); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethother"); ck_assert_int_eq(ret, 1); for (i = 1; i <= 20; i++) { ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0)); ck_assert_int_eq(ret, 1); ret = db_addtraffic_dated("ethother", 3, 7, get_timestamp(2000, 2, i, 0, 0)); ck_assert_int_eq(ret, 1); } ret = db_getdata_range(&datalist, &datainfo, "ethtest+ethother", "month", 0, "", ""); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 1); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-02-01"); ck_assert_int_eq(datalist_i->rx, 80); ck_assert_int_eq(datalist_i->tx, 180); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_addtraffic_without_monthrotate) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; cfg.monthrotate = 1; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethtest"); ck_assert_int_eq(ret, 1); for (i = 1; i <= 20; i++) { ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0)); ck_assert_int_eq(ret, 1); } ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "", ""); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 1); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-02-01"); ck_assert_int_eq(datalist_i->rx, 20); ck_assert_int_eq(datalist_i->tx, 40); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_addtraffic_with_monthrotate) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; cfg.monthrotate = 7; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethtest"); ck_assert_int_eq(ret, 1); for (i = 1; i <= 20; i++) { ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0)); ck_assert_int_eq(ret, 1); } ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "", ""); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 2); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-01-01"); ck_assert_int_eq(datalist_i->rx, 6); ck_assert_int_eq(datalist_i->tx, 12); break; case 1: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-02-01"); ck_assert_int_eq(datalist_i->rx, 14); ck_assert_int_eq(datalist_i->tx, 28); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_addtraffic_without_monthrotate_utc) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; cfg.monthrotate = 1; cfg.useutc = 1; validatecfg(CT_Daemon); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethtest"); ck_assert_int_eq(ret, 1); for (i = 1; i <= 20; i++) { ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0)); ck_assert_int_eq(ret, 1); } ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "", ""); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 1); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-02-01"); ck_assert_int_eq(datalist_i->rx, 20); ck_assert_int_eq(datalist_i->tx, 40); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_addtraffic_with_monthrotate_utc) { int ret, i; char timestamp[64]; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; cfg.monthrotate = 7; cfg.useutc = 1; validatecfg(CT_Daemon); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethtest"); ck_assert_int_eq(ret, 1); for (i = 1; i <= 20; i++) { ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0)); ck_assert_int_eq(ret, 1); } ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "", ""); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 2); datalist_i = datalist; i = 0; while (datalist_i != NULL) { switch (i) { case 0: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-01-01"); ck_assert_int_eq(datalist_i->rx, 6); ck_assert_int_eq(datalist_i->tx, 12); break; case 1: strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp)); ck_assert_str_eq(timestamp, "2000-02-01"); ck_assert_int_eq(datalist_i->rx, 14); ck_assert_int_eq(datalist_i->tx, 28); break; } datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_get_date_generator_can_generate_dates) { ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL); } END_TEST START_TEST(db_get_date_generator_can_generate_dates_with_monthrotate) { cfg.monthrotate = 10; cfg.monthrotateyears = 0; ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', datetime(foo, '-9 days'), 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL); cfg.monthrotate = 8; cfg.monthrotateyears = 1; ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', datetime(foo, '-7 days'), 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', datetime(foo, '-7 days'), 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo, 'localtime')"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL); } END_TEST START_TEST(db_get_date_generator_can_generate_dates_utc) { cfg.useutc = 1; validatecfg(CT_Daemon); ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo)"), NULL); } END_TEST START_TEST(db_get_date_generator_can_generate_dates_with_monthrotate_utc) { cfg.useutc = 1; validatecfg(CT_Daemon); cfg.monthrotate = 10; cfg.monthrotateyears = 0; ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', datetime(foo, '-9 days'))"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo)"), NULL); cfg.monthrotate = 8; cfg.monthrotateyears = 1; ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', datetime(foo, '-7 days'))"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', datetime(foo, '-7 days'))"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo)"), NULL); ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo)"), NULL); } END_TEST START_TEST(getifaceinquery_does_not_mess_regular_interfaces) { char *result; result = getifaceinquery("eth0"); ck_assert_ptr_ne(result, NULL); ck_assert_str_eq(result, "\"eth0\""); free(result); /* this isn't a realistic scenario but doesn't hurt to have a test */ result = getifaceinquery("eth0 with space"); ck_assert_ptr_ne(result, NULL); ck_assert_str_eq(result, "\"eth0 with space\""); free(result); result = getifaceinquery("em1_em2"); ck_assert_ptr_ne(result, NULL); ck_assert_str_eq(result, "\"em1_em2\""); free(result); result = getifaceinquery("em1-em2"); ck_assert_ptr_ne(result, NULL); ck_assert_str_eq(result, "\"em1-em2\""); free(result); } END_TEST START_TEST(getifaceinquery_can_create_merge_queries) { char *result; result = getifaceinquery("eth0+eth1"); ck_assert_ptr_ne(result, NULL); ck_assert_str_eq(result, "\"eth0\",\"eth1\""); free(result); result = getifaceinquery("eth1+eth0"); ck_assert_ptr_ne(result, NULL); ck_assert_str_eq(result, "\"eth1\",\"eth0\""); free(result); result = getifaceinquery("eth0+em1+eth1"); ck_assert_ptr_ne(result, NULL); ck_assert_str_eq(result, "\"eth0\",\"em1\",\"eth1\""); free(result); } END_TEST START_TEST(getifaceinquery_does_not_tolerate_nonsense) { char *result; result = getifaceinquery(""); ck_assert_ptr_eq(result, NULL); result = getifaceinquery("+eth0"); ck_assert_ptr_eq(result, NULL); result = getifaceinquery("eth0+"); ck_assert_ptr_eq(result, NULL); result = getifaceinquery("+eth0+"); ck_assert_ptr_eq(result, NULL); result = getifaceinquery("eth0++eth1"); ck_assert_ptr_eq(result, NULL); result = getifaceinquery("eth0+++eth1"); ck_assert_ptr_eq(result, NULL); result = getifaceinquery("eth0+eth1++eth2"); ck_assert_ptr_eq(result, NULL); result = getifaceinquery("+++ATH0"); ck_assert_ptr_eq(result, NULL); } END_TEST START_TEST(db_getinterfaceid_can_get_ids) { int ret; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth3"); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecount(); ck_assert_int_eq(ret, 3); ret = (int)db_getinterfaceid("eth0", 0); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfaceid("eth0", 1); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfaceid("eth1", 0); ck_assert_int_eq(ret, 2); ret = (int)db_getinterfaceid("eth2", 0); ck_assert_int_eq(ret, 0); ret = (int)db_getinterfaceid("eth3", 0); ck_assert_int_eq(ret, 3); ret = (int)db_getinterfaceid("eth2", 1); ck_assert_int_eq(ret, 4); ret = (int)db_getinterfaceid("eth2", 0); ck_assert_int_eq(ret, 4); ret = (int)db_getinterfacecount(); ck_assert_int_eq(ret, 4); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getinterfaceidin_can_get_in_groups) { int ret; char *result; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth3"); ck_assert_int_eq(ret, 1); result = db_getinterfaceidin("eth0"); ck_assert_str_eq(result, "1"); free(result); result = db_getinterfaceidin("eth0+eth1"); ck_assert_str_eq(result, "1,2"); free(result); result = db_getinterfaceidin("eth0+eth3"); ck_assert_str_eq(result, "1,3"); free(result); result = db_getinterfaceidin("eth0+eth3+eth1"); ck_assert_str_eq(result, "1,2,3"); free(result); result = db_getinterfaceidin("eth0+eth3+eth1+eth4"); ck_assert_str_eq(result, "1,2,3"); free(result); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getinterfaceidin_can_handle_error_situations) { int ret; char *result; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); result = db_getinterfaceidin("+eth0"); ck_assert_ptr_eq(result, NULL); result = db_getinterfaceidin("eth4"); ck_assert_ptr_eq(result, NULL); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getinterfaceinfo_can_handle_interface_merges) { int ret; interfaceinfo info; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addtraffic("eth0", 1, 1); ck_assert_int_eq(ret, 1); ret = db_addtraffic("eth1", 2, 2); ck_assert_int_eq(ret, 1); ret = db_addtraffic("eth2", 5, 5); ck_assert_int_eq(ret, 1); ret = db_getinterfaceinfo("eth0+ethnone", &info); ck_assert_int_eq(ret, 1); ck_assert_int_eq(info.rxtotal, 1); ck_assert_int_eq(info.txtotal, 1); ck_assert_int_gt(info.updated, 1000); ck_assert_int_lt(info.updated, 2100000000); ret = db_getinterfaceinfo("eth0+eth1", &info); ck_assert_int_eq(ret, 1); ck_assert_int_eq(info.rxtotal, 3); ck_assert_int_eq(info.txtotal, 3); ck_assert_int_gt(info.updated, 1000); ck_assert_int_lt(info.updated, 2100000000); ret = db_getinterfaceinfo("eth1+eth2", &info); ck_assert_int_eq(ret, 1); ck_assert_int_eq(info.rxtotal, 7); ck_assert_int_eq(info.txtotal, 7); ck_assert_int_gt(info.updated, 1000); ck_assert_int_lt(info.updated, 2100000000); ret = db_getinterfaceinfo("eth0+eth1+eth2", &info); ck_assert_int_eq(ret, 1); ck_assert_int_eq(info.rxtotal, 8); ck_assert_int_eq(info.txtotal, 8); ck_assert_int_gt(info.updated, 1000); ck_assert_int_lt(info.updated, 2100000000); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_getinterfaceinfo_can_handle_invalid_input) { int ret; interfaceinfo info; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addtraffic("eth0", 1, 1); ck_assert_int_eq(ret, 1); ret = db_addtraffic("eth1", 2, 2); ck_assert_int_eq(ret, 1); ret = db_addtraffic("eth2", 5, 5); ck_assert_int_eq(ret, 1); ret = db_getinterfaceinfo("eth0+", &info); ck_assert_int_eq(ret, 0); ret = db_getinterfaceinfo("+", &info); ck_assert_int_eq(ret, 0); ret = db_getinterfaceinfo("++", &info); ck_assert_int_eq(ret, 0); ret = db_getinterfaceinfo("", &info); ck_assert_int_eq(ret, 0); ret = db_getinterfaceinfo("ethunknown", &info); ck_assert_int_eq(ret, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(getqueryinterfacecount_can_count) { ck_assert_int_eq(getqueryinterfacecount("eth0"), 1); ck_assert_int_eq(getqueryinterfacecount("eth1"), 1); ck_assert_int_eq(getqueryinterfacecount("eth1+eth2"), 2); ck_assert_int_eq(getqueryinterfacecount("eth1+eth2+eth3"), 3); ck_assert_int_eq(getqueryinterfacecount("eth1+eth2+eth3+eth1"), 4); ck_assert_int_eq(getqueryinterfacecount("eth0+eth0"), 2); ck_assert_int_eq(getqueryinterfacecount("eth0++eth1"), 0); ck_assert_int_eq(getqueryinterfacecount(""), 0); ck_assert_int_eq(getqueryinterfacecount("1"), 1); ck_assert_int_eq(getqueryinterfacecount("+"), 0); ck_assert_int_eq(getqueryinterfacecount("++"), 0); ck_assert_int_eq(getqueryinterfacecount("+ +"), 0); ck_assert_int_eq(getqueryinterfacecount("+ethsomething"), 0); ck_assert_int_eq(getqueryinterfacecount("ethnothing+"), 0); ck_assert_int_eq(getqueryinterfacecount("eth+nothing"), 2); ck_assert_int_eq(getqueryinterfacecount("ethlongcanbelong+ethnotsoshort+ethdoesnotcare"), 3); } END_TEST START_TEST(top_list_returns_items_in_correct_order) { int ret; dbdatalist *datalist = NULL, *datalist_iterator = NULL; dbdatalistinfo datainfo; uint64_t previous_entry; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethtest"); ck_assert_int_eq(ret, 1); ret = db_addtraffic_dated("ethtest", 0, 0, get_timestamp(2000, 3, 10, 0, 0)); ck_assert_int_eq(ret, 1); ret = db_addtraffic_dated("ethtest", 12, 34, get_timestamp(2000, 3, 11, 0, 0)); ck_assert_int_eq(ret, 1); ret = db_addtraffic_dated("ethtest", 0, 0, get_timestamp(2000, 3, 12, 0, 0)); ck_assert_int_eq(ret, 1); ret = db_addtraffic_dated("ethtest", 0, 0, get_timestamp(2000, 3, 13, 0, 0)); ck_assert_int_eq(ret, 1); ret = db_addtraffic_dated("ethtest", 56, 78, get_timestamp(2000, 3, 14, 0, 0)); ck_assert_int_eq(ret, 1); ret = db_addtraffic_dated("ethtest", 1, 1, get_timestamp(2000, 3, 15, 0, 0)); ck_assert_int_eq(ret, 1); ret = db_addtraffic_dated("ethtest", 1, 1, get_timestamp(2000, 3, 16, 0, 0)); ck_assert_int_eq(ret, 1); ret = db_addtraffic_dated("ethtest", 45, 1, get_timestamp(2000, 3, 17, 0, 0)); ck_assert_int_eq(ret, 1); ret = db_getdata(&datalist, &datainfo, "ethtest", "top", 10); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 8); ck_assert_int_eq(datainfo.maxrx, 56); ck_assert_int_eq(datainfo.maxtx, 78); ck_assert_int_eq(datainfo.minrx, 0); ck_assert_int_eq(datainfo.mintx, 0); datalist_iterator = datalist; ck_assert_int_eq(datalist_iterator->rx, 56); ck_assert_int_eq(datalist_iterator->tx, 78); datalist_iterator = datalist_iterator->next; ck_assert_int_eq(datalist_iterator->rx, 12); ck_assert_int_eq(datalist_iterator->tx, 34); datalist_iterator = datalist_iterator->next; ck_assert_int_eq(datalist_iterator->rx, 45); ck_assert_int_eq(datalist_iterator->tx, 1); datalist_iterator = datalist_iterator->next; ck_assert_int_eq(datalist_iterator->rx, 1); ck_assert_int_eq(datalist_iterator->tx, 1); previous_entry = (uint64_t)datalist_iterator->timestamp; datalist_iterator = datalist_iterator->next; ck_assert_int_eq(datalist_iterator->rx, 1); ck_assert_int_eq(datalist_iterator->tx, 1); ck_assert_int_lt(previous_entry, (uint64_t)datalist_iterator->timestamp); datalist_iterator = datalist_iterator->next; ck_assert_int_eq(datalist_iterator->rx, 0); ck_assert_int_eq(datalist_iterator->tx, 0); previous_entry = (uint64_t)datalist_iterator->timestamp; datalist_iterator = datalist_iterator->next; ck_assert_int_eq(datalist_iterator->rx, 0); ck_assert_int_eq(datalist_iterator->tx, 0); ck_assert_int_lt(previous_entry, (uint64_t)datalist_iterator->timestamp); previous_entry = (uint64_t)datalist_iterator->timestamp; datalist_iterator = datalist_iterator->next; ck_assert_int_eq(datalist_iterator->rx, 0); ck_assert_int_eq(datalist_iterator->tx, 0); ck_assert_int_lt(previous_entry, (uint64_t)datalist_iterator->timestamp); dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setinterfacebyalias_sets_nothing_when_there_is_no_match) { int ret; char interface[32]; interface[0] = '\0'; ck_assert_int_eq(strlen(interface), 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_setinterfacebyalias(interface, "internet", 1); ck_assert_int_eq(ret, 0); ck_assert_int_eq(strlen(interface), 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setinterfacebyalias_can_set) { int ret; char interface[32]; interface[0] = '\0'; ck_assert_int_eq(strlen(interface), 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth0", "lan"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth1", "internet"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth2"); ck_assert_int_eq(ret, 1); ret = db_setinterfacebyalias(interface, "internet", 1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(strlen(interface), 4); ck_assert_str_eq(interface, "eth1"); ret = db_setinterfacebyalias(interface, "lan", 1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(strlen(interface), 4); ck_assert_str_eq(interface, "eth0"); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setinterfacebyalias_sets_highest_traffic_interface_if_alias_is_not_unique) { int ret; char interface[32]; interface[0] = '\0'; ck_assert_int_eq(strlen(interface), 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth0", "notnet"); ck_assert_int_eq(ret, 1); ret = db_settotal("eth0", 2, 2); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth12"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth12", "notnet"); ck_assert_int_eq(ret, 1); ret = db_settotal("eth12", 2, 3); ck_assert_int_eq(ret, 1); ret = db_setinterfacebyalias(interface, "notnet", 1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(strlen(interface), 5); ck_assert_str_eq(interface, "eth12"); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setinterfacebyalias_can_be_case_insensitive) { int ret; char interface[32]; interface[0] = '\0'; ck_assert_int_eq(strlen(interface), 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth0", "LAN"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth1", "Internet"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth2"); ck_assert_int_eq(ret, 1); ret = db_setinterfacebyalias(interface, "internet", 1); ck_assert_int_eq(ret, 0); ret = db_setinterfacebyalias(interface, "lan", 1); ck_assert_int_eq(ret, 0); ret = db_setinterfacebyalias(interface, "internet", 2); ck_assert_int_eq(ret, 1); ck_assert_int_eq(strlen(interface), 4); ck_assert_str_eq(interface, "eth1"); ret = db_setinterfacebyalias(interface, "lan", 2); ck_assert_int_eq(ret, 1); ck_assert_int_eq(strlen(interface), 4); ck_assert_str_eq(interface, "eth0"); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(db_setinterfacebyalias_can_match_prefix) { int ret; char interface[32]; interface[0] = '\0'; ck_assert_int_eq(strlen(interface), 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth0", "LAN"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth1", "Internet"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth2"); ck_assert_int_eq(ret, 1); ret = db_setinterfacebyalias(interface, "in", 1); ck_assert_int_eq(ret, 0); ret = db_setinterfacebyalias(interface, "la", 1); ck_assert_int_eq(ret, 0); ret = db_setinterfacebyalias(interface, "in", 2); ck_assert_int_eq(ret, 0); ret = db_setinterfacebyalias(interface, "la", 2); ck_assert_int_eq(ret, 0); ret = db_setinterfacebyalias(interface, "in", 3); ck_assert_int_eq(ret, 1); ck_assert_int_eq(strlen(interface), 4); ck_assert_str_eq(interface, "eth1"); ret = db_setinterfacebyalias(interface, "la", 3); ck_assert_int_eq(ret, 1); ck_assert_int_eq(strlen(interface), 4); ck_assert_str_eq(interface, "eth0"); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST void add_dbsql_tests(Suite *s) { TCase *tc_dbsql = tcase_create("DB SQL"); tcase_add_checked_fixture(tc_dbsql, setup, teardown); tcase_add_unchecked_fixture(tc_dbsql, setup, teardown); tcase_add_test(tc_dbsql, db_close_does_no_harm_when_db_is_already_closed); tcase_add_test(tc_dbsql, db_open_rw_can_create_database_if_file_does_not_exist); tcase_add_test(tc_dbsql, db_open_ro_cannot_create_a_database); tcase_add_test(tc_dbsql, db_getinfo_fails_with_no_open_db); tcase_add_test(tc_dbsql, db_getinfo_fails_with_nonexisting_name); tcase_add_test(tc_dbsql, db_getinfo_can_get_dbversion); tcase_add_test(tc_dbsql, db_setinfo_fails_with_no_open_db); tcase_add_test(tc_dbsql, db_setinfo_can_set_infos); tcase_add_test(tc_dbsql, db_setinfo_can_update_infos); tcase_add_test(tc_dbsql, db_setinfo_can_not_update_nonexisting_name); tcase_add_test(tc_dbsql, db_addtraffic_with_no_traffic_does_nothing); tcase_add_test(tc_dbsql, db_addtraffic_can_add_traffic_and_interfaces); tcase_add_test(tc_dbsql, db_addtraffic_can_add_traffic_and_interfaces_utc); tcase_add_test(tc_dbsql, db_addtraffic_dated_does_not_touch_updated_time); tcase_add_test(tc_dbsql, db_getinterfacecount_counts_interfaces); tcase_add_test(tc_dbsql, db_getinterfacecountbyname_counts_interfaces); tcase_add_test(tc_dbsql, db_setactive_fails_with_no_open_db); tcase_add_test(tc_dbsql, db_setactive_fails_if_interface_does_not_exist_in_database); tcase_add_test(tc_dbsql, db_setactive_can_change_interface_activity_status); tcase_add_test(tc_dbsql, db_setalias_fails_with_no_open_db); tcase_add_test(tc_dbsql, db_setalias_fails_if_interface_does_not_exist_in_database); tcase_add_test(tc_dbsql, db_setalias_can_change_interface_alias); tcase_add_test(tc_dbsql, db_setupdated_fails_with_no_open_db); tcase_add_test(tc_dbsql, db_setupdated_fails_if_interface_does_not_exist_in_database); tcase_add_test(tc_dbsql, db_setupdated_can_change_updated); tcase_add_test(tc_dbsql, db_addinterface_fails_with_no_open_db); tcase_add_test(tc_dbsql, db_addinterface_can_add_interfaces); tcase_add_test(tc_dbsql, db_addinterface_can_not_add_same_interface_twice); tcase_add_test(tc_dbsql, db_removeinterface_knows_if_interface_exists); tcase_add_test(tc_dbsql, db_removeinterface_can_remove_interfaces); tcase_add_test(tc_dbsql, db_renameinterface_knows_if_interface_exists); tcase_add_test(tc_dbsql, db_renameinterface_can_rename_interfaces); tcase_add_test(tc_dbsql, db_getcounters_with_no_interface); tcase_add_test(tc_dbsql, db_setcounters_with_no_interface); tcase_add_test(tc_dbsql, db_interface_info_manipulation); tcase_add_test(tc_dbsql, db_getiflist_lists_interfaces); tcase_add_test(tc_dbsql, db_maintenance_does_not_fault); tcase_add_test(tc_dbsql, db_data_can_be_inserted); tcase_add_test(tc_dbsql, db_data_can_be_retrieved); tcase_add_test(tc_dbsql, db_data_can_be_inserted_utc); tcase_add_test(tc_dbsql, db_data_can_be_retrieved_utc); tcase_add_test(tc_dbsql, db_fatal_errors_get_detected); tcase_add_test(tc_dbsql, db_validate_with_valid_version); tcase_add_test(tc_dbsql, db_validate_with_no_version); tcase_add_test(tc_dbsql, db_validate_with_low_version); tcase_add_test(tc_dbsql, db_validate_with_high_version); tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_without_range_defined); tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_matching_existing_data); tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_past_existing_data); tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_limiting_begin_and_end); tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_limiting_begin); tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_limiting_begin_with_limit); tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_limiting_end); tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_limiting_end_with_limit); tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_on_same_month); tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_past_first_day_of_month); tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_without_range_defined); tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_matching_existing_data); tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_past_existing_data); tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_limiting_begin_and_end); tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_limiting_begin); tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_limiting_begin_with_limit); tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_limiting_end); tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_limiting_end_with_limit); tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_on_same_hour); tcase_add_test(tc_dbsql, db_getdata_range_with_merged_interfaces); tcase_add_test(tc_dbsql, db_addtraffic_without_monthrotate); tcase_add_test(tc_dbsql, db_addtraffic_with_monthrotate); tcase_add_test(tc_dbsql, db_addtraffic_without_monthrotate_utc); tcase_add_test(tc_dbsql, db_addtraffic_with_monthrotate_utc); tcase_add_test(tc_dbsql, db_get_date_generator_can_generate_dates); tcase_add_test(tc_dbsql, db_get_date_generator_can_generate_dates_with_monthrotate); tcase_add_test(tc_dbsql, db_get_date_generator_can_generate_dates_utc); tcase_add_test(tc_dbsql, db_get_date_generator_can_generate_dates_with_monthrotate_utc); tcase_add_test(tc_dbsql, getifaceinquery_does_not_mess_regular_interfaces); tcase_add_test(tc_dbsql, getifaceinquery_can_create_merge_queries); tcase_add_test(tc_dbsql, getifaceinquery_does_not_tolerate_nonsense); tcase_add_test(tc_dbsql, db_getinterfaceid_can_get_ids); tcase_add_test(tc_dbsql, db_getinterfaceidin_can_get_in_groups); tcase_add_test(tc_dbsql, db_getinterfaceidin_can_handle_error_situations); tcase_add_test(tc_dbsql, db_getinterfaceinfo_can_handle_interface_merges); tcase_add_test(tc_dbsql, db_getinterfaceinfo_can_handle_invalid_input); tcase_add_test(tc_dbsql, getqueryinterfacecount_can_count); tcase_add_test(tc_dbsql, top_list_returns_items_in_correct_order); tcase_add_test(tc_dbsql, db_setinterfacebyalias_sets_nothing_when_there_is_no_match); tcase_add_test(tc_dbsql, db_setinterfacebyalias_can_set); tcase_add_test(tc_dbsql, db_setinterfacebyalias_sets_highest_traffic_interface_if_alias_is_not_unique); tcase_add_test(tc_dbsql, db_setinterfacebyalias_can_be_case_insensitive); tcase_add_test(tc_dbsql, db_setinterfacebyalias_can_match_prefix); suite_add_tcase(s, tc_dbsql); } vnstat-2.9/tests/common_tests.h0000644000000000000000000000013013510474536015430 0ustar rootroot#ifndef COMMON_TESTS_H #define COMMON_TESTS_H void add_common_tests(Suite *s); #endif vnstat-2.9/tests/dbsql_tests.h0000644000000000000000000000023213422305757015250 0ustar rootroot#ifndef DBSQL_TESTS_H #define DBSQL_TESTS_H void range_test_month_setup(void); void range_test_hour_setup(void); void add_dbsql_tests(Suite *s); #endif vnstat-2.9/tests/image_tests.h0000644000000000000000000000023013422305757015223 0ustar rootroot#ifndef IMAGE_TESTS_H #define IMAGE_TESTS_H char *hourly_imagescale_logic(const uint64_t max, const int rate); void add_image_tests(Suite *s); #endif vnstat-2.9/tests/fs_tests.h0000644000000000000000000000011413422305757014552 0ustar rootroot#ifndef FS_TESTS_H #define FS_TESTS_H void add_fs_tests(Suite *s); #endif vnstat-2.9/tests/vnstat_tests.c0000644000000000000000000002052414077632152015462 0ustar rootroot#include "common.h" #include "cfg.h" #include "vnstat_tests.h" #include "common_tests.h" #include "dbsql_tests.h" #include "database_tests.h" #include "config_tests.h" #include "ifinfo_tests.h" #include "misc_tests.h" #include "daemon_tests.h" #include "datacache_tests.h" #include "fs_tests.h" #include "id_tests.h" #include "iflist_tests.h" #include "cli_tests.h" #include "parseargs_tests.h" #if defined(HAVE_IMAGE) #include "image_tests.h" #endif int output_suppressed = 0; int main(void) { Suite *s; SRunner *sr; int number_failed = 0; verify_fork_status(); s = test_suite(); sr = srunner_create(s); srunner_set_log(sr, "test.log"); srunner_set_xml(sr, "test.xml"); srunner_run_all(sr, CK_NORMAL); number_failed = srunner_ntests_failed(sr); srunner_free(sr); if (number_failed == 0) { remove_directory(TESTDIR); } return number_failed; } Suite *test_suite(void) { Suite *s = suite_create("vnStat"); add_common_tests(s); add_dbsql_tests(s); add_database_tests(s); add_config_tests(s); add_ifinfo_tests(s); add_misc_tests(s); add_daemon_tests(s); add_datacache_tests(s); add_fs_tests(s); add_id_tests(s); add_iflist_tests(s); add_cli_tests(s); add_parseargs_tests(s); #if defined(HAVE_IMAGE) add_image_tests(s); #endif return s; } /* tests can't reliably be executed if check doesn't have forking enabled */ /* and only SRunner knows that so a dummy runner needs to be created */ void verify_fork_status(void) { Suite *s = suite_create("fork status check"); SRunner *sr = srunner_create(s); if (srunner_fork_status(sr) == CK_NOFORK) { printf("Error: Tests require Check to have fork mode enabled.\n"); exit(1); } srunner_free(sr); } void setup(void) { defaultcfg(); debug = 0; } void teardown(void) { return; } void suppress_output(void) { if (!output_suppressed) { fclose(stdout); output_suppressed = 1; } } int pipe_output(void) { int out_pipe[2]; if (pipe(out_pipe) != 0) { ck_abort_msg("error \"%s\" while creating pipe", strerror(errno)); } if (out_pipe[1] != STDOUT_FILENO) { dup2(out_pipe[1], STDOUT_FILENO); close(out_pipe[1]); } output_suppressed = 1; return out_pipe[0]; } void disable_logprints(void) { noexit = 2; cfg.uselogging = 0; disableprints = 1; } int clean_testdbdir(void) { struct stat statbuf; create_testdir(); if (stat(TESTDBDIR, &statbuf) != 0) { if (errno == ENOENT) { if (mkdir(TESTDBDIR, 0755) == 0) { return 1; } } ck_abort_msg("error \"%s\" while creating directory \"%s\"", strerror(errno), TESTDBDIR); } if (!remove_directory(TESTDBDIR)) { ck_abort_msg("error \"%s\" while removing directory \"%s\", please remove it manually", strerror(errno), TESTDBDIR); } if (mkdir(TESTDBDIR, 0755) != 0) { ck_abort_msg("error \"%s\" while creating directory \"%s\"", strerror(errno), TESTDBDIR); } return 1; } int create_testdir(void) { struct stat statbuf; if (stat(TESTDIR, &statbuf) != 0) { if (errno == ENOENT) { if (mkdir(TESTDIR, 0755) == 0) { return 1; } } ck_abort_msg("error \"%s\" while creating directory \"%s\"", strerror(errno), TESTDIR); } return 1; } int create_directory(const char *directory) { struct stat statbuf; if (stat(directory, &statbuf) != 0) { if (errno == ENOENT) { if (mkdir(directory, 0755) != 0) { ck_abort_msg("error \"%s\" while creating directory \"%s\"", strerror(errno), directory); } } else { ck_abort_msg("error \"%s\" while creating directory \"%s\"", strerror(errno), directory); } } return 1; } int remove_directory(const char *directory) { DIR *dir = NULL; struct dirent *di = NULL; char entryname[512]; if ((dir = opendir(directory)) == NULL) { if (errno == ENOENT) { return 1; } else { return 0; } } while ((di = readdir(dir))) { switch (di->d_type) { case DT_LNK: case DT_REG: snprintf(entryname, 512, "%s/%s", directory, di->d_name); if (unlink(entryname) != 0) { closedir(dir); return 0; } break; case DT_DIR: if (strcmp(di->d_name, ".") == 0 || strcmp(di->d_name, "..") == 0) { continue; } snprintf(entryname, 512, "%s/%s", directory, di->d_name); if (!remove_directory(entryname)) { closedir(dir); return 0; } break; default: continue; } } closedir(dir); if (rmdir(directory) != 0) { return 0; } return 1; } int create_zerosize_dbfile(const char *iface) { FILE *fp; char filename[512]; snprintf(filename, 512, "%s/%s", TESTDBDIR, iface); if ((fp = fopen(filename, "w")) == NULL) { ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename); } fclose(fp); return 1; } int check_dbfile_exists(const char *iface, const int minsize) { struct stat statbuf; char filename[512]; snprintf(filename, 512, "%s/%s", TESTDBDIR, iface); if (stat(filename, &statbuf) != 0) { if (errno == ENOENT) { return 0; } ck_abort_msg("error \"%s\" while inspecting file \"%s\"", strerror(errno), filename); } if (statbuf.st_size < minsize) { ck_abort_msg("file \"%s\" is smaller (%d) then given minimum %d", filename, (int)statbuf.st_size, minsize); } return 1; } int fake_proc_net_dev(const char *mode, const char *iface, const int rx, const int tx, const int rxp, const int txp) { FILE *devfp; char filename[512]; if (strcmp(mode, "w") != 0 && strcmp(mode, "a") != 0) { ck_abort_msg("error: only w and a modes are supported"); } create_testdir(); create_directory(TESTPROCDIR); snprintf(filename, 512, "%s/dev", TESTPROCDIR); if ((devfp = fopen(filename, mode)) == NULL) { ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename); } if (strcmp(mode, "w") == 0) { fprintf(devfp, "Inter-| Receive | Transmit\n"); fprintf(devfp, " face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed\n"); fprintf(devfp, " lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"); } fprintf(devfp, "%6s: %7d %7d 0 0 0 0 0 0 %7d %7d 0 0 0 0 0 0\n", iface, rx, rxp, tx, txp); fclose(devfp); return 1; } int fake_sys_class_net(const char *iface, const int rx, const int tx, const int rxp, const int txp, const int speed) { FILE *devfp; char dirname[512]; char filename[512]; create_testdir(); create_directory(TESTSYSCLASSNETDIR); snprintf(dirname, 512, "%s/%s", TESTSYSCLASSNETDIR, iface); create_directory(dirname); snprintf(dirname, 512, "%s/%s/statistics", TESTSYSCLASSNETDIR, iface); create_directory(dirname); if (speed != 0) { snprintf(filename, 512, "%s/%s/speed", TESTSYSCLASSNETDIR, iface); if ((devfp = fopen(filename, "w")) == NULL) { ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename); } fprintf(devfp, "%d\n", speed); fclose(devfp); } snprintf(filename, 512, "%s/%s/statistics/rx_bytes", TESTSYSCLASSNETDIR, iface); if ((devfp = fopen(filename, "w")) == NULL) { ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename); } fprintf(devfp, "%d\n", rx); fclose(devfp); snprintf(filename, 512, "%s/%s/statistics/tx_bytes", TESTSYSCLASSNETDIR, iface); if ((devfp = fopen(filename, "w")) == NULL) { ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename); } fprintf(devfp, "%d\n", tx); fclose(devfp); snprintf(filename, 512, "%s/%s/statistics/rx_packets", TESTSYSCLASSNETDIR, iface); if ((devfp = fopen(filename, "w")) == NULL) { ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename); } fprintf(devfp, "%d\n", rxp); fclose(devfp); snprintf(filename, 512, "%s/%s/statistics/tx_packets", TESTSYSCLASSNETDIR, iface); if ((devfp = fopen(filename, "w")) == NULL) { ck_abort_msg("error \"%s\" while opening file \"%s\" for writing", strerror(errno), filename); } fprintf(devfp, "%d\n", txp); fclose(devfp); return 1; } uint64_t get_timestamp(const int year, const int month, const int day, const int hour, const int minute) { struct tm stm; memset(&stm, 0, sizeof(struct tm)); stm.tm_year = year - 1900; stm.tm_mon = month - 1; stm.tm_mday = day; stm.tm_hour = hour; stm.tm_min = minute; stm.tm_isdst = -1; if (cfg.useutc) { return (uint64_t)timegm(&stm); } else { return (uint64_t)mktime(&stm); } } vnstat-2.9/tests/ifinfo_tests.h0000644000000000000000000000013013422305757015412 0ustar rootroot#ifndef IFINFO_TESTS_H #define IFINFO_TESTS_H void add_ifinfo_tests(Suite *s); #endif vnstat-2.9/tests/cli_tests.h0000644000000000000000000000011713526605603014712 0ustar rootroot#ifndef CLI_TESTS_H #define CLI_TESTS_H void add_cli_tests(Suite *s); #endif vnstat-2.9/tests/database_tests.h0000644000000000000000000000013613422305757015712 0ustar rootroot#ifndef DATABASE_TESTS_H #define DATABASE_TESTS_H void add_database_tests(Suite *s); #endif vnstat-2.9/tests/parseargs_tests.h0000644000000000000000000000014113537201712016122 0ustar rootroot#ifndef PARSEARGS_TESTS_H #define PARSEARGS_TESTS_H void add_parseargs_tests(Suite *s); #endif vnstat-2.9/tests/common_tests.c0000644000000000000000000002526114077640276015444 0ustar rootroot#include "common.h" #include "vnstat_tests.h" #include "common_tests.h" #include "dbaccess.h" #include "cfg.h" START_TEST(printe_options) { noexit = 2; cfg.uselogging = 0; ck_assert_int_eq(printe(PT_Info), 1); cfg.uselogging = 1; ck_assert_int_eq(printe(PT_Multiline), 1); noexit = 0; strcpy(errorstring, "dummy string"); suppress_output(); ck_assert_int_eq(printe(PT_Info), 1); ck_assert_int_eq(printe(PT_Warning), 1); ck_assert_int_eq(printe(PT_Error), 1); ck_assert_int_eq(printe(PT_Config), 1); ck_assert_int_eq(printe(PT_Multiline), 1); ck_assert_int_eq(printe(PT_ShortMultiline), 1); ck_assert_int_eq(printe(6), 1); } END_TEST START_TEST(logprint_options) { cfg.uselogging = 0; ck_assert_int_eq(logprint(PT_Info), 0); cfg.uselogging = 1; strcpy(cfg.logfile, "/dev/null"); strcpy(errorstring, "dummy string"); ck_assert_int_eq(logprint(PT_Info), 1); ck_assert_int_eq(logprint(PT_Warning), 1); ck_assert_int_eq(logprint(PT_Error), 1); ck_assert_int_eq(logprint(PT_Config), 1); ck_assert_int_eq(logprint(PT_Multiline), 0); ck_assert_int_eq(logprint(PT_ShortMultiline), 1); ck_assert_int_eq(logprint(6), 1); } END_TEST #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wused-but-marked-unused" #endif START_TEST(dmonth_return_within_range) { int m; m = dmonth(_i); ck_assert_int_ge(m, 28); ck_assert_int_le(m, 31); } END_TEST #if defined(__clang__) #pragma clang diagnostic pop #endif START_TEST(leapyears_are_known) { ck_assert_int_eq(isleapyear(1995), 0); ck_assert_int_eq(isleapyear(1996), 1); ck_assert_int_eq(isleapyear(1997), 0); ck_assert_int_eq(isleapyear(1998), 0); ck_assert_int_eq(isleapyear(1999), 0); ck_assert_int_eq(isleapyear(2000), 1); ck_assert_int_eq(isleapyear(2001), 0); ck_assert_int_eq(isleapyear(2002), 0); ck_assert_int_eq(isleapyear(2003), 0); ck_assert_int_eq(isleapyear(2004), 1); ck_assert_int_eq(isleapyear(2005), 0); ck_assert_int_eq(isleapyear(2006), 0); ck_assert_int_eq(isleapyear(2007), 0); ck_assert_int_eq(isleapyear(2008), 1); ck_assert_int_eq(isleapyear(2009), 0); ck_assert_int_eq(isleapyear(2010), 0); ck_assert_int_eq(isleapyear(2011), 0); ck_assert_int_eq(isleapyear(2012), 1); ck_assert_int_eq(isleapyear(2013), 0); ck_assert_int_eq(isleapyear(2014), 0); ck_assert_int_eq(isleapyear(2015), 0); ck_assert_int_eq(isleapyear(2016), 1); ck_assert_int_eq(isleapyear(2017), 0); ck_assert_int_eq(isleapyear(2018), 0); ck_assert_int_eq(isleapyear(2019), 0); ck_assert_int_eq(isleapyear(2020), 1); ck_assert_int_eq(isleapyear(2021), 0); } END_TEST START_TEST(mosecs_return_values) { time_t a, b; cfg.monthrotate = 1; ck_assert_int_eq(mosecs(0, 0), 1); a = mosecs(172800, 173000); ck_assert_int_gt(a, 1); cfg.monthrotate = 2; b = mosecs(172800, 173000); ck_assert_int_gt(b, 1); ck_assert_int_gt(a, b); } END_TEST START_TEST(mosecs_does_not_change_tz) { #if defined(_SVID_SOURCE) || defined(_XOPEN_SOURCE) || defined(__APPLE__) || defined(__linux__) extern long timezone; #else long timezone = 0; #endif long timezone_before_call; tzset(); timezone_before_call = timezone; ck_assert_int_eq(cfg.monthrotate, 1); ck_assert_int_ne(mosecs(1, 2), 0); ck_assert_int_ne(mosecs(1, 2), 1); ck_assert_int_eq(timezone_before_call, timezone); } END_TEST START_TEST(mosecs_does_not_change_struct_tm_pointer_content) { struct tm *stm; time_t current; current = time(NULL); stm = localtime(¤t); ck_assert_int_eq(cfg.monthrotate, 1); ck_assert_int_eq(current, mktime(stm)); ck_assert_int_ne(mosecs(1, 2), 0); ck_assert_int_ne(mosecs(1, 2), 1); ck_assert_int_eq(current, mktime(stm)); } END_TEST START_TEST(countercalc_no_change_32bit) { uint64_t a, b; a = b = 0; ck_assert_int_eq(countercalc(&a, &b, 0), 0); ck_assert_int_eq(countercalc(&a, &b, -1), 0); a = b = 1; ck_assert_int_eq(countercalc(&a, &b, 0), 0); ck_assert_int_eq(countercalc(&a, &b, -1), 0); } END_TEST START_TEST(countercalc_no_change_64bit) { uint64_t a, b; a = b = 0; ck_assert_int_eq(countercalc(&a, &b, 1), 0); a = b = 1; ck_assert_int_eq(countercalc(&a, &b, 1), 0); } END_TEST START_TEST(countercalc_small_change_32bit) { uint64_t a, b; a = 0; b = 1; ck_assert_int_eq(countercalc(&a, &b, 0), 1); ck_assert_int_eq(countercalc(&a, &b, -1), 1); a = 1; b = 2; ck_assert_int_eq(countercalc(&a, &b, 0), 1); ck_assert_int_eq(countercalc(&a, &b, -1), 1); b = 3; ck_assert_int_eq(countercalc(&a, &b, 0), 2); ck_assert_int_eq(countercalc(&a, &b, -1), 2); } END_TEST START_TEST(countercalc_small_change_64bit) { uint64_t a, b; a = 0; b = 1; ck_assert_int_eq(countercalc(&a, &b, 1), 1); a = 1; b = 2; ck_assert_int_eq(countercalc(&a, &b, 1), 1); b = 3; ck_assert_int_eq(countercalc(&a, &b, 1), 2); } END_TEST START_TEST(countercalc_rollover_with_32bit) { uint64_t a, b; a = 1; b = 0; ck_assert(countercalc(&a, &b, 0) == (MAX32 - 1)); ck_assert(countercalc(&a, &b, -1) == (MAX32 - 1)); } END_TEST START_TEST(countercalc_rollover_with_64bit) { uint64_t a, b; a = 1; b = 0; ck_assert(countercalc(&a, &b, 1) == (MAX64 - 1)); } END_TEST START_TEST(countercalc_rollover_with_64bit_2) { uint64_t a, b; a = MAX32 + 1; b = 0; ck_assert(countercalc(&a, &b, 1) == (MAX64 - MAX32 - 1)); } END_TEST START_TEST(countercalc_rollover_with_32bit_starting_32bit) { uint64_t a, b; a = MAX32 - 1; b = 0; ck_assert(countercalc(&a, &b, 0) == 1); ck_assert(countercalc(&a, &b, -1) == 1); } END_TEST START_TEST(countercalc_rollover_with_32bit_starting_over_32bit) { uint64_t a, b; a = MAX32 + 1; b = 0; ck_assert(countercalc(&a, &b, 0) == (MAX64 - MAX32 - 1)); ck_assert(countercalc(&a, &b, -1) == (MAX64 - MAX32 - 1)); } END_TEST START_TEST(countercalc_rollover_with_64bit_starting_32bit) { uint64_t a, b; a = MAX32 - 1; b = 0; ck_assert(countercalc(&a, &b, 1) == (MAX64 - MAX32 + 1)); } END_TEST START_TEST(countercalc_rollover_with_64bit_starting_64bit) { uint64_t a, b; a = MAX64 - 1; b = 0; ck_assert(countercalc(&a, &b, 1) == 1); } END_TEST START_TEST(strncpy_nt_with_below_maximum_length_string) { char dst[6]; strncpy_nt(dst, "123", 6); ck_assert_str_eq(dst, "123"); } END_TEST START_TEST(strncpy_nt_with_maximum_length_string) { char dst[6]; strncpy_nt(dst, "12345", 6); ck_assert_str_eq(dst, "12345"); } END_TEST START_TEST(strncpy_nt_with_over_maximum_length_string) { char dst[6]; strncpy_nt(dst, "123456", 6); ck_assert_str_eq(dst, "12345"); strncpy_nt(dst, "1234567890", 6); ck_assert_str_eq(dst, "12345"); } END_TEST START_TEST(isnumeric_empty) { ck_assert_int_eq(isnumeric(""), 0); } END_TEST START_TEST(isnumeric_it_is) { ck_assert_int_eq(isnumeric("0"), 1); ck_assert_int_eq(isnumeric("1"), 1); ck_assert_int_eq(isnumeric("12"), 1); ck_assert_int_eq(isnumeric("123"), 1); } END_TEST START_TEST(isnumeric_it_is_not) { ck_assert_int_eq(isnumeric("a"), 0); ck_assert_int_eq(isnumeric("abc"), 0); ck_assert_int_eq(isnumeric("a1"), 0); ck_assert_int_eq(isnumeric("1a"), 0); ck_assert_int_eq(isnumeric("123abc"), 0); ck_assert_int_eq(isnumeric("/"), 0); ck_assert_int_eq(isnumeric("-"), 0); } END_TEST START_TEST(getversion_returns_a_version) { ck_assert_int_gt((int)strlen(getversion()), 1); ck_assert(strchr(getversion(), '_') == NULL); ck_assert(strchr(getversion(), '.') != NULL); } END_TEST START_TEST(timeused_debug_outputs_something_expected_when_debug_is_enabled) { int pipe, len; char buffer[512]; memset(&buffer, '\0', sizeof(buffer)); debug = 1; pipe = pipe_output(); /* the assumption here is that the next two steps can always execute in less than one second resulting in a duration that starts with a zero */ timeused_debug("that_func", 1); timeused_debug("that_func", 0); fflush(stdout); len = (int)read(pipe, buffer, 512); ck_assert_int_gt(len, 1); ck_assert_ptr_ne(strstr(buffer, "that_func() in 0"), NULL); } END_TEST START_TEST(timeused_debug_does_not_output_anything_when_debug_is_disabled) { int pipe, len; char buffer[512]; memset(&buffer, '\0', sizeof(buffer)); debug = 0; pipe = pipe_output(); /* the assumption here is that the next two steps can always execute in less than one second resulting in a duration that starts with a zero */ timeused_debug("other_func", 1); timeused_debug("other_func", 0); printf("-"); // stdout needs to contain something so that read doesn't block fflush(stdout); len = (int)read(pipe, buffer, 512); ck_assert_int_eq(len, 1); } END_TEST START_TEST(timeused_tracks_used_time) { double used; struct timespec ts; used = timeused("quick_func", 1); ck_assert(used == 0.0); ts.tv_sec = 0; ts.tv_nsec = 100000000; // 0.1 s nanosleep(&ts, NULL); used = timeused("quick_func", 0); ck_assert(used > 0.0); } END_TEST __attribute__((noreturn)) START_TEST(can_panic) { suppress_output(); fclose(stderr); panicexit(__FILE__, __LINE__); } END_TEST void add_common_tests(Suite *s) { TCase *tc_common = tcase_create("Common"); tcase_add_checked_fixture(tc_common, setup, teardown); tcase_add_unchecked_fixture(tc_common, setup, teardown); tcase_add_test(tc_common, printe_options); tcase_add_test(tc_common, logprint_options); tcase_add_loop_test(tc_common, dmonth_return_within_range, 0, 12); tcase_add_test(tc_common, leapyears_are_known); tcase_add_test(tc_common, mosecs_return_values); tcase_add_test(tc_common, mosecs_does_not_change_tz); tcase_add_test(tc_common, mosecs_does_not_change_struct_tm_pointer_content); tcase_add_test(tc_common, countercalc_no_change_32bit); tcase_add_test(tc_common, countercalc_no_change_64bit); tcase_add_test(tc_common, countercalc_small_change_32bit); tcase_add_test(tc_common, countercalc_small_change_64bit); tcase_add_test(tc_common, countercalc_rollover_with_32bit); tcase_add_test(tc_common, countercalc_rollover_with_64bit); tcase_add_test(tc_common, countercalc_rollover_with_64bit_2); tcase_add_test(tc_common, countercalc_rollover_with_32bit_starting_32bit); tcase_add_test(tc_common, countercalc_rollover_with_32bit_starting_over_32bit); tcase_add_test(tc_common, countercalc_rollover_with_64bit_starting_32bit); tcase_add_test(tc_common, countercalc_rollover_with_64bit_starting_64bit); tcase_add_test(tc_common, strncpy_nt_with_below_maximum_length_string); tcase_add_test(tc_common, strncpy_nt_with_maximum_length_string); tcase_add_test(tc_common, strncpy_nt_with_over_maximum_length_string); tcase_add_test(tc_common, isnumeric_empty); tcase_add_test(tc_common, isnumeric_it_is); tcase_add_test(tc_common, isnumeric_it_is_not); tcase_add_test(tc_common, getversion_returns_a_version); tcase_add_test(tc_common, timeused_debug_outputs_something_expected_when_debug_is_enabled); tcase_add_test(tc_common, timeused_debug_does_not_output_anything_when_debug_is_disabled); tcase_add_test(tc_common, timeused_tracks_used_time); tcase_add_exit_test(tc_common, can_panic, 1); suite_add_tcase(s, tc_common); } vnstat-2.9/tests/datacache_tests.h0000644000000000000000000000014113422305757016037 0ustar rootroot#ifndef DATACACHE_TESTS_H #define DATACACHE_TESTS_H void add_datacache_tests(Suite *s); #endif vnstat-2.9/tests/parseargs_tests.c0000644000000000000000000005472414112742606016137 0ustar rootroot#include "common.h" #include "vnstat_tests.h" #include "vnstat_func.h" #include "cfg.h" #include "dbsql.h" #include "parseargs_tests.h" START_TEST(vnstat_parseargs_does_nothing_without_args) { PARAMS p; char *argv[] = {"vnstat", "-h", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_can_help) { PARAMS p; char *argv[] = {"vnstat", "--help", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); debug = 1; suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_can_longhelp) { PARAMS p; char *argv[] = {"vnstat", "--longhelp", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_can_show_version) { PARAMS p; char *argv[] = {"vnstat", "--version", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_detects_unknown_parameters) { PARAMS p; char *argv[] = {"vnstat", "--something_fishy", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_can_modify_settings) { PARAMS p; char *argv[] = {"vnstat", "--debug", "--traffic", "12", "--add", "--rename", "aname", "--config", "does_nothing", "-l", "1", "--remove", "-i", "ethsomething", "--style", "0", "--dbdir", "dbsomewhere", "-q", "-d", "1", "-m", "2", "-t", "3", "-s", "-y", "4", "-hg", "-h", "5", "-5", "6", "--oneline", "b", "--xml", "h", "7", "--json", "d", "7", "-ru", "--rateunit", "0", "--force", "--setalias", "super", "--begin", "2000-01-01", "--end", "2001-01-01", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_str_eq(p.interface, "ethsomething"); ck_assert_int_eq(p.defaultiface, 0); ck_assert_int_eq(cfg.ostyle, 4); ck_assert_str_eq(cfg.dbdir, "dbsomewhere"); ck_assert_int_eq(p.query, 1); ck_assert_int_eq(p.force, 1); ck_assert_int_eq(cfg.qmode, 10); ck_assert_int_eq(p.jsonmode, 'd'); ck_assert_int_eq(p.xmlmode, 'h'); ck_assert_int_eq(cfg.rateunit, 0); ck_assert_int_eq(p.setalias, 1); ck_assert_str_eq(p.alias, "super"); ck_assert_str_eq(p.newifname, "aname"); ck_assert_int_eq(p.renameiface, 1); ck_assert_int_eq(p.removeiface, 1); ck_assert_int_eq(p.traffic, 1); ck_assert_int_eq(cfg.sampletime, 12); ck_assert_int_eq(p.livetraffic, 1); ck_assert_int_eq(p.livemode, 1); ck_assert_int_eq(cfg.listdays, 1); ck_assert_int_eq(cfg.listmonths, 2); ck_assert_int_eq(cfg.listtop, 3); ck_assert_int_eq(cfg.listyears, 4); ck_assert_int_eq(cfg.listhours, 5); ck_assert_int_eq(cfg.listfivemins, 6); ck_assert_int_eq(cfg.listjsonxml, 7); ck_assert_str_eq(p.databegin, "2000-01-01"); ck_assert_str_eq(p.dataend, "2001-01-01"); } END_TEST START_TEST(vnstat_parseargs_does_not_allow_too_long_interface_names) { PARAMS p; char *argv[] = {"vnstat", "--iface", "12345678901234567890123456789012", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_style_requires_parameter) { PARAMS p; char *argv[] = {"vnstat", "--style", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_style_checks_parameter) { PARAMS p; char *argv[] = {"vnstat", "--style", "9001", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_knows_that_update_is_not_supported) { PARAMS p; char *argv[] = {"vnstat", "-u", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_dbdir_requires_a_directory) { PARAMS p; char *argv[] = {"vnstat", "--dbdir", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_oneline_gives_help) { PARAMS p; char *argv[] = {"vnstat", "--oneline", "a", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_xml_gives_help) { PARAMS p; char *argv[] = {"vnstat", "--xml", "b", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_xml_without_extra_params) { PARAMS p; char *argv[] = {"vnstat", "--xml", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; cfg.qmode = 0; initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_int_eq(cfg.qmode, 8); ck_assert_int_eq(p.xmlmode, 'a'); ck_assert_int_eq(cfg.listjsonxml, 0); } END_TEST START_TEST(vnstat_parseargs_xml_with_mode) { PARAMS p; char *argv[] = {"vnstat", "--xml", "m", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; cfg.qmode = 0; initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_int_eq(cfg.qmode, 8); ck_assert_int_eq(p.xmlmode, 'm'); ck_assert_int_eq(cfg.listjsonxml, 0); } END_TEST START_TEST(vnstat_parseargs_xml_with_limit) { PARAMS p; char *argv[] = {"vnstat", "--xml", "1231", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; cfg.qmode = 0; initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_int_eq(cfg.qmode, 8); ck_assert_int_eq(p.xmlmode, 'a'); ck_assert_int_eq(cfg.listjsonxml, 1231); } END_TEST START_TEST(vnstat_parseargs_xml_with_mode_and_limit) { PARAMS p; char *argv[] = {"vnstat", "--xml", "t", "2", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; cfg.qmode = 0; initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_int_eq(cfg.qmode, 8); ck_assert_int_eq(p.xmlmode, 't'); ck_assert_int_eq(cfg.listjsonxml, 2); } END_TEST START_TEST(vnstat_parseargs_json_gives_help) { PARAMS p; char *argv[] = {"vnstat", "--json", "b", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_json_without_extra_params) { PARAMS p; char *argv[] = {"vnstat", "--json", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; cfg.qmode = 0; initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_int_eq(cfg.qmode, 10); ck_assert_int_eq(p.jsonmode, 'a'); ck_assert_int_eq(cfg.listjsonxml, 0); } END_TEST START_TEST(vnstat_parseargs_json_with_mode) { PARAMS p; char *argv[] = {"vnstat", "--json", "m", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; cfg.qmode = 0; initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_int_eq(cfg.qmode, 10); ck_assert_int_eq(p.jsonmode, 'm'); ck_assert_int_eq(cfg.listjsonxml, 0); } END_TEST START_TEST(vnstat_parseargs_json_with_limit) { PARAMS p; char *argv[] = {"vnstat", "--json", "1232", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; cfg.qmode = 0; initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_int_eq(cfg.qmode, 10); ck_assert_int_eq(p.jsonmode, 'a'); ck_assert_int_eq(cfg.listjsonxml, 1232); } END_TEST START_TEST(vnstat_parseargs_json_with_mode_and_limit) { PARAMS p; char *argv[] = {"vnstat", "--json", "d", "3", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; cfg.qmode = 0; initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_int_eq(cfg.qmode, 10); ck_assert_int_eq(p.jsonmode, 'd'); ck_assert_int_eq(cfg.listjsonxml, 3); } END_TEST START_TEST(vnstat_parseargs_rateunit_gives_help) { PARAMS p; char *argv[] = {"vnstat", "--rateunit", "2", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_live_gives_help) { PARAMS p; char *argv[] = {"vnstat", "--live", "2", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_begin_gives_help) { PARAMS p; char *argv[] = {"vnstat", "--begin", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_end_gives_help) { PARAMS p; char *argv[] = {"vnstat", "--end", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_begin_validates_input) { PARAMS p; char *argv[] = {"vnstat", "--begin", "world_domination", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_end_validates_input) { PARAMS p; char *argv[] = {"vnstat", "--end", "what?", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_can_show_config) { PARAMS p; char *argv[] = {"vnstat", "--showconfig", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_iface_requires_parameter) { PARAMS p; char *argv[] = {"vnstat", "--iface", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_locale_requires_parameter) { PARAMS p; char *argv[] = {"vnstat", "--locale", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_setalias_requires_parameter) { PARAMS p; char *argv[] = {"vnstat", "--setalias", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_setalias_still_supports_nick) { PARAMS p; char *argv[] = {"vnstat", "--nick", "Underground", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_int_eq(p.setalias, 1); ck_assert_str_eq(p.alias, "Underground"); } END_TEST START_TEST(vnstat_parseargs_rename_requires_parameter) { PARAMS p; char *argv[] = {"vnstat", "--rename", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_limit_requires_parameter) { PARAMS p; char *argv[] = {"vnstat", "--limit", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_limit_cannot_be_negative) { PARAMS p; char *argv[] = {"vnstat", "--limit", "-1", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_limit_changes_defaults) { PARAMS p; char *argv[] = {"vnstat", "--limit", "1234", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_int_eq(cfg.listfivemins, 1234); ck_assert_int_eq(cfg.listhours, 1234); ck_assert_int_eq(cfg.listdays, 1234); ck_assert_int_eq(cfg.listmonths, 1234); ck_assert_int_eq(cfg.listyears, 1234); ck_assert_int_eq(cfg.listtop, 1234); ck_assert_int_eq(cfg.listjsonxml, 1234); } END_TEST START_TEST(vnstat_parseargs_limit_overrides) { PARAMS p; char *argv[] = {"vnstat", "-d", "5", "--limit", "234", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_int_eq(cfg.listfivemins, 234); ck_assert_int_eq(cfg.listhours, 234); ck_assert_int_eq(cfg.listdays, 234); ck_assert_int_eq(cfg.listmonths, 234); ck_assert_int_eq(cfg.listyears, 234); ck_assert_int_eq(cfg.listtop, 234); ck_assert_int_eq(cfg.listjsonxml, 234); } END_TEST START_TEST(vnstat_parseargs_limit_overrides_regardless_of_position) { PARAMS p; char *argv[] = {"vnstat", "--limit", "345", "-d", "5", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_int_eq(cfg.listfivemins, 345); ck_assert_int_eq(cfg.listhours, 345); ck_assert_int_eq(cfg.listdays, 345); ck_assert_int_eq(cfg.listmonths, 345); ck_assert_int_eq(cfg.listyears, 345); ck_assert_int_eq(cfg.listtop, 345); ck_assert_int_eq(cfg.listjsonxml, 345); } END_TEST START_TEST(vnstat_parseargs_iflist_gives_help) { PARAMS p; char *argv[] = {"vnstat", "--iflist", "--help", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_iflist_without_parameters_and_no_interfaces) { PARAMS p; char *argv[] = {"vnstat", "--iflist", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); remove_directory(TESTDIR); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_iflist_without_parameters_and_only_lo) { PARAMS p; char *argv[] = {"vnstat", "--iflist", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); fake_proc_net_dev("w", "lo", 0, 0, 0, 0); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_iflist_without_parameters) { PARAMS p; char *argv[] = {"vnstat", "--iflist", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); fake_proc_net_dev("w", "ethsomething", 0, 0, 0, 0); fake_proc_net_dev("a", "ethanything", 0, 0, 0, 0); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_iflist_with_verbose_mode) { PARAMS p; char *argv[] = {"vnstat", "--iflist", "0", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); fake_proc_net_dev("w", "ethsomething", 0, 0, 0, 0); fake_proc_net_dev("a", "ethanything", 0, 0, 0, 0); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_iflist_with_parseable_mode) { PARAMS p; char *argv[] = {"vnstat", "--iflist", "1", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); fake_proc_net_dev("w", "ethsomething", 0, 0, 0, 0); fake_proc_net_dev("a", "ethanything", 0, 0, 0, 0); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_dbiflist_gives_help) { PARAMS p; char *argv[] = {"vnstat", "--dbiflist", "unknown", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_dbiflist_with_no_database) { PARAMS p; char *argv[] = {"vnstat", "--dbiflist", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); suppress_output(); parseargs(&p, argc, argv); } END_TEST START_TEST(vnstat_parseargs_dbiflist_without_parameters_and_no_interfaces) { int ret; PARAMS p; char *argv[] = {"vnstat", "--dbiflist", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); suppress_output(); parseargs(&p, argc, argv); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(vnstat_parseargs_dbiflist_without_parameters) { int ret; PARAMS p; char *argv[] = {"vnstat", "--dbiflist", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("etheverything"); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethnothing"); ck_assert_int_eq(ret, 1); suppress_output(); parseargs(&p, argc, argv); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(vnstat_parseargs_dbiflist_with_verbose_mode) { int ret; PARAMS p; char *argv[] = {"vnstat", "--dbiflist", "0", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("etheverything"); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethnothing"); ck_assert_int_eq(ret, 1); suppress_output(); parseargs(&p, argc, argv); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(vnstat_parseargs_dbiflist_with_parseable_mode) { int ret; PARAMS p; char *argv[] = {"vnstat", "--dbiflist", "1", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; initparams(&p); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("etheverything"); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethnothing"); ck_assert_int_eq(ret, 1); suppress_output(); parseargs(&p, argc, argv); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(vnstat_parseargs_can_select_interface_without_parameter) { PARAMS p; char *argv[] = {"vnstat", "ethsomething", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; defaultcfg(); initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_str_eq(p.interface, "ethsomething"); ck_assert_int_eq(p.defaultiface, 0); } END_TEST START_TEST(vnstat_parseargs_can_select_interface_without_parameter_even_if_there_are_other_parameters) { PARAMS p; char *argv[] = {"vnstat", "-d", "ethsomethingtoo", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; defaultcfg(); initparams(&p); suppress_output(); ck_assert_int_ne(cfg.qmode, 1); parseargs(&p, argc, argv); ck_assert_str_eq(p.interface, "ethsomethingtoo"); ck_assert_int_eq(p.defaultiface, 0); ck_assert_int_eq(cfg.qmode, 1); } END_TEST START_TEST(vnstat_parseargs_can_select_interface_without_parameter_from_the_middle_of_the_parameter_list) { PARAMS p; char *argv[] = {"vnstat", "-m", "ethsomethings", "-ru", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; defaultcfg(); initparams(&p); suppress_output(); debug = 1; ck_assert_int_ne(cfg.qmode, 2); parseargs(&p, argc, argv); ck_assert_str_eq(p.interface, "ethsomethings"); ck_assert_int_eq(p.defaultiface, 0); ck_assert_int_eq(cfg.qmode, 2); } END_TEST START_TEST(vnstat_parseargs_knows_when_interface_name_is_too_long_even_without_parameter) { PARAMS p; char *argv[] = {"vnstat", "ethethethethethethethethethetheth", NULL}; int argc = sizeof(argv) / sizeof(char *) - 1; defaultcfg(); initparams(&p); suppress_output(); parseargs(&p, argc, argv); ck_assert_int_eq(p.defaultiface, 1); } END_TEST void add_parseargs_tests(Suite *s) { TCase *tc_pa = tcase_create("ParseArgs"); tcase_add_checked_fixture(tc_pa, setup, teardown); tcase_add_unchecked_fixture(tc_pa, setup, teardown); tcase_add_test(tc_pa, vnstat_parseargs_does_nothing_without_args); tcase_add_exit_test(tc_pa, vnstat_parseargs_can_help, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_can_longhelp, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_can_show_version, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_detects_unknown_parameters, 1); tcase_add_test(tc_pa, vnstat_parseargs_can_modify_settings); tcase_add_exit_test(tc_pa, vnstat_parseargs_does_not_allow_too_long_interface_names, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_style_requires_parameter, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_style_checks_parameter, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_knows_that_update_is_not_supported, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_dbdir_requires_a_directory, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_oneline_gives_help, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_xml_gives_help, 1); tcase_add_test(tc_pa, vnstat_parseargs_xml_without_extra_params); tcase_add_test(tc_pa, vnstat_parseargs_xml_with_mode); tcase_add_test(tc_pa, vnstat_parseargs_xml_with_limit); tcase_add_test(tc_pa, vnstat_parseargs_xml_with_mode_and_limit); tcase_add_exit_test(tc_pa, vnstat_parseargs_json_gives_help, 1); tcase_add_test(tc_pa, vnstat_parseargs_json_without_extra_params); tcase_add_test(tc_pa, vnstat_parseargs_json_with_mode); tcase_add_test(tc_pa, vnstat_parseargs_json_with_limit); tcase_add_test(tc_pa, vnstat_parseargs_json_with_mode_and_limit); tcase_add_exit_test(tc_pa, vnstat_parseargs_rateunit_gives_help, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_live_gives_help, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_begin_gives_help, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_end_gives_help, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_begin_validates_input, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_end_validates_input, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_can_show_config, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_iface_requires_parameter, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_locale_requires_parameter, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_setalias_requires_parameter, 1); tcase_add_test(tc_pa, vnstat_parseargs_setalias_still_supports_nick); tcase_add_exit_test(tc_pa, vnstat_parseargs_rename_requires_parameter, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_limit_requires_parameter, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_limit_cannot_be_negative, 1); tcase_add_test(tc_pa, vnstat_parseargs_limit_changes_defaults); tcase_add_test(tc_pa, vnstat_parseargs_limit_overrides); tcase_add_test(tc_pa, vnstat_parseargs_limit_overrides_regardless_of_position); tcase_add_exit_test(tc_pa, vnstat_parseargs_iflist_gives_help, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_iflist_without_parameters_and_no_interfaces, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_iflist_without_parameters_and_only_lo, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_iflist_without_parameters, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_iflist_with_verbose_mode, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_iflist_with_parseable_mode, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_gives_help, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_with_no_database, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_without_parameters_and_no_interfaces, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_without_parameters, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_with_verbose_mode, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_with_parseable_mode, 0); tcase_add_test(tc_pa, vnstat_parseargs_can_select_interface_without_parameter); tcase_add_test(tc_pa, vnstat_parseargs_can_select_interface_without_parameter_even_if_there_are_other_parameters); tcase_add_test(tc_pa, vnstat_parseargs_can_select_interface_without_parameter_from_the_middle_of_the_parameter_list); tcase_add_exit_test(tc_pa, vnstat_parseargs_knows_when_interface_name_is_too_long_even_without_parameter, 1); suite_add_tcase(s, tc_pa); } vnstat-2.9/tests/config_tests.h0000644000000000000000000000013013422305757015405 0ustar rootroot#ifndef CONFIG_TESTS_H #define CONFIG_TESTS_H void add_config_tests(Suite *s); #endif vnstat-2.9/tests/cli_tests.c0000644000000000000000000010735314171343332014712 0ustar rootroot#include "common.h" #include "vnstat_tests.h" #include "vnstat_func.h" #include "cfg.h" #include "dbsql.h" #include "cli_tests.h" START_TEST(vnstat_can_init_params) { PARAMS p; initparams(&p); } END_TEST START_TEST(vnstat_showhelp_does_not_crash) { PARAMS p; initparams(&p); strncpy_nt(p.definterface, "ethgone", 32); suppress_output(); showhelp(&p); } END_TEST START_TEST(vnstat_showlonghelp_does_not_crash) { PARAMS p; initparams(&p); strncpy_nt(p.definterface, "ethgone", 32); suppress_output(); showlonghelp(&p); } END_TEST START_TEST(vnstat_handlers_do_nothing_by_default) { PARAMS p, b; initparams(&p); memcpy(&b, &p, sizeof(PARAMS)); handleremoveinterface(&p); handlerenameinterface(&p); handleaddinterface(&p); handlesetalias(&p); handletrafficmeters(&p); ck_assert_int_eq(memcmp(&p, &b, sizeof(PARAMS)), 0); } END_TEST START_TEST(vnstat_handletrafficmeters_exists_when_interface_is_not_available) { PARAMS p; ck_assert_int_eq(remove_directory(TESTDIR), 1); initparams(&p); strncpy_nt(cfg.iface, "ethfoo", 32); strncpy_nt(p.interface, "default", 32); strncpy_nt(p.definterface, cfg.iface, 32); p.livetraffic = 1; suppress_output(); handletrafficmeters(&p); } END_TEST START_TEST(vnstat_handleremoveinterface_exits_if_no_interface_has_been_specified) { PARAMS p; initparams(&p); p.removeiface = 1; suppress_output(); handleremoveinterface(&p); } END_TEST START_TEST(vnstat_handleremoveinterface_exits_if_given_interface_does_not_exist) { int ret; PARAMS p; initparams(&p); p.removeiface = 1; p.defaultiface = 0; strncpy_nt(p.interface, "unknown", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("known"); ck_assert_int_eq(ret, 1); suppress_output(); handleremoveinterface(&p); } END_TEST START_TEST(vnstat_handleremoveinterface_exits_if_force_is_not_used) { int ret; PARAMS p; initparams(&p); p.removeiface = 1; p.defaultiface = 0; p.force = 0; strncpy_nt(p.interface, "known", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("known"); ck_assert_int_eq(ret, 1); suppress_output(); handleremoveinterface(&p); } END_TEST START_TEST(vnstat_handleremoveinterface_removes_interface) { int ret; PARAMS p; initparams(&p); p.removeiface = 1; p.defaultiface = 0; p.force = 1; strncpy_nt(p.interface, "known", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("known"); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecountbyname("known"); ck_assert_int_eq(ret, 1); suppress_output(); handleremoveinterface(&p); ret = (int)db_getinterfacecountbyname("known"); ck_assert_int_eq(ret, 0); } END_TEST START_TEST(vnstat_handlerenameinterface_exits_if_no_interface_has_been_specified) { PARAMS p; initparams(&p); p.renameiface = 1; suppress_output(); handlerenameinterface(&p); } END_TEST START_TEST(vnstat_handlerenameinterface_exits_if_new_interface_name_is_not_given) { PARAMS p; initparams(&p); p.renameiface = 1; p.defaultiface = 0; suppress_output(); handlerenameinterface(&p); } END_TEST START_TEST(vnstat_handlerenameinterface_exits_if_given_interface_does_not_exist) { int ret; PARAMS p; initparams(&p); p.renameiface = 1; p.defaultiface = 0; strncpy_nt(p.interface, "oldname", 32); strncpy_nt(p.newifname, "newname", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("somename"); ck_assert_int_eq(ret, 1); suppress_output(); handlerenameinterface(&p); } END_TEST START_TEST(vnstat_handlerenameinterface_exits_if_new_interface_name_already_exist) { int ret; PARAMS p; initparams(&p); p.renameiface = 1; p.defaultiface = 0; strncpy_nt(p.interface, "oldname", 32); strncpy_nt(p.newifname, "newname", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("oldname"); ck_assert_int_eq(ret, 1); ret = db_addinterface("newname"); ck_assert_int_eq(ret, 1); suppress_output(); handlerenameinterface(&p); } END_TEST START_TEST(vnstat_handlerenameinterface_exits_if_force_is_not_used) { int ret; PARAMS p; initparams(&p); p.renameiface = 1; p.defaultiface = 0; p.force = 0; strncpy_nt(p.interface, "oldname", 32); strncpy_nt(p.newifname, "newname", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("oldname"); ck_assert_int_eq(ret, 1); suppress_output(); handlerenameinterface(&p); } END_TEST START_TEST(vnstat_handlerenameinterface_renames_interface) { int ret; PARAMS p; initparams(&p); p.renameiface = 1; p.defaultiface = 0; p.force = 1; strncpy_nt(p.interface, "oldname", 32); strncpy_nt(p.newifname, "newname", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("oldname"); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecountbyname("oldname"); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecountbyname("newname"); ck_assert_int_eq(ret, 0); suppress_output(); handlerenameinterface(&p); ret = (int)db_getinterfacecountbyname("oldname"); ck_assert_int_eq(ret, 0); ret = (int)db_getinterfacecountbyname("newname"); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(vnstat_handleaddinterface_exits_if_no_interface_has_been_specified) { PARAMS p; initparams(&p); p.addiface = 1; suppress_output(); handleaddinterface(&p); } END_TEST START_TEST(vnstat_handleaddinterface_exits_if_interface_already_exist_in_database) { int ret; PARAMS p; initparams(&p); p.addiface = 1; p.defaultiface = 0; strncpy_nt(p.interface, "newiface", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("newiface"); ck_assert_int_eq(ret, 1); suppress_output(); handleaddinterface(&p); } END_TEST START_TEST(vnstat_handleaddinterface_exits_if_interface_does_not_exist) { int ret; PARAMS p; initparams(&p); p.addiface = 1; p.defaultiface = 0; strncpy_nt(p.interface, "newiface", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "notnewiface", 0, 0, 0, 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); suppress_output(); handleaddinterface(&p); } END_TEST START_TEST(vnstat_handleaddinterface_adds_interface) { int ret; PARAMS p; initparams(&p); p.addiface = 1; p.defaultiface = 0; cfg.spacecheck = 0; strncpy_nt(p.interface, "newiface", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "newiface", 0, 0, 0, 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecountbyname("newiface"); ck_assert_int_eq(ret, 0); suppress_output(); handleaddinterface(&p); ret = (int)db_getinterfacecountbyname("newiface"); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(vnstat_handleaddinterface_can_be_forced_to_add_interface_that_does_not_exist) { int ret; PARAMS p; initparams(&p); p.addiface = 1; p.defaultiface = 0; p.force = 1; cfg.spacecheck = 0; strncpy_nt(p.interface, "newiface", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "notnewiface", 0, 0, 0, 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecountbyname("newiface"); ck_assert_int_eq(ret, 0); suppress_output(); handleaddinterface(&p); ret = (int)db_getinterfacecountbyname("newiface"); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(vnstat_handlesetalias_exits_if_no_interface_has_been_specified) { PARAMS p; initparams(&p); p.setalias = 1; suppress_output(); handlesetalias(&p); } END_TEST START_TEST(vnstat_handlesetalias_exits_if_given_interface_does_not_exist) { int ret; PARAMS p; initparams(&p); p.setalias = 1; p.defaultiface = 0; strncpy_nt(p.interface, "ethiface", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("somename"); ck_assert_int_eq(ret, 1); suppress_output(); handlesetalias(&p); } END_TEST START_TEST(vnstat_handlesetalias_sets_alias) { int ret; PARAMS p; interfaceinfo info; initparams(&p); p.setalias = 1; p.defaultiface = 0; strncpy_nt(p.interface, "ethiface", 32); strncpy_nt(p.alias, "The Internet", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethiface"); ck_assert_int_eq(ret, 1); ret = db_getinterfaceinfo("ethiface", &info); ck_assert_int_eq(ret, 1); ck_assert_str_eq(info.alias, ""); suppress_output(); handlesetalias(&p); ret = db_getinterfaceinfo("ethiface", &info); ck_assert_int_eq(ret, 1); ck_assert_str_eq(info.alias, "The Internet"); } END_TEST START_TEST(vnstat_handlesetalias_clears_alias) { int ret; PARAMS p; interfaceinfo info; initparams(&p); p.setalias = 1; p.defaultiface = 0; strncpy_nt(p.interface, "ethiface", 32); strncpy_nt(p.alias, "", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethiface"); ck_assert_int_eq(ret, 1); ret = db_setalias("ethiface", "Local network"); ck_assert_int_eq(ret, 1); ret = db_getinterfaceinfo("ethiface", &info); ck_assert_int_eq(ret, 1); ck_assert_str_eq(info.alias, "Local network"); suppress_output(); handlesetalias(&p); ret = db_getinterfaceinfo("ethiface", &info); ck_assert_int_eq(ret, 1); ck_assert_str_eq(info.alias, ""); } END_TEST START_TEST(vnstat_handleaddinterface_can_also_set_alias_after_adding_interface) { int ret; PARAMS p; interfaceinfo info; initparams(&p); p.addiface = 1; p.setalias = 1; p.defaultiface = 0; cfg.spacecheck = 0; strncpy_nt(p.interface, "newiface", 32); strncpy_nt(p.alias, "The Interface", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "newiface", 0, 0, 0, 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecountbyname("newiface"); ck_assert_int_eq(ret, 0); suppress_output(); handleaddinterface(&p); ret = (int)db_getinterfacecountbyname("newiface"); ck_assert_int_eq(ret, 1); ret = db_getinterfaceinfo("newiface", &info); ck_assert_int_eq(ret, 1); ck_assert_str_eq(info.alias, "The Interface"); } END_TEST START_TEST(vnstat_handletrafficmeters_exits_when_interface_is_not_available) { PARAMS p; initparams(&p); p.traffic = 1; p.defaultiface = 1; strncpy_nt(p.interface, "someiface", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "otheriface", 0, 0, 0, 0); suppress_output(); handletrafficmeters(&p); } END_TEST START_TEST(vnstat_handletrafficmeters_exits_when_interface_is_not_available_with_configuration_tips) { PARAMS p; initparams(&p); p.traffic = 1; p.defaultiface = 1; strncpy_nt(p.interface, "someiface", 32); strncpy_nt(cfg.cfgfile, "I_do_not_have_a_config_file_here.something", 512); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "otheriface", 0, 0, 0, 0); suppress_output(); handletrafficmeters(&p); } END_TEST START_TEST(vnstat_handletrafficmeters_exits_when_specific_interface_is_not_available) { PARAMS p; initparams(&p); p.traffic = 1; p.defaultiface = 0; strncpy_nt(p.interface, "someiface", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "otheriface", 0, 0, 0, 0); suppress_output(); handletrafficmeters(&p); } END_TEST START_TEST(vnstat_handletrafficmeters_can_calculate_traffic) { PARAMS p; initparams(&p); p.traffic = 1; p.defaultiface = 0; cfg.qmode = 1; cfg.sampletime = 0; strncpy_nt(p.interface, "someiface", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "someiface", 0, 0, 0, 0); suppress_output(); handletrafficmeters(&p); } END_TEST START_TEST(vnstat_handletrafficmeters_can_handle_interface_merge_using_first_interface) { PARAMS p; initparams(&p); p.traffic = 1; p.defaultiface = 0; cfg.qmode = 1; cfg.sampletime = 0; strncpy_nt(p.interface, "someiface+anotherinterface", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "someiface", 0, 0, 0, 0); suppress_output(); handletrafficmeters(&p); } END_TEST START_TEST(vnstat_handletrafficmeters_can_calculate_traffic_and_output_json) { PARAMS p; initparams(&p); p.traffic = 1; p.defaultiface = 0; cfg.qmode = 10; cfg.sampletime = 0; strncpy_nt(p.interface, "someiface", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "someiface", 0, 0, 0, 0); suppress_output(); handletrafficmeters(&p); } END_TEST START_TEST(vnstat_handletrafficmeters_livetraffic_does_not_crash) { PARAMS p; initparams(&p); p.livetraffic = 1; p.defaultiface = 0; cfg.qmode = 1; cfg.ostyle = 0; cfg.sampletime = 0; strncpy_nt(p.interface, "someiface", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "someiface", 0, 0, 0, 0); suppress_output(); handletrafficmeters(&p); } END_TEST START_TEST(vnstat_handletrafficmeters_livetraffic_does_not_crash_with_interface_merge) { PARAMS p; initparams(&p); p.livetraffic = 1; p.defaultiface = 0; cfg.qmode = 1; cfg.ostyle = 0; cfg.sampletime = 0; strncpy_nt(p.interface, "someiface+anotherinterface", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "someiface", 0, 0, 0, 0); suppress_output(); handletrafficmeters(&p); } END_TEST START_TEST(vnstat_handletrafficmeters_livetraffic_does_not_crash_with_json) { PARAMS p; initparams(&p); p.livetraffic = 1; p.defaultiface = 0; cfg.qmode = 10; cfg.sampletime = 0; strncpy_nt(p.interface, "someiface", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "someiface", 0, 0, 0, 0); suppress_output(); handletrafficmeters(&p); } END_TEST START_TEST(handleifselection_does_nothing_when_interface_has_already_been_selected) { PARAMS p; initparams(&p); p.defaultiface = 0; strncpy_nt(p.interface, "myiface", 32); handleifselection(&p); ck_assert_str_eq(p.interface, "myiface"); } END_TEST START_TEST(handleifselection_selects_default_interface_if_field_is_filled) { PARAMS p; initparams(&p); p.defaultiface = 1; strncpy_nt(p.interface, "default", 32); strncpy_nt(p.definterface, "myiface", 32); handleifselection(&p); ck_assert_str_eq(p.interface, "myiface"); ck_assert_str_eq(p.definterface, "myiface"); } END_TEST START_TEST(handleifselection_exits_when_no_suitable_interface_is_available_for_query) { int ret; PARAMS p; initparams(&p); p.defaultiface = 1; p.query = 1; strncpy_nt(p.interface, "default", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); /* no interfaces added to database */ suppress_output(); handleifselection(&p); } END_TEST START_TEST(handleifselection_selects_only_interface_from_database_for_query) { int ret; PARAMS p; initparams(&p); p.defaultiface = 1; p.query = 1; strncpy_nt(p.interface, "default", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("lettherebemagic"); ck_assert_int_eq(ret, 1); handleifselection(&p); ck_assert_str_eq(p.interface, "lettherebemagic"); } END_TEST START_TEST(handleifselection_selects_highest_traffic_interface_from_database_for_query) { int ret; PARAMS p; initparams(&p); p.defaultiface = 1; p.query = 1; strncpy_nt(p.interface, "default", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethslow"); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethfast"); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethone"); ck_assert_int_eq(ret, 1); ret = db_settotal("ethslow", 100, 200); ck_assert_int_eq(ret, 1); ret = db_settotal("ethfast", 80, 9001); ck_assert_int_eq(ret, 1); ret = db_settotal("ethone", 1, 1); ck_assert_int_eq(ret, 1); handleifselection(&p); /* interface with most traffic in database is selected */ ck_assert_str_eq(p.interface, "ethfast"); } END_TEST START_TEST(handleifselection_exits_when_no_suitable_interface_is_available_for_traffic) { PARAMS p; initparams(&p); p.defaultiface = 1; p.query = 0; p.traffic = 1; strncpy_nt(p.interface, "default", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); /* database not available and interface listing provides nothing */ suppress_output(); handleifselection(&p); } END_TEST START_TEST(handleifselection_can_select_interface_without_database_for_traffic) { PARAMS p; initparams(&p); p.defaultiface = 1; p.query = 0; p.traffic = 1; strncpy_nt(p.interface, "default", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "firstinterface", 0, 0, 0, 0); fake_proc_net_dev("a", "secondinterface", 0, 0, 0, 0); suppress_output(); handleifselection(&p); /* first available interface is selected */ ck_assert_str_eq(p.interface, "firstinterface"); } END_TEST START_TEST(handleifselection_exits_if_only_database_shows_interfaces_for_traffic) { int ret; PARAMS p; initparams(&p); p.defaultiface = 1; p.query = 0; p.traffic = 1; strncpy_nt(p.interface, "default", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethsomething"); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethnothing"); ck_assert_int_eq(ret, 1); suppress_output(); handleifselection(&p); } END_TEST START_TEST(handleifselection_selects_only_available_interfaces_for_traffic) { int ret; PARAMS p; initparams(&p); p.defaultiface = 1; p.query = 0; p.traffic = 1; strncpy_nt(p.interface, "default", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "ethnone", 0, 0, 0, 0); fake_proc_net_dev("a", "ethslow", 0, 0, 0, 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethslow"); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethfast"); ck_assert_int_eq(ret, 1); ret = db_settotal("ethslow", 100, 200); ck_assert_int_eq(ret, 1); ret = db_settotal("ethfast", 80, 9001); ck_assert_int_eq(ret, 1); handleifselection(&p); /* interface with most traffic in database the is also available is selected */ ck_assert_str_eq(p.interface, "ethslow"); } END_TEST START_TEST(handleifselection_selects_only_available_interfaces_and_can_ignore_database_for_traffic) { int ret; PARAMS p; initparams(&p); p.defaultiface = 1; p.query = 0; p.traffic = 1; strncpy_nt(p.interface, "default", 32); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "ethnone", 0, 0, 0, 0); fake_proc_net_dev("a", "ethall", 0, 0, 0, 0); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethslow"); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethfast"); ck_assert_int_eq(ret, 1); ret = db_settotal("ethslow", 100, 200); ck_assert_int_eq(ret, 1); ret = db_settotal("ethfast", 80, 9001); ck_assert_int_eq(ret, 1); handleifselection(&p); /* first available interface is selected if none of the interfaces in database are available */ ck_assert_str_eq(p.interface, "ethnone"); } END_TEST START_TEST(showalerthelp_does_not_crash) { suppress_output(); showalerthelp(); } END_TEST START_TEST(parsealertargs_knows_which_parameters_belong_to_it) { int ret; PARAMS p; char *argv[] = {"--alert", "1", "2", "--days", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 0); ck_assert_int_eq(p.alertexit, 0); ck_assert_int_eq(p.alerttype, 0); ck_assert_int_eq(p.alertcondition, 0); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_helps_when_asked) { int ret; PARAMS p; char *argv[] = {"--alert", "1", "2", "--help", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 0); ck_assert_int_eq(p.alertexit, 0); ck_assert_int_eq(p.alerttype, 0); ck_assert_int_eq(p.alertcondition, 0); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_can_set_parameters) { int ret; PARAMS p; char *argv[] = {"--alert", "1", "2", "y", "total", "5", "KiB", NULL}; defaultcfg(); initparams(&p); debug = 1; suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 1); ck_assert_int_eq(p.alertoutput, 1); ck_assert_int_eq(p.alertexit, 2); ck_assert_int_eq(p.alerttype, 4); ck_assert_int_eq(p.alertcondition, 3); ck_assert_int_eq(p.alertlimit, 5120); } END_TEST START_TEST(parsealertargs_can_validate_output) { int ret; PARAMS p; char *argv[] = {"--alert", "a", "2", "y", "total", "5", "KiB", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 0); ck_assert_int_eq(p.alertexit, 0); ck_assert_int_eq(p.alerttype, 0); ck_assert_int_eq(p.alertcondition, 0); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_can_validate_output_range) { int ret; PARAMS p; char *argv[] = {"--alert", "4", "2", "y", "total", "5", "KiB", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 4); ck_assert_int_eq(p.alertexit, 0); ck_assert_int_eq(p.alerttype, 0); ck_assert_int_eq(p.alertcondition, 0); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_can_validate_exit) { int ret; PARAMS p; char *argv[] = {"--alert", "1", "b", "y", "total", "5", "KiB", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 1); ck_assert_int_eq(p.alertexit, 0); ck_assert_int_eq(p.alerttype, 0); ck_assert_int_eq(p.alertcondition, 0); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_can_validate_exit_range) { int ret; PARAMS p; char *argv[] = {"--alert", "1", "4", "y", "total", "5", "KiB", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 1); ck_assert_int_eq(p.alertexit, 4); ck_assert_int_eq(p.alerttype, 0); ck_assert_int_eq(p.alertcondition, 0); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_knows_first_useless_parameter_combination) { int ret; PARAMS p; char *argv[] = {"--alert", "0", "0", "y", "total", "5", "KiB", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 0); ck_assert_int_eq(p.alertexit, 0); ck_assert_int_eq(p.alerttype, 0); ck_assert_int_eq(p.alertcondition, 0); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_knows_second_useless_parameter_combination) { int ret; PARAMS p; char *argv[] = {"--alert", "0", "1", "y", "total", "5", "KiB", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 0); ck_assert_int_eq(p.alertexit, 1); ck_assert_int_eq(p.alerttype, 0); ck_assert_int_eq(p.alertcondition, 0); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_can_validate_type) { int ret; PARAMS p; char *argv[] = {"--alert", "1", "2", "a", "total", "5", "KiB", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 1); ck_assert_int_eq(p.alertexit, 2); ck_assert_int_eq(p.alerttype, 0); ck_assert_int_eq(p.alertcondition, 0); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_can_validate_condition) { int ret; PARAMS p; char *argv[] = {"--alert", "1", "2", "y", "total_recall", "5", "KiB", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 1); ck_assert_int_eq(p.alertexit, 2); ck_assert_int_eq(p.alerttype, 4); ck_assert_int_eq(p.alertcondition, 0); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_knows_first_invalid_condition_combination) { int ret; PARAMS p; char *argv[] = {"--alert", "2", "3", "y", "rx_estimate", "5", "KiB", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 2); ck_assert_int_eq(p.alertexit, 3); ck_assert_int_eq(p.alerttype, 4); ck_assert_int_eq(p.alertcondition, 4); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_knows_second_invalid_condition_combination) { int ret; PARAMS p; char *argv[] = {"--alert", "3", "2", "y", "tx_estimate", "5", "KiB", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 3); ck_assert_int_eq(p.alertexit, 2); ck_assert_int_eq(p.alerttype, 4); ck_assert_int_eq(p.alertcondition, 5); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_can_validate_limit_as_integer) { int ret; PARAMS p; char *argv[] = {"--alert", "1", "2", "y", "total", "5.5", "KiB", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 1); ck_assert_int_eq(p.alertexit, 2); ck_assert_int_eq(p.alerttype, 4); ck_assert_int_eq(p.alertcondition, 3); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_can_validate_limit_as_non_zero) { int ret; PARAMS p; char *argv[] = {"--alert", "1", "2", "y", "total", "0", "KiB", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 1); ck_assert_int_eq(p.alertexit, 2); ck_assert_int_eq(p.alerttype, 4); ck_assert_int_eq(p.alertcondition, 3); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_can_validate_limit_unit) { int ret; PARAMS p; char *argv[] = {"--alert", "1", "2", "y", "total", "5", "KeK", NULL}; defaultcfg(); initparams(&p); suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 1); ck_assert_int_eq(p.alertexit, 2); ck_assert_int_eq(p.alerttype, 4); ck_assert_int_eq(p.alertcondition, 3); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(parsealertargs_knows_the_64_bit_limit_regardless_of_used_unit) { int ret; PARAMS p; char *argv[] = {"--alert", "1", "2", "y", "total", "16", "EiB", NULL}; defaultcfg(); initparams(&p); debug = 1; suppress_output(); ret = parsealertargs(&p, argv); ck_assert_int_eq(ret, 0); ck_assert_int_eq(p.alertoutput, 1); ck_assert_int_eq(p.alertexit, 2); ck_assert_int_eq(p.alerttype, 4); ck_assert_int_eq(p.alertcondition, 3); ck_assert_int_eq(p.alertlimit, 0); } END_TEST START_TEST(handleshowalert_requires_interface_to_be_specified) { PARAMS p; defaultcfg(); initparams(&p); suppress_output(); p.alert = 1; p.defaultiface = 1; handleshowalert(&p); } END_TEST START_TEST(validateinterface_does_not_use_alias_if_interface_names_matches) { int ret; PARAMS p; defaultcfg(); initparams(&p); strncpy_nt(p.interface, "eth0", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth0", "LAN"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth1", "eth0"); ck_assert_int_eq(ret, 1); validateinterface(&p); ck_assert_str_eq(p.interface, "eth0"); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(validateinterface_supports_interface_merges) { int ret; PARAMS p; defaultcfg(); initparams(&p); strncpy_nt(p.interface, "eth0+eth1", 32); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth0", "LAN"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth1", "Internet"); ck_assert_int_eq(ret, 1); validateinterface(&p); ck_assert_str_eq(p.interface, "eth0+eth1"); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(validateinterface_detects_if_not_all_interfaces_are_available_for_merge) { int ret; PARAMS p; defaultcfg(); initparams(&p); strncpy_nt(p.interface, "eth0+eth2", 32); suppress_output(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth0", "LAN"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth1", "Internet"); ck_assert_int_eq(ret, 1); validateinterface(&p); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(validateinterface_detects_if_not_all_interfaces_are_unique_for_merge) { int ret; PARAMS p; defaultcfg(); initparams(&p); strncpy_nt(p.interface, "eth0+eth0", 32); suppress_output(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth0", "LAN"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth1", "Internet"); ck_assert_int_eq(ret, 1); validateinterface(&p); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(validateinterface_uses_all_matching_methods_if_no_match_for_exact_name_is_found) { int ret; PARAMS p; defaultcfg(); initparams(&p); debug = 1; cfg.ifacematchmethod = 3; strncpy_nt(p.interface, "inter", 32); suppress_output(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth0", "LAN"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth1", "Internet"); ck_assert_int_eq(ret, 1); validateinterface(&p); ck_assert_str_eq(p.interface, "eth1"); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(validateinterface_knows_when_to_give_up_searching) { int ret; PARAMS p; defaultcfg(); initparams(&p); debug = 1; cfg.ifacematchmethod = 3; strncpy_nt(p.interface, "outer", 32); suppress_output(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth0"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth0", "LAN"); ck_assert_int_eq(ret, 1); ret = db_addinterface("eth1"); ck_assert_int_eq(ret, 1); ret = db_setalias("eth1", "Internet"); ck_assert_int_eq(ret, 1); validateinterface(&p); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST void add_cli_tests(Suite *s) { TCase *tc_cli = tcase_create("CLI"); tcase_add_checked_fixture(tc_cli, setup, teardown); tcase_add_unchecked_fixture(tc_cli, setup, teardown); tcase_add_test(tc_cli, vnstat_can_init_params); tcase_add_test(tc_cli, vnstat_showhelp_does_not_crash); tcase_add_test(tc_cli, vnstat_showlonghelp_does_not_crash); tcase_add_test(tc_cli, vnstat_handlers_do_nothing_by_default); tcase_add_exit_test(tc_cli, vnstat_handletrafficmeters_exists_when_interface_is_not_available, 1); tcase_add_exit_test(tc_cli, vnstat_handleremoveinterface_exits_if_no_interface_has_been_specified, 1); tcase_add_exit_test(tc_cli, vnstat_handleremoveinterface_exits_if_given_interface_does_not_exist, 1); tcase_add_exit_test(tc_cli, vnstat_handleremoveinterface_exits_if_force_is_not_used, 1); tcase_add_test(tc_cli, vnstat_handleremoveinterface_removes_interface); tcase_add_exit_test(tc_cli, vnstat_handlerenameinterface_exits_if_no_interface_has_been_specified, 1); tcase_add_exit_test(tc_cli, vnstat_handlerenameinterface_exits_if_new_interface_name_is_not_given, 1); tcase_add_exit_test(tc_cli, vnstat_handlerenameinterface_exits_if_given_interface_does_not_exist, 1); tcase_add_exit_test(tc_cli, vnstat_handlerenameinterface_exits_if_new_interface_name_already_exist, 1); tcase_add_exit_test(tc_cli, vnstat_handlerenameinterface_exits_if_force_is_not_used, 1); tcase_add_test(tc_cli, vnstat_handlerenameinterface_renames_interface); tcase_add_exit_test(tc_cli, vnstat_handleaddinterface_exits_if_no_interface_has_been_specified, 1); tcase_add_exit_test(tc_cli, vnstat_handleaddinterface_exits_if_interface_already_exist_in_database, 1); tcase_add_exit_test(tc_cli, vnstat_handleaddinterface_exits_if_interface_does_not_exist, 1); tcase_add_test(tc_cli, vnstat_handleaddinterface_adds_interface); tcase_add_test(tc_cli, vnstat_handleaddinterface_can_be_forced_to_add_interface_that_does_not_exist); tcase_add_exit_test(tc_cli, vnstat_handlesetalias_exits_if_no_interface_has_been_specified, 1); tcase_add_exit_test(tc_cli, vnstat_handlesetalias_exits_if_given_interface_does_not_exist, 1); tcase_add_test(tc_cli, vnstat_handlesetalias_sets_alias); tcase_add_test(tc_cli, vnstat_handlesetalias_clears_alias); tcase_add_test(tc_cli, vnstat_handleaddinterface_can_also_set_alias_after_adding_interface); tcase_add_exit_test(tc_cli, vnstat_handletrafficmeters_exits_when_interface_is_not_available, 1); tcase_add_exit_test(tc_cli, vnstat_handletrafficmeters_exits_when_interface_is_not_available_with_configuration_tips, 1); tcase_add_exit_test(tc_cli, vnstat_handletrafficmeters_exits_when_specific_interface_is_not_available, 1); tcase_add_test(tc_cli, vnstat_handletrafficmeters_can_calculate_traffic); tcase_add_test(tc_cli, vnstat_handletrafficmeters_can_handle_interface_merge_using_first_interface); tcase_add_test(tc_cli, vnstat_handletrafficmeters_can_calculate_traffic_and_output_json); tcase_add_test(tc_cli, vnstat_handletrafficmeters_livetraffic_does_not_crash); tcase_add_test(tc_cli, vnstat_handletrafficmeters_livetraffic_does_not_crash_with_interface_merge); tcase_add_test(tc_cli, vnstat_handletrafficmeters_livetraffic_does_not_crash_with_json); tcase_add_test(tc_cli, handleifselection_does_nothing_when_interface_has_already_been_selected); tcase_add_test(tc_cli, handleifselection_selects_default_interface_if_field_is_filled); tcase_add_exit_test(tc_cli, handleifselection_exits_when_no_suitable_interface_is_available_for_query, 1); tcase_add_test(tc_cli, handleifselection_selects_only_interface_from_database_for_query); tcase_add_test(tc_cli, handleifselection_selects_highest_traffic_interface_from_database_for_query); tcase_add_exit_test(tc_cli, handleifselection_exits_when_no_suitable_interface_is_available_for_traffic, 1); tcase_add_test(tc_cli, handleifselection_can_select_interface_without_database_for_traffic); tcase_add_exit_test(tc_cli, handleifselection_exits_if_only_database_shows_interfaces_for_traffic, 1); tcase_add_test(tc_cli, handleifselection_selects_only_available_interfaces_for_traffic); tcase_add_test(tc_cli, handleifselection_selects_only_available_interfaces_and_can_ignore_database_for_traffic); tcase_add_test(tc_cli, showalerthelp_does_not_crash); tcase_add_test(tc_cli, parsealertargs_knows_which_parameters_belong_to_it); tcase_add_test(tc_cli, parsealertargs_helps_when_asked); tcase_add_test(tc_cli, parsealertargs_can_set_parameters); tcase_add_test(tc_cli, parsealertargs_can_validate_output); tcase_add_test(tc_cli, parsealertargs_can_validate_output_range); tcase_add_test(tc_cli, parsealertargs_can_validate_exit); tcase_add_test(tc_cli, parsealertargs_can_validate_exit_range); tcase_add_test(tc_cli, parsealertargs_knows_first_useless_parameter_combination); tcase_add_test(tc_cli, parsealertargs_knows_second_useless_parameter_combination); tcase_add_test(tc_cli, parsealertargs_can_validate_type); tcase_add_test(tc_cli, parsealertargs_can_validate_condition); tcase_add_test(tc_cli, parsealertargs_knows_first_invalid_condition_combination); tcase_add_test(tc_cli, parsealertargs_knows_second_invalid_condition_combination); tcase_add_test(tc_cli, parsealertargs_can_validate_limit_as_integer); tcase_add_test(tc_cli, parsealertargs_can_validate_limit_as_non_zero); tcase_add_test(tc_cli, parsealertargs_can_validate_limit_unit); tcase_add_test(tc_cli, parsealertargs_knows_the_64_bit_limit_regardless_of_used_unit); tcase_add_exit_test(tc_cli, handleshowalert_requires_interface_to_be_specified, 1); tcase_add_test(tc_cli, validateinterface_does_not_use_alias_if_interface_names_matches); tcase_add_test(tc_cli, validateinterface_supports_interface_merges); tcase_add_exit_test(tc_cli, validateinterface_detects_if_not_all_interfaces_are_available_for_merge, 1); tcase_add_exit_test(tc_cli, validateinterface_detects_if_not_all_interfaces_are_unique_for_merge, 1); tcase_add_test(tc_cli, validateinterface_uses_all_matching_methods_if_no_match_for_exact_name_is_found); tcase_add_exit_test(tc_cli, validateinterface_knows_when_to_give_up_searching, 1); suite_add_tcase(s, tc_cli); } vnstat-2.9/tests/database_tests.c0000644000000000000000000006042214171101403015671 0ustar rootroot#include "common.h" #include "vnstat_tests.h" #include "database_tests.h" #include "dbaccess.h" #include "ifinfo.h" #include "dbsql.h" #include "dbshow.h" #include "dbxml.h" #include "dbjson.h" #include "cfg.h" #include "ibw.h" #include "fs.h" int writedb(DATA *data, const char *iface, const char *dirname, int newdb); int backupdb(const char *current, const char *backup); START_TEST(initdb_activates_database) { DATA data; initdb(&data); ck_assert_int_eq(data.active, 1); } END_TEST START_TEST(readdb_with_empty_file) { DATA data; disable_logprints(); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(create_zerosize_dbfile("existingdb"), 1); ck_assert_int_eq(readdb(&data, "existingdb", TESTDBDIR, 0), -1); } END_TEST START_TEST(readdb_with_empty_file_and_backup) { DATA data; disable_logprints(); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(create_zerosize_dbfile("existingdb"), 1); ck_assert_int_eq(create_zerosize_dbfile(".existingdb"), 1); ck_assert_int_eq(readdb(&data, "existingdb", TESTDBDIR, 0), -1); } END_TEST START_TEST(readdb_with_nonexisting_file) { DATA data; disable_logprints(); strcpy(data.interface, "none"); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(readdb(&data, "existingdb", TESTDBDIR, 0), 1); ck_assert_str_eq(data.interface, "existingdb"); ck_assert_str_eq(data.nick, "existingdb"); } END_TEST START_TEST(readdb_with_existing_dbfile) { DATA data; initdb(&data); disable_logprints(); strcpy(data.interface, "ethtest"); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(writedb(&data, "ethtest", TESTDBDIR, 1), 1); ck_assert_int_eq(check_dbfile_exists("ethtest", sizeof(DATA)), 1); strcpy(data.interface, "none"); ck_assert_int_eq(readdb(&data, "ethtest", TESTDBDIR, 0), 0); ck_assert_str_eq(data.interface, "ethtest"); } END_TEST START_TEST(readdb_with_existing_dbfile_and_max_name_length) { DATA data; initdb(&data); disable_logprints(); strcpy(data.interface, "1234567890123456789012345678901"); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(writedb(&data, "1234567890123456789012345678901", TESTDBDIR, 1), 1); ck_assert_int_eq(check_dbfile_exists("1234567890123456789012345678901", sizeof(DATA)), 1); strcpy(data.interface, "none"); ck_assert_int_eq(readdb(&data, "1234567890123456789012345678901", TESTDBDIR, 0), 0); ck_assert_str_eq(data.interface, "1234567890123456789012345678901"); } END_TEST START_TEST(readdb_with_existing_dbfile_with_rename) { DATA data; initdb(&data); disable_logprints(); strcpy(data.interface, "ethtest"); strcpy(data.nick, "ethtest"); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(writedb(&data, "ethtest2", TESTDBDIR, 1), 1); ck_assert_int_eq(check_dbfile_exists("ethtest2", sizeof(DATA)), 1); strcpy(data.interface, "none"); strcpy(data.nick, "none"); ck_assert_int_eq(readdb(&data, "ethtest2", TESTDBDIR, 0), 0); ck_assert_str_eq(data.interface, "ethtest2"); ck_assert_str_eq(data.nick, "ethtest2"); } END_TEST START_TEST(readdb_with_existing_dbfile_and_over_max_name_length) { DATA data; initdb(&data); disable_logprints(); strcpy(data.interface, "dummy"); strcpy(data.nick, "dummy"); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(writedb(&data, "1234567890123456789012345678901XX", TESTDBDIR, 1), 1); ck_assert_int_eq(check_dbfile_exists("1234567890123456789012345678901XX", sizeof(DATA)), 1); strcpy(data.interface, "none"); strcpy(data.nick, "none"); ck_assert_int_eq(readdb(&data, "1234567890123456789012345678901XX", TESTDBDIR, 0), 0); ck_assert_str_eq(data.interface, "1234567890123456789012345678901"); ck_assert_str_eq(data.nick, "1234567890123456789012345678901"); } END_TEST START_TEST(validatedb_with_initdb) { DATA data; initdb(&data); strcpy(data.interface, "ethtest"); ck_assert_int_eq(validatedb(&data), 1); } END_TEST START_TEST(validatedb_with_invalid_totals) { DATA data; initdb(&data); suppress_output(); strcpy(data.interface, "ethtest"); data.day[0].rx++; ck_assert_int_eq(validatedb(&data), 0); } END_TEST START_TEST(validatedb_with_top10_use) { DATA data; initdb(&data); suppress_output(); strcpy(data.interface, "ethtest"); data.top10[0].used = 1; data.top10[1].used = 1; data.top10[2].used = 1; data.top10[5].used = 1; ck_assert_int_eq(validatedb(&data), 0); } END_TEST START_TEST(database_outputs_do_not_crash) { int ret, i; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("something"); ck_assert_int_eq(ret, 1); for (i = 1; i < 100; i++) { ret = db_addtraffic_dated("something", (uint64_t)i * 1234, (uint64_t)i * 2345, (uint64_t)i * 85000); ck_assert_int_eq(ret, 1); } ret = db_setupdated("something", (time_t)i * 85000); ck_assert_int_eq(ret, 1); suppress_output(); for (i = 0; i <= 4; i++) { cfg.ostyle = i; showdb("something", 0, "", ""); showdb("something", 1, "", ""); showdb("something", 2, "", ""); showdb("something", 3, "", ""); showdb("something", 4, "", ""); showdb("something", 5, "", ""); showdb("something", 6, "", ""); showdb("something", 7, "", ""); showdb("something", 8, "", ""); showdb("something", 9, "", ""); showdb("something", 10, "", ""); showdb("something", 11, "", ""); showdb("something", 12, "", ""); showdb("nothing", 0, "", ""); } xmlheader(); showxml("something", 'd', "", ""); showxml("something", 'm', "", ""); showxml("something", 't', "", ""); showxml("something", 'h', "", ""); showxml("something", 'y', "", ""); showxml("something", 'f', "", ""); showxml("something", 'a', "", ""); showxml("nothing", 'a', "", ""); xmlfooter(); jsonheader(); showjson("something", 0, 'd', "", ""); showjson("something", 0, 'm', "", ""); showjson("something", 0, 't', "", ""); showjson("something", 0, 'h', "", ""); showjson("something", 0, 'y', "", ""); showjson("something", 0, 'f', "", ""); showjson("something", 1, 'a', "", ""); showjson("nothing", 0, 'a', "", ""); jsonfooter(); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(database_outputs_do_not_crash_without_traffic) { int ret, i; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("something"); ck_assert_int_eq(ret, 1); ret = db_addtraffic_dated("something", 0, 0, 85000); ck_assert_int_eq(ret, 1); ret = db_setupdated("something", 85000); ck_assert_int_eq(ret, 1); suppress_output(); for (i = 0; i <= 4; i++) { cfg.ostyle = i; showdb("something", 0, "", ""); showdb("something", 1, "", ""); showdb("something", 2, "", ""); showdb("something", 3, "", ""); showdb("something", 4, "", ""); showdb("something", 5, "", ""); showdb("something", 6, "", ""); showdb("something", 7, "", ""); showdb("something", 8, "", ""); showdb("something", 9, "", ""); showdb("something", 10, "", ""); showdb("something", 11, "", ""); showdb("something", 12, "", ""); showdb("nothing", 0, "", ""); } xmlheader(); showxml("something", 'd', "", ""); showxml("something", 'm', "", ""); showxml("something", 't', "", ""); showxml("something", 'h', "", ""); showxml("something", 'y', "", ""); showxml("something", 'f', "", ""); showxml("something", 'a', "", ""); xmlfooter(); jsonheader(); showjson("something", 0, 'd', "", ""); showjson("something", 0, 'm', "", ""); showjson("something", 0, 't', "", ""); showjson("something", 0, 'h', "", ""); showjson("something", 0, 'y', "", ""); showjson("something", 0, 'f', "", ""); showjson("something", 1, 'a', "", ""); showjson("nothing", 0, 'a', "", ""); jsonfooter(); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(database_outputs_do_not_crash_without_data) { int ret, i; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("something"); ck_assert_int_eq(ret, 1); suppress_output(); for (i = 0; i <= 4; i++) { cfg.ostyle = i; showdb("something", 0, "", ""); showdb("something", 1, "", ""); showdb("something", 2, "", ""); showdb("something", 3, "", ""); showdb("something", 4, "", ""); showdb("something", 5, "", ""); showdb("something", 6, "", ""); showdb("something", 7, "", ""); showdb("something", 8, "", ""); showdb("something", 9, "", ""); showdb("something", 10, "", ""); showdb("something", 11, "", ""); showdb("something", 12, "", ""); showdb("nothing", 0, "", ""); } xmlheader(); showxml("something", 'd', "", ""); showxml("something", 'm', "", ""); showxml("something", 't', "", ""); showxml("something", 'h', "", ""); showxml("something", 'y', "", ""); showxml("something", 'f', "", ""); showxml("something", 'a', "", ""); xmlfooter(); jsonheader(); showjson("something", 0, 'd', "", ""); showjson("something", 0, 'm', "", ""); showjson("something", 0, 't', "", ""); showjson("something", 0, 'h', "", ""); showjson("something", 0, 'y', "", ""); showjson("something", 0, 'f', "", ""); showjson("something", 1, 'a', "", ""); showjson("nothing", 0, 'a', "", ""); jsonfooter(); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(database_outputs_do_not_crash_without_data_if_totals_are_wrong) { int ret, i; ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("something"); ck_assert_int_eq(ret, 1); ret = db_settotal("something", 42, 84); ck_assert_int_eq(ret, 1); ret = db_setupdated("something", 85000); ck_assert_int_eq(ret, 1); suppress_output(); for (i = 0; i <= 4; i++) { cfg.ostyle = i; showdb("something", 0, "", ""); showdb("something", 1, "", ""); showdb("something", 2, "", ""); showdb("something", 3, "", ""); showdb("something", 4, "", ""); showdb("something", 5, "", ""); showdb("something", 6, "", ""); showdb("something", 7, "", ""); showdb("something", 8, "", ""); showdb("something", 9, "", ""); showdb("something", 10, "", ""); showdb("something", 11, "", ""); showdb("something", 12, "", ""); showdb("nothing", 0, "", ""); } xmlheader(); showxml("something", 'd', "", ""); showxml("something", 'm', "", ""); showxml("something", 't', "", ""); showxml("something", 'h', "", ""); showxml("something", 'y', "", ""); showxml("something", 'f', "", ""); showxml("something", 'a', "", ""); xmlfooter(); jsonheader(); showjson("something", 0, 'd', "", ""); showjson("something", 0, 'm', "", ""); showjson("something", 0, 't', "", ""); showjson("something", 0, 'h', "", ""); showjson("something", 0, 'y', "", ""); showjson("something", 0, 'f', "", ""); showjson("something", 1, 'a', "", ""); showjson("nothing", 0, 'a', "", ""); jsonfooter(); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(showbar_with_zero_len_is_nothing) { int len; suppress_output(); len = showbar(1, 2, 3, 0); ck_assert_int_eq(len, 0); } END_TEST START_TEST(showbar_with_zero_max) { int len; suppress_output(); len = showbar(0, 0, 0, 10); ck_assert_int_eq(len, 0); } END_TEST START_TEST(showbar_with_big_max_and_small_numbers) { int len; suppress_output(); len = showbar(1, 2, 1000, 10); ck_assert_int_eq(len, 0); } END_TEST START_TEST(showbar_with_all_rx) { int pipe, len; char buffer[512]; memset(&buffer, '\0', sizeof(buffer)); cfg.rxchar[0] = 'r'; cfg.txchar[0] = 't'; pipe = pipe_output(); len = showbar(1, 0, 1, 10); ck_assert_int_eq(len, 10); fflush(stdout); len = (int)read(pipe, buffer, 512); ck_assert_str_eq(buffer, " rrrrrrrrrr"); } END_TEST START_TEST(showbar_with_all_tx) { int pipe, len; char buffer[512]; memset(&buffer, '\0', sizeof(buffer)); cfg.rxchar[0] = 'r'; cfg.txchar[0] = 't'; pipe = pipe_output(); len = showbar(0, 1, 1, 10); ck_assert_int_eq(len, 10); fflush(stdout); len = (int)read(pipe, buffer, 512); ck_assert_str_eq(buffer, " tttttttttt"); } END_TEST START_TEST(showbar_with_half_and_half) { int pipe, len; char buffer[512]; memset(&buffer, '\0', sizeof(buffer)); cfg.rxchar[0] = 'r'; cfg.txchar[0] = 't'; pipe = pipe_output(); len = showbar(1, 1, 2, 10); ck_assert_int_eq(len, 10); fflush(stdout); len = (int)read(pipe, buffer, 512); ck_assert_str_eq(buffer, " rrrrrttttt"); } END_TEST START_TEST(showbar_with_one_tenth) { int pipe, len; char buffer[512]; memset(&buffer, '\0', sizeof(buffer)); cfg.rxchar[0] = 'r'; cfg.txchar[0] = 't'; pipe = pipe_output(); len = showbar(1, 9, 10, 10); ck_assert_int_eq(len, 10); fflush(stdout); len = (int)read(pipe, buffer, 512); ck_assert_str_eq(buffer, " rttttttttt"); } END_TEST START_TEST(showbar_with_small_rx_shows_all_tx) { int pipe, len; char buffer[512]; memset(&buffer, '\0', sizeof(buffer)); cfg.rxchar[0] = 'r'; cfg.txchar[0] = 't'; pipe = pipe_output(); len = showbar(1, 1000, 1001, 10); ck_assert_int_eq(len, 10); fflush(stdout); len = (int)read(pipe, buffer, 512); ck_assert_str_eq(buffer, " tttttttttt"); } END_TEST START_TEST(showbar_with_max_smaller_than_real_max) { int len; suppress_output(); len = showbar(1, 2, 1, 10); ck_assert_int_eq(len, 0); } END_TEST START_TEST(showbar_with_half_and_half_of_half) { int pipe, len; char buffer[512]; memset(&buffer, '\0', sizeof(buffer)); cfg.rxchar[0] = 'r'; cfg.txchar[0] = 't'; pipe = pipe_output(); len = showbar(1, 1, 4, 12); ck_assert_int_eq(len, 6); fflush(stdout); len = (int)read(pipe, buffer, 512); ck_assert_str_eq(buffer, " rrrttt"); } END_TEST START_TEST(importlegacydb_does_not_overwrite_existing_interface_data) { int ret; disable_logprints(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethtest"); ck_assert_int_eq(ret, 1); ret = importlegacydb("ethtest", TESTDBDIR); ck_assert_int_eq(ret, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(importlegacydb_can_detect_when_database_read_fails) { int ret; disable_logprints(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethsomethingelse"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(create_zerosize_dbfile("ethtest"), 1); ck_assert_int_eq(create_zerosize_dbfile(".ethtest"), 1); ret = importlegacydb("ethtest", TESTDBDIR); ck_assert_int_eq(ret, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(importlegacydb_can_import_legacy_database) { int ret, i; DATA data; interfaceinfo info; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; initdb(&data); disable_logprints(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("ethsomethingelse"); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecount(); ck_assert_int_eq(ret, 1); strcpy(data.interface, "ethtest"); strcpy(data.nick, "still testing"); data.totalrx = 123123123; data.totaltx = 321321321; data.totalrxk = 1; data.totaltxk = 2; data.currx = 456; data.curtx = 654; for (i = 0; i < 24; i++) { data.hour[i].date = 788911200 + 3600 * i; data.hour[i].rx = (uint64_t)(12 * (i + 1)); data.hour[i].tx = (uint64_t)(23 * (i + 1)); } for (i = 0; i < 30; i++) { data.day[i].date = 788911200 + 86400 * (29 - i); data.day[i].used = 1; data.day[i].rx = (uint64_t)(34 * i); data.day[i].tx = (uint64_t)(45 * i); } for (i = 0; i < 12; i++) { data.month[i].month = 788911200 + 2678400 * (11 - i); data.month[i].used = 1; data.month[i].rx = (uint64_t)(56 * i); data.month[i].tx = (uint64_t)(67 * i); } for (i = 0; i < 10; i++) { data.top10[i].date = 788911200 + 86400 * i; data.top10[i].used = 1; data.top10[i].rx = (uint64_t)(89 * (9 - i + 1)); data.top10[i].tx = (uint64_t)(90 * (9 - i + 1)); } ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(writedb(&data, "ethtest", TESTDBDIR, 1), 1); ck_assert_int_eq(check_dbfile_exists("ethtest", sizeof(DATA)), 1); ret = importlegacydb("ethtest", TESTDBDIR); ck_assert_int_eq(ret, 1); ret = (int)db_getinterfacecount(); ck_assert_int_eq(ret, 2); ret = (int)db_getinterfacecountbyname("ethtest"); ck_assert_int_eq(ret, 1); ret = db_getinterfaceinfo("ethtest", &info); ck_assert_int_eq(ret, 1); ck_assert_str_eq(info.alias, data.nick); ck_assert_int_eq(info.active, data.active); ck_assert_int_eq(info.rxtotal, (data.totalrx * 1024 * 1024) + (uint64_t)(data.totalrxk * 1024)); ck_assert_int_eq(info.txtotal, (data.totaltx * 1024 * 1024) + (uint64_t)(data.totaltxk * 1024)); ck_assert_int_eq(info.rxcounter, data.currx); ck_assert_int_eq(info.txcounter, data.curtx); ck_assert_int_ge(info.created, data.created); ck_assert_int_ge(info.updated, data.lastupdated); ret = db_getdata(&datalist, &datainfo, "ethtest", "day", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 30); datalist_i = datalist; i = 29; while (datalist_i != NULL) { ck_assert_int_eq(datalist_i->rx, data.day[i].rx * 1024 * 1024); ck_assert_int_eq(datalist_i->tx, data.day[i].tx * 1024 * 1024); datalist_i = datalist_i->next; i--; } dbdatalistfree(&datalist); ret = db_getdata(&datalist, &datainfo, "ethtest", "month", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 12); datalist_i = datalist; i = 11; while (datalist_i != NULL) { ck_assert_int_eq(datalist_i->rx, data.month[i].rx * 1024 * 1024); ck_assert_int_eq(datalist_i->tx, data.month[i].tx * 1024 * 1024); datalist_i = datalist_i->next; i--; } dbdatalistfree(&datalist); ret = db_getdata(&datalist, &datainfo, "ethtest", "hour", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 24); datalist_i = datalist; i = 0; while (datalist_i != NULL) { ck_assert_int_eq(datalist_i->rx, data.hour[i].rx * 1024); ck_assert_int_eq(datalist_i->tx, data.hour[i].tx * 1024); datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_getdata(&datalist, &datainfo, "ethtest", "top", 0); ck_assert_int_eq(ret, 1); ck_assert_int_eq(datainfo.count, 10); datalist_i = datalist; i = 0; while (datalist_i != NULL) { ck_assert_int_eq(datalist_i->rx, data.top10[i].rx * 1024 * 1024); ck_assert_int_eq(datalist_i->tx, data.top10[i].tx * 1024 * 1024); datalist_i = datalist_i->next; i++; } dbdatalistfree(&datalist); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(showalert_shows_nothing_with_none_type) { int ret; defaultcfg(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("something"); ck_assert_int_eq(ret, 1); ret = db_addtraffic("something", 100, 200); ck_assert_int_eq(ret, 1); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_None, AC_Total, 42); ck_assert_int_eq(ret, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(showalert_can_alert_on_limit_and_show_things) { int ret; defaultcfg(); suppress_output(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("something"); ck_assert_int_eq(ret, 1); ret = db_setalias("something", "anything"); ck_assert_int_eq(ret, 1); ret = db_addtraffic("something", 100, 200); ck_assert_int_eq(ret, 1); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Hour, AC_Total, 250); ck_assert_int_eq(ret, 1); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Day, AC_Total, 250); ck_assert_int_eq(ret, 1); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Month, AC_Total, 250); ck_assert_int_eq(ret, 1); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Year, AC_Total, 250); ck_assert_int_eq(ret, 1); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST START_TEST(showalert_limit_and_conditions_matter) { int ret; defaultcfg(); suppress_output(); ret = db_open_rw(1); ck_assert_int_eq(ret, 1); ret = db_addinterface("something"); ck_assert_int_eq(ret, 1); ret = db_addtraffic("something", 100, 200); ck_assert_int_eq(ret, 1); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Year, AC_Total, 100); ck_assert_int_eq(ret, 1); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Year, AC_Total, 280); ck_assert_int_eq(ret, 1); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Year, AC_Total, 350); ck_assert_int_eq(ret, 0); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Year, AC_Total, 300); ck_assert_int_eq(ret, 0); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Year, AC_RX, 80); ck_assert_int_eq(ret, 1); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Year, AC_RX, 150); ck_assert_int_eq(ret, 0); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Year, AC_TX, 180); ck_assert_int_eq(ret, 1); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Year, AC_TX, 250); ck_assert_int_eq(ret, 0); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Year, AC_TX, 350); ck_assert_int_eq(ret, 0); ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Year, AC_TX, 200); ck_assert_int_eq(ret, 0); ret = db_close(); ck_assert_int_eq(ret, 1); } END_TEST void add_database_tests(Suite *s) { TCase *tc_db = tcase_create("Database"); tcase_add_checked_fixture(tc_db, setup, teardown); tcase_add_unchecked_fixture(tc_db, setup, teardown); tcase_add_test(tc_db, initdb_activates_database); tcase_add_test(tc_db, readdb_with_empty_file); tcase_add_test(tc_db, readdb_with_empty_file_and_backup); tcase_add_test(tc_db, readdb_with_nonexisting_file); tcase_add_test(tc_db, readdb_with_existing_dbfile); tcase_add_test(tc_db, readdb_with_existing_dbfile_and_max_name_length); tcase_add_test(tc_db, readdb_with_existing_dbfile_with_rename); tcase_add_test(tc_db, readdb_with_existing_dbfile_and_over_max_name_length); tcase_add_test(tc_db, validatedb_with_initdb); tcase_add_test(tc_db, validatedb_with_invalid_totals); tcase_add_test(tc_db, validatedb_with_top10_use); tcase_add_test(tc_db, database_outputs_do_not_crash); tcase_add_test(tc_db, database_outputs_do_not_crash_without_traffic); tcase_add_test(tc_db, database_outputs_do_not_crash_without_data); tcase_add_test(tc_db, database_outputs_do_not_crash_without_data_if_totals_are_wrong); tcase_add_test(tc_db, showbar_with_zero_len_is_nothing); tcase_add_test(tc_db, showbar_with_zero_max); tcase_add_test(tc_db, showbar_with_big_max_and_small_numbers); tcase_add_test(tc_db, showbar_with_all_rx); tcase_add_test(tc_db, showbar_with_all_tx); tcase_add_test(tc_db, showbar_with_half_and_half); tcase_add_test(tc_db, showbar_with_one_tenth); tcase_add_test(tc_db, showbar_with_small_rx_shows_all_tx); tcase_add_test(tc_db, showbar_with_max_smaller_than_real_max); tcase_add_test(tc_db, showbar_with_half_and_half_of_half); tcase_add_test(tc_db, importlegacydb_does_not_overwrite_existing_interface_data); tcase_add_test(tc_db, importlegacydb_can_detect_when_database_read_fails); tcase_add_test(tc_db, importlegacydb_can_import_legacy_database); tcase_add_test(tc_db, showalert_shows_nothing_with_none_type); tcase_add_test(tc_db, showalert_can_alert_on_limit_and_show_things); tcase_add_test(tc_db, showalert_limit_and_conditions_matter); suite_add_tcase(s, tc_db); } int writedb(DATA *data, const char *iface, const char *dirname, int newdb) { FILE *testdb; char file[512], backup[512]; snprintf(file, 512, "%s/%s", dirname, iface); snprintf(backup, 512, "%s/.%s", dirname, iface); /* try to make backup of old data if this isn't a new database */ if (!newdb && !backupdb(file, backup)) { snprintf(errorstring, 1024, "Unable to create database backup \"%s\".", backup); printe(PT_Error); return 0; } /* make sure version stays correct */ data->version = LEGACYDBVERSION; if ((testdb = fopen(file, "w")) == NULL) { snprintf(errorstring, 1024, "Unable to open database \"%s\" for writing: %s", file, strerror(errno)); printe(PT_Error); return 0; } /* update timestamp when not merging */ if (newdb != 2) { data->lastupdated = time(NULL); } if (fwrite(data, sizeof(DATA), 1, testdb) == 0) { snprintf(errorstring, 1024, "Unable to write database \"%s\": %s", file, strerror(errno)); printe(PT_Error); fclose(testdb); return 0; } else { if (debug) { printf("db: Database \"%s\" saved.\n", file); } fclose(testdb); if ((newdb) && (noexit == 0)) { snprintf(errorstring, 1024, "-> A new database has been created."); printe(PT_Info); } } return 1; } int backupdb(const char *current, const char *backup) { FILE *bf; int c, b, bytes; char buffer[512]; /* from */ if ((c = open(current, O_RDONLY)) == -1) { return 0; } /* to, fopen() in order to get file mode bits correctly */ if ((bf = fopen(backup, "w")) == NULL) { close(c); return 0; } b = fileno(bf); /* copy data */ while ((bytes = (int)read(c, buffer, sizeof(buffer))) > 0) { if (write(b, buffer, (size_t)bytes) < 0) { close(c); fclose(bf); return 0; } } close(c); fclose(bf); return 1; } vnstat-2.9/tests/fs_tests.c0000644000000000000000000001001414077640630014544 0ustar rootroot#include "common.h" #include "vnstat_tests.h" #include "fs_tests.h" #include "cfg.h" #include "fs.h" START_TEST(fileexists_with_no_file) { char testfile[512]; snprintf(testfile, 512, "%s/no_file", TESTDIR); ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(fileexists(""), 0); ck_assert_int_eq(fileexists(testfile), 0); } END_TEST START_TEST(fileexists_with_file) { char testfile[512]; snprintf(testfile, 512, "%s/dummy_file", TESTDBDIR); ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(create_zerosize_dbfile("dummy_file"), 1); ck_assert_int_eq(fileexists(testfile), 1); } END_TEST START_TEST(direxists_with_no_dir) { ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(direxists(""), 0); ck_assert_int_eq(direxists(TESTDIR), 0); } END_TEST START_TEST(direxists_with_dir) { ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(direxists(TESTDIR), 1); ck_assert_int_eq(direxists(TESTDBDIR), 1); } END_TEST START_TEST(mkpath_with_no_dir) { ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(mkpath("", 0775), 0); } END_TEST START_TEST(mkpath_with_dir) { ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(direxists(TESTDIR), 0); ck_assert_int_eq(direxists(TESTDBDIR), 0); ck_assert_int_eq(mkpath(TESTDIR, 0775), 1); ck_assert_int_eq(direxists(TESTDIR), 1); ck_assert_int_eq(direxists(TESTDBDIR), 0); ck_assert_int_eq(mkpath(TESTDBDIR, 0775), 1); ck_assert_int_eq(direxists(TESTDBDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(direxists(TESTDBDIR), 0); ck_assert_int_eq(mkpath(TESTDBDIR, 0775), 1); ck_assert_int_eq(direxists(TESTDBDIR), 1); } END_TEST START_TEST(preparevnstatdir_with_no_vnstat) { char testdir[512], testpath[530]; cfg.updatefileowner = 0; ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(direxists(TESTDIR), 0); snprintf(testdir, 512, "%s/here/be/dragons", TESTDIR); snprintf(testpath, 530, "%s/or_something.txt", testdir); preparevnstatdir(testpath, "user", "group"); ck_assert_int_eq(direxists(TESTDIR), 0); ck_assert_int_eq(direxists(testdir), 0); snprintf(testdir, 512, "%s/here/be/vnstat/dragons", TESTDIR); snprintf(testpath, 530, "%s/or_something.txt", testdir); preparevnstatdir(testpath, "user", "group"); ck_assert_int_eq(direxists(TESTDIR), 0); ck_assert_int_eq(direxists(testdir), 0); snprintf(testdir, 512, "%s/here/be/vnstati", TESTDIR); snprintf(testpath, 530, "%s/or_something.txt", testdir); preparevnstatdir(testpath, "user", "group"); ck_assert_int_eq(direxists(TESTDIR), 0); ck_assert_int_eq(direxists(testdir), 0); } END_TEST START_TEST(preparevnstatdir_with_vnstat) { char testdir[512], testpath[530]; cfg.updatefileowner = 0; ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(direxists(TESTDIR), 0); snprintf(testdir, 512, "%s/here/be/vnstat", TESTDIR); snprintf(testpath, 530, "%s/or_something.txt", testdir); preparevnstatdir(testpath, "user", "group"); ck_assert_int_eq(direxists(TESTDIR), 1); ck_assert_int_eq(direxists(testdir), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(direxists(TESTDIR), 0); snprintf(testdir, 512, "%s/here/be/vnstatd", TESTDIR); snprintf(testpath, 530, "%s/or_something.txt", testdir); preparevnstatdir(testpath, "user", "group"); ck_assert_int_eq(direxists(TESTDIR), 1); ck_assert_int_eq(direxists(testdir), 1); } END_TEST void add_fs_tests(Suite *s) { TCase *tc_fs = tcase_create("FS"); tcase_add_checked_fixture(tc_fs, setup, teardown); tcase_add_unchecked_fixture(tc_fs, setup, teardown); tcase_add_test(tc_fs, fileexists_with_no_file); tcase_add_test(tc_fs, fileexists_with_file); tcase_add_test(tc_fs, direxists_with_no_dir); tcase_add_test(tc_fs, direxists_with_dir); tcase_add_test(tc_fs, mkpath_with_no_dir); tcase_add_test(tc_fs, mkpath_with_dir); tcase_add_test(tc_fs, preparevnstatdir_with_no_vnstat); tcase_add_test(tc_fs, preparevnstatdir_with_vnstat); suite_add_tcase(s, tc_fs); } vnstat-2.9/tests/datacache_tests.c0000644000000000000000000001560513510235676016045 0ustar rootroot#include "common.h" #include "vnstat_tests.h" #include "datacache_tests.h" #include "datacache.h" START_TEST(datacache_can_clear_empty_cache) { datacache *dc = NULL; datacache_clear(&dc); ck_assert_ptr_eq(dc, NULL); } END_TEST START_TEST(datacache_can_add_to_cache) { int ret; datacache *dc = NULL; ret = datacache_add(&dc, "eth0", 0); ck_assert_int_eq(ret, 1); ck_assert_str_eq(dc->interface, "eth0"); ck_assert_int_eq(dc->active, 1); ck_assert_int_eq(dc->filled, 0); ck_assert_int_eq(dc->syncneeded, 0); ck_assert_int_eq(dc->currx, 0); ck_assert_int_eq(dc->curtx, 0); ck_assert_ptr_eq(dc->log, NULL); ck_assert_ptr_eq(dc->next, NULL); datacache_clear(&dc); ck_assert_ptr_eq(dc, NULL); } END_TEST START_TEST(datacache_can_add_to_cache_consistently) { int ret; datacache *dc = NULL; datacache *bookmark = NULL; ret = datacache_add(&dc, "eth0", 0); ck_assert_int_eq(ret, 1); ck_assert_str_eq(dc->interface, "eth0"); ck_assert_int_eq(dc->active, 1); ck_assert_int_eq(dc->filled, 0); ck_assert_int_eq(dc->syncneeded, 0); ck_assert_int_eq(dc->currx, 0); ck_assert_int_eq(dc->curtx, 0); ck_assert_ptr_eq(dc->log, NULL); ck_assert_ptr_eq(dc->next, NULL); bookmark = dc; ret = datacache_add(&dc, "eth1", 0); ck_assert_int_eq(ret, 1); ck_assert_str_eq(dc->interface, "eth1"); ck_assert_int_eq(dc->active, 1); ck_assert_int_eq(dc->filled, 0); ck_assert_int_eq(dc->syncneeded, 0); ck_assert_int_eq(dc->currx, 0); ck_assert_int_eq(dc->curtx, 0); ck_assert_ptr_eq(dc->log, NULL); ck_assert_ptr_ne(dc->next, NULL); ck_assert_str_eq(bookmark->interface, "eth0"); bookmark = dc; ck_assert_str_eq(bookmark->interface, "eth1"); bookmark = bookmark->next; ck_assert_str_eq(bookmark->interface, "eth0"); datacache_clear(&dc); ck_assert_ptr_eq(dc, NULL); } END_TEST START_TEST(datacache_knows_how_to_count) { int ret; datacache *dc = NULL; ret = datacache_add(&dc, "eth0", 0); ck_assert_int_eq(ret, 1); ret = datacache_count(&dc); ck_assert_int_eq(ret, 1); ret = datacache_add(&dc, "eth1", 0); ck_assert_int_eq(ret, 1); ret = datacache_count(&dc); ck_assert_int_eq(ret, 2); ret = datacache_activecount(&dc); ck_assert_int_eq(ret, 2); dc->active = 0; ret = datacache_activecount(&dc); ck_assert_int_eq(ret, 1); datacache_clear(&dc); ck_assert_ptr_eq(dc, NULL); ret = datacache_count(&dc); ck_assert_int_eq(ret, 0); ret = datacache_activecount(&dc); ck_assert_int_eq(ret, 0); } END_TEST START_TEST(datacache_can_remove) { int ret; datacache *dc = NULL; ret = datacache_add(&dc, "eth0", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&dc, "eth1", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&dc, "eth2", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&dc, "eth3", 0); ck_assert_int_eq(ret, 1); ret = datacache_count(&dc); ck_assert_int_eq(ret, 4); /* invalid removal doesn't cause issues */ ret = datacache_remove(&dc, "eth4"); ck_assert_int_eq(ret, 0); ret = datacache_count(&dc); ck_assert_int_eq(ret, 4); ck_assert_str_eq(dc->interface, "eth3"); /* head removal */ ret = datacache_remove(&dc, "eth3"); ck_assert_int_eq(ret, 1); ret = datacache_count(&dc); ck_assert_int_eq(ret, 3); ck_assert_str_eq(dc->interface, "eth2"); /* middle removal */ ret = datacache_remove(&dc, "eth1"); ck_assert_int_eq(ret, 1); ret = datacache_count(&dc); ck_assert_int_eq(ret, 2); ck_assert_str_eq(dc->interface, "eth2"); /* tail removal */ ret = datacache_remove(&dc, "eth0"); ck_assert_int_eq(ret, 1); ret = datacache_count(&dc); ck_assert_int_eq(ret, 1); ck_assert_str_eq(dc->interface, "eth2"); datacache_clear(&dc); ck_assert_ptr_eq(dc, NULL); } END_TEST START_TEST(datacache_can_do_stuff) { int ret; datacache *dc = NULL; ret = datacache_add(&dc, "eth0", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&dc, "eth1", 0); ck_assert_int_eq(ret, 1); ret = xferlog_add(&dc->log, 2, 1, 2); ck_assert_int_eq(ret, 1); ret = xferlog_add(&dc->log, 2, 10, 15); ck_assert_int_eq(ret, 1); ret = datacache_add(&dc, "eth2", 0); ck_assert_int_eq(ret, 1); ret = datacache_add(&dc, "eth3", 0); ck_assert_int_eq(ret, 1); ret = xferlog_add(&dc->log, 2, 2, 2); ck_assert_int_eq(ret, 1); ret = datacache_count(&dc); ck_assert_int_eq(ret, 4); /* suppress output to validate that debug function doesn't cause a crash */ suppress_output(); datacache_debug(&dc); printf("\n"); ret = datacache_remove(&dc, "eth1"); ck_assert_int_eq(ret, 1); ret = datacache_count(&dc); ck_assert_int_eq(ret, 3); datacache_debug(&dc); printf("\n"); datacache_clear(&dc); ck_assert_ptr_eq(dc, NULL); datacache_debug(&dc); ret = datacache_count(&dc); ck_assert_int_eq(ret, 0); } END_TEST START_TEST(xferlog_can_clear_empty_log) { xferlog *log = NULL; xferlog_clear(&log); ck_assert_ptr_eq(log, NULL); } END_TEST START_TEST(xferlog_can_log) { int ret; xferlog *log = NULL; ret = xferlog_add(&log, 1, 1, 1); ck_assert_int_eq(ret, 1); ck_assert_ptr_ne(log, NULL); xferlog_clear(&log); ck_assert_ptr_eq(log, NULL); } END_TEST START_TEST(xferlog_can_handle_multiple_entries) { int ret; xferlog *log = NULL; xferlog *bookmark = NULL; ret = xferlog_add(&log, 1, 1, 1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(log->timestamp, 1); ck_assert_int_eq(log->rx, 1); ck_assert_int_eq(log->tx, 1); bookmark = log; ret = xferlog_add(&log, 1, 1, 2); ck_assert_int_eq(ret, 1); ck_assert_int_eq(log->timestamp, 1); ck_assert_int_eq(log->rx, 2); ck_assert_int_eq(log->tx, 3); ret = xferlog_add(&log, 4, 5, 5); ck_assert_int_eq(ret, 1); ck_assert_int_eq(log->timestamp, 4); ck_assert_int_eq(log->rx, 5); ck_assert_int_eq(log->tx, 5); ret = xferlog_add(&log, 7, 4, 4); ck_assert_int_eq(ret, 1); ck_assert_int_eq(log->timestamp, 7); ck_assert_int_eq(log->rx, 4); ck_assert_int_eq(log->tx, 4); ret = xferlog_add(&log, 1, 1, 1); ck_assert_int_eq(ret, 1); ck_assert_int_eq(log->timestamp, 1); ck_assert_int_eq(log->rx, 1); ck_assert_int_eq(log->tx, 1); /* check that new addition with same timestamp doesn't modify old record */ ck_assert_int_eq(bookmark->timestamp, 1); ck_assert_int_eq(bookmark->rx, 2); ck_assert_int_eq(bookmark->tx, 3); xferlog_clear(&log); ck_assert_ptr_eq(log, NULL); } END_TEST void add_datacache_tests(Suite *s) { TCase *tc_datacache = tcase_create("Datacache"); tcase_add_checked_fixture(tc_datacache, setup, teardown); tcase_add_unchecked_fixture(tc_datacache, setup, teardown); tcase_add_test(tc_datacache, datacache_can_clear_empty_cache); tcase_add_test(tc_datacache, datacache_can_add_to_cache); tcase_add_test(tc_datacache, datacache_can_add_to_cache_consistently); tcase_add_test(tc_datacache, datacache_knows_how_to_count); tcase_add_test(tc_datacache, datacache_can_remove); tcase_add_test(tc_datacache, datacache_can_do_stuff); tcase_add_test(tc_datacache, xferlog_can_clear_empty_log); tcase_add_test(tc_datacache, xferlog_can_log); tcase_add_test(tc_datacache, xferlog_can_handle_multiple_entries); suite_add_tcase(s, tc_datacache); } vnstat-2.9/tests/iflist_tests.c0000644000000000000000000000573013510236130015422 0ustar rootroot#include "common.h" #include "vnstat_tests.h" #include "iflist_tests.h" #include "iflist.h" START_TEST(iflistfree_can_free_null) { iflist *ifl = NULL; iflistfree(&ifl); } END_TEST START_TEST(iflistadd_can_add) { int ret; iflist *ifl = NULL; ck_assert_ptr_eq(ifl, NULL); ret = iflistadd(&ifl, "eth0", 0); ck_assert_int_eq(ret, 1); ck_assert_str_eq(ifl->interface, "eth0"); ck_assert_int_eq(ifl->bandwidth, 0); ck_assert_ptr_eq(ifl->next, NULL); ret = iflistadd(&ifl, "eth1", 1); ck_assert_int_eq(ret, 1); ck_assert_str_eq(ifl->interface, "eth0"); ck_assert_int_eq(ifl->bandwidth, 0); ck_assert_ptr_ne(ifl->next, NULL); ck_assert_str_eq(ifl->next->interface, "eth1"); ck_assert_int_eq(ifl->next->bandwidth, 1); ret = iflistadd(&ifl, "eth0", 2); ck_assert_int_eq(ret, 1); ck_assert_str_eq(ifl->interface, "eth0"); ck_assert_int_eq(ifl->bandwidth, 0); ck_assert_ptr_ne(ifl->next, NULL); ck_assert_str_eq(ifl->next->interface, "eth1"); ck_assert_int_eq(ifl->next->bandwidth, 1); ck_assert_ptr_ne(ifl->next->next, NULL); ck_assert_str_eq(ifl->next->next->interface, "eth0"); ck_assert_int_eq(ifl->next->next->bandwidth, 2); iflistfree(&ifl); ck_assert_ptr_eq(ifl, NULL); } END_TEST START_TEST(iflistsearch_can_search) { int ret; iflist *ifl = NULL; ck_assert_ptr_eq(ifl, NULL); ret = iflistsearch(&ifl, "eth0"); ck_assert_int_eq(ret, 0); ret = iflistadd(&ifl, "eth0", 0); ck_assert_int_eq(ret, 1); ret = iflistsearch(&ifl, "eth0"); ck_assert_int_eq(ret, 1); ret = iflistadd(&ifl, "eth1", 1); ck_assert_int_eq(ret, 1); ret = iflistsearch(&ifl, "eth0"); ck_assert_int_eq(ret, 1); ret = iflistadd(&ifl, "eth0", 2); ck_assert_int_eq(ret, 1); ret = iflistsearch(&ifl, "eth0"); ck_assert_int_eq(ret, 1); ret = iflistadd(&ifl, "eth2", 10); ck_assert_int_eq(ret, 1); ret = iflistsearch(&ifl, "eth0"); ck_assert_int_eq(ret, 1); ret = iflistsearch(&ifl, "eth2"); ck_assert_int_eq(ret, 1); ret = iflistsearch(&ifl, "eth0"); ck_assert_int_eq(ret, 1); ret = iflistsearch(&ifl, "eth1"); ck_assert_int_eq(ret, 1); ret = iflistsearch(&ifl, "eth3"); ck_assert_int_eq(ret, 0); ret = iflistadd(&ifl, "eth3", 0); ck_assert_int_eq(ret, 1); ret = iflistsearch(&ifl, "eth3"); ck_assert_int_eq(ret, 1); ret = iflistadd(&ifl, "eth4", 0); ck_assert_int_eq(ret, 1); ret = iflistsearch(&ifl, "eth3"); ck_assert_int_eq(ret, 1); iflistfree(&ifl); ck_assert_ptr_eq(ifl, NULL); } END_TEST void add_iflist_tests(Suite *s) { TCase *tc_iflist = tcase_create("Iflist"); tcase_add_checked_fixture(tc_iflist, setup, teardown); tcase_add_unchecked_fixture(tc_iflist, setup, teardown); tcase_add_test(tc_iflist, iflistfree_can_free_null); tcase_add_test(tc_iflist, iflistadd_can_add); tcase_add_test(tc_iflist, iflistsearch_can_search); suite_add_tcase(s, tc_iflist); } vnstat-2.9/tests/misc_tests.c0000644000000000000000000011361714162723050015075 0ustar rootroot#include "common.h" #include "vnstat_tests.h" #include "misc_tests.h" #include "misc.h" #include "dbsql.h" START_TEST(getbtime_does_not_return_zero) { ck_assert_int_gt(getbtime(), 0); } END_TEST #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wused-but-marked-unused" #endif START_TEST(getunitprefix_returns_something_with_all_cfg_combinations) { const char *string; int j; cfg.unitmode = _i; for (j = 1; j <= (UNITPREFIXCOUNT + 1); j++) { string = getunitprefix(j); ck_assert_int_gt(strlen(string), 0); } } END_TEST START_TEST(getrateunitprefix_returns_something_with_all_cfg_combinations) { const char *string; int j; for (j = 1; j <= (UNITPREFIXCOUNT + 1); j++) { string = getrateunitprefix(_i, j); ck_assert_int_gt(strlen(string), 0); } } END_TEST START_TEST(getunitdivisor_returns_something_with_all_cfg_combinations) { int j; char div[16]; for (j = 1; j <= (UNITPREFIXCOUNT + 1); j++) { snprintf(div, 15, "%" PRIu64 "", getunitdivisor(_i, j)); if (j > UNITPREFIXCOUNT) { ck_assert_str_eq(div, "1"); } else { ck_assert_str_ne(div, "0"); } } } END_TEST #if defined(__clang__) #pragma clang diagnostic pop #endif START_TEST(spacecheck_does_not_check_when_not_configured) { cfg.spacecheck = 0; ck_assert_int_eq(spacecheck("/nonexistentpath"), 1); } END_TEST START_TEST(spacecheck_checks_space) { cfg.spacecheck = 1; /* it's assumed that /tmp isn't full */ ck_assert_int_eq(spacecheck("/tmp"), 1); } END_TEST START_TEST(spacecheck_fails_with_invalid_path) { noexit = 1; cfg.spacecheck = 1; ck_assert_int_eq(spacecheck("/nonexistentpath"), 0); } END_TEST START_TEST(getvalue_normal) { cfg.defaultdecimals = 2; cfg.unitmode = 0; ck_assert_str_eq(getvalue(100, 0, RT_Normal), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_Normal), "1.00 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_Normal), "1.00 MiB"); ck_assert_str_eq(getvalue(1073741824, 0, RT_Normal), "1.00 GiB"); ck_assert_str_eq(getvalue(1099511627776ULL, 0, RT_Normal), "1.00 TiB"); ck_assert_str_eq(getvalue(1125899906842624ULL, 0, RT_Normal), "1.00 PiB"); ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, RT_Normal), "1.00 EiB"); cfg.unitmode = 1; ck_assert_str_eq(getvalue(100, 0, RT_Normal), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_Normal), "1.00 KB"); ck_assert_str_eq(getvalue(1048576, 0, RT_Normal), "1.00 MB"); ck_assert_str_eq(getvalue(1073741824, 0, RT_Normal), "1.00 GB"); ck_assert_str_eq(getvalue(1099511627776ULL, 0, RT_Normal), "1.00 TB"); ck_assert_str_eq(getvalue(1125899906842624ULL, 0, RT_Normal), "1.00 PB"); ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, RT_Normal), "1.00 EB"); cfg.unitmode = 2; ck_assert_str_eq(getvalue(100, 0, RT_Normal), "100 B"); ck_assert_str_eq(getvalue(1000, 0, RT_Normal), "1.00 kB"); ck_assert_str_eq(getvalue(1000000, 0, RT_Normal), "1.00 MB"); ck_assert_str_eq(getvalue(1000000000, 0, RT_Normal), "1.00 GB"); ck_assert_str_eq(getvalue(1000000000000ULL, 0, RT_Normal), "1.00 TB"); ck_assert_str_eq(getvalue(1000000000000000ULL, 0, RT_Normal), "1.00 PB"); ck_assert_str_eq(getvalue(1000000000000000000ULL, 0, RT_Normal), "1.00 EB"); } END_TEST START_TEST(getvalue_estimate) { cfg.defaultdecimals = 2; cfg.unitmode = 0; ck_assert_str_eq(getvalue(100, 0, RT_Estimate), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_Estimate), "1 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_Estimate), "1.00 MiB"); ck_assert_str_eq(getvalue(1073741824, 0, RT_Estimate), "1.00 GiB"); ck_assert_str_eq(getvalue(1099511627776ULL, 0, RT_Estimate), "1.00 TiB"); ck_assert_str_eq(getvalue(1125899906842624ULL, 0, RT_Estimate), "1.00 PiB"); ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, RT_Estimate), "1.00 EiB"); cfg.unitmode = 1; ck_assert_str_eq(getvalue(100, 0, RT_Estimate), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_Estimate), "1 KB"); ck_assert_str_eq(getvalue(1048576, 0, RT_Estimate), "1.00 MB"); ck_assert_str_eq(getvalue(1073741824, 0, RT_Estimate), "1.00 GB"); ck_assert_str_eq(getvalue(1099511627776ULL, 0, RT_Estimate), "1.00 TB"); ck_assert_str_eq(getvalue(1125899906842624ULL, 0, RT_Estimate), "1.00 PB"); ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, RT_Estimate), "1.00 EB"); cfg.unitmode = 2; ck_assert_str_eq(getvalue(100, 0, RT_Estimate), "100 B"); ck_assert_str_eq(getvalue(1000, 0, RT_Estimate), "1 kB"); ck_assert_str_eq(getvalue(1000000, 0, RT_Estimate), "1.00 MB"); ck_assert_str_eq(getvalue(1000000000, 0, RT_Estimate), "1.00 GB"); ck_assert_str_eq(getvalue(1000000000000ULL, 0, RT_Estimate), "1.00 TB"); ck_assert_str_eq(getvalue(1000000000000000ULL, 0, RT_Estimate), "1.00 PB"); ck_assert_str_eq(getvalue(1000000000000000000ULL, 0, RT_Estimate), "1.00 EB"); } END_TEST START_TEST(getvalue_imagescale) { cfg.defaultdecimals = 2; cfg.unitmode = 0; ck_assert_str_eq(getvalue(100, 0, RT_ImageScale), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_ImageScale), "1 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_ImageScale), "1 MiB"); ck_assert_str_eq(getvalue(1073741824, 0, RT_ImageScale), "1 GiB"); ck_assert_str_eq(getvalue(1099511627776ULL, 0, RT_ImageScale), "1 TiB"); ck_assert_str_eq(getvalue(1125899906842624ULL, 0, RT_ImageScale), "1 PiB"); ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, RT_ImageScale), "1 EiB"); cfg.unitmode = 1; ck_assert_str_eq(getvalue(100, 0, RT_ImageScale), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_ImageScale), "1 KB"); ck_assert_str_eq(getvalue(1048576, 0, RT_ImageScale), "1 MB"); ck_assert_str_eq(getvalue(1073741824, 0, RT_ImageScale), "1 GB"); ck_assert_str_eq(getvalue(1099511627776ULL, 0, RT_ImageScale), "1 TB"); ck_assert_str_eq(getvalue(1125899906842624ULL, 0, RT_ImageScale), "1 PB"); ck_assert_str_eq(getvalue(1152921504606846976ULL, 0, RT_ImageScale), "1 EB"); cfg.unitmode = 2; ck_assert_str_eq(getvalue(100, 0, RT_ImageScale), "100 B"); ck_assert_str_eq(getvalue(1000, 0, RT_ImageScale), "1 kB"); ck_assert_str_eq(getvalue(1000000, 0, RT_ImageScale), "1 MB"); ck_assert_str_eq(getvalue(1000000000, 0, RT_ImageScale), "1 GB"); ck_assert_str_eq(getvalue(1000000000000ULL, 0, RT_ImageScale), "1 TB"); ck_assert_str_eq(getvalue(1000000000000000ULL, 0, RT_ImageScale), "1 PB"); ck_assert_str_eq(getvalue(1000000000000000000ULL, 0, RT_ImageScale), "1 EB"); } END_TEST START_TEST(getvalue_padding) { cfg.defaultdecimals = 2; cfg.unitmode = 0; ck_assert_str_eq(getvalue(1024, 10, RT_Normal), " 1.00 KiB"); cfg.unitmode = 1; ck_assert_str_eq(getvalue(1024, 10, RT_Normal), " 1.00 KB"); cfg.unitmode = 2; ck_assert_str_eq(getvalue(1000, 10, RT_Normal), " 1.00 kB"); } END_TEST START_TEST(getvalue_zero_values) { cfg.unitmode = 0; ck_assert_str_eq(getvalue(0, 0, RT_Normal), "0 B"); ck_assert_str_eq(getvalue(0, 10, RT_Estimate), " -- "); ck_assert_int_eq((int)strlen(getvalue(0, 10, RT_Estimate)), 10); ck_assert_int_eq((int)strlen(getvalue(0, 20, RT_Estimate)), 20); ck_assert_str_eq(getvalue(0, 0, RT_ImageScale), "0 B"); cfg.unitmode = 1; ck_assert_str_eq(getvalue(0, 0, RT_Normal), "0 B"); ck_assert_str_eq(getvalue(0, 10, RT_Estimate), " -- "); ck_assert_int_eq((int)strlen(getvalue(0, 10, RT_Estimate)), 10); ck_assert_int_eq((int)strlen(getvalue(0, 20, RT_Estimate)), 20); ck_assert_str_eq(getvalue(0, 0, RT_ImageScale), "0 B"); cfg.unitmode = 2; ck_assert_str_eq(getvalue(0, 0, RT_Normal), "0 B"); ck_assert_str_eq(getvalue(0, 10, RT_Estimate), " -- "); ck_assert_int_eq((int)strlen(getvalue(0, 10, RT_Estimate)), 10); ck_assert_int_eq((int)strlen(getvalue(0, 20, RT_Estimate)), 20); ck_assert_str_eq(getvalue(0, 0, RT_ImageScale), "0 B"); } END_TEST START_TEST(gettrafficrate_zero_interval) { int i, j; for (i = 0; i <= 1; i++) { cfg.rateunit = i; for (j = 0; j <= 2; j++) { cfg.unitmode = j; ck_assert_str_eq(gettrafficrate(1, 0, 0), "n/a"); } } } END_TEST START_TEST(gettrafficrate_bytes) { cfg.defaultdecimals = 2; cfg.rateunit = 0; cfg.unitmode = 0; ck_assert_str_eq(gettrafficrate(900, 1, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(9000, 10, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "100.00 KiB/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "100.00 KiB/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "1.00 MiB/s"); ck_assert_str_eq(gettrafficrate(1073741824, 1, 0), "1.00 GiB/s"); ck_assert_str_eq(gettrafficrate(1099511627776ULL, 1, 0), "1.00 TiB/s"); ck_assert_str_eq(gettrafficrate(1125899906842624ULL, 1, 0), "1.00 PiB/s"); ck_assert_str_eq(gettrafficrate(1152921504606846976ULL, 1, 0), "1.00 EiB/s"); cfg.unitmode = 1; ck_assert_str_eq(gettrafficrate(900, 1, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(9000, 10, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "100.00 KB/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "100.00 KB/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "1.00 MB/s"); ck_assert_str_eq(gettrafficrate(1073741824, 1, 0), "1.00 GB/s"); ck_assert_str_eq(gettrafficrate(1099511627776ULL, 1, 0), "1.00 TB/s"); ck_assert_str_eq(gettrafficrate(1125899906842624ULL, 1, 0), "1.00 PB/s"); ck_assert_str_eq(gettrafficrate(1152921504606846976ULL, 1, 0), "1.00 EB/s"); cfg.unitmode = 2; ck_assert_str_eq(gettrafficrate(900, 1, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(9000, 10, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(100000, 1, 0), "100.00 kB/s"); ck_assert_str_eq(gettrafficrate(1000000, 10, 0), "100.00 kB/s"); ck_assert_str_eq(gettrafficrate(1000000, 1, 0), "1.00 MB/s"); ck_assert_str_eq(gettrafficrate(1000000000, 1, 0), "1.00 GB/s"); ck_assert_str_eq(gettrafficrate(1000000000000ULL, 1, 0), "1.00 TB/s"); ck_assert_str_eq(gettrafficrate(1000000000000000ULL, 1, 0), "1.00 PB/s"); ck_assert_str_eq(gettrafficrate(1000000000000000000ULL, 1, 0), "1.00 EB/s"); } END_TEST START_TEST(gettrafficrate_bits) { cfg.defaultdecimals = 2; cfg.rateunit = 1; cfg.rateunitmode = 1; cfg.unitmode = 0; ck_assert_str_eq(gettrafficrate(100, 1, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(1000, 10, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "819.20 kbit/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "819.20 kbit/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "8.39 Mbit/s"); ck_assert_str_eq(gettrafficrate(1073741824, 1, 0), "8.59 Gbit/s"); ck_assert_str_eq(gettrafficrate(1099511627776ULL, 1, 0), "8.80 Tbit/s"); ck_assert_str_eq(gettrafficrate(1125899906842624ULL, 1, 0), "9.01 Pbit/s"); ck_assert_str_eq(gettrafficrate(1152921504606846976ULL, 1, 0), "9.22 Ebit/s"); cfg.unitmode = 1; ck_assert_str_eq(gettrafficrate(100, 1, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(1000, 10, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "819.20 kbit/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "819.20 kbit/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "8.39 Mbit/s"); ck_assert_str_eq(gettrafficrate(1073741824, 1, 0), "8.59 Gbit/s"); ck_assert_str_eq(gettrafficrate(1099511627776ULL, 1, 0), "8.80 Tbit/s"); ck_assert_str_eq(gettrafficrate(1125899906842624ULL, 1, 0), "9.01 Pbit/s"); ck_assert_str_eq(gettrafficrate(1152921504606846976ULL, 1, 0), "9.22 Ebit/s"); cfg.unitmode = 2; ck_assert_str_eq(gettrafficrate(100, 1, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(1000, 10, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "819.20 kbit/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "819.20 kbit/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "8.39 Mbit/s"); ck_assert_str_eq(gettrafficrate(1073741824, 1, 0), "8.59 Gbit/s"); ck_assert_str_eq(gettrafficrate(1099511627776ULL, 1, 0), "8.80 Tbit/s"); ck_assert_str_eq(gettrafficrate(1125899906842624ULL, 1, 0), "9.01 Pbit/s"); ck_assert_str_eq(gettrafficrate(1152921504606846976ULL, 1, 0), "9.22 Ebit/s"); cfg.rateunitmode = 0; cfg.unitmode = 0; ck_assert_str_eq(gettrafficrate(100, 1, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(1000, 10, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "800.00 Kibit/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "800.00 Kibit/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "8.00 Mibit/s"); ck_assert_str_eq(gettrafficrate(1073741824, 1, 0), "8.00 Gibit/s"); ck_assert_str_eq(gettrafficrate(1099511627776ULL, 1, 0), "8.00 Tibit/s"); ck_assert_str_eq(gettrafficrate(1125899906842624ULL, 1, 0), "8.00 Pibit/s"); ck_assert_str_eq(gettrafficrate(1152921504606846976ULL, 1, 0), "8.00 Eibit/s"); cfg.unitmode = 1; ck_assert_str_eq(gettrafficrate(100, 1, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(1000, 10, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "800.00 Kibit/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "800.00 Kibit/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "8.00 Mibit/s"); ck_assert_str_eq(gettrafficrate(1073741824, 1, 0), "8.00 Gibit/s"); ck_assert_str_eq(gettrafficrate(1099511627776ULL, 1, 0), "8.00 Tibit/s"); ck_assert_str_eq(gettrafficrate(1125899906842624ULL, 1, 0), "8.00 Pibit/s"); ck_assert_str_eq(gettrafficrate(1152921504606846976ULL, 1, 0), "8.00 Eibit/s"); cfg.unitmode = 2; ck_assert_str_eq(gettrafficrate(100, 1, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(1000, 10, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "800.00 Kibit/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "800.00 Kibit/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "8.00 Mibit/s"); ck_assert_str_eq(gettrafficrate(1073741824, 1, 0), "8.00 Gibit/s"); ck_assert_str_eq(gettrafficrate(1099511627776ULL, 1, 0), "8.00 Tibit/s"); ck_assert_str_eq(gettrafficrate(1125899906842624ULL, 1, 0), "8.00 Pibit/s"); ck_assert_str_eq(gettrafficrate(1152921504606846976ULL, 1, 0), "8.00 Eibit/s"); } END_TEST START_TEST(gettrafficrate_interval_divides) { cfg.defaultdecimals = 2; cfg.unitmode = 0; cfg.rateunitmode = 1; cfg.rateunit = 0; ck_assert_str_eq(gettrafficrate(102400, 1, 0), "100.00 KiB/s"); ck_assert_str_eq(gettrafficrate(102400, 2, 0), "50.00 KiB/s"); ck_assert_str_eq(gettrafficrate(102400, 10, 0), "10.00 KiB/s"); cfg.rateunit = 1; ck_assert_str_eq(gettrafficrate(102400, 1, 0), "819.20 kbit/s"); ck_assert_str_eq(gettrafficrate(102400, 2, 0), "409.60 kbit/s"); ck_assert_str_eq(gettrafficrate(102400, 10, 0), "81.92 kbit/s"); } END_TEST START_TEST(gettrafficrate_padding) { cfg.defaultdecimals = 2; cfg.unitmode = 0; cfg.rateunit = 0; ck_assert_str_eq(gettrafficrate(102400, 1, 0), "100.00 KiB/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 12), "100.00 KiB/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 14), " 100.00 KiB/s"); ck_assert_str_eq(gettrafficrate(900, 1, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(900, 1, 7), "900 B/s"); ck_assert_str_eq(gettrafficrate(900, 1, 12), " 900 B/s"); ck_assert_str_eq(gettrafficrate(900, 1, 14), " 900 B/s"); } END_TEST START_TEST(sighandler_sets_signal) { debug = 1; intsignal = 0; disable_logprints(); ck_assert(signal(SIGINT, sighandler) != SIG_ERR); ck_assert(signal(SIGHUP, sighandler) != SIG_ERR); ck_assert(signal(SIGTERM, sighandler) != SIG_ERR); ck_assert_int_eq(kill(getpid(), SIGINT), 0); ck_assert_int_eq(intsignal, SIGINT); ck_assert_int_eq(kill(getpid(), SIGHUP), 0); ck_assert_int_eq(intsignal, SIGHUP); ck_assert_int_eq(kill(getpid(), SIGTERM), 0); ck_assert_int_eq(intsignal, SIGTERM); } END_TEST START_TEST(validatedatetime_can_detect_valid_strings) { ck_assert_int_eq(validatedatetime("2018-03-24 01:23"), 1); ck_assert_int_eq(validatedatetime("1998-01-15 23:16"), 1); ck_assert_int_eq(validatedatetime("2018-03-24"), 1); ck_assert_int_eq(validatedatetime("1998-01-15"), 1); ck_assert_int_eq(validatedatetime("today"), 1); } END_TEST START_TEST(validatedatetime_can_detect_invalid_strings) { ck_assert_int_eq(validatedatetime("2018-03-24 01:23:12"), 0); ck_assert_int_eq(validatedatetime("2018-03-24 01"), 0); ck_assert_int_eq(validatedatetime("2018-03-24 01:23am"), 0); ck_assert_int_eq(validatedatetime("2018-03-24 1:23"), 0); ck_assert_int_eq(validatedatetime("2018-03-24 01-23"), 0); ck_assert_int_eq(validatedatetime("2018-03-24 "), 0); ck_assert_int_eq(validatedatetime("2018-03-24 01:23 "), 0); ck_assert_int_eq(validatedatetime("2018-03-24 "), 0); ck_assert_int_eq(validatedatetime("2018-o3-24"), 0); ck_assert_int_eq(validatedatetime("2018-03-24T01:23"), 0); ck_assert_int_eq(validatedatetime("2018-03-24_01:23"), 0); ck_assert_int_eq(validatedatetime("2018-03-241"), 0); ck_assert_int_eq(validatedatetime("2018/03/24"), 0); ck_assert_int_eq(validatedatetime("2018-03"), 0); ck_assert_int_eq(validatedatetime("1998-01"), 0); ck_assert_int_eq(validatedatetime("2018-03-"), 0); ck_assert_int_eq(validatedatetime("2018_03"), 0); ck_assert_int_eq(validatedatetime("2018-3"), 0); ck_assert_int_eq(validatedatetime("2018_03"), 0); ck_assert_int_eq(validatedatetime("2018"), 0); ck_assert_int_eq(validatedatetime("1998"), 0); ck_assert_int_eq(validatedatetime("9999"), 0); ck_assert_int_eq(validatedatetime("18-03"), 0); ck_assert_int_eq(validatedatetime("18"), 0); ck_assert_int_eq(validatedatetime(" "), 0); ck_assert_int_eq(validatedatetime(""), 0); ck_assert_int_eq(validatedatetime("wtf?"), 0); ck_assert_int_eq(validatedatetime("yesterday"), 0); ck_assert_int_eq(validatedatetime("tomorrow"), 0); } END_TEST START_TEST(validatedatetime_does_not_validate_numbers) { ck_assert_int_eq(validatedatetime("9999-99-99 99:99"), 1); ck_assert_int_eq(validatedatetime("0000-00-00 00:00"), 1); ck_assert_int_eq(validatedatetime("2018-03-24 01:90"), 1); } END_TEST START_TEST(defaultdecimals_controls_the_number_of_decimals) { cfg.unitmode = 0; cfg.rateunitmode = 1; cfg.defaultdecimals = 0; cfg.rateunit = 0; ck_assert_str_eq(getvalue(100, 0, RT_Normal), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_Normal), "1 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_Normal), "1 MiB"); ck_assert_str_eq(getvalue(100, 0, RT_Estimate), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_Estimate), "1 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_Estimate), "1 MiB"); ck_assert_str_eq(getvalue(100, 0, RT_ImageScale), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_ImageScale), "1 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_ImageScale), "1 MiB"); ck_assert_str_eq(gettrafficrate(900, 1, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(9000, 10, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "100 KiB/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "100 KiB/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "1 MiB/s"); cfg.rateunit = 1; ck_assert_str_eq(gettrafficrate(100, 1, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(1000, 10, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "819 kbit/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "819 kbit/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "8 Mbit/s"); cfg.defaultdecimals = 1; cfg.rateunit = 0; ck_assert_str_eq(getvalue(100, 0, RT_Normal), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_Normal), "1.0 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_Normal), "1.0 MiB"); ck_assert_str_eq(getvalue(100, 0, RT_Estimate), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_Estimate), "1 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_Estimate), "1.0 MiB"); ck_assert_str_eq(getvalue(100, 0, RT_ImageScale), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_ImageScale), "1 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_ImageScale), "1 MiB"); ck_assert_str_eq(gettrafficrate(900, 1, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(9000, 10, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "100.0 KiB/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "100.0 KiB/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "1.0 MiB/s"); cfg.rateunit = 1; ck_assert_str_eq(gettrafficrate(100, 1, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(1000, 10, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "819.2 kbit/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "819.2 kbit/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "8.4 Mbit/s"); cfg.defaultdecimals = 2; cfg.rateunit = 0; ck_assert_str_eq(getvalue(100, 0, RT_Normal), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_Normal), "1.00 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_Normal), "1.00 MiB"); ck_assert_str_eq(getvalue(100, 0, RT_Estimate), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_Estimate), "1 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_Estimate), "1.00 MiB"); ck_assert_str_eq(getvalue(100, 0, RT_ImageScale), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_ImageScale), "1 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_ImageScale), "1 MiB"); ck_assert_str_eq(gettrafficrate(900, 1, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(9000, 10, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "100.00 KiB/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "100.00 KiB/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "1.00 MiB/s"); cfg.rateunit = 1; ck_assert_str_eq(gettrafficrate(100, 1, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(1000, 10, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "819.20 kbit/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "819.20 kbit/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "8.39 Mbit/s"); cfg.defaultdecimals = 3; cfg.rateunit = 0; ck_assert_str_eq(getvalue(100, 0, RT_Normal), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_Normal), "1.000 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_Normal), "1.000 MiB"); ck_assert_str_eq(getvalue(100, 0, RT_Estimate), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_Estimate), "1 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_Estimate), "1.000 MiB"); ck_assert_str_eq(getvalue(100, 0, RT_ImageScale), "100 B"); ck_assert_str_eq(getvalue(1024, 0, RT_ImageScale), "1 KiB"); ck_assert_str_eq(getvalue(1048576, 0, RT_ImageScale), "1 MiB"); ck_assert_str_eq(gettrafficrate(900, 1, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(9000, 10, 0), "900 B/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "100.000 KiB/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "100.000 KiB/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "1.000 MiB/s"); cfg.rateunit = 1; ck_assert_str_eq(gettrafficrate(100, 1, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(1000, 10, 0), "800 bit/s"); ck_assert_str_eq(gettrafficrate(102400, 1, 0), "819.200 kbit/s"); ck_assert_str_eq(gettrafficrate(1024000, 10, 0), "819.200 kbit/s"); ck_assert_str_eq(gettrafficrate(1048576, 1, 0), "8.389 Mbit/s"); } END_TEST START_TEST(issametimeslot_knows_the_none_list) { ck_assert_int_eq(issametimeslot(LT_None, 10, 11), 0); } END_TEST START_TEST(issametimeslot_handles_updates_before_the_entry_time) { time_t entry, updated; entry = (time_t)get_timestamp(2019, 4, 15, 12, 31); updated = (time_t)get_timestamp(2019, 4, 15, 12, 30); ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 0); } END_TEST START_TEST(issametimeslot_knows_simple_slots) { time_t entry, updated; entry = (time_t)get_timestamp(2019, 4, 15, 12, 30); updated = entry; ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 1); updated = entry + 1; ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 1); entry = (time_t)get_timestamp(2019, 4, 1, 12, 30); updated = (time_t)get_timestamp(2019, 4, 1, 12, 34); ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 1); updated = (time_t)get_timestamp(2019, 4, 1, 12, 35); ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 0); entry = (time_t)get_timestamp(2019, 4, 1, 12, 0); updated = (time_t)get_timestamp(2019, 4, 1, 12, 59); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 1); updated = (time_t)get_timestamp(2019, 4, 1, 13, 0); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 0); entry = (time_t)get_timestamp(2019, 4, 1, 0, 0); updated = (time_t)get_timestamp(2019, 4, 1, 23, 59); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 1); updated = (time_t)get_timestamp(2019, 4, 2, 0, 0); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 0); entry = (time_t)get_timestamp(2019, 4, 1, 0, 0); updated = (time_t)get_timestamp(2019, 4, 30, 23, 59); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 1); updated = (time_t)get_timestamp(2019, 5, 1, 0, 0); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 0); entry = (time_t)get_timestamp(2019, 1, 1, 0, 0); updated = (time_t)get_timestamp(2019, 12, 31, 23, 59); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 1); entry = (time_t)get_timestamp(2019, 1, 1, 0, 0); updated = (time_t)get_timestamp(2020, 1, 1, 0, 0); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 0); } END_TEST START_TEST(issametimeslot_knows_its_slots) { time_t entry, updated; entry = (time_t)get_timestamp(2019, 4, 15, 12, 30); /* the database has the entry timestamp stored with the first possible */ /* time of the specific range resulting in many of the following scenarios */ /* never happening during normal usage */ updated = (time_t)get_timestamp(2019, 4, 15, 12, 32); ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 1); updated = (time_t)get_timestamp(2019, 4, 15, 12, 35); ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 1); updated = (time_t)get_timestamp(2019, 4, 15, 13, 00); ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 1); updated = (time_t)get_timestamp(2019, 4, 16, 13, 00); ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 1); updated = (time_t)get_timestamp(2019, 4, 30, 00, 00); ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 1); updated = (time_t)get_timestamp(2019, 4, 30, 23, 59); ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 1); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 1); updated = (time_t)get_timestamp(2019, 5, 16, 13, 00); ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 1); updated = (time_t)get_timestamp(2020, 5, 16, 13, 00); ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 0); entry = (time_t)get_timestamp(2019, 4, 1, 0, 0); updated = (time_t)get_timestamp(2019, 5, 1, 0, 0); ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 1); entry = (time_t)get_timestamp(2019, 12, 31, 23, 59); updated = (time_t)get_timestamp(2020, 1, 1, 0, 0); ck_assert_int_eq(issametimeslot(LT_5min, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Hour, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Day, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Top, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Month, entry, updated), 0); ck_assert_int_eq(issametimeslot(LT_Year, entry, updated), 0); } END_TEST START_TEST(getperiodseconds_knows_fixed_not_ongoing_periods) { time_t entry, updated; entry = (time_t)get_timestamp(2021, 1, 1, 18, 0); updated = entry; ck_assert_int_eq(getperiodseconds(LT_None, entry, updated, 0), 0); ck_assert_int_eq(getperiodseconds(LT_5min, entry, updated, 0), 300); ck_assert_int_eq(getperiodseconds(LT_Hour, entry, updated, 0), 3600); ck_assert_int_eq(getperiodseconds(LT_Day, entry, updated, 0), 86400); ck_assert_int_eq(getperiodseconds(LT_Top, entry, updated, 0), 86400); } END_TEST START_TEST(getperiodseconds_knows_dynamic_not_ongoing_periods) { time_t entry, updated; entry = (time_t)get_timestamp(2021, 1, 1, 18, 0); updated = entry; ck_assert_int_eq(getperiodseconds(LT_Month, entry, updated, 0), 2678400); /* 2021 isn't a leap year */ ck_assert_int_eq(getperiodseconds(LT_Year, entry, updated, 0), 31536000); entry = (time_t)get_timestamp(2020, 1, 1, 18, 0); updated = entry; /* 2020 is a leap year */ ck_assert_int_eq(getperiodseconds(LT_Year, entry, updated, 0), 31622400); } END_TEST START_TEST(getperiodseconds_returns_zero_when_there_is_no_time_spent) { time_t entry, updated; cfg.monthrotate = 1; entry = (time_t)get_timestamp(2021, 1, 1, 0, 0); updated = entry; ck_assert_int_eq(getperiodseconds(LT_None, entry, updated, 1), 0); ck_assert_int_eq(getperiodseconds(LT_5min, entry, updated, 1), 0); ck_assert_int_eq(getperiodseconds(LT_Hour, entry, updated, 1), 0); ck_assert_int_eq(getperiodseconds(LT_Day, entry, updated, 1), 0); ck_assert_int_eq(getperiodseconds(LT_Year, entry, updated, 1), 0); /* months are special due to cfg.monthrotate */ ck_assert_int_eq(getperiodseconds(LT_Month, entry, updated, 1), 1); /* LT_Top always returns the same value */ ck_assert_int_eq(getperiodseconds(LT_Top, entry, updated, 1), 86400); } END_TEST START_TEST(getperiodseconds_knows_spent_ongoing_time) { time_t entry, updated; cfg.monthrotate = 1; entry = (time_t)get_timestamp(2021, 1, 2, 3, 46); updated = entry; ck_assert_int_eq(getperiodseconds(LT_None, entry, updated, 1), 0); ck_assert_int_eq(getperiodseconds(LT_5min, entry, updated, 1), 60); ck_assert_int_eq(getperiodseconds(LT_Hour, entry, updated, 1), 2760); ck_assert_int_eq(getperiodseconds(LT_Day, entry, updated, 1), 13560); ck_assert_int_eq(getperiodseconds(LT_Year, entry, updated, 1), 99960); /* months are special due to cfg.monthrotate */ ck_assert_int_eq(getperiodseconds(LT_Month, entry, updated, 1), 1); /* LT_Top always returns the same value */ ck_assert_int_eq(getperiodseconds(LT_Top, entry, updated, 1), 86400); } END_TEST START_TEST(getestimates_has_error_handling) { time_t updated; uint64_t rx = 1, tx = 2; dbdatalist *datalist = NULL; updated = (time_t)get_timestamp(2021, 1, 2, 3, 46); getestimates(&rx, &tx, LT_None, updated, &datalist); ck_assert_int_eq(rx, 0); ck_assert_int_eq(tx, 0); rx = 1; tx = 2; ck_assert_int_eq(dbdatalistadd(&datalist, 0, 0, 0, 1), 1); getestimates(&rx, &tx, LT_Day, updated, &datalist); ck_assert_int_eq(rx, 0); ck_assert_int_eq(tx, 0); dbdatalistfree(&datalist); rx = 1; tx = 2; ck_assert_int_eq(dbdatalistadd(&datalist, 1000000, 0, 0, 1), 1); getestimates(&rx, &tx, LT_Day, updated, &datalist); ck_assert_int_eq(rx, 0); ck_assert_int_eq(tx, 0); dbdatalistfree(&datalist); rx = 1; tx = 2; ck_assert_int_eq(dbdatalistadd(&datalist, 0, 1000000, 0, 1), 1); getestimates(&rx, &tx, LT_Day, updated, &datalist); ck_assert_int_eq(rx, 0); ck_assert_int_eq(tx, 0); dbdatalistfree(&datalist); rx = 1; tx = 2; ck_assert_int_eq(dbdatalistadd(&datalist, 1000000, 1000000, 0, 1), 1); getestimates(&rx, &tx, LT_None, updated, &datalist); ck_assert_int_eq(rx, 0); ck_assert_int_eq(tx, 0); dbdatalistfree(&datalist); } END_TEST START_TEST(getestimates_has_a_crystal_ball) { time_t updated; uint64_t rx = 1, tx = 2; dbdatalist *datalist = NULL; cfg.monthrotate = 1; updated = (time_t)get_timestamp(2021, 1, 1, 3, 45); ck_assert_int_eq(dbdatalistadd(&datalist, 100000, 200000, updated, 1), 1); rx = 1; tx = 2; /* on the 5 minute so there's no calculation done */ getestimates(&rx, &tx, LT_5min, updated, &datalist); ck_assert_int_eq(rx, 100000); ck_assert_int_eq(tx, 200000); updated = (time_t)get_timestamp(2021, 1, 1, 3, 46); rx = 1; tx = 2; getestimates(&rx, &tx, LT_5min, updated, &datalist); ck_assert_int_eq(rx, 499800); ck_assert_int_eq(tx, 999900); rx = 1; tx = 2; getestimates(&rx, &tx, LT_Hour, updated, &datalist); ck_assert_int_eq(rx, 129600); ck_assert_int_eq(tx, 259200); updated = (time_t)get_timestamp(2021, 1, 2, 3, 0); rx = 1; tx = 2; /* on the hour so there's no calculation done */ getestimates(&rx, &tx, LT_Hour, updated, &datalist); ck_assert_int_eq(rx, 100000); ck_assert_int_eq(tx, 200000); rx = 1; tx = 2; getestimates(&rx, &tx, LT_Day, updated, &datalist); ck_assert_int_eq(rx, 777600); ck_assert_int_eq(tx, 1555200); rx = 1; tx = 2; getestimates(&rx, &tx, LT_Month, updated, &datalist); ck_assert_int_eq(rx, 2678400); ck_assert_int_eq(tx, 5356800); rx = 1; tx = 2; getestimates(&rx, &tx, LT_Year, updated, &datalist); ck_assert_int_eq(rx, 32061600); ck_assert_int_eq(tx, 64648800); dbdatalistfree(&datalist); } END_TEST START_TEST(ishelprequest_knows_what_a_help_request_is) { ck_assert_int_eq(ishelprequest("--help"), 1); ck_assert_int_eq(ishelprequest("-?"), 1); ck_assert_int_eq(ishelprequest("?"), 1); ck_assert_int_eq(ishelprequest("help"), 0); ck_assert_int_eq(ishelprequest("-h"), 0); ck_assert_int_eq(ishelprequest("--helpme"), 0); ck_assert_int_eq(ishelprequest(""), 0); ck_assert_int_eq(ishelprequest("1"), 0); ck_assert_int_eq(ishelprequest("a"), 0); } END_TEST void add_misc_tests(Suite *s) { TCase *tc_misc = tcase_create("Misc"); tcase_add_checked_fixture(tc_misc, setup, teardown); tcase_add_unchecked_fixture(tc_misc, setup, teardown); tcase_add_test(tc_misc, getbtime_does_not_return_zero); tcase_add_loop_test(tc_misc, getunitprefix_returns_something_with_all_cfg_combinations, 0, 2); tcase_add_loop_test(tc_misc, getrateunitprefix_returns_something_with_all_cfg_combinations, 0, 3); tcase_add_loop_test(tc_misc, getunitdivisor_returns_something_with_all_cfg_combinations, 0, 3); tcase_add_test(tc_misc, spacecheck_does_not_check_when_not_configured); tcase_add_test(tc_misc, spacecheck_checks_space); tcase_add_test(tc_misc, spacecheck_fails_with_invalid_path); tcase_add_test(tc_misc, getvalue_normal); tcase_add_test(tc_misc, getvalue_estimate); tcase_add_test(tc_misc, getvalue_imagescale); tcase_add_test(tc_misc, getvalue_padding); tcase_add_test(tc_misc, getvalue_zero_values); tcase_add_test(tc_misc, gettrafficrate_zero_interval); tcase_add_test(tc_misc, gettrafficrate_bytes); tcase_add_test(tc_misc, gettrafficrate_bits); tcase_add_test(tc_misc, gettrafficrate_interval_divides); tcase_add_test(tc_misc, gettrafficrate_padding); tcase_add_test(tc_misc, sighandler_sets_signal); tcase_add_test(tc_misc, validatedatetime_can_detect_valid_strings); tcase_add_test(tc_misc, validatedatetime_can_detect_invalid_strings); tcase_add_test(tc_misc, validatedatetime_does_not_validate_numbers); tcase_add_test(tc_misc, defaultdecimals_controls_the_number_of_decimals); tcase_add_test(tc_misc, issametimeslot_knows_the_none_list); tcase_add_test(tc_misc, issametimeslot_handles_updates_before_the_entry_time); tcase_add_test(tc_misc, issametimeslot_knows_simple_slots); tcase_add_test(tc_misc, issametimeslot_knows_its_slots); tcase_add_test(tc_misc, getperiodseconds_knows_fixed_not_ongoing_periods); tcase_add_test(tc_misc, getperiodseconds_knows_dynamic_not_ongoing_periods); tcase_add_test(tc_misc, getperiodseconds_returns_zero_when_there_is_no_time_spent); tcase_add_test(tc_misc, getperiodseconds_knows_spent_ongoing_time); tcase_add_test(tc_misc, getestimates_has_error_handling); tcase_add_test(tc_misc, getestimates_has_a_crystal_ball); tcase_add_test(tc_misc, ishelprequest_knows_what_a_help_request_is); suite_add_tcase(s, tc_misc); } vnstat-2.9/tests/config_tests.c0000644000000000000000000004446614077640332015422 0ustar rootroot#include "common.h" #include "vnstat_tests.h" #include "config_tests.h" #include "cfg.h" #include "cfgoutput.h" #include "ibw.h" START_TEST(validatecfg_default_all) { validatecfg(CT_All); } END_TEST START_TEST(validatecfg_default_cli) { validatecfg(CT_CLI); } END_TEST START_TEST(validatecfg_default_daemon) { validatecfg(CT_Daemon); } END_TEST START_TEST(validatecfg_default_image) { validatecfg(CT_Image); } END_TEST START_TEST(validatecfg_does_not_modify_valid_changes) { ck_assert_int_eq(cfg.listhours, LISTHOURS); cfg.listhours = 1; ck_assert_int_ne(cfg.listhours, LISTHOURS); validatecfg(CT_All); ck_assert_int_eq(cfg.listhours, 1); } END_TEST START_TEST(validatecfg_restores_invalid_values_back_to_default) { cfg.unitmode = 3; cfg.savestatus = 2; cfg.listhours = -1; suppress_output(); validatecfg(CT_All); ck_assert_int_eq(cfg.unitmode, UNITMODE); ck_assert_int_eq(cfg.savestatus, SAVESTATUS); ck_assert_int_eq(cfg.listhours, LISTHOURS); } END_TEST START_TEST(validatecfg_can_tune_updateinterval_to_avoid_rollover_issues) { cfg.updateinterval = 60; cfg.maxbw = 1000; cfg.bwdetection = 1; suppress_output(); validatecfg(CT_Daemon); ck_assert_int_ne(cfg.updateinterval, 60); ck_assert_int_eq(cfg.updateinterval, UPDATEINTERVAL); } END_TEST START_TEST(validatecfg_has_fallback_for_updateinterval_for_very_fast_interfaces) { cfg.updateinterval = 60; cfg.maxbw = 2000; cfg.bwdetection = 1; suppress_output(); validatecfg(CT_Daemon); ck_assert_int_ne(cfg.updateinterval, 60); ck_assert_int_ne(cfg.updateinterval, UPDATEINTERVAL); ck_assert_int_eq(cfg.updateinterval, (UPDATEINTERVAL / 2)); } END_TEST START_TEST(validatecfg_can_change_estimatestyle_for_images_depending_on_settings) { debug = 1; cfg.barshowsrate = 0; cfg.estimatebarvisible = 0; cfg.estimatestyle = 1; suppress_output(); validatecfg(CT_Image); ck_assert_int_eq(cfg.barshowsrate, 0); ck_assert_int_eq(cfg.estimatebarvisible, 0); ck_assert_int_eq(cfg.estimatestyle, 1); cfg.barshowsrate = 1; cfg.estimatebarvisible = 0; validatecfg(CT_Image); ck_assert_int_eq(cfg.barshowsrate, 1); ck_assert_int_eq(cfg.estimatebarvisible, 0); ck_assert_int_eq(cfg.estimatestyle, 1); cfg.barshowsrate = 0; cfg.estimatebarvisible = 1; validatecfg(CT_Image); ck_assert_int_eq(cfg.barshowsrate, 0); ck_assert_int_eq(cfg.estimatebarvisible, 1); ck_assert_int_eq(cfg.estimatestyle, 1); cfg.barshowsrate = 1; cfg.estimatebarvisible = 1; validatecfg(CT_Image); ck_assert_int_eq(cfg.barshowsrate, 1); ck_assert_int_eq(cfg.estimatebarvisible, 1); ck_assert_int_eq(cfg.estimatestyle, 0); } END_TEST START_TEST(validatecfg_limits_5_minute_result_count_to_available_data_amount) { cfg.fiveminutehours = 26; cfg.fivegresultcount = 9001; suppress_output(); validatecfg(CT_Image); ck_assert_int_eq(cfg.fiveminutehours, 26); ck_assert_int_eq(cfg.fivegresultcount, 312); } END_TEST START_TEST(validatecfg_limits_5_minute_result_count_to_minimum_usable) { cfg.fiveminutehours = 12; cfg.fivegresultcount = 9001; suppress_output(); validatecfg(CT_Image); ck_assert_int_eq(cfg.fiveminutehours, 12); ck_assert_int_eq(cfg.fivegresultcount, 288); } END_TEST START_TEST(validatecfg_limits_5_minute_result_count_to_not_be_too_much) { cfg.fiveminutehours = 9001; cfg.fivegresultcount = 12345; suppress_output(); validatecfg(CT_Image); ck_assert_int_eq(cfg.fiveminutehours, 9001); ck_assert_int_eq(cfg.fivegresultcount, FIVEGRESULTCOUNT); } END_TEST START_TEST(validatecfg_does_not_touch_5_minute_result_count_if_data_is_not_being_created) { cfg.fiveminutehours = 0; cfg.fivegresultcount = 1234; suppress_output(); validatecfg(CT_Image); ck_assert_int_eq(cfg.fiveminutehours, 0); ck_assert_int_eq(cfg.fivegresultcount, 1234); } END_TEST START_TEST(validatecfg_is_not_stupid_with_5_minute_result_count_if_there_is_no_data_limit) { cfg.fiveminutehours = -1; cfg.fivegresultcount = 1242; suppress_output(); validatecfg(CT_Image); ck_assert_int_eq(cfg.fiveminutehours, -1); ck_assert_int_eq(cfg.fivegresultcount, 1242); } END_TEST START_TEST(printcfgfile_default) { ck_assert_int_eq(ibwadd("name1", 1), 1); ck_assert_int_eq(ibwadd("name2", 2), 1); suppress_output(); printcfgfile(); } END_TEST START_TEST(printcfgfile_experimental) { cfg.experimental = 1; ck_assert_int_eq(ibwadd("name1", 1), 1); ck_assert_int_eq(ibwadd("name2", 2), 1); suppress_output(); printcfgfile(); } END_TEST START_TEST(loadcfg_included_default) { ck_assert_int_eq(loadcfg(CFGFILE, CT_All), 1); } END_TEST START_TEST(loadcfg_no_file) { ck_assert_int_eq(loadcfg("", CT_All), 1); } END_TEST START_TEST(loadcfg_nonexistent_file) { suppress_output(); ck_assert_int_eq(loadcfg("_nosuchfile_", CT_All), 0); } END_TEST START_TEST(loadcfg_not_a_cfgfile) { ck_assert_int_eq(loadcfg("Makefile", CT_All), 1); } END_TEST START_TEST(ibwloadcfg_included_default) { ck_assert_int_eq(ibwloadcfg(CFGFILE), 1); } END_TEST START_TEST(ibwloadcfg_no_file) { ck_assert_int_eq(ibwloadcfg(""), 1); } END_TEST START_TEST(ibwloadcfg_nonexistent_file) { suppress_output(); ck_assert_int_eq(ibwloadcfg("_nosuchfile_"), 0); } END_TEST START_TEST(ibwloadcfg_not_a_cfgfile) { ck_assert_int_eq(ibwloadcfg("Makefile"), 1); } END_TEST START_TEST(ibwget_with_empty_list_and_no_maxbw) { uint32_t limit; cfg.maxbw = 0; ibwflush(); ck_assert_int_eq(ibwget("does_not_exist", &limit), 0); } END_TEST START_TEST(ibwget_with_empty_list_and_maxbw) { int ret; uint32_t limit; cfg.maxbw = 10; ibwflush(); ret = ibwget("does_not_exist", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 10); } END_TEST START_TEST(ibwget_with_empty_list_gives_speed_instead_of_maxbw_if_available) { int ret; uint32_t limit; linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_sys_class_net("ethnotseen", 0, 0, 0, 0, 21); cfg.maxbw = 12; ibwflush(); ret = ibwget("ethnotseen", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 21); } END_TEST START_TEST(ibwget_with_empty_list_gives_maxbw_for_tun_even_if_speed_is_available) { int ret; uint32_t limit; linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_sys_class_net("tun142", 0, 0, 0, 0, 10); cfg.maxbw = 12; ibwflush(); ret = ibwget("tun142", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 12); } END_TEST START_TEST(ibwget_from_config) { int ret; uint32_t limit; ck_assert_int_eq(loadcfg(CFGFILE, CT_All), 1); ck_assert_int_eq(ibwloadcfg(CFGFILE), 1); cfg.maxbw = 10; ret = ibwget("ethnone", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 8); } END_TEST START_TEST(ibwget_from_config_ignores_detected_speed) { int ret; uint32_t limit; linuxonly; ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_sys_class_net("ethnone", 0, 0, 0, 0, 42); ck_assert_int_eq(loadcfg(CFGFILE, CT_All), 1); ck_assert_int_eq(ibwloadcfg(CFGFILE), 1); cfg.maxbw = 10; ret = ibwget("ethnone", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 8); } END_TEST START_TEST(ibwadd_single_success) { int ret; uint32_t limit; cfg.maxbw = 0; ck_assert_int_eq(ibwadd("newinterface", 1), 1); ret = ibwget("does_not_exist", &limit); ck_assert_int_eq(ret, 0); ck_assert_int_eq(limit, 0); ret = ibwget("newinterface", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 1); } END_TEST START_TEST(ibwadd_multi_success) { int ret; uint32_t limit; cfg.maxbw = 0; ck_assert_int_eq(ibwadd("name1", 1), 1); ck_assert_int_eq(ibwadd("name2", 2), 1); ck_assert_int_eq(ibwadd("name3", 3), 1); ck_assert_int_eq(ibwadd("name4", 2), 1); ck_assert_int_eq(ibwadd("name5", 1), 1); ck_assert_int_eq(ibwadd("name6", 10), 1); ret = ibwget("does_not_exist", &limit); ck_assert_int_eq(ret, 0); ck_assert_int_eq(limit, 0); ret = ibwget("name1", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 1); ret = ibwget("name3", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 3); ret = ibwget("name4", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 2); ret = ibwget("name6", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 10); ret = ibwget("name2", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 2); ret = ibwget("name5", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 1); ret = ibwget("name1", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 1); ret = ibwget("does_not_exist", &limit); ck_assert_int_eq(ret, 0); ck_assert_int_eq(limit, 0); } END_TEST START_TEST(ibwadd_update_success) { int ret; uint32_t limit; cfg.maxbw = 0; ck_assert_int_eq(ibwadd("name1", 1), 1); ck_assert_int_eq(ibwadd("name2", 2), 1); ret = ibwget("does_not_exist", &limit); ck_assert_int_eq(ret, 0); ck_assert_int_eq(limit, 0); ret = ibwget("name1", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 1); ret = ibwget("name2", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 2); ret = ibwget("does_not_exist", &limit); ck_assert_int_eq(ret, 0); ck_assert_int_eq(limit, 0); ck_assert_int_eq(ibwadd("name2", 5), 1); ck_assert_int_eq(ibwadd("name1", 4), 1); ret = ibwget("name1", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 4); ret = ibwget("name2", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 5); ret = ibwget("does_not_exist", &limit); ck_assert_int_eq(ret, 0); ck_assert_int_eq(limit, 0); } END_TEST START_TEST(ibwflush_success) { int ret; uint32_t limit; cfg.maxbw = 0; ck_assert_int_eq(ibwadd("name1", 1), 1); ck_assert_int_eq(ibwadd("name2", 2), 1); ret = ibwget("name1", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 1); ret = ibwget("name2", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 2); ret = ibwget("does_not_exist", &limit); ck_assert_int_eq(ret, 0); ck_assert_int_eq(limit, 0); ibwflush(); ret = ibwget("name1", &limit); ck_assert_int_eq(ret, 0); ck_assert_int_eq(limit, 0); ret = ibwget("name2", &limit); ck_assert_int_eq(ret, 0); ck_assert_int_eq(limit, 0); ret = ibwget("does_not_exist", &limit); ck_assert_int_eq(ret, 0); ck_assert_int_eq(limit, 0); ck_assert_int_eq(ibwadd("name1", 1), 1); ck_assert_int_eq(ibwadd("name2", 2), 1); ret = ibwget("name1", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 1); ret = ibwget("name2", &limit); ck_assert_int_eq(ret, 1); ck_assert_int_eq(limit, 2); ret = ibwget("does_not_exist", &limit); ck_assert_int_eq(ret, 0); ck_assert_int_eq(limit, 0); } END_TEST START_TEST(ibwlist_empty) { suppress_output(); ibwlist(); } END_TEST START_TEST(ibwlist_filled) { cfg.maxbw = 0; ck_assert_int_eq(ibwadd("name1", 1), 1); ck_assert_int_eq(ibwadd("name2", 2), 1); suppress_output(); ibwlist(); } END_TEST START_TEST(extractcfgvalue_can_extract) { int ret; char value[32], cfgline[32]; snprintf(cfgline, 32, "one 1"); ret = extractcfgvalue(value, 32, cfgline, 3); ck_assert_int_eq(ret, 1); ck_assert_str_eq(value, "1"); } END_TEST START_TEST(extractcfgvalue_can_really_extract) { int ret; char value[32], cfgline[32]; snprintf(cfgline, 32, "one\t1"); ret = extractcfgvalue(value, 32, cfgline, 3); ck_assert_int_eq(ret, 1); ck_assert_str_eq(value, "1"); snprintf(cfgline, 32, "one\t\t1"); ret = extractcfgvalue(value, 32, cfgline, 3); ck_assert_int_eq(ret, 1); ck_assert_str_eq(value, "1"); snprintf(cfgline, 32, "one \t 1"); ret = extractcfgvalue(value, 32, cfgline, 3); ck_assert_int_eq(ret, 1); ck_assert_str_eq(value, "1"); snprintf(cfgline, 32, "one \t 1 \t2"); ret = extractcfgvalue(value, 32, cfgline, 3); ck_assert_int_eq(ret, 4); ck_assert_str_eq(value, "1 \t2"); snprintf(cfgline, 32, "one \"1\""); ret = extractcfgvalue(value, 32, cfgline, 3); ck_assert_int_eq(ret, 1); ck_assert_str_eq(value, "1"); snprintf(cfgline, 32, "one\t\"1\""); ret = extractcfgvalue(value, 32, cfgline, 3); ck_assert_int_eq(ret, 1); ck_assert_str_eq(value, "1"); snprintf(cfgline, 32, "one \t \"1\""); ret = extractcfgvalue(value, 32, cfgline, 3); ck_assert_int_eq(ret, 1); ck_assert_str_eq(value, "1"); snprintf(cfgline, 32, "one \t \"1\" \t"); ret = extractcfgvalue(value, 32, cfgline, 3); ck_assert_int_eq(ret, 1); ck_assert_str_eq(value, "1"); snprintf(cfgline, 32, "one \t \"1\" \t2"); ret = extractcfgvalue(value, 32, cfgline, 3); ck_assert_int_eq(ret, 1); ck_assert_str_eq(value, "1"); snprintf(cfgline, 32, "one \t == \t \"1\" \t == well doh"); ret = extractcfgvalue(value, 32, cfgline, 3); ck_assert_int_eq(ret, 1); ck_assert_str_eq(value, "1"); } END_TEST START_TEST(extractcfgvalue_knows_when_not_to_extract) { int ret; char value[32], cfgline[32]; snprintf(cfgline, 32, "one"); ret = extractcfgvalue(value, 32, cfgline, 3); ck_assert_int_eq(ret, 0); ck_assert_str_eq(value, ""); } END_TEST START_TEST(extractcfgvalue_really_knows_when_not_to_extract) { int ret; char value[32], cfgline[32]; snprintf(cfgline, 32, "one \t "); ret = extractcfgvalue(value, 32, cfgline, 3); ck_assert_int_eq(ret, 0); ck_assert_str_eq(value, ""); } END_TEST START_TEST(setcfgvalue_can_set_chars) { int ret; char target[32]; struct cfgsetting cset[] = {{"unused", target, 0, 32, 0}}; ret = setcfgvalue(&cset[0], "one", "unused"); ck_assert_int_eq(ret, 1); ck_assert_str_eq(target, "one"); ret = setcfgvalue(&cset[0], "1", "unused"); ck_assert_int_eq(ret, 1); ck_assert_str_eq(target, "1"); ret = setcfgvalue(&cset[0], "-", "unused"); ck_assert_int_eq(ret, 1); ck_assert_str_eq(target, "-"); ret = setcfgvalue(&cset[0], "qwe rty uio ads", "unused"); ck_assert_int_eq(ret, 1); ck_assert_str_eq(target, "qwe rty uio ads"); } END_TEST START_TEST(setcfgvalue_can_set_ints) { int ret, target; struct cfgsetting cset[] = {{"unused", 0, &target, 0, 0}}; ret = setcfgvalue(&cset[0], "1", "unused"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(target, 1); ret = setcfgvalue(&cset[0], "123", "unused"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(target, 123); ret = setcfgvalue(&cset[0], "-1", "unused"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(target, -1); ret = setcfgvalue(&cset[0], "-321", "unused"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(target, -321); ret = setcfgvalue(&cset[0], "0", "unused"); ck_assert_int_eq(ret, 1); ck_assert_int_eq(target, 0); } END_TEST START_TEST(setcfgvalue_does_not_exceed_char_limit) { int ret; char target[10]; struct cfgsetting cset[] = {{"unused", target, 0, 5, 0}}; ret = setcfgvalue(&cset[0], "one", "unused"); ck_assert_int_eq(ret, 1); ck_assert_str_eq(target, "one"); ret = setcfgvalue(&cset[0], "12345", "unused"); ck_assert_int_eq(ret, 1); ck_assert_str_eq(target, "1234"); ret = setcfgvalue(&cset[0], "12 5", "unused"); ck_assert_int_eq(ret, 1); ck_assert_str_eq(target, "12 "); } END_TEST START_TEST(setcfgvalue_can_do_nothing) { int ret; struct cfgsetting cset[] = {{"unused", 0, 0, 0, 0}}; ret = setcfgvalue(&cset[0], "nothing", "unused"); ck_assert_int_eq(ret, 0); } END_TEST START_TEST(configlocale_does_not_crash) { unsetenv("LC_ALL"); snprintf(cfg.locale, 32, "en_US"); configlocale(); snprintf(cfg.locale, 32, "-"); configlocale(); setenv("LC_ALL", "en_US", 1); snprintf(cfg.locale, 32, "en_US"); configlocale(); ck_assert_int_eq(cfg.utflocale, 0); snprintf(cfg.locale, 32, "-"); configlocale(); ck_assert_int_eq(cfg.utflocale, 0); setenv("LC_ALL", "en_US.UTF-8", 1); snprintf(cfg.locale, 32, "en_US"); configlocale(); ck_assert_int_eq(cfg.utflocale, 1); snprintf(cfg.locale, 32, "-"); configlocale(); ck_assert_int_eq(cfg.utflocale, 1); } END_TEST void add_config_tests(Suite *s) { TCase *tc_config = tcase_create("Config"); tcase_add_checked_fixture(tc_config, setup, teardown); tcase_add_unchecked_fixture(tc_config, setup, teardown); tcase_add_test(tc_config, validatecfg_default_all); tcase_add_test(tc_config, validatecfg_default_cli); tcase_add_test(tc_config, validatecfg_default_daemon); tcase_add_test(tc_config, validatecfg_default_image); tcase_add_test(tc_config, validatecfg_does_not_modify_valid_changes); tcase_add_test(tc_config, validatecfg_restores_invalid_values_back_to_default); tcase_add_test(tc_config, validatecfg_can_tune_updateinterval_to_avoid_rollover_issues); tcase_add_test(tc_config, validatecfg_has_fallback_for_updateinterval_for_very_fast_interfaces); tcase_add_test(tc_config, validatecfg_can_change_estimatestyle_for_images_depending_on_settings); tcase_add_test(tc_config, validatecfg_limits_5_minute_result_count_to_available_data_amount); tcase_add_test(tc_config, validatecfg_limits_5_minute_result_count_to_minimum_usable); tcase_add_test(tc_config, validatecfg_limits_5_minute_result_count_to_not_be_too_much); tcase_add_test(tc_config, validatecfg_does_not_touch_5_minute_result_count_if_data_is_not_being_created); tcase_add_test(tc_config, validatecfg_is_not_stupid_with_5_minute_result_count_if_there_is_no_data_limit); tcase_add_test(tc_config, printcfgfile_default); tcase_add_test(tc_config, printcfgfile_experimental); tcase_add_test(tc_config, loadcfg_included_default); tcase_add_test(tc_config, loadcfg_no_file); tcase_add_test(tc_config, loadcfg_nonexistent_file); tcase_add_test(tc_config, loadcfg_not_a_cfgfile); tcase_add_test(tc_config, ibwloadcfg_included_default); tcase_add_test(tc_config, ibwloadcfg_no_file); tcase_add_test(tc_config, ibwloadcfg_nonexistent_file); tcase_add_test(tc_config, ibwloadcfg_not_a_cfgfile); tcase_add_test(tc_config, ibwget_with_empty_list_and_no_maxbw); tcase_add_test(tc_config, ibwget_with_empty_list_and_maxbw); tcase_add_test(tc_config, ibwget_with_empty_list_gives_speed_instead_of_maxbw_if_available); tcase_add_test(tc_config, ibwget_with_empty_list_gives_maxbw_for_tun_even_if_speed_is_available); tcase_add_test(tc_config, ibwget_from_config); tcase_add_test(tc_config, ibwget_from_config_ignores_detected_speed); tcase_add_test(tc_config, ibwadd_single_success); tcase_add_test(tc_config, ibwadd_multi_success); tcase_add_test(tc_config, ibwadd_update_success); tcase_add_test(tc_config, ibwflush_success); tcase_add_test(tc_config, ibwlist_empty); tcase_add_test(tc_config, ibwlist_filled); tcase_add_test(tc_config, extractcfgvalue_can_extract); tcase_add_test(tc_config, extractcfgvalue_can_really_extract); tcase_add_test(tc_config, extractcfgvalue_knows_when_not_to_extract); tcase_add_test(tc_config, extractcfgvalue_really_knows_when_not_to_extract); tcase_add_test(tc_config, setcfgvalue_can_set_chars); tcase_add_test(tc_config, setcfgvalue_can_set_ints); tcase_add_test(tc_config, setcfgvalue_does_not_exceed_char_limit); tcase_add_test(tc_config, setcfgvalue_can_do_nothing); tcase_add_test(tc_config, configlocale_does_not_crash); suite_add_tcase(s, tc_config); } vnstat-2.9/tests/iflist_tests.h0000644000000000000000000000013013501451354015423 0ustar rootroot#ifndef IFLIST_TESTS_H #define IFLIST_TESTS_H void add_iflist_tests(Suite *s); #endif vnstat-2.9/tests/daemon_tests.h0000644000000000000000000000013013510474556015405 0ustar rootroot#ifndef DAEMON_TESTS_H #define DAEMON_TESTS_H void add_daemon_tests(Suite *s); #endif vnstat-2.9/tests/misc_tests.h0000644000000000000000000000012213422305757015074 0ustar rootroot#ifndef MISC_TESTS_H #define MISC_TESTS_H void add_misc_tests(Suite *s); #endif vnstat-2.9/Makefile.am0000644000000000000000000001353514164655653013463 0ustar rootrootSUBDIRS = . AM_CFLAGS = @CFLAG_EXTRAS@ dist_man_MANS = man/vnstat.1 man/vnstat.conf.5 man/vnstatd.8 man/vnstati.1 EXTRA_DIST = cfg examples UPGRADE CHANGES FAQ INSTALL_BSD UNINSTALL bin_PROGRAMS = vnstat sbin_PROGRAMS = vnstatd if HAVE_LIBGD bin_PROGRAMS += vnstati endif vnstati_LDADD = @IMAGELIBS@ vnstat_SOURCES = src/vnstat.c \ src/vnstat_func.c src/vnstat_func.h \ src/ifinfo.c src/ifinfo.h \ src/iflist.c src/iflist.h \ src/dbsql.c src/dbsql.h \ src/dbxml.c src/dbxml.h \ src/dbjson.c src/dbjson.h \ src/dbshow.c src/dbshow.h \ src/common.c src/common.h \ src/misc.c src/misc.h \ src/cfg.c src/cfg.h \ src/cfgoutput.c src/cfgoutput.h \ src/ibw.c src/ibw.h \ src/fs.c src/fs.h \ src/id.c src/id.h \ src/traffic.c src/traffic.h vnstatd_SOURCES = src/vnstatd.c src/vnstatd.h \ src/ifinfo.c src/ifinfo.h \ src/iflist.c src/iflist.h \ src/dbsql.c src/dbsql.h \ src/dbaccess.c src/dbaccess.h \ src/datacache.c src/datacache.h \ src/common.c src/common.h \ src/misc.c src/misc.h \ src/cfg.c src/cfg.h \ src/ibw.c src/ibw.h \ src/fs.c src/fs.h \ src/id.c src/id.h \ src/daemon.c src/daemon.h vnstati_SOURCES = src/vnstati.c src/vnstati.h \ src/iflist.c src/iflist.h \ src/image.c src/image.h \ src/image_support.c src/image_support.h \ src/dbsql.c src/dbsql.h \ src/common.c src/common.h \ src/misc.c src/misc.h \ src/fs.c src/fs.h \ src/id.c src/id.h \ src/cfg.c src/cfg.h if HAVE_CHECK TESTS = check_vnstat check_PROGRAMS = check_vnstat check_vnstat_CFLAGS = @CFLAG_EXTRAS@ @CHECK_CFLAGS@ \ -DPROCNETDEV=\"testdir/proc/dev\" \ -DSYSCLASSNET=\"testdir/sysclassnet\" \ -DCFGFILE=\"tests/vnstat.conf\" \ -DCHECK_VNSTAT \ -I$(top_srcdir)/src check_vnstat_LDADD = @CHECK_LIBS@ EXTRA_check_vnstat_DEPENDENCIES = tests/vnstat.conf check_vnstat_SOURCES = tests/vnstat_tests.c tests/vnstat_tests.h \ tests/common_tests.c tests/common_tests.h \ tests/database_tests.c tests/database_tests.h \ tests/dbsql_tests.c tests/dbsql_tests.h \ tests/datacache_tests.c tests/datacache_tests.h \ tests/config_tests.c tests/config_tests.h \ tests/ifinfo_tests.c tests/ifinfo_tests.h \ tests/misc_tests.c tests/misc_tests.h \ tests/fs_tests.c tests/fs_tests.h \ tests/id_tests.c tests/id_tests.h \ tests/iflist_tests.c tests/iflist_tests.h \ tests/cli_tests.c tests/cli_tests.h \ tests/parseargs_tests.c tests/parseargs_tests.h \ tests/daemon_tests.c tests/daemon_tests.h check_vnstat_SOURCES += src/cfg.c src/cfg.h \ src/cfgoutput.c src/cfgoutput.h \ src/common.c src/common.h \ src/daemon.c src/daemon.h \ src/dbsql.c src/dbsql.h \ src/dbaccess.c src/dbaccess.h \ src/datacache.c src/datacache.h \ src/dbshow.c src/dbshow.h \ src/dbjson.c src/dbjson.h \ src/dbxml.c src/dbxml.h \ src/ibw.c src/ibw.h \ src/ifinfo.c src/ifinfo.h \ src/iflist.c src/iflist.h \ src/misc.c src/misc.h \ src/fs.c src/fs.h \ src/id.c src/id.h \ src/vnstat_func.c src/vnstat_func.h \ src/traffic.c src/traffic.h if HAVE_LIBGD check_vnstat_CFLAGS += -DHAVE_IMAGE check_vnstat_LDADD += @IMAGELIBS@ check_vnstat_SOURCES += tests/image_tests.c tests/image_tests.h \ src/image.c src/image.h \ src/image_support.c src/image_support.h endif endif INSTALL: cp -a INSTALL.md INSTALL INSTALL_BSD: cp -a INSTALL_BSD.md INSTALL_BSD UPGRADE: cp -a UPGRADE.md UPGRADE UNINSTALL: cp -a UNINSTALL.md UNINSTALL setdebug: CFLAGS='-Wall -Wextra -g' ./configure profile: CFLAGS='-Wall -Wextra -g -fprofile-arcs -ftest-coverage' LDLIBS='-fprofile-arcs -ftest-coverage' ./configure make check lcov -c -d $(PWD) -o coverage.lcov genhtml coverage.lcov --num-spaces 4 -p $(PWD) -o coverage myclean: maintainer-clean mancheck: @echo "Testing man pages for errors and warnings" @for m in $(dist_man_MANS); do \ echo " * $$m"; \ LC_ALL=en_US.UTF-8 MANROFFSEQ='' MANWIDTH=80 man --warnings -E UTF-8 -l -Tutf8 -Z $(srcdir)/$$m >/dev/null; \ done release: distcheck tar zxf $(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz rm -f $(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz fakeroot tar zcf $(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz $(PACKAGE_NAME)-$(PACKAGE_VERSION) rm -fr $(PACKAGE_NAME)-$(PACKAGE_VERSION) ls -l $(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz install-data-hook: install-exec if [ -f $(DESTDIR)$(man1dir)/vnstatd.1 ]; then rm -f $(DESTDIR)$(man1dir)/vnstatd.1; fi $(MKDIR_P) $(DESTDIR)$(sysconfdir) if IS_CROSSCOMPILED if [ ! -f $(DESTDIR)$(sysconfdir)/vnstat.conf ]; \ then cp -fv $(srcdir)/cfg/vnstat.conf $(DESTDIR)$(sysconfdir)/vnstat.conf; \ fi else $(DESTDIR)$(bindir)/vnstat$(EXEEXT) --showconfig >vnstat.conf.new if [ -f $(DESTDIR)$(sysconfdir)/vnstat.conf ]; \ then cp -fv $(DESTDIR)$(sysconfdir)/vnstat.conf vnstat.conf.old; \ fi cp -fv vnstat.conf.new $(DESTDIR)$(sysconfdir)/vnstat.conf endif @echo @echo "============================================================================" @echo " Note: No service file has been installed for starting the daemon" @echo " automatically. Such setup will need to be created manually" @echo " depending on the used environment. See the included documentation." @echo "============================================================================" @echo uninstall-hook: -rm -f $(DESTDIR)$(sysconfdir)/vnstat.conf -rmdir $(DESTDIR)$(sysconfdir) @echo @echo "==================================================================" @echo " Note: The database directory has been left untouched." @echo " It will need to be removed manually if no longer needed." @echo "==================================================================" @echo clean-local: -rm -fr coverage *.lcov *.gz test*.log test*.xml src/*.gc* tests/*.gc* tests/*.conf *.old *.new *check.png INSTALL INSTALL_BSD UPGRADE UNINSTALL check-local: check-TESTS tail -n 2 test.log tests/vnstat.conf: $(top_srcdir)/cfg/vnstat.conf sed 's/^;//g' $(top_srcdir)/cfg/vnstat.conf >$@ echo "MaxBWethnone 8" >>$@ vnstat-2.9/aclocal.m40000644000000000000000000015305214173305711013251 0ustar rootroot# generated automatically by aclocal 1.16.1 -*- Autoconf -*- # Copyright (C) 1996-2018 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])]) m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],, [m4_warning([this file was generated for autoconf 2.69. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically 'autoreconf'.])]) dnl pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- dnl serial 11 (pkg-config-0.29.1) dnl dnl Copyright © 2004 Scott James Remnant . dnl Copyright © 2012-2015 Dan Nicholson dnl dnl This program is free software; you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by dnl the Free Software Foundation; either version 2 of the License, or dnl (at your option) any later version. dnl dnl This program is distributed in the hope that it will be useful, but dnl WITHOUT ANY WARRANTY; without even the implied warranty of dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU dnl General Public License for more details. dnl dnl You should have received a copy of the GNU General Public License dnl along with this program; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA dnl 02111-1307, USA. dnl dnl As a special exception to the GNU General Public License, if you dnl distribute this file as part of a program that contains a dnl configuration script generated by Autoconf, you may include it under dnl the same distribution terms that you use for the rest of that dnl program. dnl PKG_PREREQ(MIN-VERSION) dnl ----------------------- dnl Since: 0.29 dnl dnl Verify that the version of the pkg-config macros are at least dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's dnl installed version of pkg-config, this checks the developer's version dnl of pkg.m4 when generating configure. dnl dnl To ensure that this macro is defined, also add: dnl m4_ifndef([PKG_PREREQ], dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])]) dnl dnl See the "Since" comment for each macro you use to see what version dnl of the macros you require. m4_defun([PKG_PREREQ], [m4_define([PKG_MACROS_VERSION], [0.29.1]) m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1, [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])]) ])dnl PKG_PREREQ dnl PKG_PROG_PKG_CONFIG([MIN-VERSION]) dnl ---------------------------------- dnl Since: 0.16 dnl dnl Search for the pkg-config tool and set the PKG_CONFIG variable to dnl first found in the path. Checks that the version of pkg-config found dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.9.0 is dnl used since that's the first version where most current features of dnl pkg-config existed. AC_DEFUN([PKG_PROG_PKG_CONFIG], [m4_pattern_forbid([^_?PKG_[A-Z_]+$]) m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$]) m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$]) AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility]) AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path]) AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path]) if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) fi if test -n "$PKG_CONFIG"; then _pkg_min_version=m4_default([$1], [0.9.0]) AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) PKG_CONFIG="" fi fi[]dnl ])dnl PKG_PROG_PKG_CONFIG dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) dnl ------------------------------------------------------------------- dnl Since: 0.18 dnl dnl Check to see whether a particular set of modules exists. Similar to dnl PKG_CHECK_MODULES(), but does not set variables or print errors. dnl dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) dnl only at the first occurence in configure.ac, so if the first place dnl it's called might be skipped (such as if it is within an "if", you dnl have to call PKG_CHECK_EXISTS manually AC_DEFUN([PKG_CHECK_EXISTS], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl if test -n "$PKG_CONFIG" && \ AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then m4_default([$2], [:]) m4_ifvaln([$3], [else $3])dnl fi]) dnl _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) dnl --------------------------------------------- dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting dnl pkg_failed based on the result. m4_define([_PKG_CONFIG], [if test -n "$$1"; then pkg_cv_[]$1="$$1" elif test -n "$PKG_CONFIG"; then PKG_CHECK_EXISTS([$3], [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null` test "x$?" != "x0" && pkg_failed=yes ], [pkg_failed=yes]) else pkg_failed=untried fi[]dnl ])dnl _PKG_CONFIG dnl _PKG_SHORT_ERRORS_SUPPORTED dnl --------------------------- dnl Internal check to see if pkg-config supports short errors. AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], [AC_REQUIRE([PKG_PROG_PKG_CONFIG]) if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then _pkg_short_errors_supported=yes else _pkg_short_errors_supported=no fi[]dnl ])dnl _PKG_SHORT_ERRORS_SUPPORTED dnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], dnl [ACTION-IF-NOT-FOUND]) dnl -------------------------------------------------------------- dnl Since: 0.4.0 dnl dnl Note that if there is a possibility the first call to dnl PKG_CHECK_MODULES might not happen, you should be sure to include an dnl explicit call to PKG_PROG_PKG_CONFIG in your configure.ac AC_DEFUN([PKG_CHECK_MODULES], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl pkg_failed=no AC_MSG_CHECKING([for $1]) _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) _PKG_CONFIG([$1][_LIBS], [libs], [$2]) m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS and $1[]_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details.]) if test $pkg_failed = yes; then AC_MSG_RESULT([no]) _PKG_SHORT_ERRORS_SUPPORTED if test $_pkg_short_errors_supported = yes; then $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1` else $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1` fi # Put the nasty error message in config.log where it belongs echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD m4_default([$4], [AC_MSG_ERROR( [Package requirements ($2) were not met: $$1_PKG_ERRORS Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. _PKG_TEXT])[]dnl ]) elif test $pkg_failed = untried; then AC_MSG_RESULT([no]) m4_default([$4], [AC_MSG_FAILURE( [The pkg-config script could not be found or is too old. Make sure it is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config. _PKG_TEXT To get pkg-config, see .])[]dnl ]) else $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS $1[]_LIBS=$pkg_cv_[]$1[]_LIBS AC_MSG_RESULT([yes]) $3 fi[]dnl ])dnl PKG_CHECK_MODULES dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], dnl [ACTION-IF-NOT-FOUND]) dnl --------------------------------------------------------------------- dnl Since: 0.29 dnl dnl Checks for existence of MODULES and gathers its build flags with dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags dnl and VARIABLE-PREFIX_LIBS from --libs. dnl dnl Note that if there is a possibility the first call to dnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to dnl include an explicit call to PKG_PROG_PKG_CONFIG in your dnl configure.ac. AC_DEFUN([PKG_CHECK_MODULES_STATIC], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl _save_PKG_CONFIG=$PKG_CONFIG PKG_CONFIG="$PKG_CONFIG --static" PKG_CHECK_MODULES($@) PKG_CONFIG=$_save_PKG_CONFIG[]dnl ])dnl PKG_CHECK_MODULES_STATIC dnl PKG_INSTALLDIR([DIRECTORY]) dnl ------------------------- dnl Since: 0.27 dnl dnl Substitutes the variable pkgconfigdir as the location where a module dnl should install pkg-config .pc files. By default the directory is dnl $libdir/pkgconfig, but the default can be changed by passing dnl DIRECTORY. The user can override through the --with-pkgconfigdir dnl parameter. AC_DEFUN([PKG_INSTALLDIR], [m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])]) m4_pushdef([pkg_description], [pkg-config installation directory @<:@]pkg_default[@:>@]) AC_ARG_WITH([pkgconfigdir], [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],, [with_pkgconfigdir=]pkg_default) AC_SUBST([pkgconfigdir], [$with_pkgconfigdir]) m4_popdef([pkg_default]) m4_popdef([pkg_description]) ])dnl PKG_INSTALLDIR dnl PKG_NOARCH_INSTALLDIR([DIRECTORY]) dnl -------------------------------- dnl Since: 0.27 dnl dnl Substitutes the variable noarch_pkgconfigdir as the location where a dnl module should install arch-independent pkg-config .pc files. By dnl default the directory is $datadir/pkgconfig, but the default can be dnl changed by passing DIRECTORY. The user can override through the dnl --with-noarch-pkgconfigdir parameter. AC_DEFUN([PKG_NOARCH_INSTALLDIR], [m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])]) m4_pushdef([pkg_description], [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@]) AC_ARG_WITH([noarch-pkgconfigdir], [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],, [with_noarch_pkgconfigdir=]pkg_default) AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir]) m4_popdef([pkg_default]) m4_popdef([pkg_description]) ])dnl PKG_NOARCH_INSTALLDIR dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE, dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) dnl ------------------------------------------- dnl Since: 0.28 dnl dnl Retrieves the value of the pkg-config variable for the given module. AC_DEFUN([PKG_CHECK_VAR], [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl _PKG_CONFIG([$1], [variable="][$3]["], [$2]) AS_VAR_COPY([$1], [pkg_cv_][$1]) AS_VAR_IF([$1], [""], [$5], [$4])dnl ])dnl PKG_CHECK_VAR # Copyright (C) 2002-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_AUTOMAKE_VERSION(VERSION) # ---------------------------- # Automake X.Y traces this macro to ensure aclocal.m4 has been # generated from the m4 files accompanying Automake X.Y. # (This private macro should not be called outside this file.) AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version='1.16' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. m4_if([$1], [1.16.1], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) # _AM_AUTOCONF_VERSION(VERSION) # ----------------------------- # aclocal traces this macro to find the Autoconf version. # This is a private macro too. Using m4_define simplifies # the logic in aclocal, which can simply ignore this definition. m4_define([_AM_AUTOCONF_VERSION], []) # AM_SET_CURRENT_AUTOMAKE_VERSION # ------------------------------- # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], [AM_AUTOMAKE_VERSION([1.16.1])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # AM_AUX_DIR_EXPAND -*- Autoconf -*- # Copyright (C) 2001-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets # $ac_aux_dir to '$srcdir/foo'. In other projects, it is set to # '$srcdir', '$srcdir/..', or '$srcdir/../..'. # # Of course, Automake must honor this variable whenever it calls a # tool from the auxiliary directory. The problem is that $srcdir (and # therefore $ac_aux_dir as well) can be either absolute or relative, # depending on how configure is run. This is pretty annoying, since # it makes $ac_aux_dir quite unusable in subdirectories: in the top # source directory, any form will work fine, but in subdirectories a # relative path needs to be adjusted first. # # $ac_aux_dir/missing # fails when called from a subdirectory if $ac_aux_dir is relative # $top_srcdir/$ac_aux_dir/missing # fails if $ac_aux_dir is absolute, # fails when called from a subdirectory in a VPATH build with # a relative $ac_aux_dir # # The reason of the latter failure is that $top_srcdir and $ac_aux_dir # are both prefixed by $srcdir. In an in-source build this is usually # harmless because $srcdir is '.', but things will broke when you # start a VPATH build or use an absolute $srcdir. # # So we could use something similar to $top_srcdir/$ac_aux_dir/missing, # iff we strip the leading $srcdir from $ac_aux_dir. That would be: # am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"` # and then we would define $MISSING as # MISSING="\${SHELL} $am_aux_dir/missing" # This will work as long as MISSING is not called from configure, because # unfortunately $(top_srcdir) has no meaning in configure. # However there are other variables, like CC, which are often used in # configure, and could therefore not use this "fixed" $ac_aux_dir. # # Another solution, used here, is to always expand $ac_aux_dir to an # absolute PATH. The drawback is that using absolute paths prevent a # configured tree to be moved without reconfiguration. AC_DEFUN([AM_AUX_DIR_EXPAND], [AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl # Expand $ac_aux_dir to an absolute path. am_aux_dir=`cd "$ac_aux_dir" && pwd` ]) # AM_COND_IF -*- Autoconf -*- # Copyright (C) 2008-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_COND_IF # _AM_COND_ELSE # _AM_COND_ENDIF # -------------- # These macros are only used for tracing. m4_define([_AM_COND_IF]) m4_define([_AM_COND_ELSE]) m4_define([_AM_COND_ENDIF]) # AM_COND_IF(COND, [IF-TRUE], [IF-FALSE]) # --------------------------------------- # If the shell condition COND is true, execute IF-TRUE, otherwise execute # IF-FALSE. Allow automake to learn about conditional instantiating macros # (the AC_CONFIG_FOOS). AC_DEFUN([AM_COND_IF], [m4_ifndef([_AM_COND_VALUE_$1], [m4_fatal([$0: no such condition "$1"])])dnl _AM_COND_IF([$1])dnl if test -z "$$1_TRUE"; then : m4_n([$2])[]dnl m4_ifval([$3], [_AM_COND_ELSE([$1])dnl else $3 ])dnl _AM_COND_ENDIF([$1])dnl fi[]dnl ]) # AM_CONDITIONAL -*- Autoconf -*- # Copyright (C) 1997-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_CONDITIONAL(NAME, SHELL-CONDITION) # ------------------------------------- # Define a conditional. AC_DEFUN([AM_CONDITIONAL], [AC_PREREQ([2.52])dnl m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl AC_SUBST([$1_TRUE])dnl AC_SUBST([$1_FALSE])dnl _AM_SUBST_NOTMAKE([$1_TRUE])dnl _AM_SUBST_NOTMAKE([$1_FALSE])dnl m4_define([_AM_COND_VALUE_$1], [$2])dnl if $2; then $1_TRUE= $1_FALSE='#' else $1_TRUE='#' $1_FALSE= fi AC_CONFIG_COMMANDS_PRE( [if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then AC_MSG_ERROR([[conditional "$1" was never defined. Usually this means the macro was only invoked conditionally.]]) fi])]) # Copyright (C) 1999-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # There are a few dirty hacks below to avoid letting 'AC_PROG_CC' be # written in clear, in which case automake, when reading aclocal.m4, # will think it sees a *use*, and therefore will trigger all it's # C support machinery. Also note that it means that autoscan, seeing # CC etc. in the Makefile, will ask for an AC_PROG_CC use... # _AM_DEPENDENCIES(NAME) # ---------------------- # See how the compiler implements dependency checking. # NAME is "CC", "CXX", "OBJC", "OBJCXX", "UPC", or "GJC". # We try a few techniques and use that to set a single cache variable. # # We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was # modified to invoke _AM_DEPENDENCIES(CC); we would have a circular # dependency, and given that the user is not expected to run this macro, # just rely on AC_PROG_CC. AC_DEFUN([_AM_DEPENDENCIES], [AC_REQUIRE([AM_SET_DEPDIR])dnl AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl AC_REQUIRE([AM_MAKE_INCLUDE])dnl AC_REQUIRE([AM_DEP_TRACK])dnl m4_if([$1], [CC], [depcc="$CC" am_compiler_list=], [$1], [CXX], [depcc="$CXX" am_compiler_list=], [$1], [OBJC], [depcc="$OBJC" am_compiler_list='gcc3 gcc'], [$1], [OBJCXX], [depcc="$OBJCXX" am_compiler_list='gcc3 gcc'], [$1], [UPC], [depcc="$UPC" am_compiler_list=], [$1], [GCJ], [depcc="$GCJ" am_compiler_list='gcc3 gcc'], [depcc="$$1" am_compiler_list=]) AC_CACHE_CHECK([dependency style of $depcc], [am_cv_$1_dependencies_compiler_type], [if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up # making a dummy file named 'D' -- because '-MD' means "put the output # in D". rm -rf conftest.dir mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're # using a relative directory. cp "$am_depcomp" conftest.dir cd conftest.dir # We will build objects and dependencies in a subdirectory because # it helps to detect inapplicable dependency modes. For instance # both Tru64's cc and ICC support -MD to output dependencies as a # side effect of compilation, but ICC will put the dependencies in # the current directory while Tru64 will put them in the object # directory. mkdir sub am_cv_$1_dependencies_compiler_type=none if test "$am_compiler_list" = ""; then am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` fi am__universal=false m4_case([$1], [CC], [case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac], [CXX], [case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac]) for depmode in $am_compiler_list; do # Setup a source with many dependencies, because some compilers # like to wrap large dependency lists on column 80 (with \), and # we should not choose a depcomp mode which is confused by this. # # We need to recreate these files for each test, as the compiler may # overwrite some of them when testing with obscure command lines. # This happens at least with the AIX C compiler. : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with # Solaris 10 /bin/sh. echo '/* dummy */' > sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf # We check with '-c' and '-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly # handle '-M -o', and we need to detect this. Also, some Intel # versions had trouble with output in subdirs. am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in gcc) # This depmode causes a compiler race in universal mode. test "$am__universal" = false || continue ;; nosideeffect) # After this tag, mechanisms are not by side-effect, so they'll # only be used when explicitly requested. if test "x$enable_dependency_tracking" = xyes; then continue else break fi ;; msvc7 | msvc7msys | msvisualcpp | msvcmsys) # This compiler won't grok '-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} am__minus_obj= ;; none) break ;; esac if depmode=$depmode \ source=sub/conftest.c object=$am__obj \ depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ >/dev/null 2>conftest.err && grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && grep $am__obj sub/conftest.Po > /dev/null 2>&1 && ${MAKE-make} -s -f confmf > /dev/null 2>&1; then # icc doesn't choke on unknown options, it will just issue warnings # or remarks (even with -Werror). So we grep stderr for any message # that says an option was ignored or not supported. # When given -MP, icc 7.0 and 7.1 complain thusly: # icc: Command line warning: ignoring option '-M'; no argument required # The diagnosis changed in icc 8.0: # icc: Command line remark: option '-MP' not supported if (grep 'ignoring option' conftest.err || grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else am_cv_$1_dependencies_compiler_type=$depmode break fi fi done cd .. rm -rf conftest.dir else am_cv_$1_dependencies_compiler_type=none fi ]) AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) AM_CONDITIONAL([am__fastdep$1], [ test "x$enable_dependency_tracking" != xno \ && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) ]) # AM_SET_DEPDIR # ------------- # Choose a directory name for dependency files. # This macro is AC_REQUIREd in _AM_DEPENDENCIES. AC_DEFUN([AM_SET_DEPDIR], [AC_REQUIRE([AM_SET_LEADING_DOT])dnl AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl ]) # AM_DEP_TRACK # ------------ AC_DEFUN([AM_DEP_TRACK], [AC_ARG_ENABLE([dependency-tracking], [dnl AS_HELP_STRING( [--enable-dependency-tracking], [do not reject slow dependency extractors]) AS_HELP_STRING( [--disable-dependency-tracking], [speeds up one-time build])]) if test "x$enable_dependency_tracking" != xno; then am_depcomp="$ac_aux_dir/depcomp" AMDEPBACKSLASH='\' am__nodep='_no' fi AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) AC_SUBST([AMDEPBACKSLASH])dnl _AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl AC_SUBST([am__nodep])dnl _AM_SUBST_NOTMAKE([am__nodep])dnl ]) # Generate code to set up dependency tracking. -*- Autoconf -*- # Copyright (C) 1999-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_OUTPUT_DEPENDENCY_COMMANDS # ------------------------------ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], [{ # Older Autoconf quotes --file arguments for eval, but not when files # are listed without --file. Let's play safe and only enable the eval # if we detect the quoting. # TODO: see whether this extra hack can be removed once we start # requiring Autoconf 2.70 or later. AS_CASE([$CONFIG_FILES], [*\'*], [eval set x "$CONFIG_FILES"], [*], [set x $CONFIG_FILES]) shift # Used to flag and report bootstrapping failures. am_rc=0 for am_mf do # Strip MF so we end up with the name of the file. am_mf=`AS_ECHO(["$am_mf"]) | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile which includes # dependency-tracking related rules and includes. # Grep'ing the whole file directly is not great: AIX grep has a line # limit of 2048, but all sed's we know have understand at least 4000. sed -n 's,^am--depfiles:.*,X,p' "$am_mf" | grep X >/dev/null 2>&1 \ || continue am_dirpart=`AS_DIRNAME(["$am_mf"])` am_filepart=`AS_BASENAME(["$am_mf"])` AM_RUN_LOG([cd "$am_dirpart" \ && sed -e '/# am--include-marker/d' "$am_filepart" \ | $MAKE -f - am--depfiles]) || am_rc=$? done if test $am_rc -ne 0; then AC_MSG_FAILURE([Something went wrong bootstrapping makefile fragments for automatic dependency tracking. Try re-running configure with the '--disable-dependency-tracking' option to at least be able to build the package (albeit without support for automatic dependency tracking).]) fi AS_UNSET([am_dirpart]) AS_UNSET([am_filepart]) AS_UNSET([am_mf]) AS_UNSET([am_rc]) rm -f conftest-deps.mk } ])# _AM_OUTPUT_DEPENDENCY_COMMANDS # AM_OUTPUT_DEPENDENCY_COMMANDS # ----------------------------- # This macro should only be invoked once -- use via AC_REQUIRE. # # This code is only required when automatic dependency tracking is enabled. # This creates each '.Po' and '.Plo' makefile fragment that we'll need in # order to bootstrap the dependency handling code. AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], [AC_CONFIG_COMMANDS([depfiles], [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], [AMDEP_TRUE="$AMDEP_TRUE" MAKE="${MAKE-make}"])]) # Do all the work for Automake. -*- Autoconf -*- # Copyright (C) 1996-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This macro actually does too much. Some checks are only needed if # your package does certain things. But this isn't really a big deal. dnl Redefine AC_PROG_CC to automatically invoke _AM_PROG_CC_C_O. m4_define([AC_PROG_CC], m4_defn([AC_PROG_CC]) [_AM_PROG_CC_C_O ]) # AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) # AM_INIT_AUTOMAKE([OPTIONS]) # ----------------------------------------------- # The call with PACKAGE and VERSION arguments is the old style # call (pre autoconf-2.50), which is being phased out. PACKAGE # and VERSION should now be passed to AC_INIT and removed from # the call to AM_INIT_AUTOMAKE. # We support both call styles for the transition. After # the next Automake release, Autoconf can make the AC_INIT # arguments mandatory, and then we can depend on a new Autoconf # release and drop the old call support. AC_DEFUN([AM_INIT_AUTOMAKE], [AC_PREREQ([2.65])dnl dnl Autoconf wants to disallow AM_ names. We explicitly allow dnl the ones we care about. m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl AC_REQUIRE([AC_PROG_INSTALL])dnl if test "`cd $srcdir && pwd`" != "`pwd`"; then # Use -I$(srcdir) only when $(srcdir) != ., so that make's output # is not polluted with repeated "-I." AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl # test to see if srcdir already configured if test -f $srcdir/config.status; then AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) fi fi # test whether we have cygpath if test -z "$CYGPATH_W"; then if (cygpath --version) >/dev/null 2>/dev/null; then CYGPATH_W='cygpath -w' else CYGPATH_W=echo fi fi AC_SUBST([CYGPATH_W]) # Define the identity of the package. dnl Distinguish between old-style and new-style calls. m4_ifval([$2], [AC_DIAGNOSE([obsolete], [$0: two- and three-arguments forms are deprecated.]) m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl AC_SUBST([PACKAGE], [$1])dnl AC_SUBST([VERSION], [$2])], [_AM_SET_OPTIONS([$1])dnl dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. m4_if( m4_ifdef([AC_PACKAGE_NAME], [ok]):m4_ifdef([AC_PACKAGE_VERSION], [ok]), [ok:ok],, [m4_fatal([AC_INIT should be called with package and version arguments])])dnl AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl _AM_IF_OPTION([no-define],, [AC_DEFINE_UNQUOTED([PACKAGE], ["$PACKAGE"], [Name of package]) AC_DEFINE_UNQUOTED([VERSION], ["$VERSION"], [Version number of package])])dnl # Some tools Automake needs. AC_REQUIRE([AM_SANITY_CHECK])dnl AC_REQUIRE([AC_ARG_PROGRAM])dnl AM_MISSING_PROG([ACLOCAL], [aclocal-${am__api_version}]) AM_MISSING_PROG([AUTOCONF], [autoconf]) AM_MISSING_PROG([AUTOMAKE], [automake-${am__api_version}]) AM_MISSING_PROG([AUTOHEADER], [autoheader]) AM_MISSING_PROG([MAKEINFO], [makeinfo]) AC_REQUIRE([AM_PROG_INSTALL_SH])dnl AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl AC_REQUIRE([AC_PROG_MKDIR_P])dnl # For better backward compatibility. To be removed once Automake 1.9.x # dies out for good. For more background, see: # # AC_SUBST([mkdir_p], ['$(MKDIR_P)']) # We need awk for the "check" target (and possibly the TAP driver). The # system "awk" is bad on some platforms. AC_REQUIRE([AC_PROG_AWK])dnl AC_REQUIRE([AC_PROG_MAKE_SET])dnl AC_REQUIRE([AM_SET_LEADING_DOT])dnl _AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], [_AM_PROG_TAR([v7])])]) _AM_IF_OPTION([no-dependencies],, [AC_PROVIDE_IFELSE([AC_PROG_CC], [_AM_DEPENDENCIES([CC])], [m4_define([AC_PROG_CC], m4_defn([AC_PROG_CC])[_AM_DEPENDENCIES([CC])])])dnl AC_PROVIDE_IFELSE([AC_PROG_CXX], [_AM_DEPENDENCIES([CXX])], [m4_define([AC_PROG_CXX], m4_defn([AC_PROG_CXX])[_AM_DEPENDENCIES([CXX])])])dnl AC_PROVIDE_IFELSE([AC_PROG_OBJC], [_AM_DEPENDENCIES([OBJC])], [m4_define([AC_PROG_OBJC], m4_defn([AC_PROG_OBJC])[_AM_DEPENDENCIES([OBJC])])])dnl AC_PROVIDE_IFELSE([AC_PROG_OBJCXX], [_AM_DEPENDENCIES([OBJCXX])], [m4_define([AC_PROG_OBJCXX], m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl ]) AC_REQUIRE([AM_SILENT_RULES])dnl dnl The testsuite driver may need to know about EXEEXT, so add the dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This dnl macro is hooked onto _AC_COMPILER_EXEEXT early, see below. AC_CONFIG_COMMANDS_PRE(dnl [m4_provide_if([_AM_COMPILER_EXEEXT], [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl # POSIX will say in a future version that running "rm -f" with no argument # is OK; and we want to be able to make that assumption in our Makefile # recipes. So use an aggressive probe to check that the usage we want is # actually supported "in the wild" to an acceptable degree. # See automake bug#10828. # To make any issue more visible, cause the running configure to be aborted # by default if the 'rm' program in use doesn't match our expectations; the # user can still override this though. if rm -f && rm -fr && rm -rf; then : OK; else cat >&2 <<'END' Oops! Your 'rm' program seems unable to run without file operands specified on the command line, even when the '-f' option is present. This is contrary to the behaviour of most rm programs out there, and not conforming with the upcoming POSIX standard: Please tell bug-automake@gnu.org about your system, including the value of your $PATH and any error possibly output before this message. This can help us improve future automake versions. END if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then echo 'Configuration will proceed anyway, since you have set the' >&2 echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2 echo >&2 else cat >&2 <<'END' Aborting the configuration process, to ensure you take notice of the issue. You can download and install GNU coreutils to get an 'rm' implementation that behaves properly: . If you want to complete the configuration process using your problematic 'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM to "yes", and re-run configure. END AC_MSG_ERROR([Your 'rm' program is bad, sorry.]) fi fi dnl The trailing newline in this macro's definition is deliberate, for dnl backward compatibility and to allow trailing 'dnl'-style comments dnl after the AM_INIT_AUTOMAKE invocation. See automake bug#16841. ]) dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion. Do not dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further dnl mangled by Autoconf and run in a shell conditional statement. m4_define([_AC_COMPILER_EXEEXT], m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])]) # When config.status generates a header, we must update the stamp-h file. # This file resides in the same directory as the config header # that is generated. The stamp files are numbered to have different names. # Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the # loop where config.status creates the headers, so we can generate # our stamp files there. AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], [# Compute $1's index in $config_headers. _am_arg=$1 _am_stamp_count=1 for _am_header in $config_headers :; do case $_am_header in $_am_arg | $_am_arg:* ) break ;; * ) _am_stamp_count=`expr $_am_stamp_count + 1` ;; esac done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) # Copyright (C) 2001-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_PROG_INSTALL_SH # ------------------ # Define $install_sh. AC_DEFUN([AM_PROG_INSTALL_SH], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl if test x"${install_sh+set}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; *) install_sh="\${SHELL} $am_aux_dir/install-sh" esac fi AC_SUBST([install_sh])]) # Copyright (C) 2003-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # Check whether the underlying file-system supports filenames # with a leading dot. For instance MS-DOS doesn't. AC_DEFUN([AM_SET_LEADING_DOT], [rm -rf .tst 2>/dev/null mkdir .tst 2>/dev/null if test -d .tst; then am__leading_dot=. else am__leading_dot=_ fi rmdir .tst 2>/dev/null AC_SUBST([am__leading_dot])]) # Add --enable-maintainer-mode option to configure. -*- Autoconf -*- # From Jim Meyering # Copyright (C) 1996-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_MAINTAINER_MODE([DEFAULT-MODE]) # ---------------------------------- # Control maintainer-specific portions of Makefiles. # Default is to disable them, unless 'enable' is passed literally. # For symmetry, 'disable' may be passed as well. Anyway, the user # can override the default with the --enable/--disable switch. AC_DEFUN([AM_MAINTAINER_MODE], [m4_case(m4_default([$1], [disable]), [enable], [m4_define([am_maintainer_other], [disable])], [disable], [m4_define([am_maintainer_other], [enable])], [m4_define([am_maintainer_other], [enable]) m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])]) AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles]) dnl maintainer-mode's default is 'disable' unless 'enable' is passed AC_ARG_ENABLE([maintainer-mode], [AS_HELP_STRING([--]am_maintainer_other[-maintainer-mode], am_maintainer_other[ make rules and dependencies not useful (and sometimes confusing) to the casual installer])], [USE_MAINTAINER_MODE=$enableval], [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes])) AC_MSG_RESULT([$USE_MAINTAINER_MODE]) AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes]) MAINT=$MAINTAINER_MODE_TRUE AC_SUBST([MAINT])dnl ] ) # Check to see how 'make' treats includes. -*- Autoconf -*- # Copyright (C) 2001-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_MAKE_INCLUDE() # ----------------- # Check whether make has an 'include' directive that can support all # the idioms we need for our automatic dependency tracking code. AC_DEFUN([AM_MAKE_INCLUDE], [AC_MSG_CHECKING([whether ${MAKE-make} supports the include directive]) cat > confinc.mk << 'END' am__doit: @echo this is the am__doit target >confinc.out .PHONY: am__doit END am__include="#" am__quote= # BSD make does it like this. echo '.include "confinc.mk" # ignored' > confmf.BSD # Other make implementations (GNU, Solaris 10, AIX) do it like this. echo 'include confinc.mk # ignored' > confmf.GNU _am_result=no for s in GNU BSD; do AM_RUN_LOG([${MAKE-make} -f confmf.$s && cat confinc.out]) AS_CASE([$?:`cat confinc.out 2>/dev/null`], ['0:this is the am__doit target'], [AS_CASE([$s], [BSD], [am__include='.include' am__quote='"'], [am__include='include' am__quote=''])]) if test "$am__include" != "#"; then _am_result="yes ($s style)" break fi done rm -f confinc.* confmf.* AC_MSG_RESULT([${_am_result}]) AC_SUBST([am__include])]) AC_SUBST([am__quote])]) # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- # Copyright (C) 1997-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_MISSING_PROG(NAME, PROGRAM) # ------------------------------ AC_DEFUN([AM_MISSING_PROG], [AC_REQUIRE([AM_MISSING_HAS_RUN]) $1=${$1-"${am_missing_run}$2"} AC_SUBST($1)]) # AM_MISSING_HAS_RUN # ------------------ # Define MISSING if not defined so far and test if it is modern enough. # If it is, set am_missing_run to use it, otherwise, to nothing. AC_DEFUN([AM_MISSING_HAS_RUN], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl AC_REQUIRE_AUX_FILE([missing])dnl if test x"${MISSING+set}" != xset; then case $am_aux_dir in *\ * | *\ *) MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; *) MISSING="\${SHELL} $am_aux_dir/missing" ;; esac fi # Use eval to expand $SHELL if eval "$MISSING --is-lightweight"; then am_missing_run="$MISSING " else am_missing_run= AC_MSG_WARN(['missing' script is too old or missing]) fi ]) # Helper functions for option handling. -*- Autoconf -*- # Copyright (C) 2001-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_MANGLE_OPTION(NAME) # ----------------------- AC_DEFUN([_AM_MANGLE_OPTION], [[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) # _AM_SET_OPTION(NAME) # -------------------- # Set option NAME. Presently that only means defining a flag for this option. AC_DEFUN([_AM_SET_OPTION], [m4_define(_AM_MANGLE_OPTION([$1]), [1])]) # _AM_SET_OPTIONS(OPTIONS) # ------------------------ # OPTIONS is a space-separated list of Automake options. AC_DEFUN([_AM_SET_OPTIONS], [m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) # _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) # ------------------------------------------- # Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) # Copyright (C) 1999-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_PROG_CC_C_O # --------------- # Like AC_PROG_CC_C_O, but changed for automake. We rewrite AC_PROG_CC # to automatically call this. AC_DEFUN([_AM_PROG_CC_C_O], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl AC_REQUIRE_AUX_FILE([compile])dnl AC_LANG_PUSH([C])dnl AC_CACHE_CHECK( [whether $CC understands -c and -o together], [am_cv_prog_cc_c_o], [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])]) # Make sure it works both with $CC and with simple cc. # Following AC_PROG_CC_C_O, we do the test twice because some # compilers refuse to overwrite an existing .o file with -o, # though they will create one. am_cv_prog_cc_c_o=yes for am_i in 1 2; do if AM_RUN_LOG([$CC -c conftest.$ac_ext -o conftest2.$ac_objext]) \ && test -f conftest2.$ac_objext; then : OK else am_cv_prog_cc_c_o=no break fi done rm -f core conftest* unset am_i]) if test "$am_cv_prog_cc_c_o" != yes; then # Losing compiler, so override with the script. # FIXME: It is wrong to rewrite CC. # But if we don't then we get into trouble of one sort or another. # A longer-term fix would be to have automake use am__CC in this case, # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" CC="$am_aux_dir/compile $CC" fi AC_LANG_POP([C])]) # For backward compatibility. AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) # Copyright (C) 2001-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_RUN_LOG(COMMAND) # ------------------- # Run COMMAND, save the exit status in ac_status, and log it. # (This has been adapted from Autoconf's _AC_RUN_LOG macro.) AC_DEFUN([AM_RUN_LOG], [{ echo "$as_me:$LINENO: $1" >&AS_MESSAGE_LOG_FD ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD (exit $ac_status); }]) # Check to make sure that the build environment is sane. -*- Autoconf -*- # Copyright (C) 1996-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_SANITY_CHECK # --------------- AC_DEFUN([AM_SANITY_CHECK], [AC_MSG_CHECKING([whether build environment is sane]) # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' ' case `pwd` in *[[\\\"\#\$\&\'\`$am_lf]]*) AC_MSG_ERROR([unsafe absolute working directory name]);; esac case $srcdir in *[[\\\"\#\$\&\'\`$am_lf\ \ ]]*) AC_MSG_ERROR([unsafe srcdir value: '$srcdir']);; esac # Do 'set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( am_has_slept=no for am_try in 1 2; do echo "timestamp, slept: $am_has_slept" > conftest.file set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` if test "$[*]" = "X"; then # -L didn't work. set X `ls -t "$srcdir/configure" conftest.file` fi if test "$[*]" != "X $srcdir/configure conftest.file" \ && test "$[*]" != "X conftest.file $srcdir/configure"; then # If neither matched, then we have a broken ls. This can happen # if, for instance, CONFIG_SHELL is bash and it inherits a # broken ls alias from the environment. This has actually # happened. Such a system could not be considered "sane". AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken alias in your environment]) fi if test "$[2]" = conftest.file || test $am_try -eq 2; then break fi # Just in case. sleep 1 am_has_slept=yes done test "$[2]" = conftest.file ) then # Ok. : else AC_MSG_ERROR([newly created file is older than distributed files! Check your system clock]) fi AC_MSG_RESULT([yes]) # If we didn't sleep, we still need to ensure time stamps of config.status and # generated files are strictly newer. am_sleep_pid= if grep 'slept: no' conftest.file >/dev/null 2>&1; then ( sleep 1 ) & am_sleep_pid=$! fi AC_CONFIG_COMMANDS_PRE( [AC_MSG_CHECKING([that generated files are newer than configure]) if test -n "$am_sleep_pid"; then # Hide warnings about reused PIDs. wait $am_sleep_pid 2>/dev/null fi AC_MSG_RESULT([done])]) rm -f conftest.file ]) # Copyright (C) 2009-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_SILENT_RULES([DEFAULT]) # -------------------------- # Enable less verbose build rules; with the default set to DEFAULT # ("yes" being less verbose, "no" or empty being verbose). AC_DEFUN([AM_SILENT_RULES], [AC_ARG_ENABLE([silent-rules], [dnl AS_HELP_STRING( [--enable-silent-rules], [less verbose build output (undo: "make V=1")]) AS_HELP_STRING( [--disable-silent-rules], [verbose build output (undo: "make V=0")])dnl ]) case $enable_silent_rules in @%:@ ((( yes) AM_DEFAULT_VERBOSITY=0;; no) AM_DEFAULT_VERBOSITY=1;; *) AM_DEFAULT_VERBOSITY=m4_if([$1], [yes], [0], [1]);; esac dnl dnl A few 'make' implementations (e.g., NonStop OS and NextStep) dnl do not support nested variable expansions. dnl See automake bug#9928 and bug#10237. am_make=${MAKE-make} AC_CACHE_CHECK([whether $am_make supports nested variables], [am_cv_make_support_nested_variables], [if AS_ECHO([['TRUE=$(BAR$(V)) BAR0=false BAR1=true V=1 am__doit: @$(TRUE) .PHONY: am__doit']]) | $am_make -f - >/dev/null 2>&1; then am_cv_make_support_nested_variables=yes else am_cv_make_support_nested_variables=no fi]) if test $am_cv_make_support_nested_variables = yes; then dnl Using '$V' instead of '$(V)' breaks IRIX make. AM_V='$(V)' AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' else AM_V=$AM_DEFAULT_VERBOSITY AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY fi AC_SUBST([AM_V])dnl AM_SUBST_NOTMAKE([AM_V])dnl AC_SUBST([AM_DEFAULT_V])dnl AM_SUBST_NOTMAKE([AM_DEFAULT_V])dnl AC_SUBST([AM_DEFAULT_VERBOSITY])dnl AM_BACKSLASH='\' AC_SUBST([AM_BACKSLASH])dnl _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl ]) # Copyright (C) 2001-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_PROG_INSTALL_STRIP # --------------------- # One issue with vendor 'install' (even GNU) is that you can't # specify the program used to strip binaries. This is especially # annoying in cross-compiling environments, where the build's strip # is unlikely to handle the host's binaries. # Fortunately install-sh will honor a STRIPPROG variable, so we # always use install-sh in "make install-strip", and initialize # STRIPPROG with the value of the STRIP variable (set by the user). AC_DEFUN([AM_PROG_INSTALL_STRIP], [AC_REQUIRE([AM_PROG_INSTALL_SH])dnl # Installed binaries are usually stripped using 'strip' when the user # run "make install-strip". However 'strip' might not be the right # tool to use in cross-compilation environments, therefore Automake # will honor the 'STRIP' environment variable to overrule this program. dnl Don't test for $cross_compiling = yes, because it might be 'maybe'. if test "$cross_compiling" != no; then AC_CHECK_TOOL([STRIP], [strip], :) fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) # Copyright (C) 2006-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_SUBST_NOTMAKE(VARIABLE) # --------------------------- # Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. # This macro is traced by Automake. AC_DEFUN([_AM_SUBST_NOTMAKE]) # AM_SUBST_NOTMAKE(VARIABLE) # -------------------------- # Public sister of _AM_SUBST_NOTMAKE. AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) # Check how to create a tarball. -*- Autoconf -*- # Copyright (C) 2004-2018 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_PROG_TAR(FORMAT) # -------------------- # Check how to create a tarball in format FORMAT. # FORMAT should be one of 'v7', 'ustar', or 'pax'. # # Substitute a variable $(am__tar) that is a command # writing to stdout a FORMAT-tarball containing the directory # $tardir. # tardir=directory && $(am__tar) > result.tar # # Substitute a variable $(am__untar) that extract such # a tarball read from stdin. # $(am__untar) < result.tar # AC_DEFUN([_AM_PROG_TAR], [# Always define AMTAR for backward compatibility. Yes, it's still used # in the wild :-( We should find a proper way to deprecate it ... AC_SUBST([AMTAR], ['$${TAR-tar}']) # We'll loop over all known methods to create a tar archive until one works. _am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' m4_if([$1], [v7], [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'], [m4_case([$1], [ustar], [# The POSIX 1988 'ustar' format is defined with fixed-size fields. # There is notably a 21 bits limit for the UID and the GID. In fact, # the 'pax' utility can hang on bigger UID/GID (see automake bug#8343 # and bug#13588). am_max_uid=2097151 # 2^21 - 1 am_max_gid=$am_max_uid # The $UID and $GID variables are not portable, so we need to resort # to the POSIX-mandated id(1) utility. Errors in the 'id' calls # below are definitely unexpected, so allow the users to see them # (that is, avoid stderr redirection). am_uid=`id -u || echo unknown` am_gid=`id -g || echo unknown` AC_MSG_CHECKING([whether UID '$am_uid' is supported by ustar format]) if test $am_uid -le $am_max_uid; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) _am_tools=none fi AC_MSG_CHECKING([whether GID '$am_gid' is supported by ustar format]) if test $am_gid -le $am_max_gid; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) _am_tools=none fi], [pax], [], [m4_fatal([Unknown tar format])]) AC_MSG_CHECKING([how to create a $1 tar archive]) # Go ahead even if we have the value already cached. We do so because we # need to set the values for the 'am__tar' and 'am__untar' variables. _am_tools=${am_cv_prog_tar_$1-$_am_tools} for _am_tool in $_am_tools; do case $_am_tool in gnutar) for _am_tar in tar gnutar gtar; do AM_RUN_LOG([$_am_tar --version]) && break done am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' am__untar="$_am_tar -xf -" ;; plaintar) # Must skip GNU tar: if it does not support --format= it doesn't create # ustar tarball either. (tar --version) >/dev/null 2>&1 && continue am__tar='tar chf - "$$tardir"' am__tar_='tar chf - "$tardir"' am__untar='tar xf -' ;; pax) am__tar='pax -L -x $1 -w "$$tardir"' am__tar_='pax -L -x $1 -w "$tardir"' am__untar='pax -r' ;; cpio) am__tar='find "$$tardir" -print | cpio -o -H $1 -L' am__tar_='find "$tardir" -print | cpio -o -H $1 -L' am__untar='cpio -i -H $1 -d' ;; none) am__tar=false am__tar_=false am__untar=false ;; esac # If the value was cached, stop now. We just wanted to have am__tar # and am__untar set. test -n "${am_cv_prog_tar_$1}" && break # tar/untar a dummy directory, and stop if the command works. rm -rf conftest.dir mkdir conftest.dir echo GrepMe > conftest.dir/file AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) rm -rf conftest.dir if test -s conftest.tar; then AM_RUN_LOG([$am__untar /dev/null 2>&1 && break fi done rm -rf conftest.dir AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) AC_MSG_RESULT([$am_cv_prog_tar_$1])]) AC_SUBST([am__tar]) AC_SUBST([am__untar]) ]) # _AM_PROG_TAR vnstat-2.9/man/0000755000000000000000000000000014173313377012165 5ustar rootrootvnstat-2.9/man/vnstati.10000644000000000000000000002770214171356316013745 0ustar rootroot.TH VNSTATI 1 "JANUARY 2022" "version 2.9" "User Manuals" .SH NAME vnstati \- image output support for vnStat .SH SYNOPSIS .B vnstati .RB [ \-5bcdDehiLmosStvy? ] .RB [ \-5g .RI [ limit ] .RI [ height ]] .RB [ \-\-altdate ] .RB [ \-\-begin .IR date ] .RB [ \-\-cache .IR time ] .RB [ \-\-config .IR file ] .RB [ \-\-days .RI [ limit ]] .RB [ \-\-dbdir .IR directory ] .RB [ \-\-debug ] .RB [ \-\-end .IR date ] .RB [ \-\-fivegraph .RI [ limit ] .RI [ height ]] .RB [ \-\-fiveminutes .RI [ limit ]] .RB [ \-\-headertext .IR text ] .RB [ \-\-help ] .RB [ \-hg .RI [ mode ]] .RB [ \-\-hours .RI [ limit ]] .RB [ \-\-hoursgraph .RI [ mode ]] .RB [ \-hs .RI [ graph ]] .RB [ \-\-hsummary .RI [ graph ]] .RB [ \-i .IR interface ] .RB [ \-\-iface .IR interface ] .RB [ \-\-large ] .RB [ \-\-limit .IR limit ] .RB [ \-\-locale .IR locale ] .RB [ \-\-months .RI [ limit ]] .RB [ \-ne ] .RB [ \-nh ] .RB [ \-nl ] .RB [ \-\-noedge ] .RB [ \-\-noheader ] .RB [ \-\-nolegend ] .RB [ \-\-output .IR file ] .RB [ \-ru .RI [ mode ]] .RB [ \-\-rateunit .RI [ mode ]] .RB [ \-\-scale .IR percent ] .RB [ \-\-small ] .RB [ \-\-style .IR number ] .RB [ \-\-summary ] .RB [ \-\-top .RI [ limit ]] .RB [ \-\-transparent .RI [ enabled ]] .RB [ \-\-version ] .RB [ \-vs .RI [ graph ]] .RB [ \-\-vsummary .RI [ graph ]] .RB [ \-\-months .RI [ limit ]] .RI [ interface ] .SH DESCRIPTION The purpose of .B vnstati is to provide image output support for statistics collected using .BR vnstat (1). The available image file formats depend on what is supported by the used GD library. All basic outputs of vnStat are supported excluding live traffic features. The image can be outputted either to a file or to standard output, with the later being limited to png image format. .SH OPTIONS .TP .B "--altdate" Use alternative date and time text location. The date and time text will be moved from the upper right header section to the lower left corner. This option will have no effect if .B "-nh, --noheader" has been selected. .TP .BI "-b, --begin " date Begin the list output with a specific date / time defined by .I date instead of the begin being selected based on the number of entries to be shown. If .I date isn't available in the database then the closest later date will be used. .I date supports the following formats: YYYY-MM-DD HH:MM, YYYY-MM-DD and "today". This option can only be used with list outputs. .TP .BI "-c, --cache " time Update output file only if at least .I time minutes have passed since the previous file update. This option is ignored if stdout is used as output. .TP .BI "--config " file Use .I file as configuration file instead of using automatic configuration file search functionality. .TP .BI "-d, --days " [limit] Output traffic statistics on a daily basis for the last days. The length of the list will be limited to 30 entries unless configured otherwise or unless the optional .I limit parameter is used. All entries stored in the database will be shown if .I limit is set to 0. .TP .BI "--dbdir " directory Use .I directory as database directory instead of using the directory specified in the configuration file or the hardcoded default if no configuration file is available. .TP .B "-D, --debug" Show additional debug output. .TP .BI "-e, --end " date End the list output with a specific date / time defined by .I date instead of the latest date / time in the database. If .I date isn't available in the database then the closest earlier date will be used. .I date supports the following formats: YYYY-MM-DD HH:MM and YYYY-MM-DD. This option can only be used with list outputs. The top list also requires .B "--begin" to be used at the same time with this option. .TP .BI "-5g, --fivegraph " "[limit] [height]" Output traffic statistics with a 5 minute resolution for the last 48 hours using a bar graph. The width of the graph can be modified using the optional .I limit parameter which represents the number of 5 minute entries with 12 entries for each hour. The smallest supported value is 288 (last 24 hours). Additionally, the height of the graph can be modified using the optional .I height parameter. The smallest supported height is 150 pixels. .TP .BI "-5, --fiveminutes " [limit] Output traffic statistics with a 5 minute resolution for the last hours. The length of the list will be limited to 24 entries unless configured otherwise or unless the optional .I limit parameter is used. All entries stored in the database will be shown if .I limit is set to 0. .TP .BI "--headertext " text Show .I text in image header section instead of automatically generated interface identification. .I text is limited to 64 characters and may not get completely shown if longer than the width of the image. Use with .B "--altdate" if maximal space is needed. This option will have no effect if .B "-nh, --noheader" has been selected. .TP .BI "-h, --hours " [limit] Output traffic statistics on a hourly basis. The length of the list will be limited to 24 entries unless configured otherwise or unless the optional .I limit parameter is used. All entries store in the database will be shown if the .I limit is set to 0. .TP .BI "-hg, --hoursgraph " [mode] Output traffic statistics on a hourly basis for the last 24 hours using a bar graph. The optional .I mode parameter can be used to override the configuration file setting. Available modes: 0 = 24 hour sliding window, 1 = graph begins from midnight. .TP .BI "-hs, --hsummary " [graph] Output traffic summary with the graph selected using the .B SummaryGraph setting in the configuration file next to it using a horizontal layout. The optional .I graph parameter can be used to override the configuration file setting. Available graphs: 0 = hours, 1 = 5 minutes. .TP .BI "-i, --iface " interface Use .I interface instead of default or configured interface. It is also possible to merge the information of two or more interfaces using the .I interface1+interface2+... syntax. All provided interfaces must be unique and must exist in the database when the merge syntax is used. Optionally, depending on the .B InterfaceMatchMethod configuration setting, .I interface can be replaced with .I alias previously set using .BR "vnstat --setalias" . Merge syntax isn't supported when .I alias is used. The .B "-i, --iface" option is optional and .I interface can be used as parameter on the command line for selecting the used interface even without the option being explicitly used. .TP .B "-L, --large" Use large fonts in output. .TP .BI "--limit " limit Set the maximum number of shown entries in list outputs to .IR limit . Usage of .B "--limit" overrides the default list entry limit values and the optional .I limit parameter given directly for a list query. All entries stored in the database will be shown if .I limit is set to 0. .TP .BI "--locale " locale Use .I locale instead of using the locale setting specified in the configuration file or the system default if no configuration file is available. .TP .BI "-m, --months " [limit] Output traffic statistics on a monthly basis for the last months. The length of the list will be limited to 12 entries unless configured otherwise or unless the optional .I limit parameter is used. All entries stored in the database will be shown if .I limit is set to 0. .TP .B "-ne, --noedge" Remove darker edges from around the image. .TP .B "-nh, --noheader" Remove header containing title and update time. Time of the previous update will still be visible in the lower right corner using a less visible color. .TP .B "-nl, --nolegend" Remove legend containing rx and tx color mapping information from the image. .TP .BI "-o, --output " file Write image to .I file and exit. The used image format is selected by the given file extension of .IR file . For example, "image.png" results in the file getting written using the png image format due to the ".png" extension having been used. Usage of png image format usually results in the smallest file size without loss of detail or introduction of compression artifacts. Alternatively, output can be directed to stdout by giving "-" as .I file in which case png image format is used. .TP .BI "-ru, --rateunit " [mode] Swap the configured rate unit. If rate has been configured to be shown in bytes then rate will be shown in bits if this option is present. In the same way, if rate has been configured to be shown in bits then rate will be shown in bytes when this option is present. Alternatively, .I mode with either 0 or 1 can be used as parameter for this option in order to select between bytes (0) and bits (1) regardless of the configuration file setting. .TP .BI "--scale " percent Scale output to given .I percent resulting in the image being either smaller or larger than the default size. .TP .B "-S, --small" Use small fonts in output. .TP .BI "--style " number Modify the content and style of outputs. Setting .I number to 3 will show average traffic rate in all outputs where it is supported. Other values will show bar graphics instead. .TP .B "-s, --summary" Output traffic statistics summary. .TP .BI "-t, --top " [limit] Output all time top traffic days. The length of the list will be limited to 10 entries unless configured otherwise or unless the optional .I limit parameter is used. All entries stored in the database will be shown if .I limit is set to 0. When used with .B "--begin" and optionally with .BR "--end" , the list will be generated using the daily data instead of separate top entries. The availability of daily data defines the boundaries the date specific query can access. .TP .BI "--transparent " [enabled] Toggle background color transparency depending of the .B TransparentBg setting in the configuration file. Alternatively, 0 or 1 can be given as parameter .I enabled for this option in order to either disable (0) or enable (1) transparency regardless of the configuration file setting. .TP .B "-v, --version" Show current version. .TP .BI "-vs, --vsummary " [graph] Output traffic summary with the graph selected using the .B SummaryGraph setting in the configuration file below it using a vertical layout. The optional .I graph parameter can be used to override the configuration file setting. Available graphs: 0 = hours, 1 = 5 minutes. .TP .BI "-y, --years " [limit] Output traffic statistics on a yearly basis for the last years. The list will show all entries by default unless configured otherwise or unless the optional .I limit parameter is used. All entries stored in the database will also be shown if .I limit is set to 0. .TP .B "-?, --help" Show a command option summary. .SH FILES .TP .I /var/lib/vnstat/ Default database directory. .TP .I /etc/vnstat.conf Config file that will be used unless .I $HOME/.vnstatrc exists. See .BR vnstat.conf (5) for more information. .SH EXAMPLES .TP .B "vnstati -s -i eth0 -o /tmp/vnstat.png" Output traffic summary for interface eth0 to file /tmp/vnstat.png. .TP .B "vnstati -vs -i eth0+eth1+eth2 -o /tmp/vnstat.png" Output traffic summary with hourly data under the normal summary for a merge of interfaces eth0, eth1 and eth2 to file /tmp/vnstat.png. .TP .B "vnstati -h -c 15 -o /tmp/vnstat_h.png" Output hourly traffic statistics for default interface to file /tmp/vnstat_h.png if the file has not been updated within the last 15 minutes. .TP .B "vnstati -d -ne -nh -o -" Output daily traffic statistics without displaying the header section and edges for default interface to standard output (stdout). .TP .B "vnstati -m --config /home/me/vnstat.cfg -i -o -" Output monthly traffic statistics for default interface specified in configuration file /home/me/vnstat.cfg to standard output (stdout). .SH RESTRICTIONS Depending on the built-in fonts provided by the GD library, not all characters may end up shown correctly when a UTF-8 locale is used. .PP Using long date output formats may cause misalignment in shown columns if the length of the date exceeds the fixed size allocation. .PP Scaling an image when background transparency is enabled may not result in transparency being retained. .SH AUTHOR Teemu Toivola .SH "SEE ALSO" .BR vnstat (1), .BR vnstatd (8), .BR vnstat.conf (5), .BR units (7) vnstat-2.9/man/vnstat.10000644000000000000000000004161514173312074013566 0ustar rootroot.TH VNSTAT 1 "JANUARY 2022" "version 2.9" "User Manuals" .SH NAME vnstat \- a console-based network traffic monitor .SH SYNOPSIS .B vnstat .RB [ \-5bDedhlmqstvy? ] .RB [ \-\-add ] .RB [ \-\-alert .IR "output exit type condition limit unit" ] .RB [ \-\-begin .IR date ] .RB [ \-\-config .IR file ] .RB [ \-\-days .RI [ limit ]] .RB [ \-\-dbdir .IR directory ] .RB [ \-\-dbiflist .RI [ mode ]] .RB [ \-\-debug ] .RB [ \-\-end .IR date ] .RB [ \-\-fiveminutes .RI [ limit ]] .RB [ \-\-help ] .RB [ \-hg ] .RB [ \-\-hours .RI [ limit ]] .RB [ \-\-hoursgraph ] .RB [ \-i .IR interface ] .RB [ \-\-iface .IR interface ] .RB [ \-\-iflist .RI [ mode ]] .RB [ \-\-json .RI [ mode ] .RI [ limit ]] .RB [ \-\-limit .IR limit ] .RB [ \-\-live .RI [ mode ]] .RB [ \-\-locale .IR locale ] .RB [ \-\-longhelp ] .RB [ \-\-months .RI [ limit ]] .RB [ \-\-oneline .RI [ mode ]] .RB [ \-\-query ] .RB [ \-\-rateunit .RI [ mode ]] .RB [ \-\-remove ] .RB [ \-\-rename .IR name ] .RB [ \-ru .RI [ mode ]] .RB [ \-\-setalias .IR alias ] .RB [ \-\-short ] .RB [ \-\-showconfig ] .RB [ \-\-style .IR number ] .RB [ \-\-top .RI [ limit ]] .RB [ \-tr .RI [ time ]] .RB [ \-\-traffic .RI [ time ]] .RB [ \-\-version ] .RB [ \-\-xml .RI [ mode ] .RI [ limit ]] .RB [ \-\-years .RI [ limit ]] .RI [ interface ] .SH DESCRIPTION .B vnStat is a console-based network traffic monitor. It keeps a log of 5 minute interval, hourly, daily, monthly and yearly network traffic for the selected interface(s). However, it isn't a packet sniffer. The traffic information is read from the .BR proc (5) or .B sys filesystems depending on availability resulting in light use of system resources regardless of network traffic rate. That way vnStat can be used even without root permissions on most systems. .PP Functionality is divided into two commands. The purpose of the .B vnstat command is to provide an interface for querying the traffic information stored in the database whereas the daemon .BR vnstatd (8) is responsible for data retrieval, caching and storage. Although the daemon process is constantly running as a service, it is actually spending most of its time sleeping between data updates. .SH OPTIONS .TP .B "--add" Create database entry for interface specified with .B \-i or .B \-\-iface option. The daemon can be running during this operation and will automatically start monitoring the interface without a restart within .B SaveInterval minutes if configuration option .B RescanDatabaseOnSave is enabled. Otherwise the daemon needs to be restarted in order for the added interface to be monitored. .TP .BI "--alert " "output exit type condition limit unit" Depending on values of given parameters, show alert, use different exit status or a combination of both when configured situation is met. .IP .I output parameter takes a number from 0 to 3 and controls when, if at all, the command will result in output. '0' never produces output, '1' always produces output, '2' shows output only when usage estimate exceeds .I limit and '3' shows output only when .I limit is exceeded. .IP .I exit parameter takes a number from 0 to 3 and controls the exit status of the command. '0' always uses exit status 0, '1' always uses exit status 1, '2' uses exit status 1 if usage estimate exceeds .I limit but otherwise exit status 0 and '3' uses exit status 1 if .I limit is exceeded but otherwise exit status 0. .IP .I type parameter defines to which time range type usage the .I limit is compared against. Available options: 'h', 'hour', 'hourly', 'd', 'day', 'daily', 'm', 'month', 'monthly', 'y', 'year', 'yearly'. .IP .I condition parameter defines if .I limit is compared to received (rx), transmitted (tx), total or estimated usage of these three. Available options: 'rx', 'tx', 'total', 'rx_estimate', 'tx_estimate', 'total_estimate'. .IP .I limit is a greater than zero integer without decimals which defines the traffic usage limit using the unit defined with the .I unit parameter. .I unit accepts the following options: 'B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'. Usage must exceed .I limit in order for the alarm to activate. Exactly the same usage as .I limit does not raise the alarm. .IP Estimate calculation isn't limited to the estimate options in .I condition parameter but can also be achieved by using the estimate option in .I output or .I exit parameters. Missing or invalid parameters will result in .B "--alert" specific help output being shown. .TP .BI "-b, --begin " date Begin the list output with a specific date / time defined by .I date instead of the begin being selected based on the number of entries to be shown. If .I date isn't available in the database then the closest later date will be used. .I date supports the following formats: YYYY-MM-DD HH:MM, YYYY-MM-DD and "today". This option can only be used with .B "--json" , .B "--xml" and list outputs. .TP .BI "--config " file Use .I file as configuration file instead of using automatic configuration file search functionality. .TP .BI "-d, --days " [limit] Show traffic statistics on a daily basis for the last days. The length of the list will be limited to 30 entries unless configured otherwise or unless the optional .I limit parameter is used. All entries stored in the database will be shown if .I limit is set to 0. .TP .BI "--dbdir " directory Use .I directory as database directory instead of using the directory specified in the configuration file or the hardcoded default if no configuration file is available. .TP .BI "--dbiflist " [mode] List interfaces currently in the database. If .I mode is not defined or is set to 0 then the output will use a one line verbose format. If .I mode is set to 1 then the output will contain one interface per line. See also .BR "--iflist" . .TP .B "-D, --debug" Show additional debug output. .TP .BI "-e, --end " date End the list output with a specific date / time defined by .I date instead of the latest date / time in the database. If .I date isn't available in the database then the closest earlier date will be used. .I date supports the following formats: YYYY-MM-DD HH:MM and YYYY-MM-DD. This option can only be used with .B "--json" , .B "--xml" and list outputs. The top list also requires .B "--begin" to be used at the same time with this option. .TP .BI "-5, --fiveminutes " [limit] Show traffic statistics with a 5 minute resolution for the last hours. The length of the list will be limited to 24 entries unless configured otherwise or unless the optional .I limit parameter is used. All entries stored in the database will be shown if .I limit is set to 0. .TP .BI "-h, --hours " [limit] Show traffic statistics on a hourly basis. The length of the list will be limited to 24 entries unless configured otherwise or unless the optional .I limit parameter is used. All entries store in the database will be shown if the .I limit is set to 0. .TP .B "-hg, --hoursgraph" Show traffic statistics on a hourly basis for the last 24 hours using a bar graph followed by a table representing the numerical data. .TP .BI "-i, --iface " interface Select one specific .I interface and apply actions to only it. For database queries, it is possible to merge the information of two or more interfaces using the .I interface1+interface2+... syntax. All provided interfaces must be unique and must exist in the database when the merge syntax is used. Optionally, depending on the .B InterfaceMatchMethod configuration setting, .I interface can be replaced with .I alias previously set using .BR "--setalias" . Merge syntax isn't supported when .I alias is used. The .B "-i, --iface" option is optional and .I interface can be used as parameter on the command line for selecting the used interface even without the option being explicitly used. .TP .BI "--iflist " [mode] List currently available interfaces. If .I mode is not defined or is set to 0 then the output will use a one line verbose format. If .I mode is set to 1 then the output will contain one interface per line. See also .BR "--dbiflist" . .TP .BI "--json " "[mode] [limit]" Show database content for selected interface or all interfaces in json format. All traffic values in the output are in bytes. An optional .I mode parameter can be used for limiting the output to only selected information. Everything is shown by default. Setting .I mode to 'f' will output only 5 minute resolution entries, 'h' hours, 'd' days, 'm' months, 'y' years and 't' the top days. Alternatively or in combination with .I mode an optional .I limit parameter can be used to limit the number of entries in the output. The .BI "--json" option can be used in combination with .B "-l, --live" and .B "-tr" options without .I mode or .I limit having any effect to the output. The .B "jsonversion" field in the output contains the API version information. It will be changed only when the names or structures of previously existing content gets changed. In comparison, the .B "vnstatversion" field exists only as extra information. .TP .BI "--limit " limit Set the maximum number of shown entries in list outputs to .IR limit . Usage of .B "--limit" overrides the default list entry limit values and the optional .I limit parameter given directly for a list query. All entries stored in the database will be shown if .I limit is set to 0. .B "--limit" can also be used to control the length of .B "--json" and .B "--xml" outputs. .TP .BI "-l, --live " [mode] Display current transfer rate for the selected interface in real time until interrupted. Statistics will be shown after interruption if the runtime was more than 10 seconds. An optional .I mode parameter can be used to select between the displaying of packets per second (mode 0) and transfer counters (mode 1) during execution. .B "--style" can also be used to affect the layout of the output. The output will be in json format if used in combination with .B "--json" option. .TP .BI "--locale " locale Use .I locale instead of using the locale setting specified in the configuration file or the system default if no configuration file is available. .TP .B "--longhelp" Show complete options list. .TP .BI "-m, --months " [limit] Show traffic statistics on a monthly basis for the last months. The length of the list will be limited to 12 entries unless configured otherwise or unless the optional .I limit parameter is used. All entries stored in the database will be shown if .I limit is set to 0. .TP .BI "--oneline " [mode] Show traffic summary for selected interface using one line with a parsable format. The output contains 15 fields with ; used as field delimiter. The 1st field contains the API version information of the output that will only be changed in future versions if the field content or structure changes. The following fields in order 2) interface name, 3) timestamp for today, 4) rx for today, 5) tx for today, 6) total for today, 7) average traffic rate for today, 8) timestamp for current month, 9) rx for current month, 10) tx for current month, 11) total for current month, 12) average traffic rate for current month, 13) all time total rx, 14) all time total tx, 15) all time total traffic. An optional .I mode parameter can be used to force all fields to output in bytes without the unit itself shown. .TP .B "-q, --query" Force database query mode. .TP .B "--remove" Delete the database entry for the interface specified with .B \-i or .B \-\-iface and stop monitoring it. The daemon can be running during this operation and will automatically detect the change. .TP .BI "--rename " name Rename the interface specified with .B \-i or .B \-\-iface in the database with new name .BR name . The new name cannot already exist in the database. This operation doesn't cause any data loss. The daemon should not be running during this operation. .TP .BI "-ru, --rateunit " [mode] Swap the configured rate unit. If rate has been configured to be shown in bytes then rate will be shown in bits if this option is present. In the same way, if rate has been configured to be shown in bits then rate will be shown in bytes when this option is present. Alternatively, .I mode with either 0 or 1 can be used as parameter for this option in order to select between bytes (0) and bits (1) regardless of the configuration file setting. .TP .BI "--setalias " alias Set .I alias as an alias for the selected interface to be shown in queries. The set alias can be removed by specifying an empty string for .IR alias . The daemon can be running during this operation. .TP .B "-s, --short" Use short output mode. This mode is also used when more than one interface is available in the database and no specific interface is selected. .TP .B "--showconfig" Show current configuration using the same format as the configuration file itself uses. .TP .BI "--style " number Modify the content and style of outputs. Set .I number to 0 for a narrower output, 1 for enabling bar column, 2 for same as previous but with average traffic rate visible in summary output and 3 for enabling average traffic rate in all outputs where it is supported. 4 disables the use of terminal control characters in .B "-l / --live" mode. .TP .BI "-t, --top " [limit] Show all time top traffic days. The length of the list will be limited to 10 entries unless configured otherwise or unless the optional .I limit parameter is used. All entries stored in the database will be shown if .I limit is set to 0. When used with .B "--begin" and optionally with .BR "--end" , the list will be generated using the daily data instead of separate top entries. The availability of daily data defines the boundaries the date specific query can access. .TP .BI "-tr, --traffic " [time] Calculate how much traffic goes through the selected interface during the given .I time seconds. The .I time will be 5 seconds if a number parameter isn't specified. The output will be in json format if used in combination with .B "--json" option. However, in that case, the countdown before results isn't shown. .TP .B "-v, --version" Show current version. .TP .BI "--xml " "[mode] [limit]" Show database content for selected interface or all interfaces in xml format. All traffic values in the output are in bytes. An optional .I mode parameter can be used for limiting the output to only selected information. Everything is shown by default. Setting .I mode to 'f' will output only 5 minute resolution entries, 'h' hours, 'd' days, 'm' months, 'y' years and 't' the top days. Alternatively or in combination with .I mode an optional .I limit parameter can be used to limit the number of entries in the output. The .B "xmlversion" field in the output contains the API version information. It will be changed only when the names or structures of previously existing content gets changed. In comparison, the .B "vnstatversion" field exists only as extra information. .TP .BI "-y, --years " [limit] Show traffic statistics on a yearly basis for the last years. The list will show all entries by default unless configured otherwise or unless the optional .I limit parameter is used. All entries stored in the database will also be shown if .I limit is set to 0. .TP .B "-?, --help" Show a command option summary. .SH FILES .TP .I /var/lib/vnstat/ Default database directory. .TP .I /etc/vnstat.conf Config file that will be used unless .I $HOME/.vnstatrc exists. See .BR vnstat.conf (5) for more information. .SH EXAMPLES .TP .B "vnstat" Display traffic summary for the default interface or multiple interfaces when more than one is monitored. .TP .B "vnstat -i eth0+eth1+eth3" Display traffic summary for a merge of interfaces eth0, eth1 and eth3. .TP .B "vnstat -i eth2 --xml" Output all information about interface eth2 in xml format. .TP .B "vnstat --json" Output all information of all monitored interfaces in json format. .TP .B "vnstat -i eth0 --setalias local" Give interface eth0 the alias "local". That information will be later visible as a label when eth0 is queried. .TP .B "vnstat -i eth2 --remove" Delete database entries for interface eth2 and stop monitoring it. .SH RESTRICTIONS Updates need to be executed at least as often as it is possible for the interface to generate enough traffic to overflow the kernel interface traffic counter. Otherwise, it is possible that some traffic won't be seen. With 32-bit interface traffic counters, the maximum time between two updates depends on how fast the interface can transfer 4 GiB. Note that there is no guarantee that a 64-bit kernel has 64-bit interface traffic counters for all interfaces. Calculated theoretical times are: .RS .TS l l. 10 Mbit: 54 minutes 100 Mbit: 5 minutes 1000 Mbit: 30 seconds .TE .RE .PP Virtual and aliased interfaces cannot be monitored because the kernel doesn't provide traffic information for that type of interfaces. Such interfaces are usually named eth0:0, eth0:1, eth0:2 etc. where eth0 is the actual interface being aliased. .PP Using long date output formats may cause misalignment in shown columns if the length of the date exceeds the fixed size allocation. .SH AUTHOR Teemu Toivola .SH "SEE ALSO" .BR vnstatd (8), .BR vnstati (1), .BR vnstat.conf (5), .BR proc (5), .BR ifconfig (8), .BR units (7) vnstat-2.9/man/vnstatd.80000644000000000000000000002313714164121227013736 0ustar rootroot.TH VNSTATD 8 "JANUARY 2022" "version 2.9" "User Manuals" .SH NAME vnstatd \- daemon based database updating for vnStat .SH SYNOPSIS .B vnstatd .RB [ \-Ddnpstv? ] .RB [ \-\-alwaysadd .RI [ mode ]] .RB [ \-\-config .IR file ] .RB [ \-\-daemon ] .RB [ \-\-debug ] .RB [ \-g .IR group ] .RB [ \-\-group .IR group ] .RB [ \-\-help ] .RB [ \-\-initdb ] .RB [ \-\-noadd ] .RB [ \-\-nodaemon ] .RB [ \-\-pidfile .IR file ] .RB [ \-\-sync ] .RB [ \-\-timestamp ] .RB [ \-\-u .IR user ] .RB [ \-\-user .IR user ] .RB [ \-\-version ] .SH DESCRIPTION The purpose of .B vnstatd is to provide a flexible and robust way for updating the database that .BR vnstat (1) uses. The availability of each interface is automatically tracked which removes the need for additional scripts to be implemented and called when an interface comes online or goes offline. .PP .B vnstatd is the command for starting the daemon. The daemon can either fork itself to run as a background process or stay attached to the terminal. It supports logging directly to terminal, to a user selectable file or using syslog. .PP Once started, the daemon will read .BR vnstat.conf (5) if available and then check if there is a database present in the database directory that has been specified in the configuration file. By default, if no database is found, a database will be created during startup with entries for all available interfaces excluding pseudo interfaces lo, lo0 and sit0. This automatic database entry creation behaviour can be disabled using the .B --noadd option. Alternatively, using the .B --alwaysadd option instructs the daemon to create new database entries whenever interfaces not currently in the databases become visible. .PP The daemon will proceed to track the availability of monitored interfaces, process the interface traffic statistics and write new values to the database at a configured interval. As a result, the daemon ends up spending most of the time sleeping between updates. .PP When the .B UseUTC configuration option isn't enabled, data is stored in the database using local time based on the daemon's execution environment when the configuration option isn't enabled. Any changes in the system clock or the system timezone configuration will result in data being inserted according to the new local time without any recalculation being done for already stored data. The daemon and the database in essence aren't aware of the used timezone or possible daylight saving time and cannot be configured to offset the timestamps to any direction. If a system clock or system timezone change or daylight saving time observation ending results in an already seen time period to repeat then the existing database values get incremented with the new data. .SH OPTIONS .TP .BI "--alwaysadd " [mode] Enable automatic creation of new database entries for interfaces not currently in the database even if the database file already exists when the daemon is started. New database entries will also get created for new interfaces seen while the daemon is running. Pseudo interfaces lo, lo0 and sit0 are always excluded from getting added. Using the option without .I mode defined or with .I mode set to 1 will enable the feature. Setting .I mode to 0 will disable the feature. This command line option overrides the .B AlwaysAddNewInterfaces configuration option when used. .TP .BI "--config " file Use .I file as configuration file instead of using automatic configuration file search functionality. .TP .B "-d, --daemon" Fork process to background and run as a daemon. .TP .B "-D, --debug" Provide additional output for debug purposes. The process will stay attached to the terminal for output. .TP .BI "-g, --group " group Set daemon process group to .I group during startup. .I group can be either the name of the group or a numerical group id. This option can only be used when the process is started as root. .TP .B "--initdb" Create a new empty database without interface data and exit. If the database already exists then access to it is only verified. The daemon will not stay running when this option is used. This option cannot be used in combination with .B "-d, --daemon" or .BR "-n, --nodaemon" . .TP .B "--noadd" Disable the automatic creation of new database entries for all available interfaces if the daemon is started with no database found or with a database without any interfaces. The daemon will fail to start if this option is used when the database contains no interfaces or doesn't exist. The daemon will create an empty database if one doesn't already exist. Pseudo interfaces lo, lo0 and sit0 are always excluded from getting added regardless of this option. .TP .B "-n, --nodaemon" Stay in foreground attached to the current terminal and start the update process. .TP .BI "-p, --pidfile " file Write the process id to .I file and use it for locking so that another instance of the daemon cannot be started if the same .I file is specified. This option has no effect if used in combination with .BR "-n, --nodaemon" . .TP .B "-s, --sync" Synchronize internal counters in the database with interface counters for all available interfaces before starting traffic monitoring. Use this option if the traffic between the previous shutdown and the current startup of the daemon needs to be ignored. This option isn't required in normal use because the daemon will automatically synchronize the internal counters after a system reboot, if enough time has passed since the daemon was previously running or if the internal counters are clearly out of sync. .TP .B "-t, --timestamp" Add a timestamp to the beginning of every print from the daemon when the process is running in the foreground attached to a terminal after having been started with the .B "-n, --nodaemon" option. .TP .BI "-u, --user " user Set daemon process user to .I user during startup. .I user can be either the login of the user or a numerical user id. This option can only be used when the process is started as root. .TP .B "-v, --version" Show current version of the daemon executable. .TP .B "-?, --help" Show a command option summary. .SH CONFIGURATION The behaviour of the daemon is configured mainly using the configuration keywords .B "UpdateInterval, PollInterval" and .B SaveInterval in the configuration file. .PP .B UpdateInterval defines in seconds how often the interface data is fetched and updated. This is similar to the run interval for alternative cron based updating. However, the difference is that the data doesn't directly get written to disk during updates. .PP .B PollInterval defines in seconds how often the list of available interfaces is checked for possible changes. The minimum value is 2 seconds and the maximum 60 seconds. .B PollInterval also defines the resolution for other intervals. .PP .B SaveInterval defines in minutes how often cached interface data is written to disk. A write can only occur during the updating of interface data. Therefore, the value should be a multiple of .B UpdateInterval with a maximum value of 60 minutes. .PP The default values of .B UpdateInterval 30, .B SaveInterval 5 and .B PollInterval 5 are usually suitable for most systems and provide a similar behaviour as cron based updating does but with a better resolution for interface changes and fast interfaces. .PP For embedded and/or low power systems more tuned configurations are possible. In such cases if the interfaces are mostly static the .B PollInterval can be increased to around 10-30 seconds and .B UpdateInterval set to 60 seconds. Higher values up to 300 seconds are possible if the interface speed is 10 Mbit or less. .B SaveInterval can be increased for example to 15, 30 or even 60 minutes depending on how often the data needs to be viewed. .SH SIGNALS The daemon is listening to signals .B "SIGHUP, SIGINT" and .B SIGTERM. Sending the .B SIGHUP signal to the daemon will cause cached data to be written to disk, a rescan of the database directory and a reload of settings from the configuration file. However, the pid file location will not be changed even if it's configuration setting has been modified. .PP .B SIGTERM and .B SIGINT signals will cause the daemon to write all cached data to disk and then exit. .SH FILES .TP .I /var/lib/vnstat/ Default database directory. .TP .I /etc/vnstat.conf Config file that will be used unless .I $HOME/.vnstatrc exists. See the configuration chapter and .BR vnstat.conf (5) for more information. .TP .I /var/log/vnstat/vnstat.log Log file that will be used if logging to file is enable and no other file is specified in the config file. .TP .I /var/run/vnstat/vnstat.pid File used for storing the process id when running as a background process and if no other file is specified in the configuration file or using the command line parameter. .SH RESTRICTIONS Updates need to be executed at least as often as it is possible for the interface to generate enough traffic to overflow the kernel interface traffic counter. Otherwise, it is possible that some traffic won't be seen. With 32-bit interface traffic counters, the maximum time between two updates depends on how fast the interface can transfer 4 GiB. Note that there is no guarantee that a 64-bit kernel has 64-bit interface traffic counters for all interfaces. Calculated theoretical times are: .RS .TS l l. 10 Mbit: 54 minutes 100 Mbit: 5 minutes 1000 Mbit: 30 seconds .TE .RE Virtual and aliased interfaces cannot be monitored because the kernel doesn't provide traffic information for that type of interfaces. Such interfaces are usually named eth0:0, eth0:1, eth0:2 etc. where eth0 is the actual interface being aliased. .SH AUTHOR Teemu Toivola .SH "SEE ALSO" .BR vnstat (1), .BR vnstati (1), .BR vnstat.conf (5), .BR signal (7) vnstat-2.9/man/vnstat.conf.50000644000000000000000000004252014164117043014511 0ustar rootroot.TH VNSTAT.CONF 5 "JANUARY 2022" "version 2.9" "User Manuals" .SH NAME vnstat.conf \- vnStat configuration file .SH SYNOPSIS .B /etc/vnstat.conf .SH DESCRIPTION .BR vnstat (1), .BR vnstati (1) and .BR vnstatd (8) all use the same configuration file for configuration related settings. Some of the settings are common for all three programs. The file consists of keyword-argument pairs, one per line. Empty lines and lines starting with '#' or ';' are interpreted as comments and not processed. Arguments may optionally be enclosed in double quotes (") in order to represent arguments containing spaces. Arguments can be padded with spaces or tabulator characters. A hardcoded default value will be used if a keyword can't be found from the configuration file or if the configured value cannot be parsed or is outside supported value range. .PP The configuration file is divided into three sections based on the usage of each keyword. The first section contains keywords that are considered common for all commands, the second section is for daemon related keywords and the last section is for image output. .SH COMMON KEYWORDS .TP .B DatabaseDir Specifies the directory where the database is to be stored. A full path must be given and a leading '/' isn't required. .TP .B "DayFormat, MonthFormat, TopFormat" Formatting of date in available outputs. Uses the same format as .BR date (1). (vnstat and vnstati only) .TP .B DefaultDecimals Number of decimals to use in outputs. Value range: 0..2 (vnstat and vnstati only) .TP .B EstimateBarVisible Show a visual representation of the traffic estimation if .B OutputStyle has been configured with a value of 1 or 2 to make the bar column visible. 1 = enabled, 0 = disabled. (vnstat only, see .B EstimateStyle for vnstati) .TP .B HourlyDecimals Number of decimals to use in hourly graph output. Value range: 0..2 (vnstat only) .TP .B HourlySectionStyle Select what kind of spacer is used for separating the numerical sections of the hourly graph output. 0 = none, 1 = '|', 2 = '][', 3 = '[ ]'. (vnstat only) .TP .B Interface Default interface used when no other interface is specified on the command line. Leave empty for automatic selection. The automatic selection will prioritize the interface with most traffic for outputs doing database queries. Queries not using the database will first check if the database is available and select the interface with most traffic out those that are currently visible in the system. If no database can be read then the first available interface will be used. (vnstat and vnstati only) .TP .B InterfaceMatchMethod Method for matching interface given for a query to an interface in the database. Method 0 requires the interface name to be an case sensitive exact match. Method 1 extends the previous method by allowing a case sensitive exact match of the interface alias. Method 2 extends the previous method by allowing a case insensitive exact match of the interface alias. Method 3 extends the previous method by allowing a case insensitive match of the beginning of the interface alias. Methods will be evaluated in the order described above resulting in exact interface matches always taking precedence. If any interface alias matching method results in multiple matches then the interface with the highest total traffic will be used. (vnstat and vnstati only) .TP .B "List5Mins, ListHours, ListDays, ListMonths, ListYears, ListTop" Number of entries to show in list outputs unless overridden from the command line. Set to 0 to show all entries available in the database. (vnstat and vnstati) .TP .B Locale Locale setting to be used for prints. This replaces the LC_ALL environment variable. Set to "-" or leave empty in order to use the system default value. (vnstat and vnstati only) .TP .B OutputStyle Modify the content and style of text outputs. 0 = minimal and narrow output for terminal with limited width, 1 = normal output with bar column visible, 2 = same as 1 except rate is visible in summary output, 3 = rate column is visible in all outputs where it is supported. (vnstat and vnstati only) .TP .B QueryMode Default query mode when no parameters are given. 0 = normal, 1 = days, 2 = months, 3 = top, 5 = short, 6 = years, 7 = hours graph, 8 = xml, 9 = one line, 10 = json, 11 = hours and 12 = 5 minute. (vnstat only) .TP .B RateUnit Select which unit is used when traffic rate is visible. 0 = bytes, 1 = bits. (vnstat and vnstati only) .TP .B RateUnitMode Select used prefix when traffic rate is shown in bits per second. IEC binary prefixes are calculated with powers of 1024. SI decimal prefixes are calculated with powers of 1000. 0 = IEC binary prefixes (Kibit/s...), 1 = SI decimal prefixes (kbit/s...). (vnstat and vnstati only) .TP .B "RXCharacter, TXCharacter" Character used for representing the percentual share of received and transmitted traffic in list mode outputs. (vnstat only) .TP .B "RXHourCharacter, TXHourCharacter" Character used for representing the percentual share of received and transmitted traffic in hourly graph output. (vnstat only) .TP .B Sampletime Defines how many seconds the \-tr option will sample traffic. Value range: 2..600 (vnstat only) .TP .B UnitMode Select how units are prefixed. IEC and JEDEC binary prefixes are calculated with powers of 1024. SI decimal prefixes are calculated with powers of 1000. 0 = IEC standard prefixes (B/KiB/MiB/GiB...), 1 = old style (JEDEC) binary prefixes (B/KB/MB/GB...), 2 = SI decimals prefixes (B/kB/MB/GB...) (vnstat and vnstati only) .SH DAEMON RELATED KEYWORDS .TP .B 5MinuteHours Data retention duration for the 5 minute resolution entries. The configuration defines for how many past hours entries will be stored. Set to -1 for unlimited entries or to 0 to disable the data collection of this resolution. .TP .B 64bitInterfaceCounters Select interface counter handling. Set to 1 for defining that all interfaces use 64-bit counters on the kernel side and 0 for defining 32-bit counter. Set to -1 for using the old style logic used in earlier versions where counter values within 32-bits are assumed to be 32-bit and anything larger is assumed to be a 64-bit counter. This may produce false results if a 64-bit counter is reset within the 32-bits. Set to -2 for using automatic detection based on available kernel datastructures. .TP .B AlwaysAddNewInterfaces Enable or disable automatic creation of new database entries for interfaces not currently in the database even if the database file already exists when the daemon is started. New database entries will also get created for new interfaces seen while the daemon is running. Pseudo interfaces lo, lo0 and sit0 are always excluded from getting added. 1 = enabled, 0 = disabled. .TP .B BandwidthDetection Try to automatically detect .B MaxBandwidth value for each monitored interface. Mostly only ethernet interfaces support this feature. .B MaxBandwidth will be used as fallback value if detection fails. Any interface specific .B MaxBW configuration will disable the detection for the specified interface. In Linux, the detection is disabled for tun interfaces due to the Linux kernel always reporting 10 Mbit regardless of the used real interface. 1 = enabled, 0 = disabled. .TP .B BandwidthDetectionInterval How often in minutes interface specific detection of .B MaxBandwidth is done for detecting possible changes when .B BandwidthDetection is enabled. Can be disabled by setting to 0. Value range: 0..30 .TP .B BootVariation Time in seconds how much the boot time reported by system kernel can variate between updates. Value range: 0..300 .TP .B CheckDiskSpace Enable or disable the availability check of at least some free disk space before a database write. 1 = enabled, 0 = disabled. .TP .B CreateDirs Enable or disable the creation of directories when a configured path doesn't exist. This includes .B DatabaseDir , .B LogFile and .B PidFile directories. The .B LogFile directory will be created only when .B UseLogging has been set to 1. The .B PidFile directory will be created only if the daemon is started as a background process. The daemon process will try to create the directory using permissions of the user used to start the process. .TP .B DaemonGroup Specify the group to which the daemon process should switch during startup. The group can either be the name of the group or a numerical group id. Leave empty to disable group switching. This option can only be used when the process is started as root. .TP .B DaemonUser Specify the user to which the daemon process should switch during startup. The user can either be the login of the user or a numerical user id. Leave empty to disable user switching. This option can only be used when the process is started as root. .TP .B DailyDays Data retention duration for the one day resolution entries. The configuration defines for how many past days entries will be stored. Set to -1 for unlimited entries or to 0 to disable the data collection of this resolution. .TP .B DatabaseSynchronous Change the setting of the SQLite "synchronous" flag which controls how much care is taken to ensure disk writes have fully completed when writing data to the database before continuing other actions. Higher values take extra steps to ensure data safety at the cost of slower performance. A value of 0 will result in all handling being left to the filesystem itself. Set to -1 to select the default value according to database mode controlled by .B DatabaseWriteAheadLogging setting. See SQLite documentation for more details regarding values from 1 to 3. Value range: -1..3 .TP .B DatabaseWriteAheadLogging Enable or disable SQLite Write-Ahead Logging mode for the database. See SQLite documentation for more details and note that support for read-only operations isn't available in older SQLite versions. 1 = enabled, 0 = disabled. .TP .B HourlyDays Data retention duration for the one hour resolution entries. The configuration defines for how many past days entries will be stored. Set to -1 for unlimited entries or to 0 to disable the data collection of this resolution. .TP .B LogFile Specify log file path and name to be used if UseLogging is set to 1. .TP .B MaxBandwidth Maximum bandwidth for all interfaces. If the interface specific traffic exceeds the given value then the data is assumed to be invalid and rejected. Set to 0 in order to disable the feature. Value range: 0..50000 .TP .B MaxBW Same as .B MaxBandwidth but can be used for setting individual limits for selected interfaces. The name of the interface is specified directly after the MaxBW keyword without spaces. For example MaxBWeth0 for eth0 and MaxBWppp0 for ppp0. .B BandwidthDetection is disabled on an interface specific level for each .B MaxBW configuration. Value range: 0..50000 .TP .B MonthlyMonths Data retention duration for the one month resolution entries. The configuration defines for how many past months entries will be stored. Set to -1 for unlimited entries or to 0 to disable the data collection of this resolution. .TP .B MonthRotate Day of month that months are expected to change. Usually set to 1 but can be set to alternative values for example for tracking monthly billed traffic where the billing period doesn't start on the first day. For example, if set to 7, days of February up to and including the 6th will count for January. Changing this option will not cause existing data to be recalculated. Value range: 1..28 .TP .B MonthRotateAffectsYears Enable or disable .B MonthRotate also affecting yearly data. Applicable only when .B MonthRotate has a value greater than one. 1 = enabled, 0 = disabled. .TP .B OfflineSaveInterval How often in minutes cached interface data is saved to file when all monitored interfaces are offline. Value range: .BR SaveInterval "..60" .TP .B PidFile Specify pid file path and name to be used. The file is created only if the daemon is started as a background process. .TP .B PollInterval How often in seconds interfaces are checked for status changes. Value range: 2..60 .TP .B RescanDatabaseOnSave Automatically discover added interfaces from the database and start monitoring. The rescan is done every .B SaveInterval or .B OfflineSaveInterval minutes depending on the current activity state. 1 = enabled, 0 = disabled. .TP .B SaveInterval How often in minutes cached interface data is saved to file. Value range: ( .BR UpdateInterval " / 60 )..60" .TP .B SaveOnStatusChange Enable or disable the additional saving to file of cached interface data when the availability of an interface changes, i.e., when an interface goes offline or comes online. 1 = enabled, 0 = disabled. .TP .B TimeSyncWait How many minutes to wait during daemon startup for system clock to sync if most recent database update appears to be in the future. This may be needed in systems without a real-time clock (RTC) which require some time after boot to query and set the correct time. 0 = wait disabled. Value range: 0..60 .TP .B TopDayEntries Data retention duration for the top day entries. The configuration defines how many of the past top day entries will be stored. Set to -1 for unlimited entries or to 0 to disable the data collection of this resolution. .TP .B TrafficlessEntries Create database entries even when there is no traffic during the entry's time period. 1 = enabled, 0 = disabled. .TP .B UpdateFileOwner Enable or disable the update of file ownership during daemon process startup. During daemon startup, only database, log and pid files will be modified if the user or group change feature ( .B DaemonUser or .B DaemonGroup ) is enabled and the files don't match the requested user or group. During manual database creation, this option will cause file ownership to be inherited from the database directory if the directory already exists. This option only has effect when the process is started as root or via sudo. .TP .B UpdateInterval How often in seconds the interface data is updated. Value range: .BR PollInterval "..300" .TP .B UseLogging Enable or disable logging. 0 = disabled, 1 = logfile and 2 = syslog. .TP .B UseUTC Enable or disable using UTC as timezone in the database for all entries. When enabled, all entries added to the database will use UTC regardless of the configured system timezone. When disabled, the configured system timezone will be used. Changing this setting will not result in already existing data to be modified. 1 = enabled, 0 = disabled. .TP .B YearlyYears Data retention duration for the one year resolution entries. The configuration defines for how many past years entries will be stored. Set to -1 for unlimited entries or to 0 to disable the data collection of this resolution. .SH IMAGE OUTPUT RELATED KEYWORDS .TP .B 5MinuteGraphResultCount Number of 5 minute periods to be included in the 5 minute resolution graph. The value affects the width of the graph. Value range: 288..5MinuteHours*12 .TP .B 5MinuteGraphHeight Height of 5 minute resolution graph in pixels. Value range: 150..2000 .TP .B BarColumnShowsRate The bar column represents traffic rate in list outputs when enabled. Requires also that .B OutputStyle has been configured to show the traffic rate column by using the value 3. Enabling this option will automatically cause .B EstimateStyle to have the value 0. Visually this option affects only the color legend text and the last line on the list if that line represents the currently ongoing time period. 1 = enabled, 0 = disabled. .TP .B CBackground Background color. .TP .B CEdge Edge color, if visible. .TP .B CHeader Header background color. .TP .B CHeaderTitle Header title text color. .TP .B CHeaderDate Header date text color. .TP .B CLine Line color. .TP .B CLineL Lighter version of line color. Set to '-' in order to use a calculated value based on .BR CLine . .TP .B CRx Color for received data. .TP .B CRxD Darker version of received data color. Set to '-' in order to use a calculated value based on .BR CRx . .TP .B CText Common text color. .TP .B CTx Color for transmitted data. .TP .B CTxD Darker version of transmitted data color. Set to '-' in order to use a calculated value based on .BR CTx . .TP .B EstimateStyle Show a visual representation of the traffic estimation. 0 = not shown, 1 = continuation of existing bar, 2 = separate bar. .TP .B HeaderFormat Formatting of date in header. Uses the same format as .BR date (1). .TP .B HourlyGraphMode Select the output mode of the hourly graph. 0 = 24 hour sliding window, 1 = graph begins from midnight. .TP .B HourlyRate Show hours with rate instead of transferred amount. 1 = enabled, 0 = disabled. .TP .B ImageScale Scale output to given percent. Value range: 50..500 .TP .B LargeFonts Increase the size of used fonts. 1 = enabled, 0 = disabled. .TP .B LineSpacingAdjustment Adjust line spacing in list format outputs. Positive values increase the space between lines while negative values reduce it. Value range: -5..10 .TP .B SummaryGraph Select which graph style output is shown next to the summary data in the horizontal and vertical summary outputs. 0 = hours, 1 = 5 minutes. .TP .B SummaryRate Show rate in summary output if available. 1 = enabled, 0 = disabled. .TP .B TransparentBg Set background color as transparent. 1 = enabled, 0 = disabled. .SH FILES .TP .I /etc/vnstat.conf Config file that will be used unless .I $HOME/.vnstatrc exists or alternative value is given as command line parameter. .SH RESTRICTIONS Using long date output formats may cause misalignment in shown columns if the length of the date exceeds the fixed size allocation. .SH AUTHOR Teemu Toivola .SH "SEE ALSO" .BR vnstat (1), .BR vnstati (1), .BR vnstatd (8), .BR units (7) vnstat-2.9/UPGRADE0000644000000000000000000000462314164064020012415 0ustar rootroot # New configuration settings * 2.9: HourlyGraphMode, InterfaceMatchMethod * 2.8: AlwaysAddNewInterfaces, RescanDatabaseOnSave, UseUTC * 2.7: 5MinuteGraphHeight, 5MinuteGraphResultCount, BarColumnShowsRate, EstimateBarVisible, EstimateStyle, ImageScale, LargeFonts, LineSpacingAdjustment, SummaryGraph * 2.4 - 2.6: (none) * 2.3: DatabaseWriteAheadLogging, DatabaseSynchronous * 2.2: 64bitInterfaceCounters * 2.1: (none) * 2.0: List5Mins, ListHours, ListDays, ListMonths, ListYears, ListTop, 5MinuteHours, HourlyDays, DailyDays, MonthlyMonths, YearlyYears, TopDayEntries, MonthRotateAffectsYears, TrafficlessEntries * 1.18: TimeSyncWait, DefaultDecimals, HourlyDecimals, HourlySectionStyle * 1.17: (none) * 1.16: RateUnitMode * 1.14 - 1.15: (none) * 1.13: BandwidthDetection, BandwidthDetectionInterval * 1.12: DaemonUser, DaemonGroup, CreateDirs, UpdateFileOwner * 1.10 - 1.11: (none) * 1.9: OutputStyle, SummaryLayout, SummaryRate, SaveOnStatusChange, OfflineSaveInterval * 1.8: ShowRate, RateUnit, TrafficlessDays, HourlyRate, TransparentBg * 1.7: UnitMode + all settings under vnstatd and vnstati # Upgrading from versions 1.3 and later All past versions starting from 1.3 can be upgraded directly to the current version without having to use any intermediate versions. 1. Follow the normal install procedure, `make install` step will upgrade the configuration file if it exists in the usual location. All user settings will be kept. However, unidentified content, such as unknown keywords and additional comments, will get cleaned away. 2. Review the updated configuration file. Refer to comments in the file and the `vnstat.conf` man page for documentation regarding each setting. 3. After the configuration file has been updated, restart the daemon (`vnstatd`) or configure it to use if not previously done already. Note that using a cron entry for updates (something like `vnstat -u`) is no longer supported and such commands should be removed if still existing. 4. Upgrades from 1.x to 2.x will result in data being imported from the legacy databases of each interface during the first start of the new daemon (`vnstatd`) binary. The `vnstat` and `vnstati` commands will not be able to access any data before this part of the upgrade has been completed. The legacy databases will be left untouched by the import. vnstat-2.9/src/0000755000000000000000000000000014173313400012164 5ustar rootrootvnstat-2.9/src/dbshow.c0000644000000000000000000007645114173071144013641 0ustar rootroot#include "common.h" #include "dbsql.h" #include "misc.h" #include "dbshow.h" void showdb(const char *interface, int qmode, const char *databegin, const char *dataend) { interfaceinfo info; if (!db_getinterfacecountbyname(interface)) { return; } if (!db_getinterfaceinfo(interface, &info)) { return; } if (info.created == info.updated) { printf(" %s: Not enough data available yet.\n", interface); return; } switch (qmode) { case 0: showsummary(&info, 0); break; case 1: showlist(&info, "day", databegin, dataend); break; case 2: showlist(&info, "month", databegin, dataend); break; case 3: showlist(&info, "top", databegin, dataend); break; case 5: showsummary(&info, 1); break; case 6: showlist(&info, "year", databegin, dataend); break; case 7: showhours(&info); break; case 9: showoneline(&info); break; case 11: showlist(&info, "hour", databegin, dataend); break; case 12: showlist(&info, "fiveminute", databegin, dataend); break; default: printf("Error: Not such query mode: %d\n", qmode); break; } } void showsummary(const interfaceinfo *interface, const int shortmode) { struct tm *d; char datebuff[DATEBUFFLEN]; char todaystr[DATEBUFFLEN], yesterdaystr[DATEBUFFLEN]; char fieldseparator[8]; uint64_t e_rx, e_tx; time_t current, yesterday; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; timeused_debug(__func__, 1); current = time(NULL); yesterday = current - 86400; if (interface->updated && !shortmode) { strftime(datebuff, DATEBUFFLEN, DATETIMEFORMAT, localtime(&interface->updated)); printf("Database updated: %s\n\n", datebuff); } else if (!shortmode) { printf("\n"); } if (!shortmode) { snprintf(fieldseparator, 8, " | "); indent(3); } else { snprintf(fieldseparator, 8, " / "); indent(1); } if (strcmp(interface->name, interface->alias) == 0 || strlen(interface->alias) == 0) { printf("%s", interface->name); } else { printf("%s (%s)", interface->alias, interface->name); } if (interface->active == 0) { printf(" [disabled]"); } if (shortmode) { printf(":\n"); } else { /* get formatted date for creation date */ d = localtime(&interface->created); strftime(datebuff, DATEBUFFLEN, cfg.tformat, d); printf(" since %s\n\n", datebuff); indent(10); printf("rx: %s", getvalue(interface->rxtotal, 1, RT_Normal)); indent(3); printf(" tx: %s", getvalue(interface->txtotal, 1, RT_Normal)); indent(3); printf(" total: %s\n\n", getvalue(interface->rxtotal + interface->txtotal, 1, RT_Normal)); indent(3); printf("monthly\n"); indent(5); if (cfg.ostyle >= 2) { printf(" rx | tx | total | avg. rate\n"); indent(5); printf("------------------------+-------------+-------------+---------------\n"); } else { printf(" rx | tx | total\n"); indent(5); printf("------------------------+-------------+------------\n"); } } if (!db_getdata(&datalist, &datainfo, interface->name, "month", 2)) { printf("Error: Failed to fetch month data.\n"); return; } e_rx = e_tx = 0; datalist_i = datalist; while (datalist_i != NULL) { indent(5); d = localtime(&datalist_i->timestamp); if (strftime(datebuff, DATEBUFFLEN, cfg.mformat, d) <= 8) { printf("%*s %s", getpadding(9, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal)); } else { printf("%-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal)); } printf("%s%s", fieldseparator, getvalue(datalist_i->tx, 11, RT_Normal)); printf("%s%s", fieldseparator, getvalue(datalist_i->rx + datalist_i->tx, 11, RT_Normal)); if (cfg.ostyle >= 2) { if (datalist_i->next == NULL && issametimeslot(LT_Month, datalist_i->timestamp, interface->updated)) { if (datalist_i->rx == 0 || datalist_i->tx == 0 || (interface->updated - datalist_i->timestamp) == 0) { e_rx = e_tx = 0; } else { e_rx = (uint64_t)((double)datalist_i->rx / (double)(mosecs(datalist_i->timestamp, interface->updated))) * (uint64_t)(dmonth(d->tm_mon) * 86400); e_tx = (uint64_t)((double)datalist_i->tx / (double)(mosecs(datalist_i->timestamp, interface->updated))) * (uint64_t)(dmonth(d->tm_mon) * 86400); } if (shortmode && cfg.ostyle != 0) { printf("%s%s", fieldseparator, getvalue(e_rx + e_tx, 11, RT_Estimate)); } else if (!shortmode) { printf("%s%s", fieldseparator, gettrafficrate(datalist_i->rx + datalist_i->tx, mosecs(datalist_i->timestamp, interface->updated), 14)); } } else if (!shortmode) { printf(" | %s", gettrafficrate(datalist_i->rx + datalist_i->tx, dmonth(d->tm_mon) * 86400, 14)); } } printf("\n"); datalist_i = datalist_i->next; } if (!datalist) { indent(5 + 27); printf("no data available\n"); } if (!shortmode) { indent(5); if (cfg.ostyle >= 2) { printf("------------------------+-------------+-------------+---------------\n"); } else { printf("------------------------+-------------+------------\n"); } indent(5); printf("estimated %s", getvalue(e_rx, 11, RT_Estimate)); printf(" | %s", getvalue(e_tx, 11, RT_Estimate)); printf(" | %s", getvalue(e_rx + e_tx, 11, RT_Estimate)); if (cfg.ostyle >= 2) { printf(" |\n\n"); } else { printf("\n\n"); } } dbdatalistfree(&datalist); if (!shortmode) { indent(3); printf("daily\n"); indent(5); if (cfg.ostyle >= 2) { printf(" rx | tx | total | avg. rate\n"); indent(5); printf("------------------------+-------------+-------------+---------------\n"); } else { printf(" rx | tx | total\n"); indent(5); printf("------------------------+-------------+------------\n"); } } /* get formatted date for today and yesterday */ d = localtime(¤t); strftime(todaystr, DATEBUFFLEN, cfg.dformat, d); d = localtime(&yesterday); strftime(yesterdaystr, DATEBUFFLEN, cfg.dformat, d); if (!db_getdata(&datalist, &datainfo, interface->name, "day", 2)) { printf("Error: Failed to fetch day data.\n"); return; } e_rx = e_tx = 0; datalist_i = datalist; while (datalist_i != NULL) { indent(5); d = localtime(&datalist_i->timestamp); strftime(datebuff, DATEBUFFLEN, cfg.dformat, d); if (strcmp(datebuff, todaystr) == 0) { snprintf(datebuff, DATEBUFFLEN, " today"); } else if (strcmp(datebuff, yesterdaystr) == 0) { snprintf(datebuff, DATEBUFFLEN, "yesterday"); } if (strlen(datebuff) <= 8) { printf("%*s %s", getpadding(9, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal)); } else { printf("%-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal)); } printf("%s%s", fieldseparator, getvalue(datalist_i->tx, 11, RT_Normal)); printf("%s%s", fieldseparator, getvalue(datalist_i->rx + datalist_i->tx, 11, RT_Normal)); if (cfg.ostyle >= 2) { if (datalist_i->next == NULL && issametimeslot(LT_Day, datalist_i->timestamp, interface->updated)) { d = localtime(&interface->updated); if (datalist_i->rx == 0 || datalist_i->tx == 0 || (d->tm_hour * 60 + d->tm_min) == 0) { e_rx = e_tx = 0; } else { e_rx = (uint64_t)((double)datalist_i->rx / (double)(d->tm_hour * 60 + d->tm_min)) * 1440; e_tx = (uint64_t)((double)datalist_i->tx / (double)(d->tm_hour * 60 + d->tm_min)) * 1440; } if (shortmode && cfg.ostyle != 0) { printf("%s%s", fieldseparator, getvalue(e_rx + e_tx, 11, RT_Estimate)); } else if (!shortmode) { printf("%s%s", fieldseparator, gettrafficrate(datalist_i->rx + datalist_i->tx, d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600), 14)); } } else if (!shortmode) { printf(" | %s", gettrafficrate(datalist_i->rx + datalist_i->tx, 86400, 14)); } } printf("\n"); datalist_i = datalist_i->next; } if (!shortmode) { if (!datalist) { indent(5 + 27); printf("no data available\n"); } indent(5); if (cfg.ostyle >= 2) { printf("------------------------+-------------+-------------+---------------\n"); } else { printf("------------------------+-------------+------------\n"); } indent(5); printf("estimated %s", getvalue(e_rx, 11, RT_Estimate)); printf(" | %s", getvalue(e_tx, 11, RT_Estimate)); printf(" | %s", getvalue(e_rx + e_tx, 11, RT_Estimate)); if (cfg.ostyle >= 2) { printf(" |\n"); } else { printf("\n"); } } else { printf("\n"); } dbdatalistfree(&datalist); timeused_debug(__func__, 0); } void showlist(const interfaceinfo *interface, const char *listname, const char *databegin, const char *dataend) { int32_t limit; ListType listtype = LT_None; int offset = 0, i = 1; int estimatevisible = 0; struct tm *d; time_t current; char datebuff[DATEBUFFLEN], daybuff[DATEBUFFLEN]; char titlename[16], colname[8], stampformat[64]; uint64_t e_rx = 0, e_tx = 0, e_secs = 0; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; timeused_debug(__func__, 1); if (strcmp(listname, "day") == 0) { listtype = LT_Day; strncpy_nt(colname, listname, 8); snprintf(titlename, 16, "daily"); strncpy_nt(stampformat, cfg.dformat, 64); limit = cfg.listdays; } else if (strcmp(listname, "month") == 0) { listtype = LT_Month; strncpy_nt(colname, listname, 8); snprintf(titlename, 16, "monthly"); strncpy_nt(stampformat, cfg.mformat, 64); limit = cfg.listmonths; } else if (strcmp(listname, "year") == 0) { listtype = LT_Year; strncpy_nt(colname, listname, 8); snprintf(titlename, 16, "yearly"); strncpy_nt(stampformat, "%Y", 64); limit = cfg.listyears; } else if (strcmp(listname, "top") == 0) { listtype = LT_Top; snprintf(colname, 8, "day"); snprintf(titlename, 16, "top days"); strncpy_nt(stampformat, cfg.tformat, 64); limit = cfg.listtop; offset = 6; } else if (strcmp(listname, "hour") == 0) { listtype = LT_Hour; strncpy_nt(colname, listname, 8); snprintf(titlename, 16, "hourly"); strncpy_nt(stampformat, "%H:%M", 64); limit = cfg.listhours; } else if (strcmp(listname, "fiveminute") == 0) { listtype = LT_5min; strncpy_nt(colname, "time", 8); snprintf(titlename, 16, "5 minute"); strncpy_nt(stampformat, "%H:%M", 64); limit = cfg.listfivemins; } else { return; } if (limit < 0) { limit = 0; } daybuff[0] = '\0'; if (!db_getdata_range(&datalist, &datainfo, interface->name, listname, (uint32_t)limit, databegin, dataend)) { printf("Error: Failed to fetch %s data.\n", titlename); return; } if (!datalist) { printf("No %s data available", titlename); if (strlen(databegin) || strlen(dataend)) { printf(" for given date range"); } printf(".\n"); return; } datalist_i = datalist; if (strlen(dataend) == 0 && datainfo.count > 0 && (listtype == LT_Day || listtype == LT_Month || listtype == LT_Year)) { estimatevisible = 1; getestimates(&e_rx, &e_tx, listtype, interface->updated, &datalist); if (cfg.estimatebarvisible && e_rx + e_tx > datainfo.max) { datainfo.max = e_rx + e_tx; } } if (listtype == LT_Top) { if (limit > 0 && datainfo.count < (uint32_t)limit) { limit = (int32_t)datainfo.count; } if (limit <= 0 || datainfo.count > 999) { snprintf(titlename, 16, "top"); } else { snprintf(titlename, 16, "top %d", limit); } current = time(NULL); d = localtime(¤t); strftime(daybuff, DATEBUFFLEN, stampformat, d); } printf("\n"); if (strcmp(interface->name, interface->alias) == 0 || strlen(interface->alias) == 0) { printf(" %s", interface->name); } else { printf(" %s (%s)", interface->alias, interface->name); } if (interface->active == 0) { printf(" [disabled]"); } printf(" / %s", titlename); if (listtype == LT_Top && (strlen(databegin))) { printf(" (%s -", databegin); if (strlen(dataend)) { printf(" %s)", dataend); } else { printf(">)"); } } printf("\n\n"); if (cfg.ostyle == 3) { if (listtype == LT_Top) { printf(" # %8s ", colname); } else { indent(5); printf("%8s", colname); } printf(" rx | tx | total | avg. rate\n"); if (listtype == LT_Top) { printf(" -----"); } else { indent(5); } printf("------------------------+-------------+-------------+---------------\n"); } else { if (listtype == LT_Top) { printf(" # %8s ", colname); } else { printf(" %8s", colname); } printf(" rx | tx | total\n"); if (listtype == LT_Top) { printf("------"); } printf("-------------------------+-------------+------------"); if (cfg.ostyle != 0) { printf("---------------------"); if (listtype != LT_Top) { printf("------"); } } printf("\n"); } while (datalist_i != NULL) { d = localtime(&datalist_i->timestamp); if (listtype == LT_Hour || listtype == LT_5min) { strftime(datebuff, DATEBUFFLEN, cfg.dformat, d); if (strcmp(daybuff, datebuff) != 0) { if (cfg.ostyle == 3) { indent(4); } printf(" %s\n", datebuff); strcpy(daybuff, datebuff); } } strftime(datebuff, DATEBUFFLEN, stampformat, d); if (cfg.ostyle == 3) { indent(1); if (listtype != LT_Top) { indent(3); } } if (listtype == LT_Top) { if (strcmp(daybuff, datebuff) == 0) { printf("> %2d ", i); } else { printf(" %2d ", i); } } if (strlen(datebuff) <= 9 && listtype != LT_Top) { printf(" %*s %s", getpadding(9, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal)); } else { printf(" %-*s %s", getpadding(11, datebuff), datebuff, getvalue(datalist_i->rx, 11, RT_Normal)); } printf(" | %s", getvalue(datalist_i->tx, 11, RT_Normal)); printf(" | %s", getvalue(datalist_i->rx + datalist_i->tx, 11, RT_Normal)); if (cfg.ostyle == 3) { if (datalist_i->next == NULL && issametimeslot(listtype, datalist_i->timestamp, interface->updated)) { e_secs = getperiodseconds(listtype, datalist_i->timestamp, interface->updated, 1); } else { e_secs = getperiodseconds(listtype, datalist_i->timestamp, interface->updated, 0); } printf(" | %s", gettrafficrate(datalist_i->rx + datalist_i->tx, (time_t)e_secs, 14)); } else if (cfg.ostyle != 0) { showbar(datalist_i->rx, datalist_i->tx, datainfo.max, 24 - offset); } printf("\n"); if (datalist_i->next == NULL) { break; } datalist_i = datalist_i->next; i++; } if (datainfo.count == 0) { if (cfg.ostyle != 3) { printf(" no data available\n"); } else { printf(" no data available\n"); } } if (cfg.ostyle == 3) { if (listtype == LT_Top) { printf(" -----"); } else { indent(5); } printf("------------------------+-------------+-------------+---------------\n"); } else { if (listtype == LT_Top) { printf("------"); } printf("-------------------------+-------------+------------"); if (cfg.ostyle != 0) { printf("---------------------"); if (listtype != LT_Top) { printf("------"); } } printf("\n"); } /* estimate or sum visible */ if ( (estimatevisible) || (strlen(dataend) > 0 && datainfo.count > 1 && listtype != LT_Top) ) { if (cfg.ostyle == 3) { printf(" "); } if (strlen(dataend) == 0) { printf(" estimated %s", getvalue(e_rx, 11, RT_Estimate)); printf(" | %s", getvalue(e_tx, 11, RT_Estimate)); printf(" | %s", getvalue(e_rx + e_tx, 11, RT_Estimate)); } else { if (datainfo.count < 100) { snprintf(datebuff, DATEBUFFLEN, "sum of %" PRIu32 "", datainfo.count); } else { snprintf(datebuff, DATEBUFFLEN, "sum"); } printf(" %9s %s", datebuff, getvalue(datainfo.sumrx, 11, RT_Normal)); printf(" | %s", getvalue(datainfo.sumtx, 11, RT_Normal)); printf(" | %s", getvalue(datainfo.sumrx + datainfo.sumtx, 11, RT_Normal)); } if (cfg.ostyle == 3) { printf(" |"); } else if (cfg.ostyle != 0 && estimatevisible && cfg.estimatebarvisible) { showbar(e_rx, e_tx, datainfo.max, 24 - offset); } printf("\n"); } dbdatalistfree(&datalist); timeused_debug(__func__, 0); } void showoneline(const interfaceinfo *interface) { struct tm *d; char daytemp[DATEBUFFLEN]; uint64_t div; dbdatalist *datalist = NULL; dbdatalistinfo datainfo; timeused_debug(__func__, 1); /* version string */ printf("%d;", ONELINEVERSION); /* interface name */ if (strcmp(interface->name, interface->alias) == 0 || strlen(interface->alias) == 0) { printf("%s", interface->name); } else { printf("%s (%s)", interface->alias, interface->name); } if (interface->active == 0) { printf(" [disabled]"); } printf(";"); if (!db_getdata(&datalist, &datainfo, interface->name, "day", 1)) { printf("\nError: Failed to fetch day data.\n"); return; } if (datainfo.count > 0) { d = localtime(&datalist->timestamp); strftime(daytemp, DATEBUFFLEN, cfg.dformat, d); printf("%s;", daytemp); d = localtime(&interface->updated); /* daily */ if (cfg.ostyle == 4) { printf("%" PRIu64 ";", datalist->rx); printf("%" PRIu64 ";", datalist->tx); printf("%" PRIu64 ";", datalist->rx + datalist->tx); div = (uint64_t)(d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600)); if (!div) { div = 1; } printf("%" PRIu64 ";", (datalist->rx + datalist->tx) / div); } else { printf("%s;", getvalue(datalist->rx, 1, RT_Normal)); printf("%s;", getvalue(datalist->tx, 1, RT_Normal)); printf("%s;", getvalue(datalist->rx + datalist->tx, 1, RT_Normal)); printf("%s;", gettrafficrate(datalist->rx + datalist->tx, (time_t)(d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600)), 1)); } } else { printf(";;;;;"); } dbdatalistfree(&datalist); if (!db_getdata(&datalist, &datainfo, interface->name, "month", 1)) { printf("\nError: Failed to fetch month data.\n"); return; } if (datainfo.count > 0) { d = localtime(&datalist->timestamp); strftime(daytemp, DATEBUFFLEN, cfg.mformat, d); printf("%s;", daytemp); /* monthly */ if (cfg.ostyle == 4) { printf("%" PRIu64 ";", datalist->rx); printf("%" PRIu64 ";", datalist->tx); printf("%" PRIu64 ";", datalist->rx + datalist->tx); div = (uint64_t)(mosecs(datalist->timestamp, interface->updated)); if (!div) { div = 1; } printf("%" PRIu64 ";", (datalist->rx + datalist->tx) / div); } else { printf("%s;", getvalue(datalist->rx, 1, RT_Normal)); printf("%s;", getvalue(datalist->tx, 1, RT_Normal)); printf("%s;", getvalue(datalist->rx + datalist->tx, 1, RT_Normal)); printf("%s;", gettrafficrate(datalist->rx + datalist->tx, mosecs(datalist->timestamp, interface->updated), 1)); } } else { printf(";;;;;"); } dbdatalistfree(&datalist); /* all time total */ if (cfg.ostyle == 4) { printf("%" PRIu64 ";", interface->rxtotal); printf("%" PRIu64 ";", interface->txtotal); printf("%" PRIu64 "\n", interface->rxtotal + interface->txtotal); } else { printf("%s;", getvalue(interface->rxtotal, 1, RT_Normal)); printf("%s;", getvalue(interface->txtotal, 1, RT_Normal)); printf("%s\n", getvalue(interface->rxtotal + interface->txtotal, 1, RT_Normal)); } timeused_debug(__func__, 0); } void showhours(const interfaceinfo *interface) { int i, s = 0, hour, minute, declen = cfg.hourlydecimals, div = 1; unsigned int j, k, tmax = 0, dots = 0; uint64_t max = 1; char matrix[HGLINES][81]; /* width is one over 80 so that snprintf can write the end char */ char unit[4]; struct tm *d; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; HOURDATA hourdata[24]; timeused_debug(__func__, 1); for (i = 0; i < 24; i++) { hourdata[i].rx = hourdata[i].tx = 0; hourdata[i].date = 0; } if (!db_getdata(&datalist, &datainfo, interface->name, "hour", 24)) { printf("Error: Failed to fetch hour data.\n"); return; } if (datainfo.count == 0) { return; } datalist_i = datalist; while (datalist_i != NULL) { d = localtime(&datalist_i->timestamp); if (hourdata[d->tm_hour].date != 0 || interface->updated - datalist_i->timestamp > 86400) { datalist_i = datalist_i->next; continue; } hourdata[d->tm_hour].rx = datalist_i->rx; hourdata[d->tm_hour].tx = datalist_i->tx; hourdata[d->tm_hour].date = datalist_i->timestamp; datalist_i = datalist_i->next; } dbdatalistfree(&datalist); /* tmax = time max = current hour */ /* max = transfer max */ d = localtime(&interface->updated); hour = d->tm_hour; minute = d->tm_min; for (i = 0; i < 24; i++) { if (hourdata[i].date >= hourdata[tmax].date) { tmax = (unsigned int)i; } if (hourdata[i].rx >= max) { max = hourdata[i].rx; } if (hourdata[i].tx >= max) { max = hourdata[i].tx; } } /* mr. proper */ for (i = 0; i < HGLINES; i++) { for (j = 0; j < 81; j++) { matrix[i][j] = ' '; } } /* unit selection */ while ((double)max / (pow(1024, div)) >= 100 && div < UNITPREFIXCOUNT) { div++; } strncpy_nt(unit, getunitprefix(div), 4); div = (int)(pow(1024, div - 1)); if (div == 1) { declen = 0; } /* structure */ snprintf(matrix[11], 81, " -+--------------------------------------------------------------------------->"); for (i = 0; i < 3; i++) { snprintf(matrix[14] + (i * 28), 14, " h %*srx (%s)", 1 + cfg.unitmode, " ", unit); snprintf(matrix[14] + (i * 28) + 15 + cfg.unitmode, 10, "tx (%s)", unit); } for (i = 10; i > 1; i--) matrix[i][2] = '|'; matrix[1][2] = '^'; matrix[12][2] = '|'; /* title */ if (strcmp(interface->name, interface->alias) == 0 || strlen(interface->alias) == 0) { i = snprintf(matrix[0], 81, " %s", interface->name); } else { i = snprintf(matrix[0], 81, " %s (%s)", interface->alias, interface->name); } if (interface->active == 0) { snprintf(matrix[0] + i + 1, 81, " [disabled]"); } /* time to the corner */ snprintf(matrix[0] + 74, 7, "%02d:%02d", hour, minute); /* numbers under x-axis and graphics :) */ k = 5; for (i = 23; i >= 0; i--) { s = (int)tmax - i; if (s < 0) s += 24; snprintf(matrix[12] + k, 81 - k, "%02d ", s); dots = (unsigned int)(10 * ((double)hourdata[s].rx / (double)max)); for (j = 0; j < dots; j++) matrix[10 - j][k] = cfg.rxhourchar[0]; dots = (unsigned int)(10 * ((double)hourdata[s].tx / (double)max)); for (j = 0; j < dots; j++) matrix[10 - j][k + 1] = cfg.txhourchar[0]; k = k + 3; } /* section separators */ if (cfg.hourlystyle == 1) { matrix[14][26] = '|'; matrix[14][54] = '|'; } else if (cfg.hourlystyle == 2) { matrix[14][25] = ']'; matrix[14][26] = '['; matrix[14][53] = ']'; matrix[14][54] = '['; } else if (cfg.hourlystyle == 3) { matrix[14][26] = '['; matrix[14][53] = ']'; } /* clean \0 */ for (i = 0; i < HGLINES; i++) { for (j = 0; j < 80; j++) { if (matrix[i][j] == '\0') { matrix[i][j] = ' '; } } } /* show matrix */ for (i = 0; i < HGLINES; i++) { for (j = 0; j < 80; j++) { printf("%c", matrix[i][j]); } printf("\n"); } /* hours and traffic */ for (i = 0; i <= 7; i++) { s = (int)tmax + i + 1; for (j = 0; j < 3; j++) { printf("%02d %" DECCONV "10.*f %" DECCONV "10.*f", ((unsigned int)s + (j * 8)) % 24, declen, (double)hourdata[((unsigned int)s + (j * 8)) % 24].rx / (double)div, declen, (double)hourdata[((unsigned int)s + (j * 8)) % 24].tx / (double)div); if (j < 2) { if (cfg.hourlystyle == 1) { printf(" | "); } else if (cfg.hourlystyle == 2) { printf(" ][ "); } else if (cfg.hourlystyle == 3) { if (j == 0) { printf(" [ "); } else { printf(" ] "); } } else { printf(" "); } } } printf("\n"); } timeused_debug(__func__, 0); } int showbar(const uint64_t rx, const uint64_t tx, const uint64_t max, const int len) { int i, l, width = len; if ((rx + tx) < max) { width = (int)(((double)(rx + tx) / (double)max) * len); } else if ((rx + tx) > max || max == 0) { return 0; } if (width <= 0) { return 0; } printf(" "); if (tx > rx) { l = (int)lrint(((double)rx / (double)(rx + tx) * width)); for (i = 0; i < l; i++) { printf("%c", cfg.rxchar[0]); } for (i = 0; i < (width - l); i++) { printf("%c", cfg.txchar[0]); } } else { l = (int)lrint(((double)tx / (double)(rx + tx) * width)); for (i = 0; i < (width - l); i++) { printf("%c", cfg.rxchar[0]); } for (i = 0; i < l; i++) { printf("%c", cfg.txchar[0]); } } return width; } void indent(int i) { if ((cfg.ostyle > 0) && (i > 0)) { printf("%*s", i, " "); } } int showalert(const char *interface, const AlertOutput output, const AlertExit exit, const AlertType type, const AlertCondition condition, const uint64_t limit) { interfaceinfo ifaceinfo; int i, l, ret = 0, limitexceeded = 0, estimateexceeded = 0; short ongoing = 1; double percentage = 0.0; char tablename[6], typeoutput[8], conditionname[16]; char datebuff[DATEBUFFLEN]; ListType listtype = LT_None; uint64_t bytes = 0, e_rx = 0, e_tx = 0, e_bytes = 0, periodseconds = 0; dbdatalist *datalist = NULL; dbdatalistinfo datainfo; timeused_debug(__func__, 1); if (!db_getinterfaceinfo(interface, &ifaceinfo)) { return 1; } switch (type) { case AT_None: return 0; case AT_Hour: listtype = LT_Hour; snprintf(tablename, 6, "hour"); snprintf(typeoutput, 8, "hourly"); break; case AT_Day: listtype = LT_Day; snprintf(tablename, 6, "day"); snprintf(typeoutput, 8, "daily"); break; case AT_Month: listtype = LT_Month; snprintf(tablename, 6, "month"); snprintf(typeoutput, 8, "monthly"); break; case AT_Year: listtype = LT_Year; snprintf(tablename, 6, "year"); snprintf(typeoutput, 8, "yearly"); break; } if (!db_getdata(&datalist, &datainfo, interface, tablename, 1)) { printf("Error: Failed to fetch %s data for interface %s.\n", tablename, interface); return 1; } if (!datalist) { printf("Error: No %s data available for interface %s.\n", tablename, interface); return 1; } switch (condition) { case AC_None: break; case AC_RX: bytes = datalist->rx; snprintf(conditionname, 16, "rx"); getestimates(&e_rx, &e_tx, listtype, ifaceinfo.updated, &datalist); e_bytes = e_rx; break; case AC_TX: bytes = datalist->tx; snprintf(conditionname, 16, "tx"); getestimates(&e_rx, &e_tx, listtype, ifaceinfo.updated, &datalist); e_bytes = e_tx; break; case AC_Total: bytes = datalist->rx + datalist->tx; snprintf(conditionname, 16, "total"); getestimates(&e_rx, &e_tx, listtype, ifaceinfo.updated, &datalist); e_bytes = e_rx + e_tx; break; case AC_RX_Estimate: ongoing = 0; getestimates(&e_rx, &e_tx, listtype, ifaceinfo.updated, &datalist); bytes = e_rx; snprintf(conditionname, 16, "rx estimate"); break; case AC_TX_Estimate: ongoing = 0; getestimates(&e_rx, &e_tx, listtype, ifaceinfo.updated, &datalist); bytes = e_tx; snprintf(conditionname, 16, "tx estimate"); break; case AC_Total_Estimate: ongoing = 0; getestimates(&e_rx, &e_tx, listtype, ifaceinfo.updated, &datalist); bytes = e_rx + e_tx; snprintf(conditionname, 16, "total estimate"); break; } if (bytes > limit) { limitexceeded = 1; } if (ongoing == 1 && e_bytes > limit) { estimateexceeded = 1; } if (limitexceeded && exit == AE_Exit_1_On_Limit) { ret = 1; } else if (estimateexceeded && exit == AE_Exit_1_On_Estimate) { ret = 1; } if (output != AO_No_Output) { if (output == AO_Always_Output || (output == AO_Output_On_Estimate && estimateexceeded) || ((output == AO_Output_On_Limit || output == AO_Output_On_Estimate) && limitexceeded)) { if (strlen(ifaceinfo.alias)) { printf("\n %s (%s)", ifaceinfo.alias, ifaceinfo.name); } else { printf("\n %s", interface); } if (ifaceinfo.updated) { strftime(datebuff, DATEBUFFLEN, DATETIMEFORMAT, localtime(&ifaceinfo.updated)); printf(" at %s", datebuff); } if (datalist->timestamp) { printf(" for %s ", tablename); switch (type) { case AT_None: break; case AT_Hour: strftime(datebuff, DATEBUFFLEN, "%H", localtime(&datalist->timestamp)); printf("%s of ", datebuff); strftime(datebuff, DATEBUFFLEN, cfg.dformat, localtime(&datalist->timestamp)); printf("%s", datebuff); break; case AT_Day: strftime(datebuff, DATEBUFFLEN, cfg.dformat, localtime(&datalist->timestamp)); printf("%s", datebuff); break; case AT_Month: strftime(datebuff, DATEBUFFLEN, cfg.mformat, localtime(&datalist->timestamp)); printf("%s", datebuff); break; case AT_Year: strftime(datebuff, DATEBUFFLEN, "%Y", localtime(&datalist->timestamp)); printf("%s", datebuff); break; } } printf("\n\n"); } if ((output == AO_Always_Output || output == AO_Output_On_Limit || output == AO_Output_On_Estimate) && limitexceeded) { printf(" Alert limit exceeded!\n\n"); } else if (output == AO_Always_Output || (output == AO_Output_On_Estimate && estimateexceeded)) { if (estimateexceeded) { printf(" Warning: Limit will be exceeded at current rate\n\n"); } printf(" ["); l = (int)lrint((double)(bytes) / (double)limit * ALERTUSAGELEN); if (l > ALERTUSAGELEN) { l = ALERTUSAGELEN; } for (i = 0; i < l; i++) { printf("="); } if (ongoing) { if (!estimateexceeded) { l = (int)lrint((double)(e_bytes) / (double)limit * ALERTUSAGELEN); for (; i < l; i++) { printf("-"); } } else { for (; i < ALERTUSAGELEN; i++) { printf("-"); } } } for (; i < ALERTUSAGELEN; i++) { printf("."); } printf("]\n\n"); } if (output == AO_Always_Output || (output == AO_Output_On_Estimate && estimateexceeded) || ((output == AO_Output_On_Limit || output == AO_Output_On_Estimate) && limitexceeded)) { printf(" %8s |", typeoutput); if (ongoing) { printf(" %9s |", conditionname); } else { printf(" %14s |", conditionname); } percentage = (double)(bytes) / (double)limit * 100.0; printf(" percentage | avg. rate\n"); printf(" ----------+------------------+----------------+--------------\n"); printf(" used | %16s |", getvalue(bytes, 16, RT_Normal)); periodseconds = getperiodseconds(listtype, datalist->timestamp, ifaceinfo.updated, ongoing); if (ongoing && periodseconds == 0) { periodseconds = getperiodseconds(listtype, datalist->timestamp, ifaceinfo.updated, 0); } if (percentage <= 100000.0) { printf(" %13.1f%% | %13s\n", percentage, gettrafficrate(bytes, (time_t)periodseconds, 13)); } else { printf(" %14s | %13s\n", ">100000%", gettrafficrate(bytes, (time_t)periodseconds, 13)); } printf(" limit | %16s |", getvalue(limit, 16, RT_Normal)); printf(" | %13s\n", gettrafficrate(limit, (time_t)getperiodseconds(listtype, datalist->timestamp, ifaceinfo.updated, 0), 13)); if (limitexceeded) { printf(" excess | %16s | |\n", getvalue(bytes - limit, 16, RT_Normal)); printf(" ----------+------------------+----------------+--------------\n"); } else { printf(" remaining | %16s | %13.1f%% |\n", getvalue(limit - bytes, 16, RT_Normal), 100.0 - percentage); printf(" ----------+------------------+----------------+--------------\n"); } if (ongoing && e_bytes > 0) { printf(" estimated | %16s |", getvalue(e_bytes, 16, RT_Normal)); percentage = (double)(e_bytes) / (double)limit * 100.0; if (percentage <= 100000.0) { printf(" %13.1f%%", percentage); } else { printf(" %14s", ">100000%"); } if (e_bytes > limit) { printf(", +%s\n", getvalue(e_bytes - limit, 0, RT_Normal)); } else { /* rate for estimated is always to same as for used so "bytes" intentionally used here instead of "e_bytes" */ printf(" | %13s\n", gettrafficrate(bytes, (time_t)periodseconds, 13)); } } } } dbdatalistfree(&datalist); timeused_debug(__func__, 0); return ret; } vnstat-2.9/src/dbsql.h0000644000000000000000000000671014164063055013456 0ustar rootroot#ifndef DBSQL_H #define DBSQL_H #include #include "iflist.h" typedef struct dbdatalist { time_t timestamp; int64_t rowid; uint64_t rx, tx; struct dbdatalist *next; } dbdatalist; typedef struct dbdatalistinfo { uint32_t count; time_t maxtime, mintime; uint64_t minrx, mintx; uint64_t maxrx, maxtx; uint64_t min, max; uint64_t sumrx, sumtx; } dbdatalistinfo; typedef struct interfaceinfo { char name[32], alias[32]; int active; time_t created, updated; uint64_t rxcounter, txcounter; uint64_t rxtotal, txtotal; } interfaceinfo; int db_open_ro(void); int db_open_rw(const int createifnotfound); int db_open(const int createifnotfound, const int readonly); int db_validate(const int readonly); int db_setpragmas(void); int db_close(void); int db_exec(const char *sql); int db_create(void); int db_addinterface(const char *iface); int db_removeinterface(const char *iface); int db_renameinterface(const char *iface, const char *newifname); uint64_t db_getinterfacecount(void); uint64_t db_getinterfacecountbyname(const char *iface); sqlite3_int64 db_getinterfaceid(const char *iface, const int createifnotfound); char *db_getinterfaceidin(const char *iface); int db_setinterfacebyalias(char *iface, const char *alias, const int matchmethod); int db_setactive(const char *iface, const int active); int db_setupdated(const char *iface, const time_t timestamp); int db_setcounters(const char *iface, const uint64_t rxcounter, const uint64_t txcounter); int db_getcounters(const char *iface, uint64_t *rxcounter, uint64_t *txcounter); int db_getinterfaceinfo(const char *iface, interfaceinfo *info); int db_setalias(const char *iface, const char *alias); int db_setinfo(const char *name, const char *value, const int createifnotfound); char *db_getinfo(const char *name); int db_getiflist(iflist **ifl); int db_getiflist_sorted(iflist **ifl, const int orderbytraffic); char *db_get_date_generator(const int range, const short direct, const char *nowdate); int db_addtraffic(const char *iface, const uint64_t rx, const uint64_t tx); int db_addtraffic_dated(const char *iface, const uint64_t rx, const uint64_t tx, const uint64_t timestamp); int db_setcreation(const char *iface, const time_t timestamp); int db_settotal(const char *iface, const uint64_t rx, const uint64_t tx); int db_insertdata(const char *table, const char *iface, const uint64_t rx, const uint64_t tx, const uint64_t timestamp); int db_removeoldentries(void); int db_removeoldentries_top(void); int db_vacuum(void); int db_begintransaction(void); int db_committransaction(void); int db_rollbacktransaction(void); int db_iserrcodefatal(int errcode); int db_isdiskfull(int errcode); #if HAVE_DECL_SQLITE_CHECKPOINT_RESTART void db_walcheckpoint(void); #endif int db_getdata(dbdatalist **dbdata, dbdatalistinfo *listinfo, const char *iface, const char *table, const uint32_t resultlimit); int db_getdata_range(dbdatalist **dbdata, dbdatalistinfo *listinfo, const char *iface, const char *table, const uint32_t resultlimit, const char *databegin, const char *dataend); void updatelistinfo(dbdatalistinfo *listinfo, const uint64_t rx, const uint64_t tx, const time_t timestamp); int dbdatalistadd(dbdatalist **dbdata, const uint64_t rx, const uint64_t tx, const time_t timestamp, const int64_t rowid); void dbdatalistfree(dbdatalist **dbdata); unsigned int getqueryinterfacecount(const char *input); char *getifaceinquery(const char *input); /* global db */ extern sqlite3 *db; extern int db_errcode; extern int db_intransaction; #endif vnstat-2.9/src/image.c0000644000000000000000000011056314164364436013437 0ustar rootroot#include "common.h" #include "dbsql.h" #include "misc.h" #include "image.h" #include "image_support.h" #include "vnstati.h" void initimagecontent(IMAGECONTENT *ic) { ic->im = NULL; ic->font = gdFontGetSmall(); ic->lineheight = 12; ic->large = 0; ic->showheader = 1; ic->showedge = 1; ic->showlegend = 1; ic->altdate = 0; ic->headertext[0] = '\0'; ic->databegin[0] = '\0'; ic->dataend[0] = '\0'; ic->interface.name[0] = '\0'; ic->interface.alias[0] = '\0'; } void drawimage(IMAGECONTENT *ic) { switch (cfg.qmode) { case 1: drawlist(ic, "day"); break; case 2: drawlist(ic, "month"); break; case 3: drawlist(ic, "top"); break; case 4: drawlist(ic, "year"); break; case 5: drawsummary(ic, 0, 0); break; case 51: drawsummary(ic, 1, cfg.hourlyrate); // horizontal break; case 52: drawsummary(ic, 2, cfg.hourlyrate); // vertical break; case 7: drawhourly(ic, cfg.hourlyrate); break; case 8: drawlist(ic, "hour"); break; case 9: drawlist(ic, "fiveminute"); break; case 10: drawfivegraph(ic, cfg.hourlyrate, cfg.fivegresultcount, cfg.fivegheight); break; default: printf("Error: No such query mode: %d\n", cfg.qmode); exit(EXIT_FAILURE); } /* enable background transparency if needed */ if (cfg.transbg) { gdImageColorTransparent(ic->im, ic->cbackground); } } #if HAVE_DECL_GD_NEAREST_NEIGHBOUR void scaleimage(IMAGECONTENT *ic) { gdImagePtr im_scaled; unsigned int width = 0, height = 0; if (cfg.imagescale == 100 || ic->im == NULL) { return; } width = (unsigned int)((float)gdImageSX(ic->im) * ((float)cfg.imagescale / (float)100)); height = (unsigned int)((float)gdImageSY(ic->im) * ((float)cfg.imagescale / (float)100)); if (width < 100 || height < 100) { return; } if (width > 5000 || height > 5000) { return; } /* keep output sharp when percent is an exact multiplier */ if (cfg.imagescale % 100 == 0) { gdImageSetInterpolationMethod(ic->im, GD_NEAREST_NEIGHBOUR); } im_scaled = gdImageScale(ic->im, width, height); if (im_scaled == NULL) { return; } gdImageDestroy(ic->im); ic->im = im_scaled; } #endif int drawhours(IMAGECONTENT *ic, const int xpos, const int ypos, const int rate) { int i, tmax = 0, s = 0, step, prev = 0, diff = 0, chour; int x = xpos, y = ypos, extrax = 0, extray = 0, xt = 0; double ratediv; uint64_t max = 1, scaleunit = 0; char buffer[32]; struct tm *d; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; HOURDATA hourdata[24]; gdFontPtr font; if (ic->large) { font = gdFontGetSmall(); } else { font = gdFontGetTiny(); } for (i = 0; i < 24; i++) { hourdata[i].rx = hourdata[i].tx = 0; hourdata[i].date = 0; } if (cfg.hourlygmode == 0) { buffer[0] = '\0'; } else { snprintf(buffer, 32, "today"); } if (!db_getdata_range(&datalist, &datainfo, ic->interface.name, "hour", 24, buffer, "") || datainfo.count == 0) { gdImageString(ic->im, ic->font, x + (32 * ic->font->w), y + 54, (unsigned char *)"no data available", ic->ctext); return 0; } datalist_i = datalist; while (datalist_i != NULL) { d = localtime(&datalist_i->timestamp); if (hourdata[d->tm_hour].date != 0 || ic->interface.updated - datalist_i->timestamp > 86400) { datalist_i = datalist_i->next; continue; } hourdata[d->tm_hour].rx = datalist_i->rx; hourdata[d->tm_hour].tx = datalist_i->tx; hourdata[d->tm_hour].date = datalist_i->timestamp; datalist_i = datalist_i->next; } dbdatalistfree(&datalist); ic->current = ic->interface.updated; chour = localtime(&ic->current)->tm_hour; if (cfg.rateunit) { ratediv = 450; /* x * 8 / 3600 */ } else { ratediv = 3600; } /* tmax (time max) = current hour */ /* max = transfer max */ for (i = 0; i < 24; i++) { /* convert hourly transfer to hourly rate if needed */ if (rate) { if ((ic->current - hourdata[i].date) > 3600) { hourdata[i].rx = (uint64_t)((double)hourdata[i].rx / ratediv); hourdata[i].tx = (uint64_t)((double)hourdata[i].tx / ratediv); } else { /* scale ongoing hour properly */ if (chour != i) { hourdata[i].rx = (uint64_t)((double)hourdata[i].rx / ratediv); hourdata[i].tx = (uint64_t)((double)hourdata[i].tx / ratediv); } else { d = localtime(&ic->current); diff = d->tm_min * 60; if (!diff) { diff = 60; } if (cfg.rateunit == 1) { hourdata[i].rx *= 8; hourdata[i].tx *= 8; } hourdata[i].rx = (uint64_t)((double)hourdata[i].rx / (double)diff); hourdata[i].tx = (uint64_t)((double)hourdata[i].tx / (double)diff); } } } if (hourdata[i].date >= hourdata[tmax].date) { tmax = i; } if (hourdata[i].rx >= max) { max = hourdata[i].rx; } if (hourdata[i].tx >= max) { max = hourdata[i].tx; } } if (ic->large) { x += 14; extrax = 145; extray = 35; } /* scale values */ scaleunit = getscale(max, rate); s = (int)lrint(((double)scaleunit / (double)max) * (124 + extray)); if (s < SCALEMINPIXELS) { step = 2; } else { step = 1; } xt = x + 36; for (i = step; i * s <= (124 + extray + 4); i = i + step) { gdImageDashedLine(ic->im, xt, y + 124 - (i * s), xt + 424 + extrax, y + 124 - (i * s), ic->cline); gdImageDashedLine(ic->im, xt, y + 124 - prev - (step * s) / 2, xt + 424 + extrax, y + 124 - prev - (step * s) / 2, ic->clinel); gdImageString(ic->im, font, x + 16 - (ic->large * 3), y + 121 - (i * s) - (ic->large * 3), (unsigned char *)getimagevalue(scaleunit * (unsigned int)i, 3, rate), ic->ctext); prev = i * s; } if ((prev + (step * s) / 2) <= (124 + extray + 4)) { gdImageDashedLine(ic->im, xt, y + 124 - prev - (step * s) / 2, xt + 424 + extrax, y + 124 - prev - (step * s) / 2, ic->clinel); } /* scale text */ gdImageStringUp(ic->im, font, x - 2 - (ic->large * 14), y + 58 + (rate * 10) - (extray / 2), (unsigned char *)getimagescale(scaleunit * (unsigned int)step, rate), ic->ctext); /* axis */ gdImageLine(ic->im, xt - 4, y + 124, xt + 430 + extrax, y + 124, ic->ctext); gdImageLine(ic->im, xt, y - 10 - extray, xt, y + 124 + 4, ic->ctext); /* arrows */ drawarrowup(ic, xt, y - 9 - extray); drawarrowright(ic, xt + 429 + extrax, y + 124); xt = x + 440 + extrax; /* keep alignment when midnight line isn't shown s*/ if (cfg.hourlygmode || tmax - 23 == 0) { xt--; } /* x-axis values and poles */ for (i = 0; i < 24; i++) { if (cfg.hourlygmode == 0) { s = tmax - i; if (s < 0) { s += 24; } } else { s = 23 - i; } snprintf(buffer, 32, "%02d ", s); if (hourdata[s].date == 0) { chour = ic->cline; } else { chour = ic->ctext; } gdImageString(ic->im, font, xt, y + 128, (unsigned char *)buffer, chour); drawpoles(ic, xt - 2, y - extray, 124 + extray, hourdata[s].rx, hourdata[s].tx, max); gdImageLine(ic->im, xt - 4 - (ic->large * 3), y + 124, xt + 12 + (ic->large * 3), y + 124, chour); if (s == 0 && i != 23) { /* midnight line */ gdImageLine(ic->im, xt - 5 - (ic->large * 3), y - 5 - extray, xt - 5 - (ic->large * 3), y + 124 - 1, ic->clinel); xt--; } xt = xt - (17 + ic->large * 6); } return 1; } void drawhourly(IMAGECONTENT *ic, const int rate) { int width, height, headermod = 0; width = 500 + (ic->large * 168); height = 200 + (ic->large * 48); if (!ic->showheader) { headermod = 26; height -= 22; } imageinit(ic, width, height); layoutinit(ic, " / hourly", width, height); if (drawhours(ic, 12, 46 - headermod + (ic->large * 40), rate)) { drawlegend(ic, width / 2 - (ic->large * 10), 183 - headermod + (ic->large * 46), 0); } } void drawlist(IMAGECONTENT *ic, const char *listname) { ListType listtype = LT_None; int textx, texty, offsetx = 0; int width, height, headermod, i = 1, rowcount = 0; int estimateavailable = 0, estimatevisible = 0; int32_t limit; uint64_t e_rx = 0, e_tx = 0, e_secs = 0; char buffer[512], datebuff[16], daybuff[16]; char stampformat[64], titlename[16], colname[8]; struct tm *d; time_t current; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; if (strcmp(listname, "day") == 0) { listtype = LT_Day; strncpy_nt(colname, listname, 8); snprintf(titlename, 16, "daily"); strncpy_nt(stampformat, cfg.dformat, 64); limit = cfg.listdays; } else if (strcmp(listname, "month") == 0) { listtype = LT_Month; strncpy_nt(colname, listname, 8); snprintf(titlename, 16, "monthly"); strncpy_nt(stampformat, cfg.mformat, 64); limit = cfg.listmonths; } else if (strcmp(listname, "year") == 0) { listtype = LT_Year; strncpy_nt(colname, listname, 8); snprintf(titlename, 16, "yearly"); strncpy_nt(stampformat, "%Y", 64); limit = cfg.listyears; } else if (strcmp(listname, "top") == 0) { listtype = LT_Top; snprintf(colname, 8, "day"); strncpy_nt(stampformat, cfg.tformat, 64); limit = cfg.listtop; offsetx = 5 * ic->font->w; } else if (strcmp(listname, "hour") == 0) { listtype = LT_Hour; strncpy_nt(colname, listname, 8); snprintf(titlename, 16, "hourly"); strncpy_nt(stampformat, "%H:%M", 64); limit = cfg.listhours; } else if (strcmp(listname, "fiveminute") == 0) { listtype = LT_5min; strncpy_nt(colname, "time", 8); snprintf(titlename, 16, "5 minute"); strncpy_nt(stampformat, "%H:%M", 64); limit = cfg.listfivemins; } else { return; } if (limit < 0) { limit = 0; } daybuff[0] = '\0'; db_getdata_range(&datalist, &datainfo, ic->interface.name, listname, (uint32_t)limit, ic->databegin, ic->dataend); datalist_i = datalist; if (strlen(ic->dataend) == 0 && datainfo.count > 0 && listtype != LT_Top) { getestimates(&e_rx, &e_tx, listtype, ic->interface.updated, &datalist); if ((cfg.estimatestyle > 0 || cfg.barshowsrate > 0) && e_rx + e_tx > datainfo.max) { datainfo.max = e_rx + e_tx; } estimateavailable = 1; if (listtype == LT_Day || listtype == LT_Month || listtype == LT_Year) { estimatevisible = 1; } } if (listtype == LT_Top) { if (limit > 0 && datainfo.count < (uint32_t)limit) { limit = (int32_t)datainfo.count; } if (limit <= 0 || datainfo.count > 999) { snprintf(titlename, 16, "top"); } else { snprintf(titlename, 16, "top %d", limit); } } if (listtype == LT_Hour || listtype == LT_5min) { while (datalist_i != NULL) { d = localtime(&datalist_i->timestamp); strftime(datebuff, 16, cfg.dformat, d); if (strcmp(daybuff, datebuff) != 0) { rowcount += 1; strcpy(daybuff, datebuff); } datalist_i = datalist_i->next; } datalist_i = datalist; daybuff[0] = '\0'; } rowcount += datainfo.count; width = 83 * ic->font->w + 2 + (ic->large * 2); height = 62 + 3 * ic->lineheight; // less space needed when no estimate or sum is shown (Top, 5min and Hour never have estimate) if ((!estimatevisible && datainfo.count < 2) || (listtype == LT_Top || listtype == LT_Hour || listtype == LT_5min)) { height = 62 + 2 * ic->lineheight; } // exception for 5min and Hour when having sum shown if ((listtype == LT_5min || listtype == LT_Hour) && datainfo.count > 1 && strlen(ic->dataend) > 0) { height = 62 + 3 * ic->lineheight; } height += (ic->lineheight + cfg.linespaceadjust) * rowcount - cfg.linespaceadjust; // "no data available" if (!datainfo.count) { height = 98 + (ic->large * 12); } if (!ic->showheader) { headermod = 26; height -= 22; } else { headermod = 0; } snprintf(buffer, 512, " / %s", titlename); imageinit(ic, width, height); layoutinit(ic, buffer, width, height); if (datainfo.count) { if (listtype == LT_Top) { if (cfg.ostyle <= 2) { drawlegend(ic, 66 * ic->font->w + 2, 40 - headermod, 0); } current = time(NULL); d = localtime(¤t); strftime(daybuff, 16, stampformat, d); } else { // everything else if (cfg.ostyle > 2) { if (estimateavailable && cfg.barshowsrate) { drawlegend(ic, 72 * ic->font->w, 40 - headermod, 1); } else { drawlegend(ic, 72 * ic->font->w, 40 - headermod, 0); } } else { drawlegend(ic, 64 * ic->font->w + 1, 40 - headermod, 0); } } } textx = 10; texty = 40 - headermod; if (listtype == LT_Top) { // top snprintf(buffer, 512, " # day rx tx total"); } else { // everything else snprintf(buffer, 512, " %8s rx tx total", colname); } if (cfg.ostyle > 2) { strcat(buffer, " avg. rate"); gdImageString(ic->im, ic->font, textx, texty, (unsigned char *)buffer, ic->ctext); gdImageLine(ic->im, textx + 2, texty + ic->lineheight + 4, textx + (65 * ic->font->w) + offsetx + 2, texty + ic->lineheight + 4, ic->cline); } else { gdImageString(ic->im, ic->font, textx, texty, (unsigned char *)buffer, ic->ctext); gdImageLine(ic->im, textx + 2, texty + ic->lineheight + 4, textx + (50 * ic->font->w) + offsetx - 4, texty + ic->lineheight + 4, ic->cline); } texty += ic->lineheight + 8; if (datainfo.count) { gdImageLine(ic->im, textx + (24 * ic->font->w) + offsetx, texty - 6 - ic->lineheight, textx + (24 * ic->font->w) + offsetx, texty + ((ic->lineheight + cfg.linespaceadjust) * rowcount) - cfg.linespaceadjust + 5 - (ic->large * 2), ic->cline); gdImageLine(ic->im, textx + (37 * ic->font->w) + offsetx, texty - 6 - ic->lineheight, textx + (37 * ic->font->w) + offsetx, texty + ((ic->lineheight + cfg.linespaceadjust) * rowcount) - cfg.linespaceadjust + 5 - (ic->large * 2), ic->cline); if (cfg.ostyle > 2) { gdImageLine(ic->im, textx + (50 * ic->font->w) + offsetx, texty - 6 - ic->lineheight, textx + (50 * ic->font->w) + offsetx, texty + ((ic->lineheight + cfg.linespaceadjust) * rowcount) - cfg.linespaceadjust + 5 - (ic->large * 2), ic->cline); } } else { gdImageLine(ic->im, textx + (24 * ic->font->w) + offsetx, texty - 6 - ic->lineheight, textx + (24 * ic->font->w) + offsetx, texty - 4, ic->cline); gdImageLine(ic->im, textx + (37 * ic->font->w) + offsetx, texty - 6 - ic->lineheight, textx + (37 * ic->font->w) + offsetx, texty - 4, ic->cline); if (cfg.ostyle > 2) { gdImageLine(ic->im, textx + (50 * ic->font->w) + offsetx, texty - 6 - ic->lineheight, textx + (50 * ic->font->w) + offsetx, texty - 4, ic->cline); } } while (datalist_i != NULL) { d = localtime(&datalist_i->timestamp); if (listtype == LT_5min || listtype == LT_Hour) { strftime(datebuff, 16, cfg.dformat, d); if (strcmp(daybuff, datebuff) != 0) { snprintf(buffer, 32, " %s", datebuff); gdImageString(ic->im, ic->font, textx, texty, (unsigned char *)buffer, ic->ctext); texty += ic->lineheight + cfg.linespaceadjust; strcpy(daybuff, datebuff); } } if (listtype == LT_Top) { if (strftime(datebuff, 16, stampformat, d) <= 8) { snprintf(buffer, 32, " %2d %*s", i, getpadding(8, datebuff), datebuff); strcat(buffer, " "); } else { snprintf(buffer, 32, " %2d %-*s ", i, getpadding(11, datebuff), datebuff); } if (strcmp(datebuff, daybuff) == 0) { if (cfg.ostyle > 2) { gdImageFilledRectangle(ic->im, textx + 2, texty + 2 - (ic->large * 1), textx + (65 * ic->font->w) + offsetx + 2, texty + 11 + (ic->large * 3), ic->cbgoffset); } else { gdImageFilledRectangle(ic->im, textx + 2, texty + 2 - (ic->large * 1), textx + (50 * ic->font->w) + offsetx - 4, texty + 11 + (ic->large * 3), ic->cbgoffset); } } } else { if (strftime(datebuff, 16, stampformat, d) <= 8) { snprintf(buffer, 32, " %*s", getpadding(8, datebuff), datebuff); strcat(buffer, " "); } else { snprintf(buffer, 32, " %-*s ", getpadding(11, datebuff), datebuff); } } strncat(buffer, getvalue(datalist_i->rx, 10, RT_Normal), 32); strcat(buffer, " "); strncat(buffer, getvalue(datalist_i->tx, 10, RT_Normal), 32); strcat(buffer, " "); strncat(buffer, getvalue(datalist_i->rx + datalist_i->tx, 10, RT_Normal), 32); if (cfg.ostyle > 2) { strcat(buffer, " "); if (datalist_i->next == NULL && issametimeslot(listtype, datalist_i->timestamp, ic->interface.updated)) { e_secs = getperiodseconds(listtype, datalist_i->timestamp, ic->interface.updated, 1); } else { e_secs = getperiodseconds(listtype, datalist_i->timestamp, ic->interface.updated, 0); } strncat(buffer, gettrafficrate(datalist_i->rx + datalist_i->tx, (time_t)e_secs, 14), 32); } gdImageString(ic->im, ic->font, textx, texty, (unsigned char *)buffer, ic->ctext); if (listtype == LT_Top) { if (cfg.ostyle > 2) { drawbar(ic, textx + (71 * ic->font->w) + 2, texty + 4, 9 * ic->font->w - 1, datalist_i->rx, datalist_i->tx, datainfo.max, 0); } else { drawbar(ic, textx + (56 * ic->font->w), texty + 4, 23 * ic->font->w + 3, datalist_i->rx, datalist_i->tx, datainfo.max, 0); } } else { // everything else if (cfg.ostyle > 2) { if (datalist_i->next == NULL && estimateavailable && cfg.barshowsrate) { drawbar(ic, textx + (67 * ic->font->w) - 2, texty + 4, 13 * ic->font->w + 1, e_rx, e_tx, datainfo.max, 0); } else { drawbar(ic, textx + (67 * ic->font->w) - 2, texty + 4, 13 * ic->font->w + 1, datalist_i->rx, datalist_i->tx, datainfo.max, 0); } } else { drawbar(ic, textx + (51 * ic->font->w) - 2, texty + 4, 28 * ic->font->w + 3, datalist_i->rx, datalist_i->tx, datainfo.max, 0); } } texty += ic->lineheight + cfg.linespaceadjust; if (datalist_i->next == NULL) { texty -= cfg.linespaceadjust; break; } datalist_i = datalist_i->next; i++; } if (!datainfo.count) { i = 17 * ic->font->w; if (cfg.ostyle > 2) { i += 8 * ic->font->w; } gdImageString(ic->im, ic->font, textx + i, texty, (unsigned char *)"no data available", ic->ctext); texty += ic->lineheight; } if (cfg.ostyle > 2) { gdImageLine(ic->im, textx + 2, texty + 5 - (ic->large * 2), textx + (65 * ic->font->w) + offsetx + 2, texty + 5 - (ic->large * 2), ic->cline); } else { gdImageLine(ic->im, textx + 2, texty + 5 - (ic->large * 2), textx + (50 * ic->font->w) + offsetx - 4, texty + 5 - (ic->large * 2), ic->cline); } buffer[0] = '\0'; /* estimate visible */ if (estimatevisible) { snprintf(buffer, 32, " estimated "); strncat(buffer, getvalue(e_rx, 10, RT_Estimate), 32); strcat(buffer, " "); strncat(buffer, getvalue(e_tx, 10, RT_Estimate), 32); strcat(buffer, " "); strncat(buffer, getvalue(e_rx + e_tx, 10, RT_Estimate), 32); if (cfg.estimatestyle) { if (cfg.ostyle > 2) { drawbar(ic, textx + (67 * ic->font->w) - 2, texty - ic->lineheight + 4, 13 * ic->font->w + 1, e_rx, e_tx, datainfo.max, 1); drawbar(ic, textx + (67 * ic->font->w) - 2, texty - ic->lineheight + 4, 13 * ic->font->w + 1, datalist_i->rx, datalist_i->tx, datainfo.max, 0); } else { drawbar(ic, textx + (51 * ic->font->w) - 2, texty - ic->lineheight + 4, 28 * ic->font->w + 3, e_rx, e_tx, datainfo.max, 1); drawbar(ic, textx + (51 * ic->font->w) - 2, texty - ic->lineheight + 4, 28 * ic->font->w + 3, datalist_i->rx, datalist_i->tx, datainfo.max, 0); } } /* sum visible */ } else if (strlen(ic->dataend) > 0 && datainfo.count > 1 && listtype != LT_Top) { if (datainfo.count < 100) { snprintf(datebuff, 16, "sum of %" PRIu32 "", datainfo.count); } else { snprintf(datebuff, 16, "sum"); } snprintf(buffer, 32, " %9s ", datebuff); strncat(buffer, getvalue(datainfo.sumrx, 10, RT_Normal), 32); strcat(buffer, " "); strncat(buffer, getvalue(datainfo.sumtx, 10, RT_Normal), 32); strcat(buffer, " "); strncat(buffer, getvalue(datainfo.sumrx + datainfo.sumtx, 10, RT_Normal), 32); } if (strlen(buffer) > 0) { texty += 8; gdImageString(ic->im, ic->font, textx, texty, (unsigned char *)buffer, ic->ctext); gdImageLine(ic->im, textx + (24 * ic->font->w) + offsetx, texty - 6, textx + (24 * ic->font->w) + offsetx, texty + ic->lineheight - (ic->large * 2), ic->cline); gdImageLine(ic->im, textx + (37 * ic->font->w) + offsetx, texty - 6, textx + (37 * ic->font->w) + offsetx, texty + ic->lineheight - (ic->large * 2), ic->cline); if (cfg.ostyle > 2) { gdImageLine(ic->im, textx + (50 * ic->font->w) + offsetx, texty - 6, textx + (50 * ic->font->w) + offsetx, texty + ic->lineheight - (ic->large * 2), ic->cline); } } dbdatalistfree(&datalist); } void drawsummary(IMAGECONTENT *ic, const int layout, const int rate) { int width, height, headermod; switch (layout) { // horizontal case 1: width = 163 * ic->font->w + 2 + (ic->large * 2); height = 56 + 12 * ic->lineheight; break; // vertical case 2: width = 83 * ic->font->w + 2 + (ic->large * 2); height = 370 + (ic->large * 90); break; // no hours default: width = 83 * ic->font->w + 2 + (ic->large * 2); height = 56 + 12 * ic->lineheight; break; } if (!ic->showheader) { headermod = 26; height -= 22; } else { headermod = 0; } imageinit(ic, width, height); layoutinit(ic, "", width, height); if (ic->interface.rxtotal == 0 && ic->interface.txtotal == 0) { gdImageString(ic->im, ic->font, 33 * ic->font->w, 100, (unsigned char *)"no data available", ic->ctext); return; } drawsummary_alltime(ic, 385 + (ic->large * 125), 57 - headermod + (ic->large * 10)); drawlegend(ic, 410 + (ic->large * 132), 155 - headermod + (ic->large * 40), 0); drawsummary_digest(ic, 100, 30 - headermod, "day"); drawsummary_digest(ic, 100, 29 + 7 * ic->lineheight - headermod, "month"); switch (layout) { // horizontal case 1: if (cfg.summarygraph == 1) { drawfiveminutes(ic, 496 + (ic->large * 174), height - 30 - (ic->large * 8), rate, 422 + (ic->large * 154), height - 68 + headermod - (ic->large * 8)); } else { drawhours(ic, 500 + (ic->large * 160), 46 + (ic->large * 40) - headermod, rate); } break; // vertical case 2: if (cfg.summarygraph == 1) { drawfiveminutes(ic, 8 + (ic->large * 14), height - 31 - (ic->large * 6), rate, 422 + (ic->large * 154), 132 + (ic->large * 35)); } else { drawhours(ic, 12, 215 + (ic->large * 84) - headermod, rate); } break; default: break; } } void drawsummary_alltime(IMAGECONTENT *ic, const int x, const int y) { struct tm *d; char buffer[512], datebuff[16], daytemp[32]; gdFontPtr titlefont; if (ic->large) { titlefont = gdFontGetGiant(); } else { titlefont = gdFontGetLarge(); } gdImageString(ic->im, titlefont, x + 12 + (ic->large * 10), y, (unsigned char *)"all time", ic->ctext); snprintf(buffer, 4, "rx "); strncat(buffer, getvalue(ic->interface.rxtotal, 12, RT_Normal), 32); gdImageString(ic->im, ic->font, x, y + (2 * ic->lineheight), (unsigned char *)buffer, ic->ctext); snprintf(buffer, 4, "tx "); strncat(buffer, getvalue(ic->interface.txtotal, 12, RT_Normal), 32); gdImageString(ic->im, ic->font, x, y + (3 * ic->lineheight), (unsigned char *)buffer, ic->ctext); snprintf(buffer, 4, " = "); strncat(buffer, getvalue(ic->interface.rxtotal + ic->interface.txtotal, 12, RT_Normal), 32); gdImageString(ic->im, ic->font, x, y + (4 * ic->lineheight) + 2 + (ic->large * 4), (unsigned char *)buffer, ic->ctext); d = localtime(&ic->interface.created); strftime(datebuff, 16, cfg.tformat, d); snprintf(daytemp, 24, "since %s", datebuff); snprintf(buffer, 32, "%23s", daytemp); gdImageString(ic->im, ic->font, x - 8 * ic->font->w, y + (5 * ic->lineheight) + 10 + (ic->large * 4), (unsigned char *)buffer, ic->ctext); } void drawsummary_digest(IMAGECONTENT *ic, const int x, const int y, const char *mode) { int textx, texty, offset = 0; double rxp, txp, mod; char buffer[512], datebuff[16], daytemp[32]; time_t yesterday; struct tm *d = NULL; dbdatalist *datalist = NULL; dbdatalist *data_current = NULL, *data_previous = NULL; dbdatalistinfo datainfo; gdFontPtr titlefont; if (ic->large) { titlefont = gdFontGetGiant(); } else { titlefont = gdFontGetLarge(); } yesterday = ic->current - 86400; switch(mode[0]) { case 'd': break; case 'm': break; default: printf("Error: Unsupported mode %s for summary digest\n", mode); return; } if (!db_getdata(&datalist, &datainfo, ic->interface.name, mode, 2) || datalist == NULL) { gdImageString(ic->im, ic->font, 25 * ic->font->w, y + 30, (unsigned char *)"no data available", ic->ctext); return; } else if (datalist->next == NULL) { data_current = datalist; } else { data_previous = datalist; data_current = datalist->next; } /* latest entry */ if (data_current->rx + data_current->tx == 0) { rxp = txp = 0; } else { rxp = (double)data_current->rx / (double)(data_current->rx + data_current->tx) * 100; txp = (double)100 - rxp; } /* do scaling if needed */ if (data_previous != NULL && (data_current->rx + data_current->tx) < (data_previous->rx + data_previous->tx)) { mod = (double)(data_current->rx + data_current->tx) / (double)(data_previous->rx + data_previous->tx); rxp = rxp * mod; txp = txp * mod; } /* move graph to center if there's only one to draw for this line */ if (data_previous == NULL) { offset = 85 + (ic->large * 25); } textx = x + offset; texty = y; drawdonut(ic, textx + 50 + (ic->large * 40), texty + 45 + (ic->large * 10), (float)rxp, (float)txp, 49 + (ic->large * 10), 15 + (ic->large * 3)); if (mode[0] == 'd') { /* get formatted date for today */ d = localtime(&ic->current); strftime(datebuff, 16, cfg.dformat, d); /* get formatted date for current day in database */ d = localtime(&data_current->timestamp); strftime(daytemp, 16, cfg.dformat, d); /* change daytemp to today if formatted days match */ if (strcmp(datebuff, daytemp) == 0) { strncpy_nt(daytemp, "today", 32); } } else if (mode[0] == 'm') { d = localtime(&data_current->timestamp); strftime(daytemp, 16, cfg.mformat, d); } snprintf(buffer, 32, "%*s", getpadding(12, daytemp), daytemp); gdImageString(ic->im, titlefont, textx - 54 + (ic->large * (ic->font->w * 3 - 4)), texty - 1, (unsigned char *)buffer, ic->ctext); if (cfg.summaryrate) { d = localtime(&ic->interface.updated); if (mode[0] == 'd') { snprintf(buffer, 16, "%15s", gettrafficrate(data_current->rx + data_current->tx, d->tm_sec + (d->tm_min * 60) + (d->tm_hour * 3600), 15)); } else if (mode[0] == 'm') { snprintf(buffer, 16, "%15s", gettrafficrate(data_current->rx + data_current->tx, mosecs(data_current->timestamp, ic->interface.updated), 15)); } gdImageString(ic->im, ic->font, textx - 74, texty + 4 * ic->lineheight + 10, (unsigned char *)buffer, ic->ctext); } else { texty += 7; } snprintf(buffer, 4, "rx "); strncat(buffer, getvalue(data_current->rx, 12, RT_Normal), 32); gdImageString(ic->im, ic->font, textx - 74, texty + ic->lineheight + 6, (unsigned char *)buffer, ic->ctext); snprintf(buffer, 4, "tx "); strncat(buffer, getvalue(data_current->tx, 12, RT_Normal), 32); gdImageString(ic->im, ic->font, textx - 74, texty + 2 * ic->lineheight + 6, (unsigned char *)buffer, ic->ctext); snprintf(buffer, 4, " = "); strncat(buffer, getvalue(data_current->rx + data_current->tx, 12, RT_Normal), 32); gdImageString(ic->im, ic->font, textx - 74, texty + 3 * ic->lineheight + 8, (unsigned char *)buffer, ic->ctext); /* previous entry */ if (data_previous != NULL) { if (data_previous->rx + data_previous->tx == 0) { rxp = txp = 0; } else { rxp = (double)data_previous->rx / (double)(data_previous->rx + data_previous->tx) * 100; txp = (double)100 - rxp; } /* do scaling if needed */ if ((data_previous->rx + data_previous->tx) < (data_current->rx + data_current->tx)) { mod = (double)(data_previous->rx + data_previous->tx) / (double)(data_current->rx + data_current->tx); rxp = rxp * mod; txp = txp * mod; } textx += 180 + (ic->large * 60); drawdonut(ic, textx + 50 + (ic->large * 40), texty + 45 + (ic->large * 10), (float)rxp, (float)txp, 49 + (ic->large * 10), 15 + (ic->large * 3)); if (mode[0] == 'd') { /* get formatted date for yesterday */ d = localtime(&yesterday); strftime(datebuff, 16, cfg.dformat, d); /* get formatted date for previous day in database */ d = localtime(&data_previous->timestamp); strftime(daytemp, 16, cfg.dformat, d); /* change daytemp to yesterday if formatted days match */ if (strcmp(datebuff, daytemp) == 0) { strncpy_nt(daytemp, "yesterday", 32); } } else if (mode[0] == 'm') { d = localtime(&data_previous->timestamp); strftime(daytemp, 16, cfg.mformat, d); } snprintf(buffer, 32, "%*s", getpadding(12, daytemp), daytemp); gdImageString(ic->im, titlefont, textx - 54 + (ic->large * (ic->font->w * 3 - 4)), texty - 1, (unsigned char *)buffer, ic->ctext); if (cfg.summaryrate) { if (mode[0] == 'd') { snprintf(buffer, 16, "%15s", gettrafficrate(data_previous->rx + data_previous->tx, 86400, 15)); } else if (mode[0] == 'm') { snprintf(buffer, 16, "%15s", gettrafficrate(data_previous->rx + data_previous->tx, dmonth(d->tm_mon) * 86400, 15)); } gdImageString(ic->im, ic->font, textx - 74, texty + 4 * ic->lineheight + 10, (unsigned char *)buffer, ic->ctext); } else { texty += 7; } snprintf(buffer, 4, "rx "); strncat(buffer, getvalue(data_previous->rx, 12, RT_Normal), 32); gdImageString(ic->im, ic->font, textx - 74, texty + ic->lineheight + 6, (unsigned char *)buffer, ic->ctext); snprintf(buffer, 4, "tx "); strncat(buffer, getvalue(data_previous->tx, 12, RT_Normal), 32); gdImageString(ic->im, ic->font, textx - 74, texty + 2 * ic->lineheight + 6, (unsigned char *)buffer, ic->ctext); snprintf(buffer, 4, " = "); strncat(buffer, getvalue(data_previous->rx + data_previous->tx, 12, RT_Normal), 32); gdImageString(ic->im, ic->font, textx - 74, texty + 3 * ic->lineheight + 8, (unsigned char *)buffer, ic->ctext); } data_current = NULL; data_previous = NULL; dbdatalistfree(&datalist); } void drawfivegraph(IMAGECONTENT *ic, const int rate, const int resultcount, const int height) { int imagewidth, imageheight = height, headermod = 0; imagewidth = resultcount + FIVEMINEXTRASPACE + (ic->large * 14); if (!ic->showheader) { headermod = 22; } imageinit(ic, imagewidth, imageheight); layoutinit(ic, " / 5 minute", imagewidth, imageheight); if (drawfiveminutes(ic, 8 + (ic->large * 14), imageheight - 30 - (ic->large * 8), rate, resultcount, imageheight - 68 + headermod - (ic->large * 8))) { drawlegend(ic, imagewidth / 2 - (ic->large * 10), imageheight - 17 - (ic->large * 2), 0); } } int drawfiveminutes(IMAGECONTENT *ic, const int xpos, const int ypos, const int rate, const int resultcount, const int height) { int x = xpos, y = ypos, i = 0, t = 0, rxh = 0, txh = 0, step = 0, s = 0, prev = 0; uint64_t scaleunit, max; time_t timestamp; double ratediv, e; char buffer[32]; struct tm *d; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; gdFontPtr font; if (ic->large) { font = gdFontGetSmall(); } else { font = gdFontGetTiny(); } if (!db_getdata(&datalist, &datainfo, ic->interface.name, "fiveminute", (uint32_t)resultcount) || datainfo.count == 0) { x = (resultcount + FIVEMINEXTRASPACE + (ic->large * 14)) / 2 - (8 * ic->font->w + ic->font->w / 2); gdImageString(ic->im, ic->font, x, y - (height / 2) - ic->font->h, (unsigned char *)"no data available", ic->ctext); return 0; } datalist_i = datalist; if (cfg.rateunit) { ratediv = 37.5; /* x * 8 / 300 */ } else { ratediv = 300; } /* axis */ x += 36; gdImageLine(ic->im, x, y, x + (resultcount + FIVEMINWIDTHFULLPADDING), y, ic->ctext); gdImageLine(ic->im, x + 4, y + 4, x + 4, y - height, ic->ctext); /* arrows */ drawarrowup(ic, x + 4, y - 1 - height); drawarrowright(ic, x + 1 + (resultcount + FIVEMINWIDTHFULLPADDING), y); max = datainfo.maxrx + datainfo.maxtx; if (datainfo.maxrx == datainfo.maxtx) { txh = (int)((height - FIVEMINHEIGHTOFFSET * 2) / 2); rxh = height - FIVEMINHEIGHTOFFSET * 2 - txh; max = (uint64_t)((double)datainfo.maxrx / ratediv); t = rxh; } else if (datainfo.maxrx > datainfo.maxtx) { txh = (int)lrint(((double)datainfo.maxtx / (double)max) * (height - FIVEMINHEIGHTOFFSET * 2)); rxh = height - FIVEMINHEIGHTOFFSET * 2 - txh; max = (uint64_t)((double)datainfo.maxrx / ratediv); t = rxh; } else { rxh = (int)lrint(((double)datainfo.maxrx / (double)max) * (height - FIVEMINHEIGHTOFFSET * 2)); txh = height - FIVEMINHEIGHTOFFSET * 2 - rxh; max = (uint64_t)((double)datainfo.maxtx / ratediv); t = txh; } /* center line */ x += 5; y -= txh + FIVEMINHEIGHTOFFSET; gdImageLine(ic->im, x, y, x + (resultcount + FIVEMINWIDTHPADDING), y, ic->ctext); gdImageString(ic->im, font, x - 21 - (ic->large * 3), y - 4 - (ic->large * 3), (unsigned char *)" 0", ic->ctext); /* scale values */ scaleunit = getscale(max, rate); s = (int)lrint(((double)scaleunit / (double)max) * t); if (s == 0) { s = 1; // force to show something when there's not much or any traffic, scale is likely to be wrong in this case } while (s * step < SCALEMINPIXELS) { step++; } if (debug) { printf("maxrx: %" PRIu64 "\n", datainfo.maxrx); printf("maxtx: %" PRIu64 "\n", datainfo.maxtx); printf("rxh: %d txh: %d\n", rxh, txh); printf("max divided: %" PRIu64 "\n", max); printf("scaleunit: %" PRIu64 "\nstep: %d\n", scaleunit, step); printf("pixels per step: %d\n", s); printf("mintime: %" PRIu64 "\nmaxtime: %" PRIu64 "\n", (uint64_t)datainfo.mintime, (uint64_t)datainfo.maxtime); printf("count: %u\n", datainfo.count); } /* upper part scale values */ y--; // adjust to start above center line for (i = step; i * s <= rxh; i = i + step) { gdImageDashedLine(ic->im, x, y - (i * s), x + (resultcount + FIVEMINWIDTHPADDING), y - (i * s), ic->cline); gdImageDashedLine(ic->im, x, y - prev - (step * s) / 2, x + (resultcount + FIVEMINWIDTHPADDING), y - prev - (step * s) / 2, ic->clinel); gdImageString(ic->im, font, x - 21 - (ic->large * 3), y - 3 - (i * s) - (ic->large * 3), (unsigned char *)getimagevalue(scaleunit * (unsigned int)i, 3, rate), ic->ctext); prev = i * s; } if ((prev + (step * s) / 2) <= rxh) { gdImageDashedLine(ic->im, x, y - prev - (step * s) / 2, x + (resultcount + FIVEMINWIDTHPADDING), y - prev - (step * s) / 2, ic->clinel); } y += 2; // adjust to start below center line prev = 0; /* lower part scale values */ for (i = step; i * s <= txh; i = i + step) { gdImageDashedLine(ic->im, x, y + (i * s), x + (resultcount + FIVEMINWIDTHPADDING), y + (i * s), ic->cline); gdImageDashedLine(ic->im, x, y + prev + (step * s) / 2, x + (resultcount + FIVEMINWIDTHPADDING), y + prev + (step * s) / 2, ic->clinel); gdImageString(ic->im, font, x - 21 - (ic->large * 3), y - 3 + (i * s) - (ic->large * 3), (unsigned char *)getimagevalue(scaleunit * (unsigned int)i, 3, rate), ic->ctext); prev = i * s; } if ((prev + (step * s) / 2) <= txh) { gdImageDashedLine(ic->im, x, y + prev + (step * s) / 2, x + (resultcount + FIVEMINWIDTHPADDING), y + prev + (step * s) / 2, ic->clinel); } y--; // y is now back on center line /* scale text */ gdImageStringUp(ic->im, font, x - 39 - (ic->large * 14), ypos - height / 2 + (rate * 10), (unsigned char *)getimagescale(scaleunit * (unsigned int)step, rate), ic->ctext); timestamp = datainfo.maxtime - (resultcount * 300); while (datalist_i != NULL && datalist_i->timestamp < timestamp + 300) { if (debug) { printf("Skip data, %" PRIu64 " < %" PRIu64 "\n", (uint64_t)datalist_i->timestamp, (uint64_t)timestamp + 300); } datalist_i = datalist_i->next; } for (i = 0; i < resultcount; i++) { if (datalist_i == NULL) { break; } timestamp += 300; d = localtime(×tamp); if (d->tm_min == 0 && i > 2) { if (d->tm_hour % 2 == 0) { if (d->tm_hour == 0) { gdImageLine(ic->im, x + i, y + txh - 1 + FIVEMINHEIGHTOFFSET, x + i, y - rxh - 1, ic->cline); } else { gdImageLine(ic->im, x + i, y + txh - 1 + FIVEMINHEIGHTOFFSET, x + i, y - rxh - 1, ic->cbgoffset); } if (i > font->w) { snprintf(buffer, 32, "%02d", d->tm_hour); if (datalist_i->timestamp > timestamp) { gdImageString(ic->im, font, x + i - font->w + 1, y + txh + font->h - (ic->large * 5), (unsigned char *)buffer, ic->cline); } else { gdImageString(ic->im, font, x + i - font->w + 1, y + txh + font->h - (ic->large * 5), (unsigned char *)buffer, ic->ctext); } } } else { gdImageLine(ic->im, x + i, y + txh - 1 + FIVEMINHEIGHTOFFSET, x + i, y - rxh - 1, ic->cbgoffset); } gdImageSetPixel(ic->im, x + i, y, ic->ctext); } if (datalist_i->timestamp > timestamp) { gdImageSetPixel(ic->im, x + i, y, ic->cline); gdImageSetPixel(ic->im, x + i, y + txh + FIVEMINHEIGHTOFFSET, ic->cline); continue; } /* only the last entry can be the currently ongoing period that may need scaling */ if (datalist_i->next == NULL && issametimeslot(LT_5min, datalist_i->timestamp, ic->interface.updated)) { e = (double)(ic->interface.updated - datalist_i->timestamp) / (double)300; if (e < 0.01) { e = 1; } } else { e = 1; } t = (int)lrint(((double)datalist_i->rx / e / (double)datainfo.maxrx) * rxh); if (t > rxh) { t = rxh; } drawpole(ic, x + i, y - 1, t, 1, ic->crx); t = (int)lrint(((double)datalist_i->tx / e / (double)datainfo.maxtx) * txh); if (t > txh) { t = txh; } drawpole(ic, x + i, y + 1, t, 2, ic->ctx); datalist_i = datalist_i->next; } dbdatalistfree(&datalist); return 1; } vnstat-2.9/src/traffic.h0000644000000000000000000000024613536507661013775 0ustar rootroot#ifndef TRAFFIC_H #define TRAFFIC_H void trafficmeter(const char *iface, unsigned int sampletime); void livetrafficmeter(const char *iface, const int mode); #endif vnstat-2.9/src/datacache.h0000644000000000000000000000146613510102255014237 0ustar rootroot#ifndef DATACACHE_H #define DATACACHE_H typedef struct datacache { char interface[32]; short active; short filled; short syncneeded; uint64_t currx, curtx; time_t updated; struct xferlog *log; struct datacache *next; } datacache; typedef struct xferlog { time_t timestamp; uint64_t rx, tx; struct xferlog *next; } xferlog; int datacache_add(datacache **dc, const char *interface, const short sync); int datacache_remove(datacache **dc, const char *interface); void datacache_clear(datacache **dc); int datacache_count(datacache **dc); int datacache_activecount(datacache **dc); void datacache_debug(datacache **dc); int xferlog_add(xferlog **log, const time_t timestamp, const uint64_t rx, const uint64_t tx); void xferlog_clear(xferlog **log); void xferlog_debug(xferlog **log, const int newline); #endif vnstat-2.9/src/vnstat.c0000644000000000000000000001027614173117721013665 0ustar rootroot/* vnStat - Copyright (C) 2002-2022 Teemu Toivola This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 dated June, 1991. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "common.h" #include "ifinfo.h" #include "dbsql.h" #include "misc.h" #include "cfg.h" #include "ibw.h" #include "vnstat_func.h" int main(int argc, char *argv[]) { int currentarg; DIR *dir = NULL; PARAMS p; initparams(&p); /* early check for debug and config parameter */ if (argc > 1) { for (currentarg = 1; currentarg < argc; currentarg++) { if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) { debug = 1; printf("Debug enabled, vnstat %s\n", VERSION); } else if (strcmp(argv[currentarg], "--config") == 0) { if (currentarg + 1 < argc) { strncpy_nt(p.cfgfile, argv[currentarg + 1], 512); if (debug) printf("Used config file: %s\n", p.cfgfile); currentarg++; } else { printf("Error: File for --config missing.\n"); return 1; } } } } /* load config if available */ if (!loadcfg(p.cfgfile, CT_CLI)) { return 1; } if (!ibwloadcfg(p.cfgfile)) { return 1; } configlocale(); strncpy_nt(p.interface, "default", 32); strncpy_nt(p.definterface, cfg.iface, 32); strncpy_nt(p.alias, "none", 32); parseargs(&p, argc, argv); /* open database and see if it contains any interfaces */ if (!p.traffic && !p.livetraffic) { if ((dir = opendir(cfg.dbdir)) != NULL) { if (debug) printf("Dir OK\n"); closedir(dir); if (!db_open_ro()) { printf("Error: Failed to open database \"%s/%s\" in read-only mode.\n", cfg.dbdir, DATABASEFILE); if (errno == ENOENT) { printf("The vnStat daemon should have created the database when started.\n"); printf("Check that it is configured and running. See also \"man vnstatd\".\n"); } return 1; } p.dbifcount = db_getinterfacecount(); if (debug) printf("%" PRIu64 " interface(s) found\n", p.dbifcount); if (p.dbifcount > 1) { strncpy_nt(p.definterface, cfg.iface, 32); } } else { printf("Error: Unable to open database directory \"%s\": %s\n", cfg.dbdir, strerror(errno)); if (errno == ENOENT) { printf("The vnStat daemon should have created this directory when started.\n"); printf("Check that it is configured and running. See also \"man vnstatd\".\n"); } else { printf("Make sure it is at least read enabled for current user.\n"); printf("Use --help for help.\n"); } return 1; } } /* set used interface if none specified */ handleifselection(&p); /* parameter handlers */ handleshowalert(&p); handleremoveinterface(&p); handlerenameinterface(&p); handleaddinterface(&p); handlesetalias(&p); handleshowdata(&p); handletrafficmeters(&p); /* show something if nothing was shown previously */ if (!p.query && !p.traffic && !p.livetraffic) { /* give more help if there's no database */ if (p.dbifcount == 0) { getifliststring(&p.ifacelist, 1); printf("No interfaces found in the database, nothing to do. Use --help for help.\n\n"); printf("Interfaces can be added to the database with the following command:\n"); printf(" %s --add -i eth0\n\n", argv[0]); printf("Replace 'eth0' with the interface that should be monitored.\n\n"); if (strlen(cfg.cfgfile)) { printf("The default interface can be changed by updating the \"Interface\" keyword\n"); printf("value in the configuration file \"%s\".\n\n", cfg.cfgfile); } printf("The following interfaces are currently available:\n %s\n", p.ifacelist); free(p.ifacelist); } else { printf("Nothing to do. Use --help for help.\n"); } } /* cleanup */ db_close(); ibwflush(); return 0; } vnstat-2.9/src/vnstatd.c0000644000000000000000000002630614173117712014032 0ustar rootroot/* vnStat daemon - Copyright (C) 2008-2022 Teemu Toivola This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 dated June, 1991. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "common.h" #include "datacache.h" #include "dbsql.h" #include "cfg.h" #include "ibw.h" #include "id.h" #include "misc.h" #include "daemon.h" #include "vnstatd.h" int main(int argc, char *argv[]) { int currentarg; uint32_t previflisthash; uint64_t temp; DSTATE s; initdstate(&s); /* early check for debug and config parameter */ if (argc > 1) { for (currentarg = 1; currentarg < argc; currentarg++) { if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) { debug = 1; printf("Debug enabled, vnstatd %s\n", VERSION); } else if (strcmp(argv[currentarg], "--config") == 0) { if (currentarg + 1 < argc) { strncpy_nt(s.cfgfile, argv[currentarg + 1], 512); if (debug) printf("Used config file: %s\n", s.cfgfile); currentarg++; } else { printf("Error: File for --config missing.\n"); return 1; } } } } timeused_debug("daemon_startup", 1); /* load config if available */ if (!loadcfg(s.cfgfile, CT_Daemon)) { return 1; } if (!ibwloadcfg(s.cfgfile)) { return 1; } /* init config settings */ strncpy_nt(s.user, cfg.daemonuser, 33); strncpy_nt(s.group, cfg.daemongroup, 33); s.updateinterval = cfg.updateinterval; s.saveinterval = cfg.saveinterval * 60; parseargs(&s, argc, argv); preparedirs(&s); /* set user and/or group if requested */ setgroup(s.group); setuser(s.user); if (!db_open_rw(1)) { printf("Error: Failed to open database \"%s/%s\" in read/write mode.\n", cfg.dbdir, DATABASEFILE); printf("Exiting...\n"); exit(EXIT_FAILURE); } if (s.initdb) { db_close(); if (debug) { printf("--initdb complete, exiting...\n"); } exit(EXIT_SUCCESS); } detectboot(&s); preparedatabase(&s); if (!db_removeoldentries()) { printf("Error: Database \"%s/%s\" cleanup failed: %s\n", cfg.dbdir, DATABASEFILE, strerror(errno)); printf("Exiting...\n"); exit(EXIT_FAILURE); } setsignaltraps(); /* start as daemon if requested, debug can't be enabled at the same time */ if (s.rundaemon && !debug) { if (!db_close()) { printf("Error: Failed to close database \"%s/%s\" before starting daemon: %s\n", cfg.dbdir, DATABASEFILE, strerror(errno)); printf("Exiting...\n"); exit(EXIT_FAILURE); } noexit++; daemonize(); if (!db_open_rw(0)) { snprintf(errorstring, 1024, "Failed to reopen database \"%s/%s\": %s", cfg.dbdir, DATABASEFILE, strerror(errno)); printe(PT_Error); exit(EXIT_FAILURE); } } timeused_debug("daemon_startup", 0); s.running = 1; #if defined(__linux__) && HAVE_LINUX_RTNETLINK_H #if HAVE_DECL_IFLA_STATS64 snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid:%d 64-bit)", getversion(), (int)getpid(), (int)getuid(), (int)getgid()); #else snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid:%d 32-bit)", getversion(), (int)getpid(), (int)getuid(), (int)getgid()); #endif #else snprintf(errorstring, 1024, "vnStat daemon %s started. (pid:%d uid:%d gid:%d)", getversion(), (int)getpid(), (int)getuid(), (int)getgid()); #endif printe(PT_Info); #if !HAVE_DECL_SQLITE_CHECKPOINT_RESTART if (cfg.waldb) { snprintf(errorstring, 1024, "DatabaseWriteAheadLogging is enabled but used libsqlite3 does not support it"); printe(PT_Warning); } #endif /* warmup */ if (s.dbifcount == 0) { filldatabaselist(&s); s.prevdbsave = 0; } while (s.running && s.dbifcount && waittimesync(&s)) { if (intsignal) { handleintsignals(&s); } else { sleep(5); } } /* main loop */ while (s.running) { s.current = time(NULL); /* track interface status only if at least one database exists */ if (s.dbifcount != 0) { previflisthash = s.iflisthash; interfacechangecheck(&s); if (cfg.alwaysadd && s.iflisthash != previflisthash && previflisthash != 0) { temp = s.dbifcount; s.dbifcount += addinterfaces(&s); if (temp != s.dbifcount) { datacache_status(&s.dcache); } } } /* do update only if enough time has passed since the previous update */ if ((s.current - s.prevdbupdate) >= s.updateinterval) { s.updateinterval = cfg.updateinterval; if (debug) { debugtimestamp(); datacache_debug(&s.dcache); ibwlist(); } /* fill database list if cache is empty */ if (s.dbifcount == 0) { filldatabaselist(&s); /* update data cache */ } else { s.prevdbupdate = s.current - (s.current % s.updateinterval); adjustsaveinterval(&s); checkdbsaveneed(&s); processdatacache(&s); #if HAVE_DECL_SQLITE_CHECKPOINT_RESTART if (cfg.waldb && (s.current - s.prevwaldbcheckpoint) >= WALDBCHECKPOINTINTERVALMINS * 60) { db_walcheckpoint(); s.prevwaldbcheckpoint = s.current; } #endif if (debug) { printf("\n"); } } } if (s.running && intsignal == 0) { sleep((unsigned int)(cfg.pollinterval - (time(NULL) % cfg.pollinterval))); } if (intsignal) { handleintsignals(&s); } } flushcachetodisk(&s); db_close(); datacache_clear(&s.dcache); ibwflush(); if (s.rundaemon && !debug) { close(pidfile); unlink(cfg.pidfile); } return 0; } void showhelp(void) { printf("vnStat daemon %s by Teemu Toivola \n\n", getversion()); printf(" -d, --daemon fork process to background\n"); printf(" -n, --nodaemon stay in foreground attached to the terminal\n\n"); printf(" -s, --sync sync interface counters on first update\n"); printf(" -D, --debug show additional debug and disable daemon\n"); printf(" -?, --help show this help\n"); printf(" -v, --version show version\n"); printf(" -p, --pidfile select used pid file\n"); printf(" -u, --user set daemon process user\n"); printf(" -g, --group set daemon process group\n"); printf(" -t, --timestamp add timestamp to prints when running in foreground\n"); printf(" --config select used config file\n"); printf(" --noadd prevent startup if database has no interfaces\n"); printf(" --alwaysadd [mode] automatically start monitoring all new interfaces\n"); printf(" --initdb create empty database and exit\n\n"); printf("See also \"man vnstatd\".\n"); } void parseargs(DSTATE *s, int argc, char **argv) { int currentarg, pidfiledefined = 0; /* parse parameters, maybe not the best way but... */ for (currentarg = 1; currentarg < argc; currentarg++) { if (debug) printf("arg %d: \"%s\"\n", currentarg, argv[currentarg]); if ((strcmp(argv[currentarg], "-?") == 0) || (strcmp(argv[currentarg], "--help") == 0)) { break; } else if (strcmp(argv[currentarg], "--config") == 0) { /* config has already been parsed earlier so nothing to do here */ currentarg++; } else if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) { debug = 1; } else if ((strcmp(argv[currentarg], "-d") == 0) || (strcmp(argv[currentarg], "--daemon") == 0)) { s->rundaemon = 1; s->showhelp = 0; } else if ((strcmp(argv[currentarg], "-n") == 0) || (strcmp(argv[currentarg], "--nodaemon") == 0)) { s->showhelp = 0; } else if ((strcmp(argv[currentarg], "-s") == 0) || (strcmp(argv[currentarg], "--sync") == 0)) { s->sync = 1; } else if ((strcmp(argv[currentarg], "-t") == 0) || (strcmp(argv[currentarg], "--timestamp") == 0)) { cfg.timestampprints = 1; } else if ((strcmp(argv[currentarg], "-u") == 0) || (strcmp(argv[currentarg], "--user") == 0)) { if (currentarg + 1 < argc) { strncpy_nt(s->user, argv[currentarg + 1], 33); if (debug) printf("Requested user: \"%s\"\n", s->user); currentarg++; } else { printf("Error: User for --user missing.\n"); exit(EXIT_FAILURE); } } else if ((strcmp(argv[currentarg], "-g") == 0) || (strcmp(argv[currentarg], "--group") == 0)) { if (currentarg + 1 < argc) { strncpy_nt(s->group, argv[currentarg + 1], 33); if (debug) printf("Requested group: \"%s\"\n", s->group); currentarg++; } else { printf("Error: Group for --group missing.\n"); exit(EXIT_FAILURE); } } else if (strcmp(argv[currentarg], "--noadd") == 0) { s->noadd = 1; } else if (strcmp(argv[currentarg], "--alwaysadd") == 0) { if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]) == 1 || ishelprequest(argv[currentarg + 1]))) { if (!isdigit(argv[currentarg + 1][0]) || atoi(argv[currentarg + 1]) > 1 || atoi(argv[currentarg + 1]) < 0) { if (!ishelprequest(argv[currentarg + 1])) printf("Error: Invalid mode parameter \"%s\".\n", argv[currentarg + 1]); printf(" Valid parameters for %s:\n", argv[currentarg]); printf(" 0 - disabled"); if (!cfg.alwaysadd) { printf(" (default)"); } printf("\n 1 - enabled"); if (cfg.alwaysadd) { printf(" (default)"); } printf("\n No mode parameter results in feature being enabled.\n"); exit(EXIT_FAILURE); } cfg.alwaysadd = atoi(argv[currentarg + 1]); currentarg++; } else { cfg.alwaysadd = 1; } } else if (strcmp(argv[currentarg], "--initdb") == 0) { s->initdb = 1; s->showhelp = 0; } else if ((strcmp(argv[currentarg], "-v") == 0) || (strcmp(argv[currentarg], "--version") == 0)) { printf("vnStat daemon %s by Teemu Toivola \n", getversion()); exit(EXIT_SUCCESS); } else if ((strcmp(argv[currentarg], "-p") == 0) || (strcmp(argv[currentarg], "--pidfile") == 0)) { if (currentarg + 1 < argc) { strncpy_nt(cfg.pidfile, argv[currentarg + 1], 512); cfg.pidfile[511] = '\0'; if (debug) printf("Used pid file: %s\n", cfg.pidfile); currentarg++; pidfiledefined = 1; } else { printf("Error: File for --pidfile missing.\n"); exit(EXIT_FAILURE); } } else { printf("Unknown arg \"%s\". Use --help for help.\n", argv[currentarg]); exit(EXIT_FAILURE); } } if (s->noadd && cfg.alwaysadd) { printf("Warning: --noadd and --alwaysadd can't both be enabled at the same time. --alwaysadd has been disabled.\n"); cfg.alwaysadd = 0; } if (s->rundaemon && debug) { printf("Error: --daemon and --debug can't both be used at the same time.\n"); exit(EXIT_FAILURE); } if (s->rundaemon && s->initdb) { printf("Error: --daemon and --initdb can't both be used at the same time.\n"); exit(EXIT_FAILURE); } /* show help if nothing else was asked to be done */ if (s->showhelp) { showhelp(); exit(EXIT_SUCCESS); } if (!s->rundaemon && pidfiledefined) { printf("Error: --pidfile can only be used together with --daemon\n"); exit(EXIT_FAILURE); } } vnstat-2.9/src/vnstat_func.c0000644000000000000000000012105614173310242014670 0ustar rootroot#include "common.h" #include "ifinfo.h" #include "iflist.h" #include "traffic.h" #include "dbsql.h" #include "dbxml.h" #include "dbjson.h" #include "dbshow.h" #include "misc.h" #include "cfg.h" #include "cfgoutput.h" #include "vnstat_func.h" void initparams(PARAMS *p) { db = NULL; noexit = 0; /* allow functions to exit in case of error */ debug = 0; /* debug disabled by default */ disableprints = 0; /* let prints be visible */ p->addiface = 0; p->query = 1; p->setalias = 0; p->dbifcount = 0; p->force = 0; p->traffic = 0; p->livetraffic = 0; p->defaultiface = 1; p->removeiface = 0; p->renameiface = 0; p->livemode = 0; p->limit = -1; p->ifacelist = NULL; p->interface[0] = '\0'; p->alias[0] = '\0'; p->newifname[0] = '\0'; p->filename[0] = '\0'; p->definterface[0] = '\0'; p->cfgfile[0] = '\0'; p->jsonmode = 'a'; p->xmlmode = 'a'; p->databegin[0] = '\0'; p->dataend[0] = '\0'; p->alert = 0; p->alertoutput = 0; p->alertexit = 0; p->alerttype = 0; p->alertcondition = 0; p->alertlimit = 0; } void showhelp(PARAMS *p) { printf("vnStat %s by Teemu Toivola \n\n", getversion()); printf(" -5, --fiveminutes [limit] show 5 minutes\n"); printf(" -h, --hours [limit] show hours\n"); printf(" -hg, --hoursgraph show hours graph\n"); printf(" -d, --days [limit] show days\n"); printf(" -m, --months [limit] show months\n"); printf(" -y, --years [limit] show years\n"); printf(" -t, --top [limit] show top days\n\n"); printf(" -b, --begin set list begin date\n"); printf(" -e, --end set list end date\n\n"); printf(" --oneline [mode] show simple parsable format\n"); printf(" --json [mode] [limit] show database in json format\n"); printf(" --xml [mode] [limit] show database in xml format\n"); printf(" --alert \n"); printf(" alert if limit is exceeded\n\n"); printf(" -tr, --traffic [time] calculate traffic\n"); printf(" -l, --live [mode] show transfer rate in real time\n"); printf(" -i, --iface select interface"); if (strlen(p->definterface)) { printf(" (default: %s)", p->definterface); } printf("\n\n"); printf("Use \"--longhelp\" or \"man vnstat\" for complete list of options.\n"); } void showlonghelp(PARAMS *p) { printf("vnStat %s by Teemu Toivola \n\n", getversion()); printf("Query:\n"); printf(" -q, --query query database\n"); printf(" -s, --short use short output\n"); printf(" -5, --fiveminutes [limit] show 5 minutes\n"); printf(" -h, --hours [limit] show hours\n"); printf(" -hg, --hoursgraph show hours graph\n"); printf(" -d, --days [limit] show days\n"); printf(" -m, --months [limit] show months\n"); printf(" -y, --years [limit] show years\n"); printf(" -t, --top [limit] show top days\n"); printf(" -b, --begin set list begin date\n"); printf(" -e, --end set list end date\n"); printf(" --oneline [mode] show simple parsable format\n"); printf(" --json [mode] [limit] show database in json format\n"); printf(" --xml [mode] [limit] show database in xml format\n"); printf(" --alert \n"); printf(" alert if limit is exceeded\n\n"); printf("Modify:\n"); printf(" --add add interface to database\n"); printf(" --remove remove interface from database\n"); printf(" --rename rename interface in database\n"); printf(" --setalias set alias for interface\n\n"); printf("Misc:\n"); printf(" -i, --iface select interface"); if (strlen(p->definterface)) { printf(" (default: %s)", p->definterface); } printf("\n"); printf(" -?, --help show short help\n"); printf(" -D, --debug show some additional debug information\n"); printf(" -v, --version show version\n"); printf(" -tr, --traffic [time] calculate traffic\n"); printf(" -l, --live [mode] show transfer rate in real time\n"); printf(" -ru, --rateunit [mode] swap configured rate unit\n"); printf(" --limit set output entry limit\n"); printf(" --style select output style (0-4)\n"); printf(" --iflist [mode] show list of available interfaces\n"); printf(" --dbiflist [mode] show list of interfaces in database\n"); printf(" --dbdir select database directory\n"); printf(" --locale set locale\n"); printf(" --config select config file\n"); printf(" --showconfig dump config file with current settings\n"); printf(" --longhelp show this help\n\n"); printf("See also \"man vnstat\" for longer descriptions of each option.\n"); } void parseargs(PARAMS *p, const int argc, char **argv) { int currentarg; /* parse parameters, maybe not the best way but... */ for (currentarg = 1; currentarg < argc; currentarg++) { if (debug) printf("arg %d: \"%s\"\n", currentarg, argv[currentarg]); if (strcmp(argv[currentarg], "--longhelp") == 0) { showlonghelp(p); exit(EXIT_SUCCESS); } else if ((strcmp(argv[currentarg], "-?") == 0) || (strcmp(argv[currentarg], "--help") == 0)) { showhelp(p); exit(EXIT_SUCCESS); } else if ((strcmp(argv[currentarg], "-i") == 0) || (strcmp(argv[currentarg], "--iface") == 0) || (strcmp(argv[currentarg], "--interface") == 0)) { if (currentarg + 1 < argc) { if (strlen(argv[currentarg + 1]) > 31) { printf("Error: Interface name is limited to 31 characters.\n"); exit(EXIT_FAILURE); } strncpy_nt(p->interface, argv[currentarg + 1], 32); if (strlen(p->interface)) { p->defaultiface = 0; } else { strncpy_nt(p->definterface, p->interface, 32); } if (debug) printf("Used interface: \"%s\"\n", p->interface); currentarg++; } else { printf("Error: Interface for %s missing.\n", argv[currentarg]); exit(EXIT_FAILURE); } } else if (strcmp(argv[currentarg], "--config") == 0) { /* config has already been parsed earlier so nothing to do here */ currentarg++; } else if (strcmp(argv[currentarg], "--setalias") == 0 || strcmp(argv[currentarg], "--nick") == 0) { if (strcmp(argv[currentarg], "--nick") == 0) { printf("Warning: --nick is deprecated and will be removed in a future release. Use --setalias instead.\n"); } if (currentarg + 1 < argc) { strncpy_nt(p->alias, argv[currentarg + 1], 32); if (debug) printf("Used alias: \"%s\"\n", p->alias); p->setalias = 1; currentarg++; } else { printf("Error: Alias for %s missing.\n", argv[currentarg]); exit(EXIT_FAILURE); } } else if ((strcmp(argv[currentarg], "--style")) == 0) { if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.ostyle = atoi(argv[currentarg + 1]); if (cfg.ostyle > 4 || cfg.ostyle < 0) { printf("Error: Invalid style parameter \"%d\"\n", cfg.ostyle); showstylehelp(); exit(EXIT_FAILURE); } if (debug) printf("Style changed: %d\n", cfg.ostyle); currentarg++; } else { printf("Error: Style parameter for --style missing.\n"); showstylehelp(); exit(EXIT_FAILURE); } } else if ((strcmp(argv[currentarg], "--dbdir")) == 0) { if (currentarg + 1 < argc) { strncpy_nt(cfg.dbdir, argv[currentarg + 1], 512); if (debug) printf("DatabaseDir: \"%s\"\n", cfg.dbdir); currentarg++; } else { printf("Error: Directory for %s missing.\n", argv[currentarg]); exit(EXIT_FAILURE); } } else if ((strcmp(argv[currentarg], "--locale")) == 0) { if (currentarg + 1 < argc) { setlocale(LC_ALL, argv[currentarg + 1]); if (debug) printf("Locale: \"%s\"\n", argv[currentarg + 1]); currentarg++; } else { printf("Error: Locale for %s missing.\n", argv[currentarg]); exit(EXIT_FAILURE); } } else if (strcmp(argv[currentarg], "--add") == 0) { p->addiface = 1; p->query = 0; } else if ((strcmp(argv[currentarg], "-u") == 0) || (strcmp(argv[currentarg], "--update") == 0)) { printf("Error: The \"%s\" parameter is not supported in this version.\n", argv[currentarg]); exit(EXIT_FAILURE); } else if ((strcmp(argv[currentarg], "-q") == 0) || (strcmp(argv[currentarg], "--query") == 0)) { p->query = 1; } else if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) { debug = 1; } else if ((strcmp(argv[currentarg], "-d") == 0) || (strcmp(argv[currentarg], "--days") == 0)) { cfg.qmode = 1; if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.listdays = atoi(argv[currentarg + 1]); if (cfg.listdays < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } } else if ((strcmp(argv[currentarg], "-m") == 0) || (strcmp(argv[currentarg], "--months") == 0)) { cfg.qmode = 2; if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.listmonths = atoi(argv[currentarg + 1]); if (cfg.listmonths < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } } else if ((strcmp(argv[currentarg], "-t") == 0) || (strcmp(argv[currentarg], "--top") == 0)) { cfg.qmode = 3; if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.listtop = atoi(argv[currentarg + 1]); if (cfg.listtop < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } } else if ((strcmp(argv[currentarg], "-s") == 0) || (strcmp(argv[currentarg], "--short") == 0)) { cfg.qmode = 5; } else if ((strcmp(argv[currentarg], "-y") == 0) || (strcmp(argv[currentarg], "--years") == 0)) { cfg.qmode = 6; if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.listyears = atoi(argv[currentarg + 1]); if (cfg.listyears < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } } else if ((strcmp(argv[currentarg], "-hg") == 0) || (strcmp(argv[currentarg], "--hoursgraph") == 0)) { cfg.qmode = 7; } else if ((strcmp(argv[currentarg], "-h") == 0) || (strcmp(argv[currentarg], "--hours") == 0)) { cfg.qmode = 11; if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.listhours = atoi(argv[currentarg + 1]); if (cfg.listhours < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } } else if ((strcmp(argv[currentarg], "-5") == 0) || (strcmp(argv[currentarg], "--fiveminutes") == 0)) { cfg.qmode = 12; if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.listfivemins = atoi(argv[currentarg + 1]); if (cfg.listfivemins < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } } else if (strcmp(argv[currentarg], "--oneline") == 0) { cfg.qmode = 9; if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]) == 1 || ishelprequest(argv[currentarg + 1]))) { if (argv[currentarg + 1][0] == 'b') { cfg.ostyle = 4; currentarg++; } else { if (!ishelprequest(argv[currentarg + 1])) printf("Error: Invalid mode parameter \"%s\".\n", argv[currentarg + 1]); printf(" Valid parameters for --oneline:\n"); printf(" (none) - automatically scaled units visible\n"); printf(" b - all values in bytes\n"); exit(EXIT_FAILURE); } } } else if (strcmp(argv[currentarg], "--xml") == 0) { cfg.qmode = 8; if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]) == 1 || ishelprequest(argv[currentarg + 1]))) { p->xmlmode = argv[currentarg + 1][0]; if (strlen(argv[currentarg + 1]) != 1 || strchr("afhdmyt", p->xmlmode) == NULL) { if (!ishelprequest(argv[currentarg + 1])) printf("Error: Invalid mode parameter \"%s\".\n", argv[currentarg + 1]); printf(" Valid parameters for --xml:\n"); printf(" a - all (default)\n"); printf(" f - only 5 minutes\n"); printf(" h - only hours\n"); printf(" d - only days\n"); printf(" m - only months\n"); printf(" y - only years\n"); printf(" t - only top\n"); exit(EXIT_FAILURE); } currentarg++; } if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.listjsonxml = atoi(argv[currentarg + 1]); if (cfg.listjsonxml < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } } else if (strcmp(argv[currentarg], "--json") == 0) { cfg.qmode = 10; if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]) == 1 || ishelprequest(argv[currentarg + 1]))) { p->jsonmode = argv[currentarg + 1][0]; if (strlen(argv[currentarg + 1]) != 1 || strchr("afhdmyt", p->jsonmode) == NULL) { if (!ishelprequest(argv[currentarg + 1])) printf("Error: Invalid mode parameter \"%s\".\n", argv[currentarg + 1]); printf(" Valid parameters for --json:\n"); printf(" a - all (default)\n"); printf(" f - only 5 minutes\n"); printf(" h - only hours\n"); printf(" d - only days\n"); printf(" m - only months\n"); printf(" y - only years\n"); printf(" t - only top\n"); exit(EXIT_FAILURE); } currentarg++; } if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.listjsonxml = atoi(argv[currentarg + 1]); if (cfg.listjsonxml < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } } else if ((strcmp(argv[currentarg], "-ru") == 0) || (strcmp(argv[currentarg], "--rateunit")) == 0) { if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]) == 1 || ishelprequest(argv[currentarg + 1]))) { if (!isdigit(argv[currentarg + 1][0]) || atoi(argv[currentarg + 1]) > 1 || atoi(argv[currentarg + 1]) < 0) { if (!ishelprequest(argv[currentarg + 1])) printf("Error: Invalid parameter \"%s\".\n", argv[currentarg + 1]); printf(" Valid parameters for %s:\n", argv[currentarg]); printf(" 0 - bytes\n"); printf(" 1 - bits\n"); exit(EXIT_FAILURE); } cfg.rateunit = atoi(argv[currentarg + 1]); if (debug) printf("Rateunit changed: %d\n", cfg.rateunit); currentarg++; } else { cfg.rateunit = !cfg.rateunit; if (debug) printf("Rateunit changed: %d\n", cfg.rateunit); } } else if ((strcmp(argv[currentarg], "-tr") == 0) || (strcmp(argv[currentarg], "--traffic") == 0)) { if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.sampletime = atoi(argv[currentarg + 1]); currentarg++; } p->traffic = 1; p->query = 0; } else if ((strcmp(argv[currentarg], "-l") == 0) || (strcmp(argv[currentarg], "--live") == 0)) { if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]) == 1 || ishelprequest(argv[currentarg + 1]))) { if (!isdigit(argv[currentarg + 1][0]) || atoi(argv[currentarg + 1]) > 1 || atoi(argv[currentarg + 1]) < 0) { if (!ishelprequest(argv[currentarg + 1])) printf("Error: Invalid mode parameter \"%s\".\n", argv[currentarg + 1]); printf(" Valid parameters for %s:\n", argv[currentarg]); printf(" 0 - show packets per second (default)\n"); printf(" 1 - show transfer counters\n"); exit(EXIT_FAILURE); } p->livemode = atoi(argv[currentarg + 1]); currentarg++; } p->livetraffic = 1; p->query = 0; } else if (strcmp(argv[currentarg], "--force") == 0) { p->force = 1; } else if (strcmp(argv[currentarg], "--showconfig") == 0) { printcfgfile(); exit(EXIT_SUCCESS); } else if (strcmp(argv[currentarg], "--remove") == 0) { p->removeiface = 1; p->query = 0; } else if (strcmp(argv[currentarg], "--rename") == 0) { if (currentarg + 1 < argc) { strncpy_nt(p->newifname, argv[currentarg + 1], 32); if (debug) printf("Given new interface name: \"%s\"\n", p->newifname); p->renameiface = 1; p->query = 0; currentarg++; } else { printf("Error: New interface name for %s missing.\n", argv[currentarg]); exit(EXIT_FAILURE); } } else if ((strcmp(argv[currentarg], "-b") == 0) || (strcmp(argv[currentarg], "--begin") == 0)) { if (currentarg + 1 < argc) { if (!validatedatetime(argv[currentarg + 1])) { printf("Error: Invalid date format, expected YYYY-MM-DD HH:MM, YYYY-MM-DD or \"today\".\n"); exit(EXIT_FAILURE); } strncpy_nt(p->databegin, argv[currentarg + 1], 18); currentarg++; } else { printf("Error: Date of format YYYY-MM-DD HH:MM, YYYY-MM-DD or \"today\" for %s missing.\n", argv[currentarg]); exit(EXIT_FAILURE); } } else if ((strcmp(argv[currentarg], "-e") == 0) || (strcmp(argv[currentarg], "--end") == 0)) { if (currentarg + 1 < argc) { if (!validatedatetime(argv[currentarg + 1])) { printf("Error: Invalid date format, expected YYYY-MM-DD HH:MM or YYYY-MM-DD.\n"); exit(EXIT_FAILURE); } strncpy_nt(p->dataend, argv[currentarg + 1], 18); currentarg++; } else { printf("Error: Date of format YYYY-MM-DD HH:MM or YYYY-MM-DD for %s missing.\n", argv[currentarg]); exit(EXIT_FAILURE); } } else if (strcmp(argv[currentarg], "--iflist") == 0) { p->query = 0; if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]) == 1 || ishelprequest(argv[currentarg + 1]))) { if (!isdigit(argv[currentarg + 1][0]) || atoi(argv[currentarg + 1]) > 1 || atoi(argv[currentarg + 1]) < 0) { if (!ishelprequest(argv[currentarg + 1])) printf("Error: Invalid mode parameter \"%s\".\n", argv[currentarg + 1]); printf(" Valid parameters for --iflist:\n"); printf(" 0 - show verbose (default)\n"); printf(" 1 - show one interface per line\n"); exit(EXIT_FAILURE); } p->query = atoi(argv[currentarg + 1]); currentarg++; } showiflist(p->query); exit(EXIT_SUCCESS); } else if (strcmp(argv[currentarg], "--dbiflist") == 0) { p->query = 0; if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]) == 1 || ishelprequest(argv[currentarg + 1]))) { if (!isdigit(argv[currentarg + 1][0]) || atoi(argv[currentarg + 1]) > 1 || atoi(argv[currentarg + 1]) < 0) { if (!ishelprequest(argv[currentarg + 1])) printf("Error: Invalid mode parameter \"%s\".\n", argv[currentarg + 1]); printf(" Valid parameters for --dbiflist:\n"); printf(" 0 - show verbose (default)\n"); printf(" 1 - show one interface per line\n"); exit(EXIT_FAILURE); } p->query = atoi(argv[currentarg + 1]); currentarg++; } showdbiflist(p->query); exit(EXIT_SUCCESS); } else if (strcmp(argv[currentarg], "--limit") == 0) { if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { p->limit = atoi(argv[currentarg + 1]); if (p->limit < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } else { printf("Error: Invalid or missing parameter for %s.\n", argv[currentarg]); exit(EXIT_FAILURE); } } else if (strcmp(argv[currentarg], "--alert") == 0) { if (currentarg + 6 >= argc) { printf("Error: Invalid parameter count for %s.\n", argv[currentarg]); showalerthelp(); exit(EXIT_FAILURE); } if (!parsealertargs(p, argv + currentarg)) { exit(EXIT_FAILURE); } else { currentarg += 6; p->alert = 1; } } else if ((strcmp(argv[currentarg], "-v") == 0) || (strcmp(argv[currentarg], "--version") == 0)) { printf("vnStat %s by Teemu Toivola \n", getversion()); exit(EXIT_SUCCESS); } else { if (argv[currentarg][0] == '-' || strlen(argv[currentarg]) == 1) { printf("Unknown parameter \"%s\". Use --help for help.\n", argv[currentarg]); exit(EXIT_FAILURE); } else { if (strlen(argv[currentarg]) > 31) { printf("Error: Interface name is limited to 31 characters.\n"); exit(EXIT_FAILURE); } strncpy_nt(p->interface, argv[currentarg], 32); if (strlen(p->interface)) { p->defaultiface = 0; } else { strncpy_nt(p->definterface, p->interface, 32); } if (debug) printf("Used interface: \"%s\"\n", p->interface); } } } if (p->limit != -1) { cfg.listfivemins = cfg.listhours = cfg.listdays = cfg.listmonths = cfg.listyears = cfg.listtop = cfg.listjsonxml = p->limit; } } int parsealertargs(PARAMS *p, char **argv) { int i, u, found, currentarg = 0; uint64_t alertlimit = 0, unitmultiplier = 1; int32_t unitmode = cfg.unitmode; const char *alerttypes[] = {"h", "hour", "hourly", "d", "day", "daily", "m", "month", "monthly", "y", "year", "yearly"}; const char *alertconditions[] = {"rx", "tx", "total", "rx_estimate", "tx_estimate", "total_estimate"}; // order must match that of AlertCondition in dbshow.h for (i = 1; i <= 6; i++) { if (argv[currentarg + i][0] == '-' || ishelprequest(argv[currentarg + i])) { showalerthelp(); return 0; } } currentarg++; // output if (!isnumeric(argv[currentarg])) { printf("Error: Non-numeric output parameter \"%s\" for %s.\n", argv[currentarg], argv[0]); showalerthelp(); return 0; } p->alertoutput = (unsigned int)atoi(argv[currentarg]); if (p->alertoutput > 3) { printf("Error: Output parameter out of range for %s.\n", argv[0]); showalerthelp(); return 0; } if (debug) { printf("Alert output: %u\n", p->alertoutput); } currentarg++; // exit if (!isnumeric(argv[currentarg])) { printf("Error: Non-numeric exit parameter \"%s\" for %s.\n", argv[currentarg], argv[0]); showalerthelp(); return 0; } p->alertexit = (unsigned int)atoi(argv[currentarg]); if (p->alertexit > 3) { printf("Error: Exit parameter out of range for %s.\n", argv[0]); showalerthelp(); return 0; } if (debug) { printf("Alert exit: %u\n", p->alertexit); } if (p->alertoutput == AO_No_Output && (p->alertexit == AE_Always_Exit_0 || p->alertexit == AE_Always_Exit_1)) { printf("Error: Configuring %s for no output and always same exit status provides no real usability.\n", argv[0]); showalerthelp(); return 0; } currentarg++; // type found = 0; for (i = 0; i < 12; i++) { if (strcmp(argv[currentarg], alerttypes[i]) == 0) { found = 1; break; } } if (!found) { printf("Error: Invalid type parameter \"%s\" for %s.\n", argv[currentarg], argv[0]); showalerthelp(); return 0; } switch (argv[currentarg][0]) { case 'h': p->alerttype = AT_Hour; break; case 'd': p->alerttype = AT_Day; break; case 'm': p->alerttype = AT_Month; break; case 'y': p->alerttype = AT_Year; break; default: return 0; } if (debug) { printf("Alert type: %u\n", p->alerttype); } currentarg++; // condition found = 0; for (i = 0; i < 6; i++) { if (strcmp(argv[currentarg], alertconditions[i]) == 0) { found = 1; p->alertcondition = (unsigned int)i + 1; break; } } if (!found) { printf("Error: Invalid condition parameter \"%s\" for %s.\n", argv[currentarg], argv[0]); showalerthelp(); return 0; } if (debug) { printf("Alert condition: %u\n", p->alertcondition); } currentarg++; if ((p->alertcondition == AC_RX_Estimate || p->alertcondition == AC_TX_Estimate || p->alertcondition == AC_Total_Estimate) && (p->alertoutput == AO_Output_On_Estimate || p->alertexit == AE_Exit_1_On_Estimate)) { if (p->alertoutput == AO_Output_On_Estimate) { printf("Error: Estimate conditions cannot be used in combination with output parameter \"2\".\n"); } if (p->alertexit == AE_Exit_1_On_Estimate) { printf("Error: Estimate conditions cannot be used in combination with exit parameter \"2\".\n"); } showalerthelp(); return 0; } // limit if (!isnumeric(argv[currentarg])) { printf("Error: Limit parameter for %s must be a greater than zero integer without decimals.\n", argv[0]); showalerthelp(); return 0; } alertlimit = strtoull(argv[currentarg], (char **)NULL, 0); if (alertlimit == 0) { printf("Error: Invalid limit parameter \"%s\" for %s.\n", argv[currentarg], argv[0]); showalerthelp(); return 0; } if (debug) { printf("Alert limit: %" PRIu64 "\n", alertlimit); } currentarg++; // limit unit found = 0; for (u = 0; u < 3; u++) { cfg.unitmode = u; for (i = 1; i <= UNITPREFIXCOUNT; i++) { if (strcmp(argv[currentarg], getunitprefix(i)) == 0) { found = 1; break; } } if (found) { break; } } cfg.unitmode = unitmode; if (!found) { printf("Error: Invalid limit unit parameter \"%s\" for %s.\n", argv[currentarg], argv[0]); showalerthelp(); return 0; } unitmultiplier = getunitdivisor(u, i); if (alertlimit > (uint64_t)(MAX64 / unitmultiplier)) { printf("Error: %" PRIu64 " %s exceeds maximum supported limit of %" PRIu64 " %s.\n", alertlimit, argv[currentarg], (uint64_t)(MAX64 / unitmultiplier), argv[currentarg]); return 0; } p->alertlimit = alertlimit * unitmultiplier; if (debug) { printf("Alert unit %s is %d %d = %" PRIu64 "\n", argv[currentarg], u, i, unitmultiplier); printf("Alert real limit is %" PRIu64 " * %" PRIu64 " = %" PRIu64 "\n", alertlimit, unitmultiplier, p->alertlimit); } return 1; } void showalerthelp(void) { printf("\n"); printf("Valid parameters for\n--alert \n\n"); printf(" \n"); printf(" 0 - no output\n"); printf(" 1 - always show output\n"); printf(" 2 - show output only if usage estimate exceeds limit\n"); printf(" 3 - show output only if limit is exceeded\n\n"); printf(" \n"); printf(" 0 - always use exit status 0\n"); printf(" 1 - always use exit status 1\n"); printf(" 2 - use exit status 1 if usage estimate exceeds limit\n"); printf(" 3 - use exit status 1 if limit is exceeded\n\n"); printf(" \n"); printf(" h, hour, hourly d, day, daily\n"); printf(" m, month, monthly y, year, yearly\n\n"); printf(" \n"); printf(" rx, tx, total, rx_estimate, tx_estimate, total_estimate\n\n"); printf(" \n"); printf(" greater than zero integer without decimals\n\n"); printf(" for \n"); printf(" B, KiB, MiB, GiB, TiB, PiB, EiB\n"); printf(" B, KB, MB, GB, TB, PB, EB\n"); } void showstylehelp(void) { printf(" Valid parameters for --style:\n"); printf(" 0 - a more narrow output\n"); printf(" 1 - enable bar column if available\n"); printf(" 2 - average traffic rate in summary output\n"); printf(" 3 - average traffic rate in all outputs if available\n"); printf(" 4 - disable terminal control characters in -l / --live\n"); printf(" and show raw values in --oneline\n"); } void handleshowalert(PARAMS *p) { int alert = 0; if (!p->alert) { return; } if (p->defaultiface) { printf("Error: An interface needs to be explicitly specified for --alert.\n"); exit(EXIT_FAILURE); } validateinterface(p); alert = showalert(p->interface, p->alertoutput, p->alertexit, p->alerttype, p->alertcondition, p->alertlimit); if ((alert || p->alertexit == AE_Always_Exit_1) && p->alertexit != AE_Always_Exit_0) { exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); } void handleremoveinterface(PARAMS *p) { if (!p->removeiface) { return; } if (p->defaultiface) { printf("Error: An interface needs to be explicitly specified for --remove.\n"); exit(EXIT_FAILURE); } if (!db_getinterfacecountbyname(p->interface)) { printf("Error: Interface \"%s\" not found in database.\n", p->interface); exit(EXIT_FAILURE); } if (!p->force) { printf("Warning:\nThe current option would remove all data about interface \"%s\" from the database. ", p->interface); printf("Add --force in order to really do that.\n"); exit(EXIT_FAILURE); } #ifndef CHECK_VNSTAT if (!db_close() || !db_open_rw(0)) { printf("Error: Handling database \"%s/%s\" failing: %s\n", cfg.dbdir, DATABASEFILE, strerror(errno)); exit(EXIT_FAILURE); } #endif if (db_removeinterface(p->interface)) { printf("Interface \"%s\" removed from database.\n", p->interface); printf("The interface will no longer be monitored. Use --add if monitoring the interface is again needed.\n"); #ifndef CHECK_VNSTAT db_close(); exit(EXIT_SUCCESS); #endif } else { printf("Error: Removing interface \"%s\" from database failed.\n", p->interface); exit(EXIT_FAILURE); } } void handlerenameinterface(PARAMS *p) { if (!p->renameiface) { return; } if (p->defaultiface) { printf("Error: An interface needs to be explicitly specified for --rename.\n"); exit(EXIT_FAILURE); } if (!strlen(p->newifname)) { printf("Error: New interface name must be at least one character long.\n"); exit(EXIT_FAILURE); } if (!db_getinterfacecountbyname(p->interface)) { printf("Error: Interface \"%s\" not found in database.\n", p->interface); exit(EXIT_FAILURE); } if (db_getinterfacecountbyname(p->newifname)) { printf("Error: Interface \"%s\" already exists in database.\n", p->newifname); exit(EXIT_FAILURE); } if (!p->force) { printf("Warning:\nThe current option would rename interface \"%s\" -> \"%s\" in the database. ", p->interface, p->newifname); printf("Add --force in order to really do that.\n"); exit(EXIT_FAILURE); } #ifndef CHECK_VNSTAT if (!db_close() || !db_open_rw(0)) { printf("Error: Handling database \"%s/%s\" failing: %s\n", cfg.dbdir, DATABASEFILE, strerror(errno)); exit(EXIT_FAILURE); } #endif if (db_renameinterface(p->interface, p->newifname)) { printf("Interface \"%s\" has been renamed \"%s\".\n", p->interface, p->newifname); #ifndef CHECK_VNSTAT db_close(); exit(EXIT_SUCCESS); #endif } else { printf("Error: Renaming interface \"%s\" -> \"%s\" failed.\n", p->interface, p->newifname); exit(EXIT_FAILURE); } } void handleaddinterface(PARAMS *p) { if (!p->addiface) { return; } if (p->defaultiface) { printf("Error: An interface needs to be explicitly specified for --add.\n"); exit(EXIT_FAILURE); } db_errcode = 0; if (db_getinterfacecountbyname(p->interface)) { printf("Error: Interface \"%s\" already exists in the database.\n", p->interface); exit(EXIT_FAILURE); } if (db_errcode) { exit(EXIT_FAILURE); } if (!p->force && !getifinfo(p->interface)) { getifliststring(&p->ifacelist, 1); printf("Only available interfaces can be added for monitoring.\n\n"); printf("The following interfaces are currently available:\n %s\n", p->ifacelist); free(p->ifacelist); exit(EXIT_FAILURE); } if (!p->force && !spacecheck(cfg.dbdir)) { printf("Error: Not enough free diskspace available.\n"); exit(EXIT_FAILURE); } #ifndef CHECK_VNSTAT if (!db_close() || !db_open_rw(0)) { printf("Error: Handling database \"%s/%s\" failing: %s\n", cfg.dbdir, DATABASEFILE, strerror(errno)); exit(EXIT_FAILURE); } #endif printf("Adding interface \"%s\" to database for monitoring.\n", p->interface); if (db_addinterface(p->interface)) { if (cfg.rescanonsave) { printf("vnStat daemon will automatically start monitoring \"%s\" within %d minutes if the daemon process is currently running.\n", p->interface, cfg.saveinterval); } else { printf("Restart vnStat daemon if it is currently running in order to start monitoring \"%s\".\n", p->interface); } handlesetalias(p); #ifndef CHECK_VNSTAT db_close(); exit(EXIT_SUCCESS); #endif } else { printf("Error: Adding interface \"%s\" to database failed.\n", p->interface); exit(EXIT_FAILURE); } } void handlesetalias(PARAMS *p) { if (!p->setalias) { return; } if (p->defaultiface) { printf("Error: An interface needs to be explicitly specified for --setalias.\n"); exit(EXIT_FAILURE); } if (!db_getinterfacecountbyname(p->interface)) { printf("Error: Interface \"%s\" not found in database.\n", p->interface); exit(EXIT_FAILURE); } #ifndef CHECK_VNSTAT if (!db_close() || !db_open_rw(0)) { printf("Error: Handling database \"%s/%s\" failing: %s\n", cfg.dbdir, DATABASEFILE, strerror(errno)); exit(EXIT_FAILURE); } #endif if (db_setalias(p->interface, p->alias)) { printf("Alias of interface \"%s\" set to \"%s\".\n", p->interface, p->alias); #ifndef CHECK_VNSTAT db_close(); exit(EXIT_SUCCESS); #endif } else { printf("Error: Setting interface \"%s\" alias failed.\n", p->interface); exit(EXIT_FAILURE); } } void handleshowdata(PARAMS *p) { int ifcount = 0; iflist *dbifl = NULL, *dbifl_i = NULL; if (!p->query) { return; } /* show only specified file */ if (!p->defaultiface) { showoneinterface(p); return; } /* show all interfaces if none is explicitly specified */ if (p->dbifcount == 0) { p->query = 0; } else if ((cfg.qmode == 0 || cfg.qmode == 8 || cfg.qmode == 10) && (p->dbifcount > 1)) { if (cfg.qmode == 0) { if (cfg.ostyle != 0) { printf("\n rx / tx / total / estimated\n"); } else { printf("\n rx / tx / total\n"); } } else if (cfg.qmode == 8) { xmlheader(); } else if (cfg.qmode == 10) { jsonheader(); } if (db_getiflist(&dbifl) <= 0) { return; } dbifl_i = dbifl; while (dbifl_i != NULL) { strncpy_nt(p->interface, dbifl_i->interface, 32); if (debug) printf("\nProcessing interface \"%s\"...\n", p->interface); if (cfg.qmode == 0) { showdb(p->interface, 5, "", ""); } else if (cfg.qmode == 8) { showxml(p->interface, p->xmlmode, p->databegin, p->dataend); } else if (cfg.qmode == 10) { showjson(p->interface, ifcount, p->jsonmode, p->databegin, p->dataend); } ifcount++; dbifl_i = dbifl_i->next; } iflistfree(&dbifl); if (cfg.qmode == 8) { xmlfooter(); } else if (cfg.qmode == 10) { jsonfooter(); } /* show in qmode if there's only one interface or qmode!=0 */ } else { showoneinterface(p); } } void showoneinterface(PARAMS *p) { validateinterface(p); if (cfg.qmode == 5) { if (cfg.ostyle != 0) { printf("\n rx / tx / total / estimated\n"); } else { printf("\n rx / tx / total\n"); } } if (cfg.qmode != 8 && cfg.qmode != 10) { showdb(p->interface, cfg.qmode, p->databegin, p->dataend); } else if (cfg.qmode == 8) { xmlheader(); showxml(p->interface, p->xmlmode, p->databegin, p->dataend); xmlfooter(); } else if (cfg.qmode == 10) { jsonheader(); showjson(p->interface, 0, p->jsonmode, p->databegin, p->dataend); jsonfooter(); } } void handletrafficmeters(PARAMS *p) { int i; if (!p->traffic && !p->livetraffic) { return; } if (strchr(p->interface, '+') != NULL) { printf("This feature doesn't support interface merges (\"%s\"), ", p->interface); for (i = 0; i < (int)strlen(p->interface); i++) { if (p->interface[i] == '+') { p->interface[i] = '\0'; break; } } p->defaultiface = 0; printf("using \"%s\" instead.\n", p->interface); } if (!isifavailable(p->interface)) { getifliststring(&p->ifacelist, 0); if (p->defaultiface) { printf("Error: Configured default interface \"%s\" isn't available.\n\n", p->interface); if (strlen(cfg.cfgfile)) { printf("Update \"Interface\" keyword value in configuration file \"%s\" to change ", cfg.cfgfile); printf("the default interface or give an alternative interface with or without the -i parameter.\n\n"); } else { printf("An alternative interface can be given with or without the -i parameter.\n\n"); } printf("The following interfaces are currently available:\n %s\n", p->ifacelist); } else { printf("Error: Unable to get interface \"%s\" statistics.\n\n", p->interface); printf("The following interfaces are currently available:\n %s\n", p->ifacelist); } free(p->ifacelist); exit(EXIT_FAILURE); } /* calculate traffic */ if (p->traffic) { trafficmeter(p->interface, (unsigned int)cfg.sampletime); } /* live traffic */ if (p->livetraffic) { livetrafficmeter(p->interface, p->livemode); } } void handleifselection(PARAMS *p) { int ifcount, dbifcount = 0, iffound = 0, dbopened = 0; iflist *ifl = NULL; iflist *dbifl = NULL, *dbifl_iterator = NULL; if (!p->defaultiface) { return; } if (strlen(p->definterface)) { strncpy_nt(p->interface, p->definterface, 32); return; } if (p->traffic || p->livetraffic) { ifcount = getiflist(&ifl, 0, 1); /* try to open database for extra information */ if (db == NULL) { if (!db_open_ro()) { db = NULL; } else { dbopened = 1; } } if (db != NULL) { dbifcount = db_getiflist_sorted(&dbifl, 1); if (dbopened) { db_close(); } } if (dbifcount > 0 && ifcount > 0) { dbifl_iterator = dbifl; while (dbifl_iterator != NULL) { if (iflistsearch(&ifl, dbifl_iterator->interface)) { strncpy_nt(p->interface, dbifl_iterator->interface, 32); iffound = 1; if (debug) printf("Automatically selected interface with db: \"%s\"\n", p->interface); break; } dbifl_iterator = dbifl_iterator->next; } } if (!iffound) { if (ifcount > 0) { strncpy_nt(p->interface, ifl->interface, 32); if (debug) printf("Automatically selected interface without db: \"%s\"\n", p->interface); } else { printf("Error: Unable to find any suitable interface.\n"); iflistfree(&ifl); iflistfree(&dbifl); exit(EXIT_FAILURE); } } iflistfree(&ifl); } else if (p->query) { if (db_getiflist_sorted(&dbifl, 1) <= 0) { printf("Error: Unable to discover suitable interface from database.\n"); iflistfree(&dbifl); exit(EXIT_FAILURE); } strncpy_nt(p->interface, dbifl->interface, 32); if (debug) printf("Automatically selected interface from db: \"%s\"\n", p->interface); } iflistfree(&dbifl); } void showiflist(const int parseable) { char *ifacelist = NULL; iflist *ifl = NULL, *ifl_iterator = NULL; if (!parseable) { if (!getifliststring(&ifacelist, 1)) { exit(EXIT_FAILURE); } if (strlen(ifacelist)) { printf("Available interfaces: %s\n", ifacelist); } else { printf("No usable interfaces found.\n"); } free(ifacelist); } else { if (!getiflist(&ifl, 0, 1)) { exit(EXIT_FAILURE); } ifl_iterator = ifl; while (ifl_iterator != NULL) { printf("%s\n", ifl_iterator->interface); ifl_iterator = ifl_iterator->next; } iflistfree(&ifl); } } void showdbiflist(const int parseable) { int dbifcount; iflist *dbifl = NULL, *dbifl_i = NULL; if (db == NULL && !db_open_ro()) { printf("Error: Failed to open database \"%s/%s\" in read-only mode.\n", cfg.dbdir, DATABASEFILE); exit(EXIT_FAILURE); } dbifcount = db_getiflist(&dbifl); if (dbifcount < 0) { printf("Error: Failed to get interface list from database \"%s/%s\".\n", cfg.dbdir, DATABASEFILE); exit(EXIT_FAILURE); } if (dbifcount == 0 && !parseable) { printf("Database is empty."); } else { dbifl_i = dbifl; if (!parseable) { printf("Interfaces in database:"); while (dbifl_i != NULL) { printf(" %s", dbifl_i->interface); dbifl_i = dbifl_i->next; } printf("\n"); } else { while (dbifl_i != NULL) { printf("%s\n", dbifl_i->interface); dbifl_i = dbifl_i->next; } } } iflistfree(&dbifl); db_close(); } void validateinterface(PARAMS *p) { int i, found = 0; timeused_debug(__func__, 1); if (!db_getinterfacecountbyname(p->interface)) { if (strchr(p->interface, '+') == NULL) { for (i = 1; i <= cfg.ifacematchmethod; i++) { found = db_setinterfacebyalias(p->interface, p->interface, i); if (found) { if (debug) { printf("Found \"%s\" with method %d\n", p->interface, i); } break; } } if (!found) { printf("Error: No interface matching \"%s\" found in database.\n", p->interface); exit(EXIT_FAILURE); } } else { printf("Error: Not all requested interfaces found in database or given interfaces aren't unique.\n"); exit(EXIT_FAILURE); } } timeused_debug(__func__, 0); } vnstat-2.9/src/image_support.h0000644000000000000000000000316614156427647015245 0ustar rootroot#ifndef IMAGE_SUPPORT_H #define IMAGE_SUPPORT_H #include "image.h" void imageinit(IMAGECONTENT *ic, const int width, const int height); void colorinitcheck(const char *color, const int value, const char *cfgtext, const int *rgb); void layoutinit(IMAGECONTENT *ic, const char *title, const int width, const int height); void drawlegend(IMAGECONTENT *ic, const int x, const int y, const short israte); void drawbar(IMAGECONTENT *ic, const int x, const int y, const int len, const uint64_t rx, const uint64_t tx, const uint64_t max, const short isestimate); void drawpoles(IMAGECONTENT *ic, const int x, const int y, const int len, const uint64_t rx, const uint64_t tx, const uint64_t max); void drawdonut(IMAGECONTENT *ic, const int x, const int y, const float rxp, const float txp, const int size, const int holesize); void drawdonut_libgd_bug_workaround(IMAGECONTENT *ic, const int x, const int y, const float rxp, const float txp, const int size, const int holesize); void drawdonut_libgd_native(IMAGECONTENT *ic, const int x, const int y, const float rxp, const float txp, const int size, const int holesize); void drawpole(IMAGECONTENT *ic, const int x, const int y, const int length, const int direction, const int maincolor); void drawarrowup(IMAGECONTENT *ic, const int x, const int y); void drawarrowright(IMAGECONTENT *ic, const int x, const int y); void hextorgb(const char *input, int *rgb); void modcolor(int *rgb, const int offset, const int force); char *getimagevalue(const uint64_t b, const int len, const int rate); char *getimagescale(const uint64_t b, const int rate); uint64_t getscale(const uint64_t input, const int rate); #endif vnstat-2.9/src/vnstati.c0000644000000000000000000006234714173117732014046 0ustar rootroot/* vnStat image output - Copyright (C) 2007-2022 Teemu Toivola This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 dated June, 1991. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "common.h" #include "iflist.h" #include "dbsql.h" #include "image.h" #include "cfg.h" #include "misc.h" #include "vnstati.h" int main(int argc, char *argv[]) { int currentarg; IPARAMS p; IMAGECONTENT ic; initiparams(&p); initimagecontent(&ic); /* early check for debug and config parameter */ if (argc > 1) { for (currentarg = 1; currentarg < argc; currentarg++) { if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug") == 0)) { debug = 1; printf("Debug enabled, vnstati %s, LibGD %d.%d.%d\n", VERSION, GD_MAJOR_VERSION, GD_MINOR_VERSION, GD_RELEASE_VERSION); } else if (strcmp(argv[currentarg], "--config") == 0) { if (currentarg + 1 < argc) { strncpy_nt(p.cfgfile, argv[currentarg + 1], 512); if (debug) printf("Used config file: %s\n", p.cfgfile); currentarg++; } else { printf("Error: File for --config missing.\n"); return 1; } } } } /* load config if available */ if (!loadcfg(p.cfgfile, CT_Image)) { return 1; } cfg.qmode = 0; configlocale(); strncpy_nt(p.interface, cfg.iface, 32); ic.current = time(NULL); parseargs(&p, &ic, argc, argv); validateinput(&p); validateoutput(&p); handlecaching(&p, &ic); handledatabase(&p, &ic); if (debug) printf("Qmode: %d\n", cfg.qmode); drawimage(&ic); db_close(); if (ic.im == NULL) { return 1; } #if HAVE_DECL_GD_NEAREST_NEIGHBOUR scaleimage(&ic); #endif writeoutput(&p, &ic); if (debug) printf("all done\n"); return 0; } void initiparams(IPARAMS *p) { db = NULL; noexit = 0; /* allow functions to exit in case of error */ debug = 0; /* debug disabled by default */ disableprints = 0; /* let prints be visible */ p->interface[0] = '\0'; p->filename[0] = '\0'; p->cfgfile[0] = '\0'; p->cache = 0; p->help = 0; p->limit = -1; } void showihelp(IPARAMS *p) { printf("vnStat image output %s by Teemu Toivola \n\n", getversion()); printf(" -5, --fiveminutes [limit] output 5 minutes\n"); printf(" -5g, --fivegraph [limit] [height] output 5 minutes graph\n"); printf(" -h, --hours [limit] output hours\n"); printf(" -hg, --hoursgraph output hours graph\n"); printf(" -d, --days [limit] output days\n"); printf(" -m, --months [limit] output months\n"); printf(" -y, --years [limit] output years\n"); printf(" -t, --top [limit] output top days\n"); printf(" -s, --summary output summary\n"); printf(" -hs, --hsummary [graph] output horizontal summary with graph\n"); printf(" -vs, --vsummary [graph] output vertical summary with graph\n\n"); printf(" -nh, --noheader remove header from output\n"); printf(" -ne, --noedge remove edge from output\n"); printf(" -nl, --nolegend remove legend from output\n"); printf(" -ru, --rateunit [mode] swap configured rate unit\n"); printf(" -S, --small use small fonts"); if (!cfg.largefonts) { printf(" (default)"); } printf("\n"); printf(" -L, --large use large fonts"); if (cfg.largefonts) { printf(" (default)"); } printf("\n"); printf(" -o, --output select output filename\n"); printf(" -c, --cache update output only when too old\n"); printf(" -i, --iface select interface"); if (strlen(p->interface)) { printf(" (default: %s)", p->interface); } printf("\n"); printf(" -b, --begin set list begin date\n"); printf(" -e, --end set list end date\n"); printf(" -?, --help this help\n"); printf(" -D, --debug show some additional debug information\n"); printf(" -v, --version show version\n"); printf(" --limit set list entry limit\n"); printf(" --dbdir select database directory\n"); printf(" --style select output style (0-3)\n"); printf(" --locale set locale\n"); printf(" --config select config file\n"); printf(" --altdate use alternative date location\n"); printf(" --headertext specify header text string\n"); #if HAVE_DECL_GD_NEAREST_NEIGHBOUR printf(" --scale change image size by scaling it\n"); #endif printf(" --transparent [enabled] toggle background transparency\n\n"); printf("See also \"man vnstati\".\n"); } void parseargs(IPARAMS *p, IMAGECONTENT *ic, int argc, char **argv) { int currentarg; /* parse parameters */ for (currentarg = 1; currentarg < argc; currentarg++) { if (debug) printf("arg %d: \"%s\"\n", currentarg, argv[currentarg]); if ((strcmp(argv[currentarg], "-?") == 0) || (strcmp(argv[currentarg], "--help")) == 0) { p->help = 1; } else if ((strcmp(argv[currentarg], "-i") == 0) || (strcmp(argv[currentarg], "--iface")) == 0 || (strcmp(argv[currentarg], "--interface") == 0)) { if (currentarg + 1 < argc) { if (strlen(argv[currentarg + 1]) > 31) { printf("Error: Interface name is limited to 31 characters.\n"); exit(EXIT_FAILURE); } strncpy_nt(p->interface, argv[currentarg + 1], 32); if (debug) printf("Used interface: \"%s\"\n", p->interface); currentarg++; } else { printf("Error: Interface for %s missing.\n", argv[currentarg]); exit(EXIT_FAILURE); } } else if ((strcmp(argv[currentarg], "-o") == 0) || (strcmp(argv[currentarg], "--output")) == 0) { if (currentarg + 1 < argc) { strncpy_nt(p->filename, argv[currentarg + 1], 512); if (debug) printf("Output file: \"%s\"\n", p->filename); currentarg++; } else { printf("Error: Filename for %s missing.\n", argv[currentarg]); exit(EXIT_FAILURE); } } else if ((strcmp(argv[currentarg], "-c") == 0) || (strcmp(argv[currentarg], "--cache")) == 0) { if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { p->cache = atoi(argv[currentarg + 1]); if (debug) printf("Cache time: %d minutes\n", p->cache); currentarg++; } else { printf("Error: Parameter for %s missing or invalid.\n", argv[currentarg]); exit(EXIT_FAILURE); } } else if ((strcmp(argv[currentarg], "--style")) == 0) { if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.ostyle = atoi(argv[currentarg + 1]); if (cfg.ostyle > 3 || cfg.ostyle < 0) { printf("Error: Invalid style parameter \"%d\" for --style.\n", cfg.ostyle); exit(EXIT_FAILURE); } if (debug) printf("Style changed: %d\n", cfg.ostyle); currentarg++; } else { printf("Error: Style parameter for --style missing.\n"); exit(EXIT_FAILURE); } } else if ((strcmp(argv[currentarg], "--scale")) == 0) { #if HAVE_DECL_GD_NEAREST_NEIGHBOUR if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.imagescale = atoi(argv[currentarg + 1]); if (cfg.imagescale > 500 || cfg.imagescale < 50) { printf("Error: Invalid parameter \"%d\" for --scale. Supported value range: 50 <= N <= 500\n", cfg.imagescale); exit(EXIT_FAILURE); } if (debug) printf("Scale changed: %d\n", cfg.imagescale); currentarg++; } else { printf("Error: Percent parameter for --scale missing.\n"); exit(EXIT_FAILURE); } #else printf("Error: Function needed by --scale is not available in used LibGD %d.%d.%d.\n", GD_MAJOR_VERSION, GD_MINOR_VERSION, GD_RELEASE_VERSION); exit(EXIT_FAILURE); #endif } else if ((strcmp(argv[currentarg], "--transparent")) == 0) { if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.transbg = atoi(argv[currentarg + 1]); if (cfg.transbg > 1 || cfg.transbg < 0) { printf("Error: Invalid parameter \"%d\" for --transparent.\n", cfg.transbg); exit(EXIT_FAILURE); } if (debug) printf("Transparency changed: %d\n", cfg.transbg); currentarg++; } else { cfg.transbg = !cfg.transbg; if (debug) printf("Transparency changed: %d\n", cfg.transbg); } } else if ((strcmp(argv[currentarg], "--dbdir")) == 0) { if (currentarg + 1 < argc) { strncpy_nt(cfg.dbdir, argv[currentarg + 1], 512); if (debug) printf("DatabaseDir: \"%s\"\n", cfg.dbdir); currentarg++; } else { printf("Error: Directory for --dbdir missing.\n"); exit(EXIT_FAILURE); } } else if ((strcmp(argv[currentarg], "--locale")) == 0) { if (currentarg + 1 < argc) { setlocale(LC_ALL, argv[currentarg + 1]); if (debug) printf("Locale: \"%s\"\n", argv[currentarg + 1]); currentarg++; } else { printf("Error: Locale for --locale missing.\n"); exit(EXIT_FAILURE); } } else if (strcmp(argv[currentarg], "--config") == 0) { /* config has already been parsed earlier so nothing to do here */ currentarg++; } else if ((strcmp(argv[currentarg], "--headertext")) == 0) { if (currentarg + 1 < argc) { strncpy_nt(ic->headertext, argv[currentarg + 1], 65); if (debug) printf("Header text: \"%s\"\n", ic->headertext); currentarg++; } else { printf("Error: Text string parameter for --headertext missing.\n"); exit(EXIT_FAILURE); } } else if (strcmp(argv[currentarg], "--altdate") == 0) { ic->altdate = 1; } else if ((strcmp(argv[currentarg], "-L") == 0) || (strcmp(argv[currentarg], "--large")) == 0) { cfg.largefonts = 1; } else if ((strcmp(argv[currentarg], "-S") == 0) || (strcmp(argv[currentarg], "--small")) == 0) { cfg.largefonts = 0; } else if ((strcmp(argv[currentarg], "-D") == 0) || (strcmp(argv[currentarg], "--debug")) == 0) { debug = 1; } else if ((strcmp(argv[currentarg], "-d") == 0) || (strcmp(argv[currentarg], "--days")) == 0) { cfg.qmode = 1; if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.listdays = atoi(argv[currentarg + 1]); if (cfg.listdays < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } } else if ((strcmp(argv[currentarg], "-m") == 0) || (strcmp(argv[currentarg], "--months")) == 0) { cfg.qmode = 2; if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.listmonths = atoi(argv[currentarg + 1]); if (cfg.listmonths < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } } else if ((strcmp(argv[currentarg], "-t") == 0) || (strcmp(argv[currentarg], "--top")) == 0) { cfg.qmode = 3; if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.listtop = atoi(argv[currentarg + 1]); if (cfg.listtop < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } } else if ((strcmp(argv[currentarg], "-y") == 0) || (strcmp(argv[currentarg], "--years")) == 0) { cfg.qmode = 4; if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.listyears = atoi(argv[currentarg + 1]); if (cfg.listyears < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } } else if ((strcmp(argv[currentarg], "-h") == 0) || (strcmp(argv[currentarg], "--hours")) == 0) { cfg.qmode = 8; if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.listhours = atoi(argv[currentarg + 1]); if (cfg.listhours < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } } else if ((strcmp(argv[currentarg], "-5") == 0) || (strcmp(argv[currentarg], "--fiveminutes")) == 0) { cfg.qmode = 9; if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.listfivemins = atoi(argv[currentarg + 1]); if (cfg.listfivemins < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } } else if ((strcmp(argv[currentarg], "-s") == 0) || (strcmp(argv[currentarg], "--summary")) == 0) { cfg.qmode = 5; } else if ((strcmp(argv[currentarg], "-hg") == 0) || (strcmp(argv[currentarg], "--hoursgraph") == 0) || (strcmp(argv[currentarg], "--hourlygraph")) == 0) { cfg.qmode = 7; if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]) == 1 || ishelprequest(argv[currentarg + 1]))) { if (!isdigit(argv[currentarg + 1][0]) || atoi(argv[currentarg + 1]) > 1 || atoi(argv[currentarg + 1]) < 0) { if (!ishelprequest(argv[currentarg + 1])) printf("Error: Invalid mode selection \"%s\".\n", argv[currentarg + 1]); printf(" Valid modes for %s:\n", argv[currentarg]); printf(" 0 - 24 hour sliding windows\n"); printf(" 1 - graph start from midnight\n"); exit(EXIT_FAILURE); } cfg.hourlygmode = atoi(argv[currentarg + 1]); if (debug) printf("Hourly graph mode changed: %d\n", cfg.hourlygmode); currentarg++; } } else if ((strcmp(argv[currentarg], "-5g") == 0) || (strcmp(argv[currentarg], "--fivegraph")) == 0) { cfg.qmode = 10; if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.fivegresultcount = atoi(argv[currentarg + 1]); if (cfg.fivegresultcount < FIVEGMINRESULTCOUNT) { printf("Error: Invalid limit parameter \"%s\" for %s. A value equal or over %d is expected.\n", argv[currentarg + 1], argv[currentarg], FIVEGMINRESULTCOUNT); exit(EXIT_FAILURE); } else if (cfg.fivegresultcount > cfg.fiveminutehours * 12) { printf("Error: Invalid limit parameter \"%s\" for %s. Value cannot be larger than configured data retention (5MinuteHours %d * 12 = %d).\n", argv[currentarg + 1], argv[currentarg], cfg.fiveminutehours, cfg.fiveminutehours * 12); exit(EXIT_FAILURE); } currentarg++; } if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { cfg.fivegheight = atoi(argv[currentarg + 1]); if (cfg.fivegheight < FIVEGMINHEIGHT) { printf("Error: Invalid height parameter \"%s\" for %s. A value equal or over %d is expected.\n", argv[currentarg + 1], argv[currentarg], FIVEGMINHEIGHT); exit(EXIT_FAILURE); } currentarg++; } } else if ((strcmp(argv[currentarg], "-hs") == 0) || (strcmp(argv[currentarg], "--hsummary")) == 0) { cfg.qmode = 51; if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]) == 1 || ishelprequest(argv[currentarg + 1]))) { if (!isdigit(argv[currentarg + 1][0]) || atoi(argv[currentarg + 1]) > 1 || atoi(argv[currentarg + 1]) < 0) { if (!ishelprequest(argv[currentarg + 1])) printf("Error: Invalid graph selection \"%s\".\n", argv[currentarg + 1]); printf(" Valid graphs for %s:\n", argv[currentarg]); printf(" 0 - hours\n"); printf(" 1 - 5 minutes\n"); exit(EXIT_FAILURE); } cfg.summarygraph = atoi(argv[currentarg + 1]); if (debug) printf("Summary graph changed: %d\n", cfg.summarygraph); currentarg++; } } else if ((strcmp(argv[currentarg], "-vs") == 0) || (strcmp(argv[currentarg], "--vsummary")) == 0) { cfg.qmode = 52; if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]) == 1 || ishelprequest(argv[currentarg + 1]))) { if (!isdigit(argv[currentarg + 1][0]) || atoi(argv[currentarg + 1]) > 1 || atoi(argv[currentarg + 1]) < 0) { if (!ishelprequest(argv[currentarg + 1])) printf("Error: Invalid graph selection \"%s\".\n", argv[currentarg + 1]); printf(" Valid graphs for %s:\n", argv[currentarg]); printf(" 0 - hours\n"); printf(" 1 - 5 minutes\n"); exit(EXIT_FAILURE); } cfg.summarygraph = atoi(argv[currentarg + 1]); if (debug) printf("Summary graph changed: %d\n", cfg.summarygraph); currentarg++; } } else if ((strcmp(argv[currentarg], "-nh") == 0) || (strcmp(argv[currentarg], "--noheader")) == 0) { ic->showheader = 0; } else if ((strcmp(argv[currentarg], "-ne") == 0) || (strcmp(argv[currentarg], "--noedge")) == 0) { ic->showedge = 0; } else if ((strcmp(argv[currentarg], "-nl") == 0) || (strcmp(argv[currentarg], "--nolegend")) == 0) { ic->showlegend = 0; } else if ((strcmp(argv[currentarg], "-ru") == 0) || (strcmp(argv[currentarg], "--rateunit")) == 0) { if (currentarg + 1 < argc && (strlen(argv[currentarg + 1]) == 1 || ishelprequest(argv[currentarg + 1]))) { if (!isdigit(argv[currentarg + 1][0]) || atoi(argv[currentarg + 1]) > 1 || atoi(argv[currentarg + 1]) < 0) { if (!ishelprequest(argv[currentarg + 1])) printf("Error: Invalid parameter \"%s\".\n", argv[currentarg + 1]); printf(" Valid parameters for %s:\n", argv[currentarg]); printf(" 0 - bytes\n"); printf(" 1 - bits\n"); exit(EXIT_FAILURE); } cfg.rateunit = atoi(argv[currentarg + 1]); if (debug) printf("Rateunit changed: %d\n", cfg.rateunit); currentarg++; } else { cfg.rateunit = !cfg.rateunit; if (debug) printf("Rateunit changed: %d\n", cfg.rateunit); } } else if ((strcmp(argv[currentarg], "-b") == 0) || (strcmp(argv[currentarg], "--begin") == 0)) { if (currentarg + 1 < argc) { if (!validatedatetime(argv[currentarg + 1])) { printf("Error: Invalid date format, expected YYYY-MM-DD HH:MM, YYYY-MM-DD or \"today\".\n"); exit(EXIT_FAILURE); } strncpy_nt(ic->databegin, argv[currentarg + 1], 18); currentarg++; } else { printf("Error: Date of format YYYY-MM-DD HH:MM, YYYY-MM-DD or \"today\" for %s missing.\n", argv[currentarg]); exit(EXIT_FAILURE); } } else if ((strcmp(argv[currentarg], "-e") == 0) || (strcmp(argv[currentarg], "--end") == 0)) { if (currentarg + 1 < argc) { if (!validatedatetime(argv[currentarg + 1])) { printf("Error: Invalid date format, expected YYYY-MM-DD HH:MM or YYYY-MM-DD.\n"); exit(EXIT_FAILURE); } strncpy_nt(ic->dataend, argv[currentarg + 1], 18); currentarg++; } else { printf("Error: Date of format YYYY-MM-DD HH:MM or YYYY-MM-DD for %s missing.\n", argv[currentarg]); exit(EXIT_FAILURE); } } else if (strcmp(argv[currentarg], "--limit") == 0) { if (currentarg + 1 < argc && isdigit(argv[currentarg + 1][0])) { p->limit = atoi(argv[currentarg + 1]); if (p->limit < 0) { printf("Error: Invalid limit parameter \"%s\" for %s. Only a zero and positive numbers are allowed.\n", argv[currentarg + 1], argv[currentarg]); exit(EXIT_FAILURE); } currentarg++; } else { printf("Error: Invalid or missing parameter for %s.\n", argv[currentarg]); exit(EXIT_FAILURE); } } else if ((strcmp(argv[currentarg], "-v") == 0) || (strcmp(argv[currentarg], "--version")) == 0) { printf("vnStat image output %s by Teemu Toivola (LibGD %d.%d.%d)\n", getversion(), GD_MAJOR_VERSION, GD_MINOR_VERSION, GD_RELEASE_VERSION); exit(EXIT_SUCCESS); } else { if (argv[currentarg][0] == '-') { printf("Unknown parameter \"%s\". Use --help for help.\n", argv[currentarg]); exit(EXIT_FAILURE); } else { if (strlen(argv[currentarg]) > 31) { printf("Error: Interface name is limited to 31 characters.\n"); exit(EXIT_FAILURE); } strncpy_nt(p->interface, argv[currentarg], 32); if (debug) printf("Used interface: \"%s\"\n", p->interface); } } } if (p->help || argc == 1) { showihelp(p); exit(EXIT_SUCCESS); } if (p->limit != -1) { cfg.listfivemins = cfg.listhours = cfg.listdays = cfg.listmonths = cfg.listyears = cfg.listtop = cfg.listjsonxml = p->limit; } if (cfg.largefonts) { ic->font = gdFontGetLarge(); ic->lineheight = 16; ic->large = 1; } else { ic->font = gdFontGetSmall(); ic->lineheight = 12; ic->large = 0; } } void validateinput(IPARAMS *p) { if (!cfg.qmode || !strlen(p->filename)) { printf("At least output mode and file parameter needs to be given. "); printf("Use -? or --help for getting short help.\n"); exit(EXIT_FAILURE); } } void handlecaching(IPARAMS *p, IMAGECONTENT *ic) { struct stat filestat; if (p->cache == 0 || p->filename[0] == '-') { return; } if (stat(p->filename, &filestat) == 0) { if ((ic->current - filestat.st_mtime) < (p->cache * 60)) { if (debug) printf("Using cached file (%d<%d).\n", (int)(ic->current - filestat.st_mtime), p->cache * 60); exit(EXIT_SUCCESS); } } else { /* abort if error is something else than file not found */ if (errno != ENOENT) { printf("Error: Getting status for file \"%s\" failed: %s (%d)\n", p->filename, strerror(errno), errno); exit(EXIT_FAILURE); } } } void handledatabase(IPARAMS *p, IMAGECONTENT *ic) { int i, found = 0; iflist *dbifl = NULL; if (!db_open_ro()) { printf("Error: Failed to open database \"%s/%s\" in read-only mode.\n", cfg.dbdir, DATABASEFILE); exit(EXIT_FAILURE); } if (strlen(p->interface)) { if (!db_getinterfacecountbyname(p->interface)) { if (strchr(p->interface, '+') == NULL) { for (i = 1; i <= cfg.ifacematchmethod; i++) { found = db_setinterfacebyalias(p->interface, p->interface, i); if (found) { if (debug) { printf("Found \"%s\" with method %d\n", p->interface, i); } break; } } if (!found) { printf("Error: No interface matching \"%s\" found in database.\n", p->interface); exit(EXIT_FAILURE); } } else { printf("Error: Not all requested interfaces found in database or given interfaces aren't unique.\n"); exit(EXIT_FAILURE); } } } else { if (db_getiflist_sorted(&dbifl, 1) <= 0) { printf("Error: Unable to discover suitable interface from database.\n"); exit(EXIT_FAILURE); } strncpy_nt(p->interface, dbifl->interface, 32); iflistfree(&dbifl); if (debug) printf("Automatically selected interface: \"%s\"\n", p->interface); } if (!db_getinterfaceinfo(p->interface, &ic->interface)) { printf("Error: Failed to fetch interface \"%s\" details from database.\n", p->interface); exit(EXIT_FAILURE); } } void validateoutput(IPARAMS *p) { #if HAVE_DECL_GDIMAGEFILE /* not output to stdout */ if (!(strlen(p->filename) == 1 && p->filename[0] == '-')) { if (!gdSupportsFileType(p->filename, 1)) { printf("Error: Image format file extension for \"%s\" is not supported or recognized\n\n", p->filename); showsupportedfileextensions(); exit(EXIT_FAILURE); } } #else /* show warning if given filename doesn't end with .png when gdImageFile() isn't available */ if (!(strlen(p->filename) >= 4 && strcmp(p->filename + strlen(p->filename) - 4, ".png") == 0)) { printf("Warning: Image format selection based on file extension is not available in used LibGD %d.%d.%d, \"%s\" will be written as png.\n", GD_MAJOR_VERSION, GD_MINOR_VERSION, GD_RELEASE_VERSION, p->filename); } #endif } void writeoutput(IPARAMS *p, IMAGECONTENT *ic) { if (ic->im == NULL) { return; } /* output to stdout is always png */ if (strlen(p->filename) == 1 && p->filename[0] == '-') { if ((p->pngout = fdopen(1, "w")) == NULL) { printf("Error: Opening stdout for output failed: %s\n", strerror(errno)); exit(EXIT_FAILURE); } gdImagePng(ic->im, p->pngout); fclose(p->pngout); } else { #if HAVE_DECL_GDIMAGEFILE /* avoid "Palette image not supported by webp" */ if (strlen(p->filename) >= 5 && strcmp(p->filename + strlen(p->filename) - 5, ".webp") == 0) { gdImagePaletteToTrueColor(ic->im); } if (!gdImageFile(ic->im, p->filename)) { printf("Error: Writing output to \"%s\" failed: %s\n", p->filename, strerror(errno)); exit(EXIT_FAILURE); } #else if ((p->pngout = fopen(p->filename, "w")) == NULL) { printf("Error: Opening file \"%s\" for output failed: %s\n", p->filename, strerror(errno)); exit(EXIT_FAILURE); } gdImagePng(ic->im, p->pngout); fclose(p->pngout); #endif } gdImageDestroy(ic->im); } #if HAVE_DECL_GDIMAGEFILE void showsupportedfileextensions(void) { int i; const char *extensions[] = {".avif", ".bmp", ".gif", ".heif", ".heix", ".jpeg", ".jpg", ".png", ".tga", ".tif", ".tiff", ".wbmp", ".webp", ".xbm", ".xpm"}; printf("Supported image format file extensions in current environment:\n"); for (i = 0; i < 15; i++) { if (gdSupportsFileType(extensions[i], 1)) { printf("%s ", extensions[i]); } } printf("\n"); } #endif vnstat-2.9/src/misc.h0000644000000000000000000000270014075560322013277 0ustar rootroot#ifndef MISC_H #define MISC_H #define UNITPREFIXCOUNT 7 #include "dbsql.h" typedef enum RequestType { RT_Normal = 1, RT_Estimate, RT_ImageScale } RequestType; typedef enum ListType { LT_None = 0, LT_5min, LT_Hour, LT_Day, LT_Month, LT_Year, LT_Top } ListType; int spacecheck(const char *path); void sighandler(int sig); uint64_t getbtime(void); char *getvalue(const uint64_t bytes, const int len, const RequestType type); int getunitspacing(const int len, const int index); char *gettrafficrate(const uint64_t bytes, const time_t interval, const int len); const char *getunitprefix(const int index); const char *getrateunitprefix(const int unitmode, const int index); uint64_t getunitdivisor(const int unitmode, const int index); int getunit(void); char *getratestring(const uint64_t rate, const int len, const int declen); int getratespacing(const int len, const int unitmode, const int unitindex); int getpadding(const int len, const char *str); void cursortocolumn(const int column); void cursorhide(void); void cursorshow(void); void eraseline(void); int validatedatetime(const char *str); int issametimeslot(const ListType listtype, const time_t entry, const time_t updated); uint64_t getperiodseconds(const ListType listtype, const time_t entry, const time_t updated, const short isongoing); void getestimates(uint64_t *rx, uint64_t *tx, const ListType listtype, const time_t updated, dbdatalist **dbdata); int ishelprequest(const char *arg); #endif vnstat-2.9/src/cfgoutput.h0000644000000000000000000000016414164572527014377 0ustar rootroot#ifndef CFGOUTPUT_H #define CFGOUTPUT_H void printcfgfile(void); void defaultcomment(const int isdefault); #endif vnstat-2.9/src/dbaccess.h0000644000000000000000000000233313537742620014122 0ustar rootroot#ifndef DBACCESS_H #define DBACCESS_H /* legacy database version */ /* import is supported only from version 3 */ /* 1 = 1.0, 2 = 1.1-1.2, 3 = 1.3-1.8 */ #define LEGACYDBVERSION 3 /* all structs below are used for supporting data import */ /* from the legacy database format => don't modify */ #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wpadded" #endif typedef struct { time_t date; uint64_t rx, tx; } HOUR; typedef struct { time_t date; uint64_t rx, tx; int rxk, txk; int used; } DAY; typedef struct { time_t month; uint64_t rx, tx; int rxk, txk; int used; } MONTH; /* legacy database structure */ typedef struct { int version; char interface[32]; char nick[32]; int active; uint64_t totalrx, totaltx, currx, curtx; int totalrxk, totaltxk; time_t lastupdated, created; DAY day[30]; MONTH month[12]; DAY top10[10]; HOUR hour[24]; uint64_t btime; } DATA; #if defined(__clang__) #pragma clang diagnostic pop #endif int importlegacydb(const char *iface, const char *dirname); int insertlegacydata(DATA *data, const char *iface); int readdb(DATA *data, const char *iface, const char *dirname, const int force); void initdb(DATA *data); int validatedb(DATA *data); #endif vnstat-2.9/src/vnstatd.h0000644000000000000000000000016413537010015014020 0ustar rootroot#ifndef VNSTATD_H #define VNSTATD_H void showhelp(void); void parseargs(DSTATE *s, int argc, char **argv); #endif vnstat-2.9/src/ifinfo.c0000644000000000000000000002472014110512306013604 0ustar rootroot#include "common.h" #include "ibw.h" #include "ifinfo.h" int getifinfo(const char *iface) { char inface[32]; ifinfo.filled = 0; ifinfo.timestamp = 0; #if defined(__linux__) && HAVE_LINUX_RTNETLINK_H if (cfg.is64bit == -2) { #if HAVE_DECL_IFLA_STATS64 ifinfo.is64bit = 1; #else ifinfo.is64bit = 0; #endif } else { ifinfo.is64bit = (short)cfg.is64bit; } #else if (cfg.is64bit < 0) { ifinfo.is64bit = -1; } else { ifinfo.is64bit = (short)cfg.is64bit; } #endif if (strcmp(iface, "default") == 0) { strncpy_nt(inface, cfg.iface, 32); } else { strncpy_nt(inface, iface, 32); } #if defined(__linux__) || defined(CHECK_VNSTAT) /* try getting interface info from /proc */ if (readproc(inface) == 1) { ifinfo.timestamp = time(NULL); return 1; } else { if (debug) printf("Failed to use %s as source.\n", PROCNETDEV); } /* try getting interface info from /sys */ if (readsysclassnet(inface) == 1) { ifinfo.timestamp = time(NULL); return 1; } #elif defined(BSD_VNSTAT) if (readifaddrs(inface) == 1) { ifinfo.timestamp = time(NULL); return 1; } #endif snprintf(errorstring, 1024, "Unable to get interface \"%s\" statistics.", inface); printe(PT_Error); return 0; } int getifliststring(char **ifacelist, int showspeed) { char temp[64]; iflist *ifl = NULL, *ifl_iterator = NULL; /* initialize list string */ *ifacelist = (char *)malloc(sizeof(char)); if (*ifacelist == NULL) { panicexit(__FILE__, __LINE__); } *ifacelist[0] = '\0'; if (getiflist(&ifl, showspeed, 1) > 0) { ifl_iterator = ifl; while (ifl_iterator != NULL) { *ifacelist = (char *)realloc(*ifacelist, ((strlen(*ifacelist) + strlen(ifl_iterator->interface) + 2) * sizeof(char))); if (*ifacelist == NULL) { panicexit(__FILE__, __LINE__); } strcat(*ifacelist, ifl_iterator->interface); strcat(*ifacelist, " "); if (showspeed && ifl_iterator->bandwidth > 0) { snprintf(temp, 64, "(%u Mbit) ", ifl_iterator->bandwidth); *ifacelist = (char *)realloc(*ifacelist, ((strlen(*ifacelist) + strlen(temp) + 1) * sizeof(char))); if (*ifacelist == NULL) { panicexit(__FILE__, __LINE__); } strcat(*ifacelist, temp); } ifl_iterator = ifl_iterator->next; } iflistfree(&ifl); return 1; } iflistfree(&ifl); return 0; } int getiflist(iflist **ifl, const int getspeed, const int validate) { int result = 0; int32_t maxbw = cfg.maxbw; /* disable MaxBandwidth during list creation to avoid having it being set as the default value when nothing is detected */ cfg.maxbw = 0; #if defined(__linux__) || defined(CHECK_VNSTAT) result = getiflist_linux(ifl, getspeed, validate); #elif defined(BSD_VNSTAT) result = getiflist_bsd(ifl, getspeed, validate); #else #error vnStat only supports Linux and BSD like systems #endif cfg.maxbw = maxbw; return result; } #if defined(__linux__) || defined(CHECK_VNSTAT) int getiflist_linux(iflist **ifl, const int getspeed, const int validate) { char temp[64]; char interface[32]; FILE *fp; DIR *dp; struct dirent *di; char procline[512]; uint32_t bwlimit = 0; if ((fp = fopen(PROCNETDEV, "r")) != NULL) { /* make list of interfaces */ while (fgets(procline, 512, fp) != NULL) { sscanf(procline, "%63s", temp); if (strlen(temp) > 0 && (isdigit(temp[(strlen(temp) - 1)]) || temp[(strlen(temp) - 1)] == ':')) { sscanf(temp, "%31[^':']s", interface); if (validate && !isifvalid(interface)) { continue; } bwlimit = 0; if (getspeed && ibwget(interface, &bwlimit)) { iflistadd(ifl, interface, bwlimit); } else { iflistadd(ifl, interface, 0); } } } fclose(fp); return 1; } else { if ((dp = opendir(SYSCLASSNET)) != NULL) { /* make list of interfaces */ while ((di = readdir(dp))) { if (di->d_name[0] == '.' || strlen(di->d_name) > 31) { continue; } if (validate && !isifvalid(di->d_name)) { continue; } bwlimit = 0; if (getspeed && ibwget(di->d_name, &bwlimit)) { iflistadd(ifl, di->d_name, bwlimit); } else { iflistadd(ifl, di->d_name, 0); } } closedir(dp); return 1; } } return 0; } #elif defined(BSD_VNSTAT) int getiflist_bsd(iflist **ifl, const int getspeed, const int validate) { struct ifaddrs *ifap, *ifa; uint32_t bwlimit = 0; if (getifaddrs(&ifap) >= 0) { /* make list of interfaces */ for (ifa = ifap; ifa; ifa = ifa->ifa_next) { if (ifa->ifa_addr->sa_family != AF_LINK || strlen(ifa->ifa_name) > 31) { continue; } if (validate && !isifvalid(ifa->ifa_name)) { continue; } bwlimit = 0; if (getspeed && ibwget(ifa->ifa_name, &bwlimit)) { iflistadd(ifl, ifa->ifa_name, getifspeed(ifa->ifa_name)); } else { iflistadd(ifl, ifa->ifa_name, 0); } } freeifaddrs(ifap); return 1; } return 0; } #endif int readproc(const char *iface) { FILE *fp; char temp[4][64], procline[512], *proclineptr, ifaceid[33]; int check; if ((fp = fopen(PROCNETDEV, "r")) == NULL) { if (debug) printf("Error (debug): Unable to read %s: %s\n", PROCNETDEV, strerror(errno)); return 0; } strncpy_nt(ifaceid, iface, 32); strcat(ifaceid, ":"); check = 0; while (fgets(procline, 512, fp) != NULL) { sscanf(procline, "%63s", temp[0]); if (strncmp(ifaceid, temp[0], strlen(ifaceid)) == 0) { /* if (debug) printf("\n%s\n", procline); */ check = 1; break; } } fclose(fp); if (check == 0) { if (debug) printf("Requested interface \"%s\" not found.\n", iface); return 0; } else { strncpy_nt(ifinfo.name, iface, 32); /* get rx and tx from procline */ proclineptr = strchr(procline, ':'); sscanf(proclineptr + 1, "%63s %63s %*s %*s %*s %*s %*s %*s %63s %63s", temp[0], temp[1], temp[2], temp[3]); ifinfo.rx = strtoull(temp[0], (char **)NULL, 0); ifinfo.tx = strtoull(temp[2], (char **)NULL, 0); /* daemon doesn't need packet data */ if (!noexit) { ifinfo.rxp = strtoull(temp[1], (char **)NULL, 0); ifinfo.txp = strtoull(temp[3], (char **)NULL, 0); } ifinfo.filled = 1; } return 1; } int readsysclassnet(const char *iface) { FILE *fp; char path[64], file[76], buffer[64]; strncpy_nt(ifinfo.name, iface, 32); snprintf(path, 64, "%s/%s/statistics", SYSCLASSNET, iface); if (debug) printf("path: %s\n", path); /* rx bytes */ snprintf(file, 76, "%s/rx_bytes", path); if ((fp = fopen(file, "r")) == NULL) { if (debug) printf("Unable to read: %s - %s\n", file, strerror(errno)); return 0; } else { if (fgets(buffer, 64, fp) != NULL) { ifinfo.rx = strtoull(buffer, (char **)NULL, 0); } else { fclose(fp); return 0; } } fclose(fp); /* tx bytes */ snprintf(file, 76, "%s/tx_bytes", path); if ((fp = fopen(file, "r")) == NULL) { if (debug) printf("Unable to read: %s - %s\n", file, strerror(errno)); return 0; } else { if (fgets(buffer, 64, fp) != NULL) { ifinfo.tx = strtoull(buffer, (char **)NULL, 0); } else { fclose(fp); return 0; } } fclose(fp); /* daemon doesn't need packet data */ if (!noexit) { /* rx packets */ snprintf(file, 76, "%s/rx_packets", path); if ((fp = fopen(file, "r")) == NULL) { if (debug) printf("Unable to read: %s - %s\n", file, strerror(errno)); return 0; } else { if (fgets(buffer, 64, fp) != NULL) { ifinfo.rxp = strtoull(buffer, (char **)NULL, 0); } else { fclose(fp); return 0; } } fclose(fp); /* tx packets */ snprintf(file, 76, "%s/tx_packets", path); if ((fp = fopen(file, "r")) == NULL) { if (debug) printf("Unable to read: %s - %s\n", file, strerror(errno)); return 0; } else { if (fgets(buffer, 64, fp) != NULL) { ifinfo.txp = strtoull(buffer, (char **)NULL, 0); } else { fclose(fp); return 0; } } fclose(fp); } ifinfo.filled = 1; return 1; } #if defined(BSD_VNSTAT) int getifdata(const char *iface, struct if_data *ifd) { struct ifaddrs *ifap, *ifa; int check = 0; if (getifaddrs(&ifap) < 0) { if (debug) printf("readifaddrs:getifaddrs() failed.\n"); return 0; } for (ifa = ifap; ifa; ifa = ifa->ifa_next) { if ((strcmp(ifa->ifa_name, iface) == 0) && (ifa->ifa_addr->sa_family == AF_LINK)) { if (ifa->ifa_data != NULL) { memcpy(ifd, ifa->ifa_data, sizeof(struct if_data)); check = 1; } break; } } freeifaddrs(ifap); return check; } int readifaddrs(const char *iface) { struct if_data ifd; if (!getifdata(iface, &ifd)) { if (debug) printf("Requested interface \"%s\" not found.\n", iface); return 0; } else { strncpy_nt(ifinfo.name, iface, 32); ifinfo.rx = ifd.ifi_ibytes; ifinfo.tx = ifd.ifi_obytes; ifinfo.rxp = ifd.ifi_ipackets; ifinfo.txp = ifd.ifi_opackets; ifinfo.filled = 1; if (cfg.is64bit == -2) { if (sizeof(ifd.ifi_ibytes) == 8) { ifinfo.is64bit = 1; } else { ifinfo.is64bit = 0; } } } return 1; } #endif uint32_t getifspeed(const char *iface) { uint64_t speed = 0; #if defined(__linux__) FILE *fp; char file[64], buffer[64]; snprintf(file, 64, "%s/%s/speed", SYSCLASSNET, iface); if ((fp = fopen(file, "r")) == NULL) { if (debug) printf("Unable to open: %s - %s\n", file, strerror(errno)); return 0; } else { if (fgets(buffer, 64, fp) != NULL) { speed = strtoull(buffer, (char **)NULL, 0); } else { if (debug) printf("Unable to read: %s - %s\n", file, strerror(errno)); fclose(fp); return 0; } } fclose(fp); #elif defined(BSD_VNSTAT) struct if_data ifd; if (!getifdata(iface, &ifd)) { if (debug) printf("Requested interface \"%s\" not found.\n", iface); return 0; } else { speed = (uint64_t)ifd.ifi_baudrate; } #endif if (debug) printf("getifspeed: \"%s\": %" PRIu64 "\n", iface, speed); if (speed > 1000000) { speed = 0; } return (uint32_t)speed; } int isifavailable(const char *iface) { int ret = 0, printstatus; printstatus = disableprints; disableprints = 1; ret = getifinfo(iface); disableprints = printstatus; return ret; } int isifvalid(const char *iface) { if (strstr(iface, ":") != NULL) { return 0; } else if (strcmp(iface, "lo") == 0) { return 0; } else if (strcmp(iface, "lo0") == 0) { return 0; } else if (strcmp(iface, "sit0") == 0) { return 0; } return 1; } /* tun interfaces have speed hardcoded as 10 in the Linux kernel regardless of used interface and can't be trusted to provide correct details as a result even if the information is available: https://github.com/torvalds/linux/blob/9d31d2338950293ec19d9b095fbaa9030899dcb4/drivers/net/tun.c#L3456 */ int istun(const char *iface) { #if defined(__linux__) if (strlen(iface) > 3 && strncmp(iface, "tun", 3) == 0) { if (isdigit(iface[3])) { return 1; } } #endif return 0; } vnstat-2.9/src/iflist.h0000644000000000000000000000045213505511017013632 0ustar rootroot#ifndef IFLIST_H #define IFLIST_H typedef struct iflist { char interface[32]; uint32_t bandwidth; struct iflist *next; } iflist; int iflistadd(iflist **ifl, const char *iface, const uint32_t bandwidth); int iflistsearch(iflist **ifl, const char *iface); void iflistfree(iflist **ifl); #endif vnstat-2.9/src/common.h0000644000000000000000000002324614166123703013643 0ustar rootroot#ifndef COMMON_H #define COMMON_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD_kernel__) #include #include #include #include #include #include #define BSD_VNSTAT #endif /* OpenBSD and NetBSD don't support the ' character (decimal conversion) in printf formatting */ #if !defined(__OpenBSD__) && !defined(__NetBSD__) #define DECCONV "'" #else #define DECCONV #endif /* used in debug to get function name */ #if __STDC_VERSION__ < 199901L #if __GNUC__ >= 2 #define __func__ __FUNCTION__ #else #define __func__ "function" #endif #endif /* Note! These are only the default values for settings and most can be changed later from the config file. */ /* location of the database directory */ #ifndef DATABASEDIR #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) #define DATABASEDIR "/var/db/vnstat" #else #define DATABASEDIR "/var/lib/vnstat" #endif #endif /* database file name */ #define DATABASEFILE "vnstat.db" /* modifier used for sqlite date and time functions */ #define DATABASELOCALTIMEMODIFIER ", 'localtime'" /* on which day should months change */ #define MONTHROTATE 1 #define MONTHROTATEYEARS 0 /* date output formats for -d, -m, -t and image header*/ /* see 'man date' for control codes 1.x values <1.8 values */ #define DFORMAT "%Y-%m-%d" /* "%x" "%d.%m." */ #define MFORMAT "%Y-%m" /* "%b '%y" "%b '%y" */ #define TFORMAT "%Y-%m-%d" /* "%x" "%d.%m.%y" */ #define HFORMAT "%Y-%m-%d %H:%M" /* "%x %H:%M" "%d.%m.%Y %H:%M" */ #ifndef DATETIMEFORMAT #define DATETIMEFORMAT "%Y-%m-%d %H:%M:%S" #endif /* characters used for visuals */ #define RXCHAR "%" #define TXCHAR ":" #define RXHOURCHAR "r" #define TXHOURCHAR "t" /* unit mode */ /* 0 = KiB/MiB/GiB/TiB, 1 = KB/MB/GB/TB */ #define UNITMODE 0 /* rate unit mode */ /* 0 = Kibit/s..., 1 = kbit/s... */ #define RATEUNITMODE 1 /* output style */ /* 0 = minimal/narrow, 1 = bars everywhere */ /* 2 = same as 1 + rate in summary */ /* 3 = rate everywhere */ #define OSTYLE 3 #define ESTIMATEBARVISIBLE 1 /* rate in vnstati summary output */ #define SUMMARYRATE 1 /* rate in vnstati hourly output */ #define HOURLYRATE 1 /* rate unit */ /* 0 = bytes, 1 = bits */ #define RATEUNIT 1 /* number of decimals */ #define DEFAULTDECIMALS 2 #define HOURLYDECIMALS 1 /* hourly section style */ #define HOURLYSTYLE 2 /* default interface */ #ifndef DEFIFACE #define DEFIFACE "" #endif /* default locale */ #define LOCALE "-" /* bandwidth detection, 0 = feature disabled */ #define BWDETECT 1 #define BWDETECTINTERVAL 5 /* default maximum bandwidth (Mbit) for all interfaces */ /* 0 = feature disabled */ #define DEFMAXBW 1000 /* maximum allowed config value for bandwidth */ #define BWMAX 50000 /* how many seconds should sampling take by default */ #define DEFSAMPTIME 5 /* default query mode */ /* 0 = normal, 1 = days, 2 = months, 3 = top, 5 = short */ /* 7 = hours, 8 = xml, 9 = one line, 10 = json */ #define DEFQMODE 0 /* interface match method */ /* 0 = interface name exact case sensitive, 1 = 0 + case sensitive exact alias */ /* 2 = 1 + case insensitive exact alias, 3 = 2 + case insensitive beginning of alias */ #define IFACEMATCHMETHOD 3 /* how much the boot time can variate between updates (seconds) */ #define BVAR 15 /* check disk space by default */ #define USESPACECHECK 1 /* create trafficless entries by default */ #define TRAFFICLESSENTRIES 1 /* list outputs */ #define LISTFIVEMINS 24 #define LISTHOURS 24 #define LISTDAYS 30 #define LISTMONTHS 12 #define LISTYEARS 0 #define LISTTOP 10 #define LISTJSONXML 0 /* data retention defaults */ #define FIVEMINUTEHOURS 48 #define HOURLYDAYS 4 #define DAILYDAYS 62 #define MONTHLYMONTHS 25 #define YEARLYYEARS -1 #define TOPDAYENTRIES 20 /* assume that locale can be UTF-n when enabled */ #define UTFLOCALE 1 /* 1 = 2.0 */ #define SQLDBVERSION "1" /* xml format version */ /* 1 = 1.7-1.16, 2 = 2.0 */ #define XMLVERSION 2 /* json format version */ /* 1 = 1.13-1.16, 2 = 2.0 */ #define JSONVERSION 2 /* json format version, -tr */ /* 1 = 1.18- */ #define JSONVERSION_TR 1 /* json format version, --live */ /* 1 = 1.18- */ #define JSONVERSION_LIVE 1 /* --oneline format version */ #define ONELINEVERSION 1 /* integer limits */ #define MAX32 4294967295ULL #define MAX64 18446744073709551615ULL /* sampletime in seconds for live traffic */ /* don't use values below 2 */ #define LIVETIME 2 /* /proc/net/dev */ #ifndef PROCNETDEV #define PROCNETDEV "/proc/net/dev" #endif /* /sys/class/net */ #ifndef SYSCLASSNET #define SYSCLASSNET "/sys/class/net" #endif /* daemon defaults */ #define UPDATEINTERVAL 20 #define TIMESYNCWAIT 5 #define POLLINTERVAL 5 #define SAVEINTERVAL 5 #define OFFSAVEINTERVAL 30 #define RESCANONSAVE 1 #define ALWAYSADD 0 #define SAVESTATUS 1 #define USELOGGING 2 #define CREATEDIRS 1 #define UPDATEFILEOWNER 1 #define LOGFILE "/var/log/vnstat/vnstat.log" #define PIDFILE "/var/run/vnstat/vnstat.pid" #define IS64BIT -2 #define WALDB 0 #define WALDBCHECKPOINTINTERVALMINS 240 #define SLOWDBWARNLIMIT 4.0 // needs to be less than DBREADTIMEOUTSECS #define DBSYNCHRONOUS -1 #define USEUTC 0 /* database read timeout */ #define DBREADTIMEOUTSECS 5 /* no transparency by default */ #define TRANSBG 0 /* small fonts by default */ #define LARGEFONTS 0 /* no extra space between lines by default */ #define LINESPACEADJUST 0 /* no image scaling by default */ #define IMAGESCALE 100 /* image output estimate bar style */ /* 0 = not shown, 1 = continuation of existing bar, 2 = separate bar */ #define ESTIMATESTYLE 1 /* bar column in list outputs shows rate when rate column is visible */ #define BARSHOWSRATE 0 /* 5 minute graph size */ #define FIVEGRESULTCOUNT 576 #define FIVEGHEIGHT 300 #define FIVEGMINRESULTCOUNT 288 #define FIVEGMINHEIGHT 150 /* hourly graph mode (0 = 24 hour sliding window, 1 = begins from midnight) */ #define HOURLYGMODE 0 /* graph used in extended summary, 0 = hours, 1 = 5 minutes*/ #define SUMMARYGRAPH 0 /* default colors */ #define CBACKGROUND "FFFFFF" #define CEDGE "AEAEAE" #define CHEADER "606060" #define CHEADERTITLE "FFFFFF" #define CHEADERDATE "FFFFFF" #define CTEXT "000000" #define CLINE "B0B0B0" #define CLINEL "-" #define CRX "92CF00" #define CRXD "-" #define CTX "606060" #define CTXD "-" /* number of retries after non-fatal database errors, */ /* will result in given number + 1 tries in total before exit, */ /* a full disk (as reported by sqlite) will no cause retries or exit */ #define DBRETRYLIMIT 5 /* internal config structure */ typedef struct { char dformat[64], mformat[64], tformat[64], hformat[64]; char iface[32]; char locale[32]; char dbdir[512], dbtzmodifier[14]; char rxchar[2], txchar[2], rxhourchar[2], txhourchar[2]; char cbg[8], cedge[8], cheader[8], cheadertitle[8], cheaderdate[8], ctext[8]; char cline[8], clinel[8], cvnstat[8], crx[8], crxd[8], ctx[8], ctxd[8]; int32_t unitmode, rateunitmode, rateunit, bvar, qmode, ifacematchmethod, sampletime, hourlyrate, summaryrate; int32_t monthrotate, monthrotateyears, maxbw, spacecheck, trafficlessentries, transbg, ostyle; int32_t defaultdecimals, hourlydecimals, hourlystyle, is64bit, waldb, dbsynchronous, useutc, imagescale; int32_t largefonts, linespaceadjust, estimatebarvisible, estimatestyle, barshowsrate, fivegresultcount; int32_t fivegheight, summarygraph, hourlygmode, alwaysadd; char cfgfile[512], logfile[512], pidfile[512]; char daemonuser[33], daemongroup[33]; int32_t timesyncwait, updateinterval, pollinterval, saveinterval, offsaveinterval, rescanonsave, savestatus; int32_t uselogging, createdirs, updatefileowner, bwdetection, bwdetectioninterval, utflocale; int32_t fiveminutehours, hourlydays, dailydays, monthlymonths, yearlyyears, topdayentries; int32_t listfivemins, listhours, listdays, listmonths, listyears, listtop, listjsonxml; int32_t timestampprints, experimental; } CFG; /* internal interface information structure */ typedef struct { char name[32]; short filled; short is64bit; uint64_t rx; uint64_t tx; uint64_t rxp; uint64_t txp; time_t timestamp; } IFINFO; typedef struct ibwnode { char interface[32]; uint32_t limit; uint32_t fallback; short retries; time_t detected; struct ibwnode *next; } ibwnode; typedef enum PrintType { PT_Info = 0, PT_Infoless, PT_Warning, PT_Error, PT_Config, PT_Multiline, PT_ShortMultiline } PrintType; /* common functions */ int printe(const PrintType type); int logprint(const PrintType type); int verifylogaccess(void); int dmonth(const int month); int isleapyear(const int year); time_t mosecs(time_t month, time_t updated); uint64_t countercalc(const uint64_t *a, const uint64_t *b, const short is64bit); char *strncpy_nt(char *dest, const char *src, size_t n); int isnumeric(const char *s); void panicexit(const char *sourcefile, const int sourceline) __attribute__((noreturn)); char *getversion(void); double timeused(const char *func, const int reset); void timeused_debug(const char *func, const int reset); /* global variables */ extern CFG cfg; extern IFINFO ifinfo; extern char errorstring[1024]; extern ibwnode *ifacebw; extern int debug; extern int noexit; /* = running as daemon if 2 */ extern int intsignal; extern int pidfile; extern int disableprints; #endif vnstat-2.9/src/config.h.in0000644000000000000000000001504614173305711014223 0ustar rootroot/* src/config.h.in. Generated from configure.ac by autoheader. */ /* Define to 1 if you have the `alarm' function. */ #undef HAVE_ALARM /* Define to 1 if your system has a working `chown' function. */ #undef HAVE_CHOWN /* Define to 1 if you have the declaration of `gdImageFile', and to 0 if you don't. */ #undef HAVE_DECL_GDIMAGEFILE /* Define to 1 if you have the declaration of `GD_NEAREST_NEIGHBOUR', and to 0 if you don't. */ #undef HAVE_DECL_GD_NEAREST_NEIGHBOUR /* Define to 1 if you have the declaration of `IFLA_STATS64', and to 0 if you don't. */ #undef HAVE_DECL_IFLA_STATS64 /* Define to 1 if you have the declaration of `O_CLOEXEC', and to 0 if you don't. */ #undef HAVE_DECL_O_CLOEXEC /* Define to 1 if you have the declaration of `SQLITE_CHECKPOINT_RESTART', and to 0 if you don't. */ #undef HAVE_DECL_SQLITE_CHECKPOINT_RESTART /* Define to 1 if you have the declaration of `SQLITE_CHECKPOINT_TRUNCATE', and to 0 if you don't. */ #undef HAVE_DECL_SQLITE_CHECKPOINT_TRUNCATE /* Define to 1 if you have the `dup2' function. */ #undef HAVE_DUP2 /* Define to 1 if you have the header file. */ #undef HAVE_FCNTL_H /* Define to 1 if you have the `fork' function. */ #undef HAVE_FORK /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H /* Define to 1 if you have the `m' library (-lm). */ #undef HAVE_LIBM /* Define to 1 if you have the `sqlite3' library (-lsqlite3). */ #undef HAVE_LIBSQLITE3 /* Define to 1 if you have the header file. */ #undef HAVE_LINUX_RTNETLINK_H /* Define to 1 if you have the header file. */ #undef HAVE_LOCALE_H /* Define to 1 if you have the `localtime_r' function. */ #undef HAVE_LOCALTIME_R /* Define to 1 if you have the `mbstowcs' function. */ #undef HAVE_MBSTOWCS /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H /* Define to 1 if you have the `memset' function. */ #undef HAVE_MEMSET /* Define to 1 if you have the `mkdir' function. */ #undef HAVE_MKDIR /* Define to 1 if you have the `pow' function. */ #undef HAVE_POW /* Define to 1 if you have the `rmdir' function. */ #undef HAVE_RMDIR /* Define to 1 if you have the `setlocale' function. */ #undef HAVE_SETLOCALE /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H /* Define to 1 if you have the `strcasecmp' function. */ #undef HAVE_STRCASECMP /* Define to 1 if you have the `strchr' function. */ #undef HAVE_STRCHR /* Define to 1 if you have the `strdup' function. */ #undef HAVE_STRDUP /* Define to 1 if you have the `strerror' function. */ #undef HAVE_STRERROR /* Define to 1 if you have the header file. */ #undef HAVE_STRINGS_H /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H /* Define to 1 if you have the `strncasecmp' function. */ #undef HAVE_STRNCASECMP /* Define to 1 if you have the `strstr' function. */ #undef HAVE_STRSTR /* Define to 1 if you have the `strtol' function. */ #undef HAVE_STRTOL /* Define to 1 if you have the `strtoul' function. */ #undef HAVE_STRTOUL /* Define to 1 if you have the `strtoull' function. */ #undef HAVE_STRTOULL /* Define to 1 if you have the header file. */ #undef HAVE_SYSLOG_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_FILE_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_MOUNT_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_PARAM_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_SOCKET_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STATVFS_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TIME_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H /* Define to 1 if you have the `tzset' function. */ #undef HAVE_TZSET /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H /* Define to 1 if you have the `vfork' function. */ #undef HAVE_VFORK /* Define to 1 if you have the header file. */ #undef HAVE_VFORK_H /* Define to 1 if you have the header file. */ #undef HAVE_WCHAR_H /* Define to 1 if you have the `wcswidth' function. */ #undef HAVE_WCSWIDTH /* Define to 1 if `fork' works. */ #undef HAVE_WORKING_FORK /* Define to 1 if `vfork' works. */ #undef HAVE_WORKING_VFORK /* Name of package */ #undef PACKAGE /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT /* Define to the full name of this package. */ #undef PACKAGE_NAME /* Define to the full name and version of this package. */ #undef PACKAGE_STRING /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME /* Define to the home page for this package. */ #undef PACKAGE_URL /* Define to the version of this package. */ #undef PACKAGE_VERSION /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS /* Define to 1 if you can safely include both and . */ #undef TIME_WITH_SYS_TIME /* Version number of package */ #undef VERSION /* Define for Solaris 2.5.1 so the uint32_t typedef from , , or is not used. If the typedef were allowed, the #define below would cause a syntax error. */ #undef _UINT32_T /* Define for Solaris 2.5.1 so the uint64_t typedef from , , or is not used. If the typedef were allowed, the #define below would cause a syntax error. */ #undef _UINT64_T /* Define to `int' if doesn't define. */ #undef gid_t /* Define to the type of a signed integer type of width exactly 32 bits if such a type exists and the standard includes do not define it. */ #undef int32_t /* Define to `int' if does not define. */ #undef mode_t /* Define to `int' if does not define. */ #undef pid_t /* Define to `unsigned int' if does not define. */ #undef size_t /* Define to `int' if doesn't define. */ #undef uid_t /* Define to the type of an unsigned integer type of width exactly 32 bits if such a type exists and the standard includes do not define it. */ #undef uint32_t /* Define to the type of an unsigned integer type of width exactly 64 bits if such a type exists and the standard includes do not define it. */ #undef uint64_t /* Define as `fork' if `vfork' does not work. */ #undef vfork vnstat-2.9/src/ibw.c0000644000000000000000000001203614077626772013141 0ustar rootroot#include "common.h" #include "cfg.h" #include "ifinfo.h" #include "ibw.h" int ibwloadcfg(const char *cfgfile) { FILE *fd; int ret; ifacebw = NULL; ret = opencfgfile(cfgfile, &fd); if (ret != 2) return ret; rewind(fd); ibwcfgread(fd); fclose(fd); if (debug) ibwlist(); return 1; } int ibwadd(const char *iface, const uint32_t limit) { ibwnode *n, *p = ifacebw; /* add new node if list is empty */ if (p == NULL) { n = (ibwnode *)malloc(sizeof(ibwnode)); if (n == NULL) { return 0; } n->next = ifacebw; ifacebw = n; strncpy_nt(n->interface, iface, 32); n->limit = limit; n->fallback = limit; n->retries = 0; n->detected = 0; } else { /* update previous value if already in list */ while (p != NULL) { if (strcmp(p->interface, iface) == 0) { p->limit = limit; return 1; } p = p->next; } /* add new node if not found */ n = (ibwnode *)malloc(sizeof(ibwnode)); if (n == NULL) { return 0; } n->next = ifacebw; ifacebw = n; strncpy_nt(n->interface, iface, 32); n->limit = limit; n->fallback = limit; n->retries = 0; n->detected = 0; } return 1; } void ibwlist(void) { int i = 1; ibwnode *p = ifacebw; if (p == NULL) { printf("ibw list is empty.\n"); return; } printf("ibw: "); while (p != NULL) { printf("%2d: i\"%s\" l%u f%u r%d d%u ", i, p->interface, p->limit, p->fallback, p->retries, (unsigned int)p->detected); p = p->next; i++; } printf("\n"); } int ibwget(const char *iface, uint32_t *limit) { ibwnode *p = ifacebw; time_t current; uint32_t speed; *limit = 0; current = time(NULL); /* search for interface specific limit */ while (p != NULL) { if (strcasecmp(p->interface, iface) == 0) { /* never override manually configured limits */ if (p->detected == 0 && p->limit > 0) { *limit = p->limit; return 1; } if (!istun(iface) && cfg.bwdetection && p->retries < 5) { if (cfg.bwdetectioninterval > 0 && (current - p->detected) > (cfg.bwdetectioninterval * 60)) { speed = getifspeed(iface); if (speed > 0) { if (p->detected > 0 && speed != p->limit) { snprintf(errorstring, 1024, "Detected bandwidth limit for \"%s\" changed from %" PRIu32 " Mbit to %" PRIu32 " Mbit.", iface, p->limit, speed); printe(PT_Info); } p->limit = speed; p->retries = 0; p->detected = current; *limit = speed; return 1; } p->retries++; } } if (p->limit > 0) { *limit = p->limit; return 1; } else { return 0; } } p = p->next; } if (!istun(iface) && cfg.bwdetection) { if (ibwadd(iface, (uint32_t)cfg.maxbw)) { p = ibwgetnode(iface); if (p != NULL) { speed = getifspeed(iface); if (speed > 0) { p->limit = speed; p->retries = 0; p->detected = current; *limit = speed; return 1; } p->retries++; } } } /* return default limit if specified */ if (cfg.maxbw > 0) { *limit = (uint32_t)cfg.maxbw; return 1; } return 0; } ibwnode *ibwgetnode(const char *iface) { ibwnode *p = ifacebw; while (p != NULL) { if (strcasecmp(p->interface, iface) == 0) { return p; } p = p->next; } return NULL; } void ibwflush(void) { ibwnode *f, *p = ifacebw; while (p != NULL) { f = p; p = p->next; free(f); } ifacebw = NULL; } int ibwcfgread(FILE *fd) { char cfgline[512], name[512], value[512]; int i, j, linelen, count = 0; long ivalue; /* start from value search from first line */ rewind(fd); /* cycle all lines */ while (!feof(fd)) { cfgline[0] = '\0'; /* get current line */ if (fgets(cfgline, 512, fd) == NULL) { break; } linelen = (int)strlen(cfgline); if (linelen <= 8 || cfgline[0] == '#') { continue; } if (strncasecmp(cfgline, "MaxBW", 5) != 0) { continue; } /* clear name and value buffers */ for (j = 0; j < 512; j++) { name[j] = value[j] = '\0'; } /* get interface name */ j = 0; for (i = 5; i < linelen; i++) { if (cfgline[i] == ' ' || cfgline[i] == '=' || cfgline[i] == '\t' || cfgline[i] == '\n' || cfgline[i] == '\r') { break; } else { name[j] = cfgline[i]; j++; } } /* get new line if no usable name was found */ if (strlen(name) == 0) { continue; } /* search value */ j = 0; for (i++; i < linelen; i++) { if (cfgline[i] == '\n' || cfgline[i] == '\r') { break; } else if (cfgline[i] == '\"') { if (j == 0) { continue; } else { break; } } else { if (j == 0 && (cfgline[i] == ' ' || cfgline[i] == '=' || cfgline[i] == '\t')) { continue; } else { value[j] = cfgline[i]; j++; } } } /* get new line if no usable value was found */ if ((strlen(value) == 0) || (!isdigit(value[0]))) { continue; } /* add interface and limit to list if value is within limits */ ivalue = strtol(value, (char **)NULL, 0); if (ivalue < 0 || ivalue > BWMAX) { snprintf(errorstring, 1024, "Invalid value \"%ld\" for MaxBW%s, ignoring parameter.", ivalue, name); printe(PT_Config); } else { ibwadd(name, (uint32_t)ivalue); } } return count; } vnstat-2.9/src/dbsql.c0000644000000000000000000010766114164072221013453 0ustar rootroot#include "common.h" #include "misc.h" #include "iflist.h" #include "dbsql.h" /* global db */ sqlite3 *db; int db_errcode; int db_intransaction; int db_open_ro(void) { return db_open(0, 1); } int db_open_rw(const int createifnotfound) { return db_open(createifnotfound, 0); } int db_open(const int createifnotfound, const int readonly) { int rc, createdb = 0; char dbfilename[530]; #ifdef CHECK_VNSTAT /* use ram based database when testing for shorter test execution times by reducing disk i/o */ snprintf(dbfilename, 530, ":memory:"); createdb = 1; #else struct stat filestat; if (db != NULL) { return 1; } snprintf(dbfilename, 530, "%s/%s", cfg.dbdir, DATABASEFILE); /* create database if file doesn't exist */ if (stat(dbfilename, &filestat) != 0) { if (errno == ENOENT && createifnotfound && !readonly) { createdb = 1; } else { if (debug) printf("Error (debug): Handling database \"%s\" failed: %s\n", dbfilename, strerror(errno)); return 0; } } else { if (filestat.st_size == 0) { if (createifnotfound) { createdb = 1; } else { printf("Error: Database \"%s\" contains 0 bytes and isn't a valid database, exiting.\n", dbfilename); exit(EXIT_FAILURE); } } } #endif db_errcode = 0; db_intransaction = 0; if (readonly) { rc = sqlite3_open_v2(dbfilename, &db, SQLITE_OPEN_READONLY, NULL); } else { rc = sqlite3_open_v2(dbfilename, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); } if (rc) { db_errcode = rc; if (debug) printf("Error (debug): Can't open database \"%s\": %s\n", dbfilename, sqlite3_errmsg(db)); return 0; } else { if (debug) printf("Database \"%s\" open (ro: %d)\n", dbfilename, readonly); } if (createdb) { #ifndef CHECK_VNSTAT if (!spacecheck(cfg.dbdir)) { printf("Error: Not enough free diskspace available in \"%s\", exiting.\n", cfg.dbdir); db_close(); exit(EXIT_FAILURE); } #endif if (!db_create()) { if (debug) printf("Error (debug): Creating database \"%s\" structure failed\n", dbfilename); db_close(); return 0; } else { if (debug) printf("Database \"%s\" structure created\n", dbfilename); if (!db_setinfo("dbversion", SQLDBVERSION, 1)) { if (debug) printf("Error (debug): Writing version info to database \"%s\" failed\n", dbfilename); db_close(); return 0; } } } /* set pragmas */ if (!readonly) { sqlite3_busy_timeout(db, cfg.updateinterval * 1000); if (!db_setpragmas()) { db_close(); return 0; } } else { /* set busy timeout when database is open in read-only mode */ sqlite3_busy_timeout(db, DBREADTIMEOUTSECS * 1000); } if (!createdb) { if (!db_validate(readonly)) { db_close(); return 0; } } if (createifnotfound && !readonly) { if (!db_setinfo("vnstatversion", getversion(), 1)) { db_close(); return 0; } } return 1; } int db_validate(const int readonly) { int dbversion, currentversion; db_errcode = 0; dbversion = atoi(db_getinfo("dbversion")); if (db_errcode) { return 0; } currentversion = atoi(SQLDBVERSION); if (debug) { printf("Database version \"%d\", current version \"%d\"\n", dbversion, currentversion); } if (dbversion == currentversion) { return 1; } else if (dbversion == 0) { printf("Error: Database version \"%d\" suggests error situation in database, exiting.\n", dbversion); return 0; } else if (dbversion > currentversion) { printf("Error: Database version \"%d\" is not supported. Support is available up to version \"%d\", exiting.\n", dbversion, currentversion); return 0; } else if (dbversion < currentversion) { if (readonly) { /* database upgrade actions should be performed here once needed */ printf("Error: Unable to upgrade read-only database from version \"%d\" to \"%d\", exiting.\n", dbversion, currentversion); return 0; } /* database upgrade actions should be performed here once needed, then return 1 */ /* however, since this is the first database version, always return 0 */ } return 0; } int db_setpragmas(void) { int rc; char sql[25]; sqlite3_stmt *sqlstmt; /* enable use of foreign keys */ if (!db_exec("PRAGMA foreign_keys = ON")) { return 0; } rc = sqlite3_prepare_v2(db, "PRAGMA foreign_keys", -1, &sqlstmt, NULL); if (rc != SQLITE_OK) { db_errcode = rc; snprintf(errorstring, 1024, "Exec prepare \"PRAGMA foreign_keys;\" failed (%d): %s", rc, sqlite3_errmsg(db)); printe(PT_Error); return 0; } /* PRAGMA foreign_keys; is expected to return one row if the feature is supported */ rc = sqlite3_step(sqlstmt); if (rc != SQLITE_ROW) { db_errcode = rc; snprintf(errorstring, 1024, "PRAGMA foreign_keys returned no row (%d): %s", rc, sqlite3_errmsg(db)); printe(PT_Error); sqlite3_finalize(sqlstmt); return 0; } rc = sqlite3_finalize(sqlstmt); if (rc) { db_errcode = rc; snprintf(errorstring, 1024, "Exec finalize \"PRAGMA foreign_keys;\" failed (%d): %s", rc, sqlite3_errmsg(db)); printe(PT_Error); return 0; } #if HAVE_DECL_SQLITE_CHECKPOINT_RESTART /* set journal_mode */ if (cfg.waldb) { if (!db_exec("PRAGMA journal_mode = WAL")) { return 0; } } else { if (!db_exec("PRAGMA journal_mode = DELETE")) { return 0; } } #endif /* set synchronous */ if (cfg.dbsynchronous == -1) { #if HAVE_DECL_SQLITE_CHECKPOINT_RESTART if (cfg.waldb) { if (!db_exec("PRAGMA synchronous = 1")) { return 0; } } else { if (!db_exec("PRAGMA synchronous = 2")) { return 0; } } #else if (!db_exec("PRAGMA synchronous = 2")) { return 0; } #endif } else { snprintf(sql, 25, "PRAGMA synchronous = %d", cfg.dbsynchronous); if (!db_exec(sql)) { return 0; } } return 1; } int db_close(void) { int rc; if (db == NULL) { return 1; } rc = sqlite3_close(db); if (rc == SQLITE_OK) { db = NULL; if (debug) printf("Database closed\n"); return 1; } else { db_errcode = rc; if (debug) printf("Error (debug): Closing database failed (%d): %s\n", rc, sqlite3_errmsg(db)); return 0; } } int db_exec(const char *sql) { int rc; sqlite3_stmt *sqlstmt; rc = sqlite3_prepare_v2(db, sql, -1, &sqlstmt, NULL); if (rc != SQLITE_OK) { db_errcode = rc; snprintf(errorstring, 1024, "Exec prepare failed (%d: %s): \"%s\"", rc, sqlite3_errmsg(db), sql); printe(PT_Error); return 0; } rc = sqlite3_step(sqlstmt); if (rc != SQLITE_DONE && rc != SQLITE_ROW) { db_errcode = rc; snprintf(errorstring, 1024, "Exec step failed (%d: %s): \"%s\"", rc, sqlite3_errmsg(db), sql); printe(PT_Error); sqlite3_finalize(sqlstmt); return 0; } rc = sqlite3_finalize(sqlstmt); if (rc) { db_errcode = rc; snprintf(errorstring, 1024, "Exec finalize failed (%d: %s): \"%s\"", rc, sqlite3_errmsg(db), sql); printe(PT_Error); return 0; } return 1; } int db_create(void) { int i; const char *constsql; char *sql; char buffer[32]; const char *datatables[] = {"fiveminute", "hour", "day", "month", "year", "top"}; if (!db_begintransaction()) { return 0; } constsql = "CREATE TABLE info(\n" " id INTEGER PRIMARY KEY,\n" " name TEXT UNIQUE NOT NULL,\n" " value TEXT NOT NULL)"; if (!db_exec(constsql)) { db_rollbacktransaction(); return 0; } constsql = "CREATE TABLE interface(\n" " id INTEGER PRIMARY KEY,\n" " name TEXT UNIQUE NOT NULL,\n" " alias TEXT,\n" " active INTEGER NOT NULL,\n" " created DATE NOT NULL,\n" " updated DATE NOT NULL,\n" " rxcounter INTEGER NOT NULL,\n" " txcounter INTEGER NOT NULL,\n" " rxtotal INTEGER NOT NULL,\n" " txtotal INTEGER NOT NULL)"; if (!db_exec(constsql)) { db_rollbacktransaction(); return 0; } sql = malloc(sizeof(char) * 512); for (i = 0; i < 6; i++) { sqlite3_snprintf(512, sql, "CREATE TABLE %s(\n" " id INTEGER PRIMARY KEY,\n" " interface INTEGER REFERENCES interface(id) ON DELETE CASCADE,\n" " date DATE NOT NULL,\n" " rx INTEGER NOT NULL,\n" " tx INTEGER NOT NULL,\n" " CONSTRAINT u UNIQUE (interface, date))", datatables[i]); if (!db_exec(sql)) { free(sql); db_rollbacktransaction(); return 0; } } free(sql); snprintf(buffer, 32, "%" PRIu64 "", (uint64_t)MAX32); if (!db_setinfo("btime", buffer, 1)) { db_rollbacktransaction(); return 0; } return db_committransaction(); } int db_addinterface(const char *iface) { char sql[256]; if (!strlen(iface)) { return 0; } sqlite3_snprintf(256, sql, "insert into interface (name, active, created, updated, rxcounter, txcounter, rxtotal, txtotal) values ('%q', 1, datetime('now'%s), datetime('now'%s), 0, 0, 0, 0)", iface, cfg.dbtzmodifier, cfg.dbtzmodifier); return db_exec(sql); } int db_removeinterface(const char *iface) { char sql[64]; sqlite3_int64 ifaceid = 0; ifaceid = db_getinterfaceid(iface, 0); if (ifaceid == 0) { return 0; } sqlite3_snprintf(64, sql, "delete from interface where id=%" PRId64 "", (int64_t)ifaceid); return db_exec(sql); } int db_renameinterface(const char *iface, const char *newifname) { char sql[128]; sqlite3_int64 ifaceid = 0; if (!strlen(newifname)) { return 0; } ifaceid = db_getinterfaceid(iface, 0); if (ifaceid == 0) { return 0; } sqlite3_snprintf(128, sql, "update interface set name='%q' where id=%" PRId64 "", newifname, (int64_t)ifaceid); return db_exec(sql); } uint64_t db_getinterfacecount(void) { return db_getinterfacecountbyname(""); } uint64_t db_getinterfacecountbyname(const char *iface) { int rc; uint64_t result = 0; char sql[128], *inquery = NULL; sqlite3_stmt *sqlstmt; if (strchr(iface, '+') == NULL) { if (strlen(iface) > 0) { sqlite3_snprintf(128, sql, "select count(*) from interface where name='%q'", iface); } else { sqlite3_snprintf(128, sql, "select count(*) from interface"); } } else { inquery = getifaceinquery(iface); if (inquery == NULL) { return 0; } sqlite3_snprintf(128, sql, "select count(*) from interface where name in (%q)", inquery); free(inquery); } rc = sqlite3_prepare_v2(db, sql, -1, &sqlstmt, NULL); if (rc != SQLITE_OK) { db_errcode = rc; snprintf(errorstring, 1024, "Failed to get interface count from database (%d): %s", rc, sqlite3_errmsg(db)); printe(PT_Error); return 0; } if (sqlite3_column_count(sqlstmt) != 1) { return 0; } if (sqlite3_step(sqlstmt) == SQLITE_ROW) { result = (uint64_t)sqlite3_column_int64(sqlstmt, 0); } sqlite3_finalize(sqlstmt); /* consider merge query as invalid if not all requested interfaces are found or are not unique */ if (strchr(iface, '+') != NULL) { if (result != getqueryinterfacecount(iface)) { result = 0; } } return result; } sqlite3_int64 db_getinterfaceid(const char *iface, const int createifnotfound) { int rc; char sql[128]; sqlite3_int64 ifaceid = 0; sqlite3_stmt *sqlstmt; sqlite3_snprintf(128, sql, "select id from interface where name='%q'", iface); rc = sqlite3_prepare_v2(db, sql, -1, &sqlstmt, NULL); if (rc == SQLITE_OK) { if (sqlite3_step(sqlstmt) == SQLITE_ROW) { ifaceid = sqlite3_column_int64(sqlstmt, 0); } sqlite3_finalize(sqlstmt); } else { db_errcode = rc; snprintf(errorstring, 1024, "Failed to get interface id from database (%d): %s", rc, sqlite3_errmsg(db)); printe(PT_Error); } if (ifaceid == 0 && createifnotfound) { if (!db_addinterface(iface)) { return 0; } ifaceid = sqlite3_last_insert_rowid(db); } return ifaceid; } char *db_getinterfaceidin(const char *iface) { int rc; char sql[256], *result, *inquery; sqlite3_stmt *sqlstmt; result = NULL; inquery = getifaceinquery(iface); if (inquery == NULL) { return NULL; } sqlite3_snprintf(256, sql, "select group_concat(id) from interface where name in (%q)", inquery); free(inquery); rc = sqlite3_prepare_v2(db, sql, -1, &sqlstmt, NULL); if (rc == SQLITE_OK) { if (sqlite3_step(sqlstmt) == SQLITE_ROW) { if (sqlite3_column_text(sqlstmt, 0) != NULL) { result = strdup((const char *)sqlite3_column_text(sqlstmt, 0)); } } sqlite3_finalize(sqlstmt); } else { db_errcode = rc; snprintf(errorstring, 1024, "Failed to get interface id from database (%d): %s", rc, sqlite3_errmsg(db)); printe(PT_Error); } return result; } int db_setinterfacebyalias(char *iface, const char *alias, const int matchmethod) { int rc; char sql[256]; sqlite3_stmt *sqlstmt; switch (matchmethod) { // case sensitive case 1: sqlite3_snprintf(256, sql, "select name from interface where alias='%q' order by rxtotal+txtotal desc", alias); break; // case insensitive case 2: sqlite3_snprintf(256, sql, "select name from interface where alias='%q' collate nocase order by rxtotal+txtotal desc", alias); break; // case insensitive prefix case 3: sqlite3_snprintf(256, sql, "select name from interface where alias like '%q%%' collate nocase order by rxtotal+txtotal desc", alias); break; default: return 0; } rc = sqlite3_prepare_v2(db, sql, -1, &sqlstmt, NULL); if (rc != SQLITE_OK) { db_errcode = rc; snprintf(errorstring, 1024, "Failed to get interface alias from database (%d): %s", rc, sqlite3_errmsg(db)); printe(PT_Error); return 0; } if (sqlite3_column_count(sqlstmt) != 1) { return 0; } rc = 0; if (sqlite3_step(sqlstmt) == SQLITE_ROW) { if (sqlite3_column_text(sqlstmt, 0) != NULL) { strncpy_nt(iface, (const char *)sqlite3_column_text(sqlstmt, 0), 32); rc++; } } sqlite3_finalize(sqlstmt); return rc; } int db_setactive(const char *iface, const int active) { char sql[64]; sqlite3_int64 ifaceid = 0; ifaceid = db_getinterfaceid(iface, 0); if (ifaceid == 0) { return 0; } sqlite3_snprintf(64, sql, "update interface set active=%d where id=%" PRId64 "", active, (int64_t)ifaceid); return db_exec(sql); } int db_setupdated(const char *iface, const time_t timestamp) { char sql[256]; sqlite3_int64 ifaceid = 0; ifaceid = db_getinterfaceid(iface, 0); if (ifaceid == 0) { return 0; } sqlite3_snprintf(256, sql, "update interface set updated=datetime(%" PRIu64 ", 'unixepoch'%s) where id=%" PRId64 "", (uint64_t)timestamp, cfg.dbtzmodifier, (int64_t)ifaceid); return db_exec(sql); } int db_setcounters(const char *iface, const uint64_t rxcounter, const uint64_t txcounter) { char sql[256]; sqlite3_int64 ifaceid = 0; ifaceid = db_getinterfaceid(iface, 0); if (ifaceid == 0) { return 0; } sqlite3_snprintf(256, sql, "update interface set rxcounter=%" PRIu64 ", txcounter=%" PRIu64 " where id=%" PRId64 "", rxcounter, txcounter, (int64_t)ifaceid); return db_exec(sql); } int db_getcounters(const char *iface, uint64_t *rxcounter, uint64_t *txcounter) { int rc; char sql[128]; sqlite3_int64 ifaceid = 0; sqlite3_stmt *sqlstmt; *rxcounter = *txcounter = 0; ifaceid = db_getinterfaceid(iface, 0); if (ifaceid == 0) { return 0; } sqlite3_snprintf(128, sql, "select rxcounter, txcounter from interface where id=%" PRId64 "", (int64_t)ifaceid); rc = sqlite3_prepare_v2(db, sql, -1, &sqlstmt, NULL); if (rc != SQLITE_OK) { db_errcode = rc; snprintf(errorstring, 1024, "Failed to get interface counters from database (%d): %s", rc, sqlite3_errmsg(db)); printe(PT_Error); return 0; } if (sqlite3_column_count(sqlstmt) != 2) { sqlite3_finalize(sqlstmt); return 0; } if (sqlite3_step(sqlstmt) == SQLITE_ROW) { *rxcounter = (uint64_t)sqlite3_column_int64(sqlstmt, 0); *txcounter = (uint64_t)sqlite3_column_int64(sqlstmt, 1); } sqlite3_finalize(sqlstmt); return 1; } int db_getinterfaceinfo(const char *iface, interfaceinfo *info) { int rc; char sql[512], *ifaceidin = NULL; sqlite3_int64 ifaceid; sqlite3_stmt *sqlstmt; if (strchr(iface, '+') == NULL) { ifaceid = db_getinterfaceid(iface, 0); if (ifaceid == 0) { return 0; } sqlite3_snprintf(512, sql, "select name, alias, active, strftime('%%s', created, 'utc'), strftime('%%s', updated, 'utc'), rxcounter, txcounter, rxtotal, txtotal from interface where id=%" PRId64 "", (int64_t)ifaceid); } else { ifaceidin = db_getinterfaceidin(iface); if (ifaceidin == NULL || strlen(ifaceidin) < 1) { free(ifaceidin); return 0; } sqlite3_snprintf(512, sql, "select \"%q\", NULL, max(active), max(strftime('%%s', created, 'utc')), min(strftime('%%s', updated, 'utc')), 0, 0, sum(rxtotal), sum(txtotal) from interface where id in (%q)", iface, ifaceidin); free(ifaceidin); } rc = sqlite3_prepare_v2(db, sql, -1, &sqlstmt, NULL); if (rc != SQLITE_OK) { db_errcode = rc; snprintf(errorstring, 1024, "Failed to get interface information from database (%d): %s", rc, sqlite3_errmsg(db)); printe(PT_Error); return 0; } if (sqlite3_column_count(sqlstmt) != 9) { return 0; } if (sqlite3_step(sqlstmt) == SQLITE_ROW) { if (sqlite3_column_text(sqlstmt, 0) != NULL) { strncpy_nt(info->name, (const char *)sqlite3_column_text(sqlstmt, 0), 32); } else { info->name[0] = '\0'; } if (sqlite3_column_text(sqlstmt, 1) != NULL) { strncpy_nt(info->alias, (const char *)sqlite3_column_text(sqlstmt, 1), 32); } else { info->alias[0] = '\0'; } info->active = sqlite3_column_int(sqlstmt, 2); info->created = (time_t)sqlite3_column_int64(sqlstmt, 3); info->updated = (time_t)sqlite3_column_int64(sqlstmt, 4); info->rxcounter = (uint64_t)sqlite3_column_int64(sqlstmt, 5); info->txcounter = (uint64_t)sqlite3_column_int64(sqlstmt, 6); info->rxtotal = (uint64_t)sqlite3_column_int64(sqlstmt, 7); info->txtotal = (uint64_t)sqlite3_column_int64(sqlstmt, 8); } sqlite3_finalize(sqlstmt); return 1; } int db_setalias(const char *iface, const char *alias) { char sql[128]; sqlite3_int64 ifaceid = 0; ifaceid = db_getinterfaceid(iface, 0); if (ifaceid == 0) { return 0; } sqlite3_snprintf(128, sql, "update interface set alias='%q' where id=%" PRId64 "", alias, (int64_t)ifaceid); return db_exec(sql); } int db_setinfo(const char *name, const char *value, const int createifnotfound) { int rc; char sql[128]; sqlite3_snprintf(128, sql, "update info set value='%q' where name='%q'", value, name); rc = db_exec(sql); if (!rc || (!sqlite3_changes(db) && !createifnotfound)) { return 0; } if (!sqlite3_changes(db) && createifnotfound) { sqlite3_snprintf(512, sql, "insert into info (name, value) values ('%q', '%q')", name, value); rc = db_exec(sql); } return rc; } char *db_getinfo(const char *name) { int rc; char sql[128]; static char buffer[64]; sqlite3_stmt *sqlstmt; buffer[0] = '\0'; sqlite3_snprintf(128, sql, "select value from info where name='%q'", name); rc = sqlite3_prepare_v2(db, sql, -1, &sqlstmt, NULL); if (rc != SQLITE_OK) { db_errcode = rc; snprintf(errorstring, 1024, "Failed to get info value for \"%s\" from database (%d): %s", name, rc, sqlite3_errmsg(db)); printe(PT_Error); return buffer; } if (sqlite3_step(sqlstmt) == SQLITE_ROW) { if (sqlite3_column_text(sqlstmt, 0) != NULL) { strncpy_nt(buffer, (const char *)sqlite3_column_text(sqlstmt, 0), 64); } } sqlite3_finalize(sqlstmt); return buffer; } int db_getiflist(iflist **ifl) { return db_getiflist_sorted(ifl, 0); } int db_getiflist_sorted(iflist **ifl, const int orderbytraffic) { int rc; const char *constsql; sqlite3_stmt *sqlstmt; if (!orderbytraffic) { constsql = "select name from interface order by name asc"; } else { constsql = "select name from interface order by rxtotal+txtotal desc"; } rc = sqlite3_prepare_v2(db, constsql, -1, &sqlstmt, NULL); if (rc != SQLITE_OK) { db_errcode = rc; snprintf(errorstring, 1024, "Failed to get interface list from database (%d): %s", rc, sqlite3_errmsg(db)); printe(PT_Error); return -1; } rc = 0; while (sqlite3_step(sqlstmt) == SQLITE_ROW) { if (sqlite3_column_text(sqlstmt, 0) == NULL) { continue; } if (!iflistadd(ifl, (const char *)sqlite3_column_text(sqlstmt, 0), 0)) { break; } rc++; } sqlite3_finalize(sqlstmt); return rc; } char *db_get_date_generator(const int range, const short direct, const char *nowdate) { static char dgen[512]; dgen[0] = '\0'; switch (range) { case 0: /* 5min */ snprintf(dgen, 512, "datetime(%s, ('-' || (strftime('%%M', %s)) || ' minutes'), ('-' || (strftime('%%S', %s)) || ' seconds'), ('+' || (round(strftime('%%M', %s)/5,0)*5) || ' minutes')%s)", nowdate, nowdate, nowdate, nowdate, cfg.dbtzmodifier); break; case 1: /* hour */ snprintf(dgen, 512, "strftime('%%Y-%%m-%%d %%H:00:00', %s%s)", nowdate, cfg.dbtzmodifier); break; case 2: /* day */ case 5: /* top */ snprintf(dgen, 512, "date(%s%s)", nowdate, cfg.dbtzmodifier); break; case 3: /* month */ if (direct || cfg.monthrotate == 1) { snprintf(dgen, 512, "strftime('%%Y-%%m-01', %s%s)", nowdate, cfg.dbtzmodifier); } else { snprintf(dgen, 512, "strftime('%%Y-%%m-01', datetime(%s, '-%d days')%s)", nowdate, cfg.monthrotate - 1, cfg.dbtzmodifier); } break; case 4: /* year */ if (direct || cfg.monthrotate == 1 || cfg.monthrotateyears == 0) { snprintf(dgen, 512, "strftime('%%Y-01-01', %s%s)", nowdate, cfg.dbtzmodifier); } else { snprintf(dgen, 512, "strftime('%%Y-01-01', datetime(%s, '-%d days')%s)", nowdate, cfg.monthrotate - 1, cfg.dbtzmodifier); } break; default: break; } return dgen; } int db_addtraffic(const char *iface, const uint64_t rx, const uint64_t tx) { return db_addtraffic_dated(iface, rx, tx, 0); } int db_addtraffic_dated(const char *iface, const uint64_t rx, const uint64_t tx, const uint64_t timestamp) { int i, intransaction = db_intransaction; char sql[1024], nowdate[64]; sqlite3_int64 ifaceid = 0; const char *datatables[] = {"fiveminute", "hour", "day", "month", "year", "top"}; int32_t *featurecfg[] = {&cfg.fiveminutehours, &cfg.hourlydays, &cfg.dailydays, &cfg.monthlymonths, &cfg.yearlyyears, &cfg.topdayentries}; ifaceid = db_getinterfaceid(iface, 1); if (ifaceid == 0) { return 0; } if (timestamp > 0) { snprintf(nowdate, 64, "datetime(%" PRIu64 ", 'unixepoch')", timestamp); } else { snprintf(nowdate, 64, "'now'"); } if (debug) printf("db add %s (%" PRId64 ") %" PRIu64 ": rx %" PRIu64 " - tx %" PRIu64 "\n", iface, (int64_t)ifaceid, timestamp, rx, tx); if (!intransaction) { if (!db_begintransaction()) { return 0; } } /* total */ if (rx > 0 || tx > 0) { sqlite3_snprintf(1024, sql, "update interface set rxtotal=rxtotal+%" PRIu64 ", txtotal=txtotal+%" PRIu64 " where id=%" PRId64 "", rx, tx, (int64_t)ifaceid); if (!db_exec(sql)) { db_rollbacktransaction(); return 0; } } /* time specific */ for (i = 0; i < 6; i++) { if (featurecfg[i] == 0) { continue; } sqlite3_snprintf(1024, sql, "insert or ignore into %s (interface, date, rx, tx) values (%" PRId64 ", %s, 0, 0)", datatables[i], (int64_t)ifaceid, db_get_date_generator(i, 0, nowdate)); if (!db_exec(sql)) { db_rollbacktransaction(); return 0; } sqlite3_snprintf(1024, sql, "update %s set rx=rx+%" PRIu64 ", tx=tx+%" PRIu64 " where interface=%" PRId64 " and date=%s", datatables[i], rx, tx, (int64_t)ifaceid, db_get_date_generator(i, 0, nowdate)); if (!db_exec(sql)) { db_rollbacktransaction(); return 0; } } if (!intransaction) { return db_committransaction(); } return 1; } int db_setcreation(const char *iface, const time_t timestamp) { char sql[256]; sqlite3_int64 ifaceid = 0; ifaceid = db_getinterfaceid(iface, 0); if (ifaceid == 0) { return 0; } sqlite3_snprintf(256, sql, "update interface set created=datetime(%" PRIu64 ", 'unixepoch'%s) where id=%" PRId64 "", (uint64_t)timestamp, cfg.dbtzmodifier, (int64_t)ifaceid); return db_exec(sql); } int db_settotal(const char *iface, const uint64_t rx, const uint64_t tx) { char sql[256]; sqlite3_int64 ifaceid = 0; ifaceid = db_getinterfaceid(iface, 0); if (ifaceid == 0) { return 0; } sqlite3_snprintf(256, sql, "update interface set rxtotal=%" PRIu64 ", txtotal=%" PRIu64 " where id=%" PRId64 "", rx, tx, (int64_t)ifaceid); return db_exec(sql); } /* used only for legacy data import */ int db_insertdata(const char *table, const char *iface, const uint64_t rx, const uint64_t tx, const uint64_t timestamp) { int i, index = -1; char sql[1024], nowdate[64]; sqlite3_int64 ifaceid = 0; const char *datatables[] = {"hour", "day", "month", "year", "top"}; for (i = 0; i < 5; i++) { if (strcmp(table, datatables[i]) == 0) { index = i; break; } } if (index == -1) { return 0; } ifaceid = db_getinterfaceid(iface, 0); if (ifaceid == 0) { return 0; } /* legacy data is always local timezone and needs to be enforced here as a result */ if (cfg.useutc) { snprintf(nowdate, 64, "datetime(%" PRIu64 ", 'unixepoch', 'localtime')", timestamp); } else { snprintf(nowdate, 64, "datetime(%" PRIu64 ", 'unixepoch')", timestamp); } sqlite3_snprintf(1024, sql, "insert or ignore into %s (interface, date, rx, tx) values (%" PRId64 ", %s, %" PRIu64 ", %" PRIu64 ")", table, (int64_t)ifaceid, db_get_date_generator(index + 1, 1, nowdate), rx, tx); return db_exec(sql); } int db_removeoldentries(void) { char sql[256]; if (debug) { printf("db: removing old entries\n"); } if (!db_begintransaction()) { return 0; } if (!db_removeoldentries_top()) { db_rollbacktransaction(); return 0; } if (cfg.fiveminutehours > 0) { if (debug) { printf("db: fiveminute cleanup (%dh)\n", cfg.fiveminutehours); } sqlite3_snprintf(256, sql, "delete from fiveminute where date < datetime('now', '-%d hours'%s)", cfg.fiveminutehours, cfg.dbtzmodifier); if (!db_exec(sql)) { db_rollbacktransaction(); return 0; } } if (cfg.hourlydays > 0) { if (debug) { printf("db: hour cleanup (%dd)\n", cfg.hourlydays); } sqlite3_snprintf(256, sql, "delete from hour where date < datetime('now', '-%d days'%s)", cfg.hourlydays, cfg.dbtzmodifier); if (!db_exec(sql)) { db_rollbacktransaction(); return 0; } } if (cfg.dailydays > 0) { if (debug) { printf("db: day cleanup (%dd)\n", cfg.dailydays); } sqlite3_snprintf(256, sql, "delete from day where date < date('now', '-%d days'%s)", cfg.dailydays, cfg.dbtzmodifier); if (!db_exec(sql)) { db_rollbacktransaction(); return 0; } } if (cfg.monthlymonths > 0) { if (debug) { printf("db: month cleanup (%dm)\n", cfg.monthlymonths); } sqlite3_snprintf(256, sql, "delete from month where date < date('now', '-%d months'%s)", cfg.monthlymonths, cfg.dbtzmodifier); if (!db_exec(sql)) { db_rollbacktransaction(); return 0; } } if (cfg.yearlyyears > 0) { if (debug) { printf("db: year cleanup (%dy)\n", cfg.yearlyyears); } sqlite3_snprintf(256, sql, "delete from year where date < date('now', '-%d years'%s)", cfg.yearlyyears, cfg.dbtzmodifier); if (!db_exec(sql)) { db_rollbacktransaction(); return 0; } } return db_committransaction(); } int db_removeoldentries_top(void) { int errorcount = 0; char sql[512]; iflist *dbifl = NULL, *dbifl_iterator = NULL; sqlite3_int64 ifaceid; if (cfg.topdayentries <= 0) { return 1; } if (db_getiflist(&dbifl) < 0) { return 0; } dbifl_iterator = dbifl; while (dbifl_iterator != NULL) { if (debug) { printf("db: top cleanup: %s (%d)\n", dbifl_iterator->interface, cfg.topdayentries); } ifaceid = db_getinterfaceid(dbifl_iterator->interface, 0); if (ifaceid == 0) { errorcount++; dbifl_iterator = dbifl_iterator->next; continue; } sqlite3_snprintf(512, sql, "delete from top where id in ( select id from top where interface=%" PRId64 " and date!=date('now'%s) order by rx+tx desc, date asc limit -1 offset %d )", (int64_t)ifaceid, cfg.dbtzmodifier, cfg.topdayentries); if (!db_exec(sql)) { errorcount++; dbifl_iterator = dbifl_iterator->next; continue; } dbifl_iterator = dbifl_iterator->next; } iflistfree(&dbifl); if (errorcount) { return 0; } return 1; } int db_vacuum(void) { if (debug) { printf("db: vacuum\n"); } return db_exec("VACUUM"); } int db_begintransaction(void) { int rc; if (debug) { printf("db: begin transaction\n"); } rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, 0); if (rc) { db_errcode = rc; snprintf(errorstring, 1024, "Begin transaction to database failed (%d): %s", rc, sqlite3_errmsg(db)); printe(PT_Error); return 0; } db_intransaction = 1; return 1; } int db_committransaction(void) { int rc; if (debug) { printf("db: commit transaction\n"); } db_intransaction = 0; rc = sqlite3_exec(db, "COMMIT", 0, 0, 0); if (rc) { snprintf(errorstring, 1024, "Commit transaction to database failed (%d): %s", rc, sqlite3_errmsg(db)); printe(PT_Error); /* execute rollback if commit failure left the transaction open */ if (!sqlite3_get_autocommit(db)) { db_rollbacktransaction(); } db_errcode = rc; return 0; } return 1; } int db_rollbacktransaction(void) { int rc; if (debug) { printf("db: rollback transaction\n"); } db_intransaction = 0; rc = sqlite3_exec(db, "ROLLBACK", 0, 0, 0); if (rc) { db_errcode = rc; snprintf(errorstring, 1024, "Transaction rollback failed (%d): %s", rc, sqlite3_errmsg(db)); printe(PT_Error); return 0; } return 1; } int db_iserrcodefatal(int errcode) { switch (errcode) { case SQLITE_OK: case SQLITE_FULL: case SQLITE_IOERR: case SQLITE_LOCKED: case SQLITE_BUSY: return 0; default: return 1; } } int db_isdiskfull(int errcode) { if (errcode == SQLITE_FULL) { return 1; } else { return 0; } } #if HAVE_DECL_SQLITE_CHECKPOINT_RESTART void db_walcheckpoint(void) { double used_secs = 0.0; timeused(__func__, 1); #if HAVE_DECL_SQLITE_CHECKPOINT_TRUNCATE sqlite3_wal_checkpoint_v2(db, NULL, SQLITE_CHECKPOINT_TRUNCATE, NULL, NULL); #else sqlite3_wal_checkpoint_v2(db, NULL, SQLITE_CHECKPOINT_RESTART, NULL, NULL); #endif timeused(__func__, 0); used_secs = timeused(__func__, 0); if (used_secs > SLOWDBWARNLIMIT) { snprintf(errorstring, 1024, "Write-Ahead Logging checkpoint took %.1f seconds.", used_secs); printe(PT_Warning); } } #endif int db_getdata(dbdatalist **dbdata, dbdatalistinfo *listinfo, const char *iface, const char *table, const uint32_t resultlimit) { return db_getdata_range(dbdata, listinfo, iface, table, resultlimit, "", ""); } int db_getdata_range(dbdatalist **dbdata, dbdatalistinfo *listinfo, const char *iface, const char *table, const uint32_t resultlimit, const char *databegin, const char *dataend) { int ret, i, rc; const char *datatables[] = {"fiveminute", "hour", "day", "month", "year", "top"}; char sql[512], limit[64], dbegin[37], dend[44], *ifaceidin = NULL; sqlite3_stmt *sqlstmt; time_t timestamp; int64_t rowid; uint64_t rx, tx; listinfo->count = 0; ret = 0; for (i = 0; i < 6; i++) { if (strcmp(table, datatables[i]) == 0) { ret = 1; break; } } if (!ret) { return 0; } ifaceidin = db_getinterfaceidin(iface); if (ifaceidin == NULL) { return 0; } dbegin[0] = '\0'; if (strlen(databegin)) { if (strcmp(databegin, "today") == 0) { snprintf(dbegin, 37, "and date >= date('now'%s)", cfg.dbtzmodifier); } else { snprintf(dbegin, 37, "and date >= '%s'", databegin); } } dend[0] = '\0'; if (strlen(dataend)) { if (strchr(dataend, ':')) { snprintf(dend, 44, "and date <= datetime('%s')", dataend); } else { snprintf(dend, 44, "and date <= datetime('%s 23:59:59')", dataend); } } limit[0] = '\0'; if (resultlimit > 0 && (!strlen(dbegin) || !strlen(dend))) { snprintf(limit, 64, "limit %" PRIu32 "", resultlimit); } /* note that using the linked list reverses the order */ /* most recent last in the linked list is considered the normal order */ if (strcmp(table, "top") == 0) { /* 'top' entries, requires different query due to rx+tx ordering */ if (strlen(dbegin)) { if (resultlimit > 0) { snprintf(limit, 64, "limit %" PRIu32 "", resultlimit); } sqlite3_snprintf(512, sql, "select * from (select id, strftime('%%s', date, 'utc') as unixdate, sum(rx) as rx, sum(tx) as tx from day where interface in (%q) %s %s group by date order by rx+tx desc, unixdate asc %s) order by rx+tx asc, unixdate desc", ifaceidin, dbegin, dend, limit); } else { sqlite3_snprintf(512, sql, "select * from (select id, strftime('%%s', date, 'utc') as unixdate, sum(rx) as rx, sum(tx) as tx from top where interface in (%q) group by date order by rx+tx desc, unixdate asc %s) order by rx+tx asc, unixdate desc", ifaceidin, limit); } } else { if (strlen(dbegin) && strlen(limit)) { sqlite3_snprintf(512, sql, "select * from (select id, strftime('%%s', date, 'utc') as unixdate, sum(rx), sum(tx) from %s where interface in (%q) %s %s group by date order by unixdate asc %s) order by unixdate desc", table, ifaceidin, dbegin, dend, limit); } else { sqlite3_snprintf(512, sql, "select id, strftime('%%s', date, 'utc') as unixdate, sum(rx), sum(tx) from %s where interface in (%q) %s %s group by date order by unixdate desc %s", table, ifaceidin, dbegin, dend, limit); } } free(ifaceidin); rc = sqlite3_prepare_v2(db, sql, -1, &sqlstmt, NULL); if (rc != SQLITE_OK) { db_errcode = rc; snprintf(errorstring, 1024, "Get data prepare failed (%d: %s): \"%s\"", rc, sqlite3_errmsg(db), sql); printe(PT_Error); return 0; } rc = sqlite3_column_count(sqlstmt); if (rc != 4) { snprintf(errorstring, 1024, "Get data returned unexpected column count %d instead of 4: \"%s\"", rc, sql); printe(PT_Error); sqlite3_finalize(sqlstmt); return 0; } while (sqlite3_step(sqlstmt) == SQLITE_ROW) { rowid = (int64_t)sqlite3_column_int64(sqlstmt, 0); timestamp = (time_t)sqlite3_column_int64(sqlstmt, 1); rx = (uint64_t)sqlite3_column_int64(sqlstmt, 2); tx = (uint64_t)sqlite3_column_int64(sqlstmt, 3); if (!dbdatalistadd(dbdata, rx, tx, timestamp, rowid)) { snprintf(errorstring, 1024, "Storing data for processing failed: %s", strerror(errno)); printe(PT_Error); ret = 0; break; } updatelistinfo(listinfo, rx, tx, timestamp); } sqlite3_finalize(sqlstmt); /* clean list on failure */ if (!ret) { dbdatalistfree(dbdata); listinfo->count = 0; } return ret; } void updatelistinfo(dbdatalistinfo *listinfo, const uint64_t rx, const uint64_t tx, const time_t timestamp) { if (listinfo->count == 0) { listinfo->maxtime = timestamp; listinfo->mintime = timestamp; listinfo->maxrx = rx; listinfo->minrx = rx; listinfo->maxtx = tx; listinfo->mintx = tx; listinfo->min = rx + tx; listinfo->max = rx + tx; listinfo->sumrx = rx; listinfo->sumtx = tx; } else { if (timestamp > listinfo->maxtime) { listinfo->maxtime = timestamp; } if (timestamp < listinfo->mintime) { listinfo->mintime = timestamp; } if (rx < listinfo->minrx) { listinfo->minrx = rx; } if (tx < listinfo->mintx) { listinfo->mintx = tx; } if (rx > listinfo->maxrx) { listinfo->maxrx = rx; } if (tx > listinfo->maxtx) { listinfo->maxtx = tx; } if (rx + tx > listinfo->max) { listinfo->max = rx + tx; } if (rx + tx < listinfo->min) { listinfo->min = rx + tx; } listinfo->sumrx += rx; listinfo->sumtx += tx; } listinfo->count++; } int dbdatalistadd(dbdatalist **dbdata, const uint64_t rx, const uint64_t tx, const time_t timestamp, const int64_t rowid) { dbdatalist *newdata; newdata = malloc(sizeof(dbdatalist)); if (newdata == NULL) { return 0; } newdata->next = *dbdata; *dbdata = newdata; newdata->rowid = rowid; newdata->timestamp = timestamp; newdata->rx = rx; newdata->tx = tx; return 1; } void dbdatalistfree(dbdatalist **dbdata) { dbdatalist *dbdata_prev; while (*dbdata != NULL) { dbdata_prev = *dbdata; *dbdata = (*dbdata)->next; free(dbdata_prev); } } unsigned int getqueryinterfacecount(const char *input) { unsigned int i, ifacecount = 1; if (!strlen(input) || input[0] == '+' || input[strlen(input) - 1] == '+') { return 0; } for (i = 0; i < (unsigned int)strlen(input); i++) { if (input[i] == '+') { if (i > 0 && input[i - 1] == '+') { return 0; } else { ifacecount++; } } } return ifacecount; } char *getifaceinquery(const char *input) { unsigned int i, j, ifacecount; char *result; ifacecount = getqueryinterfacecount(input); if (ifacecount == 0) { return NULL; } /* each interface requires two quotes and comma or \0 so 3 extra chars */ j = (unsigned int)strlen(input) + ifacecount * 3; result = malloc(sizeof(char) * j); if (result == NULL) { panicexit(__FILE__, __LINE__); } memset(result, '\0', j); result[0] = '"'; j = 1; for (i = 0; i < (unsigned int)strlen(input); i++) { if (input[i] == '+') { strcat(result, "\",\""); j += 3; } else { result[j] = input[i]; j++; } } result[j] = '"'; return result; } vnstat-2.9/src/dbjson.h0000644000000000000000000000061013422305427013617 0ustar rootroot#ifndef DBJSON_H #define DBJSON_H void showjson(const char *interface, const int ifcount, const char mode, const char *databegin, const char *dataend); void jsondump(const interfaceinfo *interface, const char *tablename, const int datetype, const char *databegin, const char *dataend); void jsondate(const time_t *date, const int type); void jsonheader(void); void jsonfooter(void); #endif vnstat-2.9/src/id.h0000644000000000000000000000027413454462161012746 0ustar rootroot#ifndef ID_H #define ID_H uid_t getuser(const char *user); gid_t getgroup(const char *group); void setuser(const char *user); void setgroup(const char *group); int hasroot(void); #endif vnstat-2.9/src/traffic.c0000644000000000000000000002652714072143525013771 0ustar rootroot#include "common.h" #include "ifinfo.h" #include "misc.h" #include "traffic.h" void trafficmeter(const char *iface, unsigned int sampletime) { /* received bytes packets errs drop fifo frame compressed multicast */ /* transmitted bytes packets errs drop fifo colls carrier compressed */ uint64_t rx, tx, rxp, txp; int json = 0; IFINFO firstinfo; char buffer[256]; if (cfg.qmode == 10) { json = 1; } #ifndef CHECK_VNSTAT /* less than 2 seconds doesn't produce good results */ if (sampletime < 2) { printf("Error: Time for sampling too short.\n"); exit(EXIT_FAILURE); } #endif /* read interface info and get values to the first list */ if (!getifinfo(iface)) { printf("Error: Interface \"%s\" not available, exiting.\n", iface); exit(EXIT_FAILURE); } firstinfo.rx = ifinfo.rx; firstinfo.tx = ifinfo.tx; firstinfo.rxp = ifinfo.rxp; firstinfo.txp = ifinfo.txp; /* wait sampletime and print some nice dots so that the user thinks something is done :) */ if (!json) { snprintf(buffer, 256, "Sampling %s (%u seconds average)", iface, sampletime); printf("%s", buffer); fflush(stdout); sleep(sampletime / 3); printf("."); fflush(stdout); sleep(sampletime / 3); printf("."); fflush(stdout); sleep(sampletime / 3); printf("."); fflush(stdout); if ((sampletime / 3) * 3 != sampletime) { sleep(sampletime - ((sampletime / 3) * 3)); } cursortocolumn(1); eraseline(); } else { sleep(sampletime); } #ifdef CHECK_VNSTAT sampletime = 1; #endif /* read those values again... */ if (!getifinfo(iface)) { printf("Error: Interface \"%s\" not available, exiting.\n", iface); exit(EXIT_FAILURE); } /* calculate traffic and packets seen between updates */ rx = countercalc(&firstinfo.rx, &ifinfo.rx, ifinfo.is64bit); tx = countercalc(&firstinfo.tx, &ifinfo.tx, ifinfo.is64bit); rxp = countercalc(&firstinfo.rxp, &ifinfo.rxp, ifinfo.is64bit); txp = countercalc(&firstinfo.txp, &ifinfo.txp, ifinfo.is64bit); /* show the difference in a readable format or json */ if (!json) { printf("%" PRIu64 " packets sampled in %d seconds\n", rxp + txp, sampletime); printf("Traffic average for %s\n", iface); printf("\n rx %s %5" PRIu64 " packets/s\n", gettrafficrate(rx, sampletime, 15), (uint64_t)(rxp / sampletime)); printf(" tx %s %5" PRIu64 " packets/s\n\n", gettrafficrate(tx, sampletime, 15), (uint64_t)(txp / sampletime)); } else { printf("{\"jsonversion\":\"%d\",", JSONVERSION_TR); printf("\"vnstatversion\":\"%s\",", getversion()); printf("\"interface\":\"%s\",", iface); printf("\"sampletime\":%u,", sampletime); printf("\"rx\":{"); printf("\"ratestring\":\"%s\",", gettrafficrate(rx, sampletime, 0)); printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(rx / sampletime)); printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(rxp / sampletime)); printf("\"bytes\":%" PRIu64 ",", rx); printf("\"packets\":%" PRIu64 "", rxp); printf("},"); printf("\"tx\":{"); printf("\"ratestring\":\"%s\",", gettrafficrate(tx, sampletime, 0)); printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(tx / sampletime)); printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(txp / sampletime)); printf("\"bytes\":%" PRIu64 ",", tx); printf("\"packets\":%" PRIu64 "", txp); printf("}}\n"); } } void livetrafficmeter(const char *iface, const int mode) { /* received bytes packets errs drop fifo frame compressed multicast */ /* transmitted bytes packets errs drop fifo colls carrier compressed */ uint64_t rx, tx, rxp, txp, timespent, timeslept; uint64_t rxtotal, txtotal, rxptotal, txptotal; uint64_t rxpmin, txpmin, rxpmax, txpmax; uint64_t rxmin, txmin, rxmax, txmax; uint64_t index = 1; int ratewidth, ppswidth, paddingwidth, json = 0; char buffer[256], buffer2[256]; IFINFO previnfo; if (cfg.qmode == 10) { json = 1; } if (!json) { printf("Monitoring %s... (press CTRL-C to stop)\n\n", iface); if (cfg.ostyle != 4) { printf(" getting traffic..."); fflush(stdout); } } /* enable signal trap */ intsignal = 0; if (signal(SIGINT, sighandler) == SIG_ERR) { perror("signal"); exit(EXIT_FAILURE); } /* set some defaults */ rxtotal = txtotal = rxptotal = txptotal = rxpmax = txpmax = 0; rxpmin = txpmin = rxmin = txmin = MAX64; rxmax = txmax = 0; timeslept = 0; timespent = (uint64_t)time(NULL); /* read /proc/net/dev and get values to the first list */ if (!getifinfo(iface)) { printf("Error: Interface \"%s\" not available, exiting.\n", iface); exit(EXIT_FAILURE); } ratewidth = 15; ppswidth = 5; paddingwidth = 8; /* narrow output mode */ if (cfg.ostyle == 0) { ratewidth = 12; ppswidth = 3; paddingwidth = 4; } if (!json) { cursorhide(); } else { printf("{\"jsonversion\":\"%d\",", JSONVERSION_LIVE); printf("\"vnstatversion\":\"%s\",", getversion()); printf("\"interface\":\"%s\",", iface); printf("\"sampletime\":%d}\n", LIVETIME); } /* loop until user gets bored */ while (intsignal == 0) { timeslept = (uint64_t)time(NULL); #ifndef CHECK_VNSTAT /* wait 2 seconds for more traffic */ sleep(LIVETIME); #endif timeslept = (uint64_t)time(NULL) - timeslept; /* break loop without calculations because sleep was probably interrupted */ if (intsignal) { break; } /* use values from previous loop if this isn't the first time */ previnfo.rx = ifinfo.rx; previnfo.tx = ifinfo.tx; previnfo.rxp = ifinfo.rxp; previnfo.txp = ifinfo.txp; /* read those values again... */ if (!getifinfo(iface)) { cursorshow(); printf("Error: Interface \"%s\" not available, exiting.\n", iface); exit(EXIT_FAILURE); } /* calculate traffic and packets seen between updates */ rx = countercalc(&previnfo.rx, &ifinfo.rx, ifinfo.is64bit); tx = countercalc(&previnfo.tx, &ifinfo.tx, ifinfo.is64bit); rxp = countercalc(&previnfo.rxp, &ifinfo.rxp, ifinfo.is64bit); txp = countercalc(&previnfo.txp, &ifinfo.txp, ifinfo.is64bit); /* update totals */ rxtotal += rx; txtotal += tx; rxptotal += rxp; txptotal += txp; /* update min & max */ if (rxmin > rx) { rxmin = rx; } if (txmin > tx) { txmin = tx; } if (rxmax < rx) { rxmax = rx; } if (txmax < tx) { txmax = tx; } if (rxpmin > rxp) { rxpmin = rxp; } if (txpmin > txp) { txpmin = txp; } if (rxpmax < rxp) { rxpmax = rxp; } if (txpmax < txp) { txpmax = txp; } /* show the difference in a readable format or json */ if (!json) { if (mode == 0) { /* packets per second visible */ snprintf(buffer, 128, " rx: %s %*" PRIu64 " p/s", gettrafficrate(rx, LIVETIME, ratewidth), ppswidth, rxp / LIVETIME); snprintf(buffer2, 128, " %*s tx: %s %*" PRIu64 " p/s", paddingwidth, " ", gettrafficrate(tx, LIVETIME, ratewidth), ppswidth, txp / LIVETIME); } else { /* total transfer amount visible */ snprintf(buffer, 128, " rx: %s %s", gettrafficrate(rx, LIVETIME, ratewidth), getvalue(rxtotal, 1, RT_Normal)); snprintf(buffer2, 128, " %*s tx: %s %s", paddingwidth, " ", gettrafficrate(tx, LIVETIME, ratewidth), getvalue(txtotal, 1, RT_Normal)); } strcat(buffer, buffer2); if (cfg.ostyle != 4 || !debug) { cursortocolumn(1); eraseline(); } if (cfg.ostyle != 4) { printf("%s", buffer); } else { printf("%s\n", buffer); } } else { printf("{\"index\":%" PRIu64 ",", index); printf("\"seconds\":%" PRIu64 ",", (uint64_t)time(NULL) - timespent); printf("\"rx\":{"); printf("\"ratestring\":\"%s\",", gettrafficrate(rx, LIVETIME, 0)); printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(rx / LIVETIME)); printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(rxp / LIVETIME)); printf("\"bytes\":%" PRIu64 ",", rx); printf("\"packets\":%" PRIu64 ",", rxp); printf("\"totalbytes\":%" PRIu64 ",", rxtotal); printf("\"totalpackets\":%" PRIu64 "", rxptotal); printf("},"); printf("\"tx\":{"); printf("\"ratestring\":\"%s\",", gettrafficrate(tx, LIVETIME, 0)); printf("\"bytespersecond\":%" PRIu64 ",", (uint64_t)(tx / LIVETIME)); printf("\"packetspersecond\":%" PRIu64 ",", (uint64_t)(txp / LIVETIME)); printf("\"bytes\":%" PRIu64 ",", tx); printf("\"packets\":%" PRIu64 ",", txp); printf("\"totalbytes\":%" PRIu64 ",", txtotal); printf("\"totalpackets\":%" PRIu64 "", txptotal); printf("}}\n"); index++; } fflush(stdout); #ifdef CHECK_VNSTAT break; #endif } timespent = (uint64_t)time(NULL) - timespent - timeslept; #ifdef CHECK_VNSTAT timespent = 10; #endif if (!json) { cursorshow(); printf("\n\n"); } /* print some statistics if enough time did pass */ if (!json && timespent >= 10) { printf("\n %s / traffic statistics\n\n", iface); printf(" rx | tx\n"); printf("--------------------------------------+------------------\n"); printf(" bytes %s", getvalue(rxtotal, 15, RT_Normal)); printf(" | %s", getvalue(txtotal, 15, RT_Normal)); printf("\n"); printf("--------------------------------------+------------------\n"); printf(" max %s", gettrafficrate(rxmax, LIVETIME, 15)); printf(" | %s\n", gettrafficrate(txmax, LIVETIME, 15)); printf(" average %s", gettrafficrate(rxtotal, (time_t)timespent, 15)); printf(" | %s\n", gettrafficrate(txtotal, (time_t)timespent, 15)); printf(" min %s", gettrafficrate(rxmin, LIVETIME, 15)); printf(" | %s\n", gettrafficrate(txmin, LIVETIME, 15)); printf("--------------------------------------+------------------\n"); printf(" packets %12" PRIu64 " | %12" PRIu64 "\n", rxptotal, txptotal); printf("--------------------------------------+------------------\n"); printf(" max %9" PRIu64 " p/s | %9" PRIu64 " p/s\n", rxpmax / LIVETIME, txpmax / LIVETIME); printf(" average %9" PRIu64 " p/s | %9" PRIu64 " p/s\n", rxptotal / timespent, txptotal / timespent); printf(" min %9" PRIu64 " p/s | %9" PRIu64 " p/s\n", rxpmin / LIVETIME, txpmin / LIVETIME); printf("--------------------------------------+------------------\n"); if (timespent <= 60) { printf(" time %9" PRIu64 " seconds\n", timespent); } else { printf(" time %7.2f minutes\n", (double)timespent / (double)60); } printf("\n"); } else if (json) { printf("{\"seconds\":%" PRIu64 ",", timespent); printf("\"rx\":{"); printf("\"maxratestring\":\"%s\",", gettrafficrate(rxmax, LIVETIME, 0)); printf("\"averageratestring\":\"%s\",", gettrafficrate(rxtotal, (time_t)timespent, 0)); printf("\"minratestring\":\"%s\",", gettrafficrate(rxmin, LIVETIME, 0)); printf("\"totalbytes\":%" PRIu64 ",", rxtotal); printf("\"maxbytes\":%" PRIu64 ",", rxmax); printf("\"minbytes\":%" PRIu64 ",", rxmin); printf("\"totalpackets\":%" PRIu64 ",", rxptotal); printf("\"maxpackets\":%" PRIu64 ",", rxpmax); printf("\"minpackets\":%" PRIu64 "", rxpmin); printf("},"); printf("\"tx\":{"); printf("\"maxratestring\":\"%s\",", gettrafficrate(txmax, LIVETIME, 0)); printf("\"averageratestring\":\"%s\",", gettrafficrate(txtotal, (time_t)timespent, 0)); printf("\"minratestring\":\"%s\",", gettrafficrate(txmin, LIVETIME, 0)); printf("\"totalbytes\":%" PRIu64 ",", txtotal); printf("\"maxbytes\":%" PRIu64 ",", txmax); printf("\"minbytes\":%" PRIu64 ",", txmin); printf("\"totalpackets\":%" PRIu64 ",", txptotal); printf("\"maxpackets\":%" PRIu64 ",", txpmax); printf("\"minpackets\":%" PRIu64 "", txpmin); printf("}}\n"); } } vnstat-2.9/src/misc.c0000644000000000000000000003124614162675541013310 0ustar rootroot#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__APPLE__) && !defined(__FreeBSD_kernel__) #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wreserved-id-macro" #endif #define _XOPEN_SOURCE 600 #if defined(__clang__) #pragma clang diagnostic pop #endif #endif /* enable wcswidth on kFreeBSD */ #if defined(__FreeBSD_kernel__) && defined(__GLIBC__) #define __USE_XOPEN #define _XOPEN_SOURCE #endif #include "common.h" #include "misc.h" #include int spacecheck(const char *path) { struct statvfs buf; uint64_t free; /* do space check only when configured for it */ if (!cfg.spacecheck) { return 1; } if (statvfs(path, &buf)) { if (noexit) { return 0; } else { snprintf(errorstring, 1024, "Free diskspace check failed: %s", strerror(errno)); printe(PT_Error); exit(EXIT_FAILURE); } } free = (uint64_t)((double)buf.f_bavail / (double)1024) * buf.f_bsize; if (debug) { printf("bsize %d\n", (int)buf.f_bsize); printf("blocks %lu\n", (unsigned long int)buf.f_blocks); printf("bfree %lu\n", (unsigned long int)buf.f_bfree); printf("bavail %lu\n", (unsigned long int)buf.f_bavail); printf("ffree %lu\n", (unsigned long int)buf.f_ffree); printf("%" PRIu64 " free space left\n", free); } /* the database is likely to be less than 200 kiB but let's require */ /* 1 MiB to be on the safe side, anyway, the filesystem should */ /* always have more free space than that */ if (free <= 1024) { return 0; } else { return 1; } } void sighandler(int sig) { /* set signal */ intsignal = sig; if (debug) { switch (sig) { case SIGHUP: snprintf(errorstring, 1024, "DEBUG: SIGHUP (%d)", sig); break; case SIGTERM: snprintf(errorstring, 1024, "DEBUG: SIGTERM (%d)", sig); break; case SIGINT: snprintf(errorstring, 1024, "DEBUG: SIGINT (%d)", sig); break; default: snprintf(errorstring, 1024, "DEBUG: Unknown signal %d", sig); break; } printe(PT_Info); } } uint64_t getbtime(void) { uint64_t result = 0; #if defined(__linux__) FILE *fp; int check; char temp[64], statline[128]; if ((fp = fopen("/proc/stat", "r")) == NULL) { snprintf(errorstring, 1024, "Unable to read /proc/stat: %s", strerror(errno)); printe(PT_Error); if (noexit) { return 0; } else { exit(1); } } check = 0; while (fgets(statline, 128, fp) != NULL) { sscanf(statline, "%63s", temp); if (strcmp(temp, "btime") == 0) { /* if (debug) printf("\n%s\n",statline); */ check = 1; break; } } fclose(fp); if (check == 0) { snprintf(errorstring, 1024, "btime missing from /proc/stat."); printe(PT_Error); if (noexit) { return 0; } else { exit(1); } } result = strtoull(statline + 6, (char **)NULL, 0); #elif defined(BSD_VNSTAT) struct timeval btm; size_t len = sizeof(btm); int mib[2] = {CTL_KERN, KERN_BOOTTIME}; if (sysctl(mib, 2, &btm, &len, NULL, 0) < 0) { if (debug) printf("sysctl(kern.boottime) failed.\n"); return 0; } result = (uint64_t)btm.tv_sec; #endif return result; } char *getvalue(const uint64_t bytes, const int len, const RequestType type) { static char buffer[64]; int i, declen = cfg.defaultdecimals, p = 1024; uint64_t limit; if (type == RT_ImageScale) { declen = 0; } if (cfg.unitmode == 2) { p = 1000; } if ((type == RT_Estimate) && (bytes == 0)) { declen = len - (int)strlen(getunitprefix(2)) - 2; if (declen < 2) { declen = 2; } snprintf(buffer, 64, "%*s %*s", declen, "--", (int)strlen(getunitprefix(2)), " "); } else { for (i = UNITPREFIXCOUNT - 1; i > 0; i--) { limit = (uint64_t)(pow(p, i - 1)) * 1000; if (bytes >= limit) { if (i > 1) { snprintf(buffer, 64, "%" DECCONV "*.*f %s", getunitspacing(len, 5), declen, (double)bytes / (double)(getunitdivisor(cfg.unitmode, i + 1)), getunitprefix(i + 1)); } else { if (type == RT_Estimate) { declen = 0; } snprintf(buffer, 64, "%" DECCONV "*.*f %s", getunitspacing(len, 2), declen, (double)bytes / (double)(getunitdivisor(cfg.unitmode, i + 1)), getunitprefix(i + 1)); } return buffer; } } snprintf(buffer, 64, "%" DECCONV "*" PRIu64 " %s", getunitspacing(len, 1), bytes, getunitprefix(1)); } return buffer; } int getunitspacing(const int len, const int index) { int l = len; /* tune spacing according to unit */ /* +1 for space between number and unit */ l -= (int)strlen(getunitprefix(index)) + 1; if (l < 0) { l = 1; } return l; } char *gettrafficrate(const uint64_t bytes, const time_t interval, const int len) { static char buffer[64]; int declen = cfg.defaultdecimals; uint64_t b = bytes; if (interval == 0) { snprintf(buffer, 64, "%*s", len, "n/a"); return buffer; } /* convert to proper unit */ if (cfg.rateunit == 1) { b *= 8; } return getratestring(b / (uint64_t)interval, len, declen); } const char *getunitprefix(const int index) { /* clang-format off */ static const char *unitprefix[] = { "na", "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", /* IEC - 1024^n */ "B", "KB", "MB", "GB", "TB", "PB", "EB", /* JEDEC - 1024^n */ "B", "kB", "MB", "GB", "TB", "PB", "EB" }; /* SI - 1000^n */ /* clang-format on */ if (index > UNITPREFIXCOUNT) { return unitprefix[0]; } else { return unitprefix[(cfg.unitmode * UNITPREFIXCOUNT) + index]; } } const char *getrateunitprefix(const int unitmode, const int index) { /* clang-format off */ static const char *rateunitprefix[] = { "na", "B/s", "KiB/s", "MiB/s", "GiB/s", "TiB/s", "PiB/s", "EiB/s", /* IEC - 1024^n */ "B/s", "KB/s", "MB/s", "GB/s", "TB/s", "PB/s", "EB/s", /* JEDEC - 1024^n */ "B/s", "kB/s", "MB/s", "GB/s", "TB/s", "PB/s", "EB/s", /* SI - 1000^n */ "bit/s", "Kibit/s", "Mibit/s", "Gibit/s", "Tibit/s", "Pibit/s", "Eibit/s", /* IEC - 1024^n */ "bit/s", "kbit/s", "Mbit/s", "Gbit/s", "Tbit/s", "Pbit/s", "Ebit/s" }; /* SI - 1000^n */ /* clang-format on */ if (index > UNITPREFIXCOUNT) { return rateunitprefix[0]; } else { return rateunitprefix[(unitmode * UNITPREFIXCOUNT) + index]; } } uint64_t getunitdivisor(const int unitmode, const int index) { if (index > UNITPREFIXCOUNT) { return 1; } else { if (unitmode == 2 || unitmode == 4) { return (uint64_t)(pow(1000, index - 1)); } else { return (uint64_t)(pow(1024, index - 1)); } } } int getunit(void) { int unit; if (cfg.rateunit == 0) { unit = cfg.unitmode; } else { unit = 3 + cfg.rateunitmode; } return unit; } char *getratestring(const uint64_t rate, const int len, const int declen) { int l, i, unit, p = 1024; static char buffer[64]; uint64_t limit; unit = getunit(); if (unit == 2 || unit == 4) { p = 1000; } for (i = UNITPREFIXCOUNT - 1; i > 0; i--) { limit = (uint64_t)(pow(p, i - 1)) * 1000; if (rate >= limit) { l = getratespacing(len, unit, i + 1); snprintf(buffer, 64, "%" DECCONV "*.*f %s", l, declen, (double)rate / (double)(getunitdivisor(unit, i + 1)), getrateunitprefix(unit, i + 1)); return buffer; } } l = getratespacing(len, unit, 1); snprintf(buffer, 64, "%" DECCONV "*.0f %s", l, (double)rate / (double)(getunitdivisor(unit, 1)), getrateunitprefix(unit, 1)); return buffer; } int getratespacing(const int len, const int unitmode, const int unitindex) { int l = len; l -= (int)strlen(getrateunitprefix(unitmode, unitindex)) + 1; if (l < 0) { l = 1; } return l; } int getpadding(const int len, const char *str) { #if defined(HAVE_MBSTOWCS) && defined(HAVE_WCSWIDTH) wchar_t wbuffer[64]; if (!cfg.utflocale) { return len; } if ((int)mbstowcs(wbuffer, str, 64) < 0) { return len; } return len + ((int)strlen(str) - wcswidth(wbuffer, 64)); #else return len; #endif } void cursortocolumn(const int column) { printf("\033[%dG", column); } void cursorhide(void) { printf("\033[?25l"); } void cursorshow(void) { printf("\033[?25h"); } void eraseline(void) { printf("\033[2K"); } /* validity of date or time itself isn't checked here as sqlite handles that */ int validatedatetime(const char *str) { short valid; unsigned int len, i, t; const char *templates[] = {"dddd-dd-dd dd:dd", "dddd-dd-dd"}; len = (unsigned int)strlen(str); if (strcmp(str, "today") == 0) { return 1; } if (len > strlen(templates[0])) { return 0; } for (t = 0; t < 2; t++) { if (len != strlen(templates[t])) { continue; } valid = 1; for (i = 0; i < strlen(templates[t]); i++) { switch (templates[t][i]) { case 'd': if (!isdigit(str[i])) { valid = 0; } break; default: if (str[i] != templates[t][i]) { valid = 0; } break; } if (!valid) { break; } } if (!valid) { continue; } return 1; } return 0; } int issametimeslot(const ListType listtype, const time_t entry, const time_t updated) { struct tm e, u; if (updated < entry) { return 0; } if (entry == updated) { return 1; } if (localtime_r(&entry, &e) == NULL || localtime_r(&updated, &u) == NULL) { return 0; } switch (listtype) { case LT_5min: if ((entry - (entry % 300)) == (updated - (updated % 300))) { return 1; } break; case LT_Hour: if (e.tm_year == u.tm_year && e.tm_yday == u.tm_yday && e.tm_hour == u.tm_hour) { return 1; } break; case LT_Top: case LT_Day: if (e.tm_year == u.tm_year && e.tm_yday == u.tm_yday) { return 1; } break; case LT_Month: if (e.tm_year == u.tm_year && e.tm_mon == u.tm_mon) { return 1; } break; case LT_Year: if (e.tm_year == u.tm_year) { return 1; } break; case LT_None: return 0; } return 0; } uint64_t getperiodseconds(const ListType listtype, const time_t entry, const time_t updated, const short isongoing) { struct tm e, u; uint64_t seconds = 0; if (localtime_r(&entry, &e) == NULL || localtime_r(&updated, &u) == NULL) { return 0; } if (isongoing) { if (listtype == LT_Day) { seconds = (uint64_t)u.tm_sec + (uint64_t)u.tm_min * 60 + (uint64_t)u.tm_hour * 3600; } else if (listtype == LT_Month) { seconds = (uint64_t)mosecs(entry, updated); } else if (listtype == LT_Year) { seconds = (uint64_t)u.tm_yday * 86400 + (uint64_t)u.tm_sec + (uint64_t)u.tm_min * 60 + (uint64_t)u.tm_hour * 3600; } else if (listtype == LT_Top) { seconds = 86400; } else if (listtype == LT_Hour) { seconds = (uint64_t)u.tm_sec + (uint64_t)u.tm_min * 60; } else if (listtype == LT_5min) { seconds = (uint64_t)u.tm_sec + (uint64_t)u.tm_min % 5 * 60; } } else { if (listtype == LT_Day || listtype == LT_Top) { seconds = 86400; } else if (listtype == LT_Month) { seconds = (uint64_t)dmonth(e.tm_mon) * 86400; } else if (listtype == LT_Year) { seconds = (uint64_t)(365 + isleapyear(e.tm_year + 1900)) * 86400; } else if (listtype == LT_Hour) { seconds = 3600; } else if (listtype == LT_5min) { seconds = 300; } } return seconds; } void getestimates(uint64_t *rx, uint64_t *tx, const ListType listtype, const time_t updated, dbdatalist **dbdata) { struct tm u; uint64_t div = 0, mult = 0; dbdatalist *datalist_i = *dbdata; *rx = *tx = 0; if (datalist_i == NULL) { return; } if (localtime_r(&updated, &u) == NULL) { return; } /* last entry on the list is the most recent entry */ while (datalist_i->next != NULL) { datalist_i = datalist_i->next; } if (datalist_i->rx == 0 || datalist_i->tx == 0) { return; } /* LT_5min and LT_Hour don't have the estimate line visible in outputs */ /* but are used by BarColumnShowsRate which requires "past" values for */ /* full hours / 5 minutes for the bar to show correctly */ if (listtype == LT_5min) { div = ((uint64_t)u.tm_min % 5 * 60) + (uint64_t)u.tm_sec; if (div == 0) { div = 1; mult = 1; } else { mult = 300; } } else if (listtype == LT_Hour) { div = (uint64_t)u.tm_min * 60 + (uint64_t)u.tm_sec; if (div == 0) { div = 1; mult = 1; } else { mult = 3600; } } else if (listtype == LT_Day) { div = (uint64_t)u.tm_hour * 3600 + (uint64_t)u.tm_min * 60 + (uint64_t)u.tm_sec; mult = 86400; } else if (listtype == LT_Month) { div = (uint64_t)mosecs(datalist_i->timestamp, updated); mult = (uint64_t)dmonth(u.tm_mon) * 86400; } else if (listtype == LT_Year) { div = (uint64_t)u.tm_yday * 1440 + (uint64_t)u.tm_hour * 60 + (uint64_t)u.tm_min; mult = (uint64_t)(365 + isleapyear(u.tm_year + 1900)) * 1440; } if (div > 0) { *rx = (uint64_t)((double)datalist_i->rx / (double)div) * mult; *tx = (uint64_t)((double)datalist_i->tx / (double)div) * mult; } } int ishelprequest(const char *arg) { if (strlen(arg) == 0) { return 0; } if (strlen(arg) == 1 && arg[0] == '?') { return 1; } else if ((strcmp(arg, "-?") == 0) || (strcmp(arg, "--help") == 0)) { return 1; } return 0; } vnstat-2.9/src/cfg.h0000644000000000000000000000150314076272310013101 0ustar rootroot#ifndef CFG_H #define CFG_H struct cfgsetting { const char *name; char *locc; int32_t *loci; short namelen; short found; }; typedef enum ConfigType { CT_All = 0, CT_CLI, CT_Daemon, CT_Image } ConfigType; int loadcfg(const char *cfgfile, const ConfigType type); void validatebool(const char *cfgname, int32_t *cfgptr, const int32_t defaultvalue); void validateint(const char *cfgname, int32_t *cfgptr, const int32_t defaultvalue, const int32_t minvalue, const int32_t maxvalue); void validatecfg(const ConfigType type); void defaultcfg(void); int opencfgfile(const char *cfgfile, FILE **fd); int extractcfgvalue(char *value, const unsigned int valuelen, const char *cfgline, const unsigned int cfglen); int setcfgvalue(const struct cfgsetting *cset, const char *value, const char *cfgline); void configlocale(void); #endif vnstat-2.9/src/dbaccess.c0000644000000000000000000003177513537742633014135 0ustar rootroot#include "common.h" #include "dbsql.h" #include "dbaccess.h" int importlegacydb(const char *iface, const char *dirname) { DATA data; snprintf(errorstring, 1024, "Importing data from legacy database \"%s\".", iface); printe(PT_Infoless); if (db_getinterfacecountbyname(iface)) { return 0; } if (readdb(&data, iface, dirname, 0) != 0) { return 0; } if (!db_addinterface(iface)) { return 0; } if (!insertlegacydata(&data, iface)) { return 0; } return 1; } int insertlegacydata(DATA *data, const char *iface) { int i, year; time_t yeartime; struct tm *stm; uint64_t rx, tx; if (!db_begintransaction()) { return 0; } if (!db_setactive(iface, data->active)) { db_rollbacktransaction(); return 0; } if (strcmp(iface, data->nick) != 0) { if (!db_setalias(iface, data->nick)) { db_rollbacktransaction(); return 0; } } if (!db_setcounters(iface, data->currx, data->curtx)) { db_rollbacktransaction(); return 0; } if (!db_setcreation(iface, data->created)) { db_rollbacktransaction(); return 0; } for (i = 23; i >= 0; i--) { if (data->hour[i].date > 0 && (data->hour[i].rx > 0 || data->hour[i].tx > 0)) { if (!db_insertdata("hour", iface, data->hour[i].rx * 1024, data->hour[i].tx * 1024, (uint64_t)data->hour[i].date)) { db_rollbacktransaction(); return 0; } } } for (i = 29; i >= 0; i--) { if (data->day[i].used) { if (!db_insertdata("day", iface, data->day[i].rx * 1024 * 1024 + (uint64_t)data->day[i].rxk * 1024, data->day[i].tx * 1024 * 1024 + (uint64_t)data->day[i].txk * 1024, (uint64_t)data->day[i].date)) { db_rollbacktransaction(); return 0; } } } for (i = 11; i >= 0; i--) { if (data->month[i].used) { if (!db_insertdata("month", iface, data->month[i].rx * 1024 * 1024 + (uint64_t)data->month[i].rxk * 1024, data->month[i].tx * 1024 * 1024 + (uint64_t)data->month[i].txk * 1024, (uint64_t)data->month[i].month)) { db_rollbacktransaction(); return 0; } } } for (i = 9; i >= 0; i--) { if (data->top10[i].used) { if (!db_insertdata("top", iface, data->top10[i].rx * 1024 * 1024 + (uint64_t)data->top10[i].rxk * 1024, data->top10[i].tx * 1024 * 1024 + (uint64_t)data->top10[i].txk * 1024, (uint64_t)data->top10[i].date)) { db_rollbacktransaction(); return 0; } } } /* construct yearly data from legacy monthly data */ rx = 0; tx = 0; year = 0; yeartime = 0; for (i = 11; i >= 0; i--) { if (!data->month[i].used) { continue; } stm = localtime(&data->month[i].month); /* sanity check for possible invalid data */ if (stm->tm_year + 1900 <= 1980 || stm->tm_year + 1900 >= 2050) { continue; } if (stm->tm_year + 1900 != year) { if (year != 0 && (rx > 0 || tx > 0)) { if (!db_insertdata("year", iface, rx, tx, (uint64_t)yeartime)) { db_rollbacktransaction(); return 0; } } year = stm->tm_year + 1900; yeartime = data->month[i].month; rx = 0; tx = 0; } rx += data->month[i].rx * 1024 * 1024 + (uint64_t)data->month[i].rxk * 1024; tx += data->month[i].tx * 1024 * 1024 + (uint64_t)data->month[i].txk * 1024; } if (year != 0 && (rx > 0 || tx > 0)) { if (!db_insertdata("year", iface, rx, tx, (uint64_t)yeartime)) { db_rollbacktransaction(); return 0; } } if (!db_settotal(iface, data->totalrx * 1024 * 1024 + (uint64_t)data->totalrxk * 1024, data->totaltx * 1024 * 1024 + (uint64_t)data->totaltxk * 1024)) { db_rollbacktransaction(); return 0; } return db_committransaction(); } int readdb(DATA *data, const char *iface, const char *dirname, const int force) { FILE *legacydb; char file[512], backup[512]; snprintf(file, 512, "%s/%s", dirname, iface); snprintf(backup, 512, "%s/.%s", dirname, iface); if ((legacydb = fopen(file, "r")) == NULL) { snprintf(errorstring, 1024, "Unable to read database \"%s\": %s", file, strerror(errno)); printe(PT_Error); /* create new database template */ initdb(data); strncpy_nt(data->interface, iface, 32); strncpy_nt(data->nick, data->interface, 32); return 1; } if (fread(data, sizeof(DATA), 1, legacydb) != 1 || ferror(legacydb)) { data->version = -1; if (debug) { printf("db: Database read failed for file \"%s\".\n", file); } } else { if (debug) { data->interface[sizeof(data->interface) - 1] = '\0'; printf("db: Database loaded for interface \"%s\"...\n", data->interface); } } data->interface[sizeof(data->interface) - 1] = '\0'; data->nick[sizeof(data->nick) - 1] = '\0'; if (data->version == LEGACYDBVERSION) { if (!validatedb(data) && !force) { data->version = -1; if (debug) { printf("db: Database for interface \"%s\" fails to validate, trying with backup\n", data->interface); } } } /* convert old database to new format if necessary */ if (data->version < LEGACYDBVERSION) { if (data->version == -1) { /* close current db and try using backup if database conversion failed */ fclose(legacydb); if ((legacydb = fopen(backup, "r")) == NULL) { snprintf(errorstring, 1024, "Unable to open backup database \"%s\": %s", backup, strerror(errno)); printe(PT_Error); if (noexit) { return -1; } else { exit(EXIT_FAILURE); } } if (fread(data, sizeof(DATA), 1, legacydb) != 1 || ferror(legacydb)) { snprintf(errorstring, 1024, "Database load failed even when using backup (%s). Aborting.", strerror(errno)); printe(PT_Error); fclose(legacydb); if (noexit) { return -1; } else { exit(EXIT_FAILURE); } } else { if (debug) { data->interface[sizeof(data->interface) - 1] = '\0'; printf("db: Backup database loaded for interface \"%s\"...\n", data->interface); } } data->interface[sizeof(data->interface) - 1] = '\0'; data->nick[sizeof(data->nick) - 1] = '\0'; if (data->version == LEGACYDBVERSION) { if (!validatedb(data)) { data->version = -1; if (debug) { printf("db: Backup database for interface \"%s\" fails to validate\n", data->interface); } } } if (data->version != LEGACYDBVERSION) { if (data->version == -1) { snprintf(errorstring, 1024, "Unable to use database \"%s\" or its backup.", file); printe(PT_Error); fclose(legacydb); if (noexit) { return -1; } else { exit(EXIT_FAILURE); } } } snprintf(errorstring, 1024, "Database possibly corrupted, using backup instead."); printe(PT_Info); } } else if (data->version > LEGACYDBVERSION) { snprintf(errorstring, 1024, "Downgrading database \"%s\" (v%d) is not supported.", file, data->version); printe(PT_Error); fclose(legacydb); if (noexit) { return -1; } else { exit(EXIT_FAILURE); } } fclose(legacydb); if (strcmp(data->interface, iface)) { snprintf(errorstring, 1024, "Warning:\nThe previous interface for this file was \"%s\".", data->interface); printe(PT_Multiline); snprintf(errorstring, 1024, "It has now been replaced with \"%s\".", iface); printe(PT_Multiline); snprintf(errorstring, 1024, "You can ignore this message if you renamed the filename."); printe(PT_Multiline); snprintf(errorstring, 1024, "Interface name mismatch, renamed \"%s\" -> \"%s\"", data->interface, iface); printe(PT_ShortMultiline); if (strcmp(data->interface, data->nick) == 0) { strncpy_nt(data->nick, iface, 32); } strncpy_nt(data->interface, iface, 32); } return 0; } void initdb(DATA *data) { int i; time_t current; struct tm *d; current = time(NULL); d = localtime(¤t); /* set default values for a new database */ data->version = LEGACYDBVERSION; data->active = 1; data->totalrx = 0; data->totaltx = 0; data->currx = 0; data->curtx = 0; data->totalrxk = 0; data->totaltxk = 0; data->lastupdated = current; data->created = current; /* days */ for (i = 0; i <= 29; i++) { data->day[i].rx = 0; data->day[i].tx = 0; data->day[i].rxk = 0; data->day[i].txk = 0; data->day[i].date = 0; data->day[i].used = 0; } /* months */ for (i = 0; i <= 11; i++) { data->month[i].rx = 0; data->month[i].tx = 0; data->month[i].rxk = 0; data->month[i].txk = 0; data->month[i].month = 0; data->month[i].used = 0; } /* top10 */ for (i = 0; i <= 9; i++) { data->top10[i].rx = 0; data->top10[i].tx = 0; data->top10[i].rxk = 0; data->top10[i].txk = 0; data->top10[i].date = 0; data->top10[i].used = 0; } /* hours */ for (i = 0; i <= 23; i++) { data->hour[i].rx = 0; data->hour[i].tx = 0; data->hour[i].date = 0; } data->day[0].used = data->month[0].used = 1; data->day[0].date = current; /* calculate new date for current month if current day is less than the set monthrotate value so that new databases begin from the right month */ if (d->tm_mday < cfg.monthrotate) { d->tm_mday = cfg.monthrotate; d->tm_mon--; data->month[0].month = mktime(d); } else { data->month[0].month = current; } data->btime = MAX32; } int validatedb(DATA *data) { int i, used; uint64_t rxsum, txsum; const char *invaliddb = "Invalid database"; if (debug) { printf("validating loaded database\n"); } /* enforce string termination */ data->interface[sizeof(data->interface) - 1] = '\0'; data->nick[sizeof(data->nick) - 1] = '\0'; if (data->version > LEGACYDBVERSION) { snprintf(errorstring, 1024, "%s: %s version: %d", data->interface, invaliddb, data->version); printe(PT_Error); return 0; } if (data->active < 0 || data->active > 1) { snprintf(errorstring, 1024, "%s: %s activity status: %d", data->interface, invaliddb, data->active); printe(PT_Error); return 0; } if (!strlen(data->interface)) { snprintf(errorstring, 1024, "%s interface string: %s", invaliddb, data->interface); printe(PT_Error); return 0; } if (!data->created || !data->lastupdated || !data->btime) { snprintf(errorstring, 1024, "%s: %s timestamp.", data->interface, invaliddb); printe(PT_Error); return 0; } rxsum = txsum = 0; used = 1; for (i = 0; i < 30; i++) { if (data->day[i].used < 0 || data->day[i].used > 1) { snprintf(errorstring, 1024, "%s: %s daily use information: %d %d", data->interface, invaliddb, i, data->day[i].used); printe(PT_Error); return 0; } if (data->day[i].rxk < 0 || data->day[i].txk < 0) { snprintf(errorstring, 1024, "%s: %s daily traffic: %d", data->interface, invaliddb, i); printe(PT_Error); return 0; } if (data->day[i].used && !used) { snprintf(errorstring, 1024, "%s: %s daily use order: %d", data->interface, invaliddb, i); printe(PT_Error); return 0; } else if (!data->day[i].used) { used = 0; } if (data->day[i].used) { rxsum += data->day[i].rx; txsum += data->day[i].tx; } } for (i = 1; i < 30; i++) { if (!data->day[i].used) { break; } if (data->day[i - 1].date < data->day[i].date) { snprintf(errorstring, 1024, "%s: %s daily date order: %u (%d) < %u (%d)", data->interface, invaliddb, (unsigned int)data->day[i - 1].date, i - 1, (unsigned int)data->day[i].date, i); printe(PT_Error); return 0; } } if (data->totalrx < rxsum || data->totaltx < txsum) { snprintf(errorstring, 1024, "%s: %s total traffic compared to daily usage.", data->interface, invaliddb); printe(PT_Error); return 0; } rxsum = txsum = 0; used = 1; for (i = 0; i < 12; i++) { if (data->month[i].used < 0 || data->month[i].used > 1) { snprintf(errorstring, 1024, "%s: %s monthly use information: %d %d", data->interface, invaliddb, i, data->month[i].used); printe(PT_Error); return 0; } if (data->month[i].rxk < 0 || data->month[i].txk < 0) { snprintf(errorstring, 1024, "%s: %s monthly traffic: %d", data->interface, invaliddb, i); printe(PT_Error); return 0; } if (data->month[i].used && !used) { snprintf(errorstring, 1024, "%s: %s monthly use order: %d", data->interface, invaliddb, i); printe(PT_Error); return 0; } else if (!data->month[i].used) { used = 0; } if (data->month[i].used) { rxsum += data->month[i].rx; txsum += data->month[i].tx; } } for (i = 1; i < 12; i++) { if (!data->month[i].used) { break; } if (data->month[i - 1].month < data->month[i].month) { snprintf(errorstring, 1024, "%s: %s monthly date order: %u (%d) < %u (%d)", data->interface, invaliddb, (unsigned int)data->month[i - 1].month, i - 1, (unsigned int)data->month[i].month, i); printe(PT_Error); return 0; } } if (data->totalrx < rxsum || data->totaltx < txsum) { snprintf(errorstring, 1024, "%s: %s total traffic compared to monthly usage.", data->interface, invaliddb); printe(PT_Error); return 0; } used = 1; for (i = 0; i < 10; i++) { if (data->top10[i].used < 0 || data->top10[i].used > 1) { snprintf(errorstring, 1024, "%s: %s top10 use information: %d %d", data->interface, invaliddb, i, data->top10[i].used); printe(PT_Error); return 0; } if (data->top10[i].rxk < 0 || data->top10[i].txk < 0) { snprintf(errorstring, 1024, "%s: %s top10 traffic: %d", data->interface, invaliddb, i); printe(PT_Error); return 0; } if (data->top10[i].used && !used) { snprintf(errorstring, 1024, "%s: %s top10 use order: %d", data->interface, invaliddb, i); printe(PT_Error); return 0; } else if (!data->top10[i].used) { used = 0; } } return 1; } vnstat-2.9/src/cfg.c0000644000000000000000000004665714171102052013106 0ustar rootroot#include "common.h" #include "cfg.h" int loadcfg(const char *cfgfile, const ConfigType type) { FILE *fd; int i; unsigned int linelen, cfglen; char value[512], cfgline[512]; struct cfgsetting cset[] = {/* cfg string, char var name, int var name, char len, fill status */ {"Interface", cfg.iface, 0, 32, 0}, {"DatabaseDir", cfg.dbdir, 0, 512, 0}, {"Locale", cfg.locale, 0, 32, 0}, {"MonthRotate", 0, &cfg.monthrotate, 0, 0}, {"MonthRotateAffectsYears", 0, &cfg.monthrotateyears, 0, 0}, {"DayFormat", cfg.dformat, 0, 64, 0}, {"MonthFormat", cfg.mformat, 0, 64, 0}, {"TopFormat", cfg.tformat, 0, 64, 0}, {"RXCharacter", cfg.rxchar, 0, 2, 0}, {"TXCharacter", cfg.txchar, 0, 2, 0}, {"RXHourCharacter", cfg.rxhourchar, 0, 2, 0}, {"TXHourCharacter", cfg.txhourchar, 0, 2, 0}, {"UnitMode", 0, &cfg.unitmode, 0, 0}, {"RateUnitMode", 0, &cfg.rateunitmode, 0, 0}, {"OutputStyle", 0, &cfg.ostyle, 0, 0}, {"EstimateBarVisible", 0, &cfg.estimatebarvisible, 0, 0}, {"RateUnit", 0, &cfg.rateunit, 0, 0}, {"DefaultDecimals", 0, &cfg.defaultdecimals, 0, 0}, {"HourlyDecimals", 0, &cfg.hourlydecimals, 0, 0}, {"HourlySectionStyle", 0, &cfg.hourlystyle, 0, 0}, {"BandwidthDetection", 0, &cfg.bwdetection, 0, 0}, {"MaxBandwidth", 0, &cfg.maxbw, 0, 0}, {"Sampletime", 0, &cfg.sampletime, 0, 0}, {"QueryMode", 0, &cfg.qmode, 0, 0}, {"CheckDiskSpace", 0, &cfg.spacecheck, 0, 0}, {"BootVariation", 0, &cfg.bvar, 0, 0}, {"TrafficlessEntries", 0, &cfg.trafficlessentries, 0, 0}, {"List5Mins", 0, &cfg.listfivemins, 0, 0}, {"ListHours", 0, &cfg.listhours, 0, 0}, {"ListDays", 0, &cfg.listdays, 0, 0}, {"ListMonths", 0, &cfg.listmonths, 0, 0}, {"ListYears", 0, &cfg.listyears, 0, 0}, {"ListTop", 0, &cfg.listtop, 0, 0}, {"InterfaceMatchMethod", 0, &cfg.ifacematchmethod, 0, 0}, {"5MinuteHours", 0, &cfg.fiveminutehours, 0, 0}, {"HourlyDays", 0, &cfg.hourlydays, 0, 0}, {"DailyDays", 0, &cfg.dailydays, 0, 0}, {"MonthlyMonths", 0, &cfg.monthlymonths, 0, 0}, {"YearlyYears", 0, &cfg.yearlyyears, 0, 0}, {"TopDayEntries", 0, &cfg.topdayentries, 0, 0}, {"DaemonUser", cfg.daemonuser, 0, 33, 0}, {"DaemonGroup", cfg.daemongroup, 0, 33, 0}, {"TimeSyncWait", 0, &cfg.timesyncwait, 0, 0}, {"UpdateInterval", 0, &cfg.updateinterval, 0, 0}, {"PollInterval", 0, &cfg.pollinterval, 0, 0}, {"SaveInterval", 0, &cfg.saveinterval, 0, 0}, {"OfflineSaveInterval", 0, &cfg.offsaveinterval, 0, 0}, {"RescanDatabaseOnSave", 0, &cfg.rescanonsave, 0, 0}, {"AlwaysAddNewInterfaces", 0, &cfg.alwaysadd, 0, 0}, {"BandwidthDetectionInterval", 0, &cfg.bwdetectioninterval, 0, 0}, {"SaveOnStatusChange", 0, &cfg.savestatus, 0, 0}, {"UseLogging", 0, &cfg.uselogging, 0, 0}, {"CreateDirs", 0, &cfg.createdirs, 0, 0}, {"UpdateFileOwner", 0, &cfg.updatefileowner, 0, 0}, {"LogFile", cfg.logfile, 0, 512, 0}, {"PidFile", cfg.pidfile, 0, 512, 0}, {"64bitInterfaceCounters", 0, &cfg.is64bit, 0, 0}, {"DatabaseWriteAheadLogging", 0, &cfg.waldb, 0, 0}, {"DatabaseSynchronous", 0, &cfg.dbsynchronous, 0, 0}, {"UseUTC", 0, &cfg.useutc, 0, 0}, {"HeaderFormat", cfg.hformat, 0, 64, 0}, {"HourlyRate", 0, &cfg.hourlyrate, 0, 0}, {"SummaryRate", 0, &cfg.summaryrate, 0, 0}, {"TransparentBg", 0, &cfg.transbg, 0, 0}, {"LargeFonts", 0, &cfg.largefonts, 0, 0}, {"LineSpacingAdjustment", 0, &cfg.linespaceadjust, 0, 0}, {"ImageScale", 0, &cfg.imagescale, 0, 0}, {"5MinuteGraphResultCount", 0, &cfg.fivegresultcount, 0, 0}, {"5MinuteGraphHeight", 0, &cfg.fivegheight, 0, 0}, {"HourlyGraphMode", 0, &cfg.hourlygmode, 0, 0}, {"SummaryGraph", 0, &cfg.summarygraph, 0, 0}, {"EstimateStyle", 0, &cfg.estimatestyle, 0, 0}, {"BarColumnShowsRate", 0, &cfg.barshowsrate, 0, 0}, {"CBackground", cfg.cbg, 0, 8, 0}, {"CEdge", cfg.cedge, 0, 8, 0}, {"CHeader", cfg.cheader, 0, 8, 0}, {"CHeaderTitle", cfg.cheadertitle, 0, 8, 0}, {"CHeaderDate", cfg.cheaderdate, 0, 8, 0}, {"CText", cfg.ctext, 0, 8, 0}, {"CLine", cfg.cline, 0, 8, 0}, {"CLineL", cfg.clinel, 0, 8, 0}, {"CRx", cfg.crx, 0, 8, 0}, {"CRxD", cfg.crxd, 0, 8, 0}, {"CTx", cfg.ctx, 0, 8, 0}, {"CTxD", cfg.ctxd, 0, 8, 0}, {"Experimental", 0, &cfg.experimental, 0, 0}, {0, 0, 0, 0, 0}}; /* load default config */ defaultcfg(); i = opencfgfile(cfgfile, &fd); if (i != 2) return i; rewind(fd); /* parse every config file line */ while (!feof(fd)) { cfgline[0] = '\0'; if (fgets(cfgline, 512, fd) == NULL) { break; } linelen = (unsigned int)strlen(cfgline); if (linelen <= 2 || cfgline[0] == '#' || cfgline[0] == ';') { continue; } for (i = 0; cset[i].name != 0; i++) { if (cset[i].found) { continue; } cfglen = (unsigned int)strlen(cset[i].name); if ((linelen < (cfglen + 2)) || (strncasecmp(cfgline, cset[i].name, cfglen) != 0)) { continue; } if (!extractcfgvalue(value, 512, cfgline, cfglen)) { if (debug) printf(" c: %s -> \"%s\" with no value, keeping default.\n", cfgline, cset[i].name); cset[i].found = 1; break; } if (!setcfgvalue(&cset[i], value, cfgline)) { continue; } cset[i].found = 1; break; } if ((debug) && (!cset[i].found) && (strncasecmp(cfgline, "MaxBW", 5) != 0)) printf("Unknown configuration line: %s", cfgline); } fclose(fd); /* validate config */ validatecfg(type); return 1; } void validatebool(const char *cfgname, int32_t *cfgptr, const int32_t defaultvalue) { validateint(cfgname, cfgptr, defaultvalue, 0, 1); } void validateint(const char *cfgname, int32_t *cfgptr, const int32_t defaultvalue, const int32_t minvalue, const int32_t maxvalue) { if (maxvalue > minvalue) { if (*cfgptr < minvalue || *cfgptr > maxvalue) { snprintf(errorstring, 1024, "Invalid value \"%d\" for %s. Value needs to be between %d and %d. Using default value %d.", *cfgptr, cfgname, minvalue, maxvalue, defaultvalue); printe(PT_Config); *cfgptr = defaultvalue; } } else { if (*cfgptr < minvalue) { snprintf(errorstring, 1024, "Invalid value \"%d\" for %s. Value needs to be at least %d. Using default value %d.", *cfgptr, cfgname, minvalue, defaultvalue); printe(PT_Config); *cfgptr = defaultvalue; } } } void validatecfg(const ConfigType type) { uint32_t rolloversecs; const char *invalidvalue = "Invalid value for"; const char *resettingto = "using default value"; const char *noslashstart = "doesn't start with \"/\", using default value instead."; validateint("UnitMode", &cfg.unitmode, UNITMODE, 0, 2); validatebool("RateUnitMode", &cfg.rateunitmode, RATEUNITMODE); validateint("OutputStyle", &cfg.ostyle, OSTYLE, 0, 3); validatebool("EstimateBarVisible", &cfg.estimatebarvisible, ESTIMATEBARVISIBLE); validateint("DefaultDecimals", &cfg.defaultdecimals, DEFAULTDECIMALS, 0, 2); validateint("HourlyDecimals", &cfg.hourlydecimals, HOURLYDECIMALS, 0, 2); validateint("HourlySectionStyle", &cfg.hourlystyle, HOURLYSTYLE, 0, 3); validateint("BootVariation", &cfg.bvar, BVAR, 0, 300); validateint("Sampletime", &cfg.sampletime, DEFSAMPTIME, 2, 600); validateint("MonthRotate", &cfg.monthrotate, MONTHROTATE, 1, 28); validatebool("MonthRotateAffectsYears", &cfg.monthrotateyears, MONTHROTATEYEARS); validateint("MaxBandwidth", &cfg.maxbw, DEFMAXBW, 0, BWMAX); validatebool("CheckDiskSpace", &cfg.spacecheck, USESPACECHECK); validateint("TimeSyncWait", &cfg.timesyncwait, TIMESYNCWAIT, 0, 60); validateint("PollInterval", &cfg.pollinterval, POLLINTERVAL, 2, 60); validatebool("SaveOnStatusChange", &cfg.savestatus, SAVESTATUS); validateint("UseLogging", &cfg.uselogging, USELOGGING, 0, 2); validateint("CreateDirs", &cfg.createdirs, CREATEDIRS, 0, 2); validateint("UpdateFileOwner", &cfg.updatefileowner, UPDATEFILEOWNER, 0, 2); validateint("64bitInterfaceCounters", &cfg.is64bit, IS64BIT, -2, 1); validatebool("DatabaseWriteAheadLogging", &cfg.waldb, WALDB); validateint("DatabaseSynchronous", &cfg.dbsynchronous, DBSYNCHRONOUS, -1, 3); validatebool("UseUTC", &cfg.useutc, USEUTC); if (type == CT_Image || type == CT_All) { validatebool("TransparentBg", &cfg.transbg, TRANSBG); validatebool("LargeFonts", &cfg.largefonts, LARGEFONTS); validateint("LineSpacingAdjustment", &cfg.linespaceadjust, LINESPACEADJUST, -5, 10); validateint("ImageScale", &cfg.imagescale, IMAGESCALE, 50, 500); validateint("5MinuteGraphResultCount", &cfg.fivegresultcount, FIVEGRESULTCOUNT, FIVEGMINRESULTCOUNT, 2000); validateint("5MinuteGraphHeight", &cfg.fivegheight, FIVEGHEIGHT, FIVEGMINHEIGHT, 2000); validateint("HourlyGraphMode", &cfg.hourlygmode, HOURLYGMODE, 0, 1); validatebool("SummaryGraph", &cfg.summarygraph, SUMMARYGRAPH); validateint("EstimateStyle", &cfg.estimatestyle, ESTIMATESTYLE, 0, 2); validatebool("BarColumnShowsRate", &cfg.barshowsrate, BARSHOWSRATE); validatebool("HourlyRate", &cfg.hourlyrate, HOURLYRATE); validatebool("SummaryRate", &cfg.summaryrate, SUMMARYRATE); } validatebool("TrafficlessEntries", &cfg.trafficlessentries, TRAFFICLESSENTRIES); validateint("List5Mins", &cfg.listfivemins, LISTFIVEMINS, 0, 0); validateint("ListHours", &cfg.listhours, LISTHOURS, 0, 0); validateint("ListDays", &cfg.listdays, LISTDAYS, 0, 0); validateint("ListMonths", &cfg.listmonths, LISTMONTHS, 0, 0); validateint("ListYears", &cfg.listyears, LISTYEARS, 0, 0); validateint("ListTop", &cfg.listtop, LISTTOP, 0, 0); validateint("InterfaceMatchMethod", &cfg.ifacematchmethod, IFACEMATCHMETHOD, 0, 3); validateint("5MinuteHours", &cfg.fiveminutehours, FIVEMINUTEHOURS, -1, -1); validateint("HourlyDays", &cfg.hourlydays, HOURLYDAYS, -1, -1); validateint("DailyDays", &cfg.dailydays, DAILYDAYS, -1, -1); validateint("MonthlyMonths", &cfg.monthlymonths, MONTHLYMONTHS, -1, -1); validateint("YearlyYears", &cfg.yearlyyears, YEARLYYEARS, -1, -1); validateint("TopDayEntries", &cfg.topdayentries, TOPDAYENTRIES, -1, -1); validatebool("BandwidthDetection", &cfg.bwdetection, BWDETECT); validateint("BandwidthDetectionInterval", &cfg.bwdetectioninterval, BWDETECTINTERVAL, 0, 30); validatebool("Experimental", &cfg.experimental, 0); if (cfg.useutc) { strncpy_nt(cfg.dbtzmodifier, "", 14); } else { strncpy_nt(cfg.dbtzmodifier, DATABASELOCALTIMEMODIFIER, 14); } if (cfg.dbdir[0] != '/') { strncpy_nt(cfg.dbdir, DATABASEDIR, 512); snprintf(errorstring, 1024, "DatabaseDir %s", noslashstart); printe(PT_Config); } if (cfg.logfile[0] != '/') { strncpy_nt(cfg.logfile, LOGFILE, 512); snprintf(errorstring, 1024, "LogFile %s", noslashstart); printe(PT_Config); } if (cfg.pidfile[0] != '/') { strncpy_nt(cfg.pidfile, PIDFILE, 512); snprintf(errorstring, 1024, "PidFile %s", noslashstart); printe(PT_Config); } if (type == CT_Daemon || type == CT_All) { validatebool("RescanDatabaseOnSave", &cfg.rescanonsave, RESCANONSAVE); validatebool("AlwaysAddNewInterfaces", &cfg.alwaysadd, ALWAYSADD); if (cfg.updateinterval < cfg.pollinterval || cfg.updateinterval > 300) { if (cfg.pollinterval > UPDATEINTERVAL) { cfg.updateinterval = cfg.pollinterval; } else { cfg.updateinterval = UPDATEINTERVAL; } snprintf(errorstring, 1024, "%s UpdateInterval, %s %d.", invalidvalue, resettingto, cfg.updateinterval); printe(PT_Config); } if ((cfg.saveinterval * 60) < cfg.updateinterval || cfg.saveinterval > 60) { if (cfg.updateinterval > (SAVEINTERVAL * 60)) { cfg.saveinterval = cfg.updateinterval; } else { cfg.saveinterval = SAVEINTERVAL; } snprintf(errorstring, 1024, "%s SaveInterval, %s %d.", invalidvalue, resettingto, cfg.saveinterval); printe(PT_Config); } if (cfg.offsaveinterval < cfg.saveinterval || cfg.offsaveinterval > 60) { if (cfg.saveinterval > OFFSAVEINTERVAL) { cfg.offsaveinterval = cfg.saveinterval; } else { cfg.offsaveinterval = OFFSAVEINTERVAL; } snprintf(errorstring, 1024, "%s OfflineSaveInterval, %s %d.", invalidvalue, resettingto, cfg.offsaveinterval); printe(PT_Config); } /* enforce update interval to be short enough that 32-bit interface counter rollover can be detected */ /* 1.02 is the same 2% safety buffer as used in processifinfo() in daemon.c */ if (cfg.maxbw > 0) { rolloversecs = (uint32_t)((float)MAX32 / ((float)cfg.maxbw * 1024 * 1024 * (float)1.02 / 8)); if (rolloversecs <= (uint32_t)cfg.updateinterval) { cfg.updateinterval = UPDATEINTERVAL; if (rolloversecs <= (uint32_t)cfg.updateinterval) { cfg.updateinterval /= 2; } snprintf(errorstring, 1024, "UpdateInterval has been reset to %d seconds in order to ensure correct counter rollover detection at %d Mbit.", cfg.updateinterval, cfg.maxbw); printe(PT_Config); } } } /* affects only image output */ if (type == CT_Image || type == CT_All) { if (cfg.barshowsrate && cfg.estimatebarvisible) { cfg.estimatestyle = 0; if (debug) { printf("BarColumnShowsRate and EstimateBarVisible both enabled -> EstimateStyle set to 0\n"); } } if (cfg.fiveminutehours > 0 && cfg.fivegresultcount > cfg.fiveminutehours * 12) { if (cfg.fiveminutehours * 12 < FIVEGMINRESULTCOUNT) { snprintf(errorstring, 1024, "Value \"%d\" for 5MinuteHours is too small for 5MinuteGraphResultCount with value \"%d\" (smallest supported value: %d). Value for 5MinuteHours needs to be at least %d if 5MinuteGraphResultCount is set to %d.", cfg.fiveminutehours, cfg.fivegresultcount, FIVEGMINRESULTCOUNT, FIVEGMINRESULTCOUNT / 12, FIVEGMINRESULTCOUNT); cfg.fivegresultcount = FIVEGMINRESULTCOUNT; } else { snprintf(errorstring, 1024, "5MinuteGraphResultCount has been adjusted to %d because requested \"%d\" requires more data than can be available with value %d for 5MinuteHours.", cfg.fiveminutehours * 12, cfg.fivegresultcount, cfg.fiveminutehours); cfg.fivegresultcount = cfg.fiveminutehours * 12; } printe(PT_Config); } } } void defaultcfg(void) { ifacebw = NULL; cfg.bvar = BVAR; cfg.qmode = DEFQMODE; cfg.sampletime = DEFSAMPTIME; cfg.monthrotate = MONTHROTATE; cfg.monthrotateyears = MONTHROTATEYEARS; cfg.unitmode = UNITMODE; cfg.rateunitmode = RATEUNITMODE; cfg.ostyle = OSTYLE; cfg.estimatebarvisible = ESTIMATEBARVISIBLE; cfg.rateunit = RATEUNIT; cfg.defaultdecimals = DEFAULTDECIMALS; cfg.hourlydecimals = HOURLYDECIMALS; cfg.hourlystyle = HOURLYSTYLE; cfg.bwdetection = BWDETECT; cfg.bwdetectioninterval = BWDETECTINTERVAL; cfg.maxbw = DEFMAXBW; cfg.spacecheck = USESPACECHECK; cfg.hourlyrate = HOURLYRATE; cfg.summaryrate = SUMMARYRATE; cfg.trafficlessentries = TRAFFICLESSENTRIES; cfg.utflocale = UTFLOCALE; cfg.ifacematchmethod = IFACEMATCHMETHOD; cfg.listfivemins = LISTFIVEMINS; cfg.listhours = LISTHOURS; cfg.listdays = LISTDAYS; cfg.listmonths = LISTMONTHS; cfg.listyears = LISTYEARS; cfg.listtop = LISTTOP; cfg.listjsonxml = LISTJSONXML; cfg.fiveminutehours = FIVEMINUTEHOURS; cfg.hourlydays = HOURLYDAYS; cfg.dailydays = DAILYDAYS; cfg.monthlymonths = MONTHLYMONTHS; cfg.yearlyyears = YEARLYYEARS; cfg.topdayentries = TOPDAYENTRIES; strncpy_nt(cfg.dbdir, DATABASEDIR, 512); strncpy_nt(cfg.dbtzmodifier, DATABASELOCALTIMEMODIFIER, 14); strncpy_nt(cfg.iface, DEFIFACE, 32); strncpy_nt(cfg.locale, LOCALE, 32); strncpy_nt(cfg.dformat, DFORMAT, 64); strncpy_nt(cfg.mformat, MFORMAT, 64); strncpy_nt(cfg.tformat, TFORMAT, 64); strncpy_nt(cfg.hformat, HFORMAT, 64); strncpy_nt(cfg.rxchar, RXCHAR, 2); strncpy_nt(cfg.txchar, TXCHAR, 2); strncpy_nt(cfg.rxhourchar, RXHOURCHAR, 2); strncpy_nt(cfg.txhourchar, TXHOURCHAR, 2); cfg.daemonuser[0] = '\0'; cfg.daemongroup[0] = '\0'; cfg.timesyncwait = TIMESYNCWAIT; cfg.updateinterval = UPDATEINTERVAL; cfg.pollinterval = POLLINTERVAL; cfg.saveinterval = SAVEINTERVAL; cfg.offsaveinterval = OFFSAVEINTERVAL; cfg.rescanonsave = RESCANONSAVE; cfg.alwaysadd = ALWAYSADD; cfg.savestatus = SAVESTATUS; cfg.uselogging = USELOGGING; cfg.createdirs = CREATEDIRS; cfg.updatefileowner = UPDATEFILEOWNER; strncpy_nt(cfg.logfile, LOGFILE, 512); strncpy_nt(cfg.pidfile, PIDFILE, 512); cfg.is64bit = IS64BIT; cfg.waldb = WALDB; cfg.dbsynchronous = DBSYNCHRONOUS; cfg.useutc = USEUTC; cfg.transbg = TRANSBG; cfg.largefonts = LARGEFONTS; cfg.linespaceadjust = LINESPACEADJUST; cfg.imagescale = IMAGESCALE; cfg.fivegresultcount = FIVEGRESULTCOUNT; cfg.fivegheight = FIVEGHEIGHT; cfg.hourlygmode = HOURLYGMODE; cfg.summarygraph = SUMMARYGRAPH; cfg.estimatestyle = ESTIMATESTYLE; cfg.barshowsrate = BARSHOWSRATE; strncpy_nt(cfg.cbg, CBACKGROUND, 8); strncpy_nt(cfg.cedge, CEDGE, 8); strncpy_nt(cfg.cheader, CHEADER, 8); strncpy_nt(cfg.cheadertitle, CHEADERTITLE, 8); strncpy_nt(cfg.cheaderdate, CHEADERDATE, 8); strncpy_nt(cfg.ctext, CTEXT, 8); strncpy_nt(cfg.cline, CLINE, 8); strncpy_nt(cfg.clinel, CLINEL, 8); strncpy_nt(cfg.crx, CRX, 8); strncpy_nt(cfg.crxd, CRXD, 8); strncpy_nt(cfg.ctx, CTX, 8); strncpy_nt(cfg.ctxd, CTXD, 8); cfg.timestampprints = 0; cfg.experimental = 0; } int opencfgfile(const char *cfgfile, FILE **fd) { char buffer[512]; int i, tryhome; /* clear buffer */ for (i = 0; i < 512; i++) { buffer[i] = '\0'; } cfg.cfgfile[0] = '\0'; /* possible config files: 1) --config 2) $HOME/.vnstatrc 3) /etc/vnstat.conf 4) none */ if (cfgfile[0] != '\0') { /* try to open given file */ if ((*fd = fopen(cfgfile, "r")) != NULL) { strncpy_nt(cfg.cfgfile, cfgfile, 512); if (debug) printf("Config file: --config\n"); } else { snprintf(errorstring, 1024, "Unable to open given config file \"%s\": %s", cfgfile, strerror(errno)); printe(PT_Error); return 0; } } else { if (getenv("HOME")) { strncpy_nt(buffer, getenv("HOME"), 500); strcat(buffer, "/.vnstatrc"); tryhome = 1; } else { tryhome = 0; } /* try to open first available config file */ if (tryhome && (*fd = fopen(buffer, "r")) != NULL) { strncpy_nt(cfg.cfgfile, buffer, 512); } else if ((*fd = fopen("/etc/vnstat.conf", "r")) != NULL) { snprintf(cfg.cfgfile, 512, "/etc/vnstat.conf"); } else if ((*fd = fopen("/usr/local/etc/vnstat.conf", "r")) != NULL) { snprintf(cfg.cfgfile, 512, "/usr/local/etc/vnstat.conf"); } else { if (debug) printf("Config file: none\n"); return 1; } if (debug) printf("Config file: %s\n", cfg.cfgfile); } return 2; } int extractcfgvalue(char *value, const unsigned int valuelen, const char *cfgline, const unsigned int cfglen) { unsigned int i, j, linelen; linelen = (unsigned int)strlen(cfgline); for (i = 0; i < valuelen; i++) { value[i] = '\0'; } i = 0; for (j = cfglen; j < linelen; j++) { if (cfgline[j] == '\n' || cfgline[j] == '\r') { break; } else if (cfgline[j] == '\"') { if (i == 0) { continue; } else { break; } } else { if (i == 0 && (cfgline[j] == ' ' || cfgline[j] == '=' || cfgline[j] == '\t')) { continue; } else { value[i] = cfgline[j]; i++; } } } return (int)strlen(value); } int setcfgvalue(const struct cfgsetting *cset, const char *value, const char *cfgline) { if (cset->namelen > 0) { strncpy_nt(cset->locc, value, (size_t)cset->namelen); if (debug) printf(" c: %s -> \"%s\": \"%s\"\n", cfgline, cset->name, cset->locc); } else if ((strlen(value) > 1 && isdigit(value[1])) || isdigit(value[0])) { *cset->loci = (int32_t)strtol(value, (char **)NULL, 0); if (debug) printf(" i: %s -> \"%s\": %d\n", cfgline, cset->name, *cset->loci); } else { return 0; } return 1; } void configlocale(void) { const char *env = getenv("LC_ALL"); if (cfg.locale[0] != '-' && strlen(cfg.locale) > 0) { setlocale(LC_ALL, cfg.locale); } else { if (env) { setlocale(LC_ALL, env); } else { setlocale(LC_ALL, ""); } } if (env) { if (strstr(env, "UTF") != NULL) { cfg.utflocale = 1; } else { cfg.utflocale = 0; } } } vnstat-2.9/src/fs.h0000644000000000000000000000107413537746304012767 0ustar rootroot#ifndef FS_H #define FS_H /* O_CLOEXEC is specified starting POSIX.1-2008 / glibc 2.12 / Linux 2.6.23 */ #if HAVE_DECL_O_CLOEXEC #define FS_OPEN_RO_FLAGS O_RDONLY | O_CLOEXEC #else #define FS_OPEN_RO_FLAGS O_RDONLY #endif int direxists(const char *dir); int fileexists(const char *file); int mkpath(const char *dir, const mode_t mode); void preparevnstatdir(const char *dir, const char *user, const char *group); void updatedirowner(const char *dir, const char *user, const char *group); void updatedirownerid(const char *dir, const uid_t uid, const gid_t gid); #endif vnstat-2.9/src/cfgoutput.c0000644000000000000000000003424514164653244014375 0ustar rootroot#include "common.h" #include "cfgoutput.h" void printcfgfile(void) { ibwnode *p = ifacebw; /* common / vnstat section */ printf("# vnStat %s configuration file\n", getversion()); printf("#\n"); printf("# lines starting with # or ; are comments, everything has default\n"); printf("# values, remove ; before each option to change its value\n\n\n"); if (cfg.experimental) { printf("Experimental %d\n\n", cfg.experimental); } printf("# default interface (leave empty for automatic selection)\n"); defaultcomment(strcmp(cfg.iface, DEFIFACE) == 0); printf("Interface \"%s\"\n\n", cfg.iface); printf("# location of the database directory\n"); defaultcomment(strcmp(cfg.dbdir, DATABASEDIR) == 0); printf("DatabaseDir \"%s\"\n\n", cfg.dbdir); printf("# locale (LC_ALL) (\"-\" = use system locale)\n"); defaultcomment(strcmp(cfg.locale, LOCALE) == 0); printf("Locale \"%s\"\n\n", cfg.locale); printf("# date output formats for -d, -m, -t and -w\n"); defaultcomment(strcmp(cfg.dformat, DFORMAT) == 0); printf("DayFormat \"%s\"\n", cfg.dformat); defaultcomment(strcmp(cfg.mformat, MFORMAT) == 0); printf("MonthFormat \"%s\"\n", cfg.mformat); defaultcomment(strcmp(cfg.tformat, TFORMAT) == 0); printf("TopFormat \"%s\"\n\n", cfg.tformat); printf("# characters used for visuals\n"); defaultcomment(strcmp(cfg.rxchar, RXCHAR) == 0); printf("RXCharacter \"%c\"\n", cfg.rxchar[0]); defaultcomment(strcmp(cfg.txchar, TXCHAR) == 0); printf("TXCharacter \"%c\"\n", cfg.txchar[0]); defaultcomment(strcmp(cfg.rxhourchar, RXHOURCHAR) == 0); printf("RXHourCharacter \"%c\"\n", cfg.rxhourchar[0]); defaultcomment(strcmp(cfg.txhourchar, TXHOURCHAR) == 0); printf("TXHourCharacter \"%c\"\n\n", cfg.txhourchar[0]); printf("# how units are prefixed when traffic is shown\n"); printf("# 0 = IEC standard prefixes (KiB/MiB/GiB...)\n"); printf("# 1 = old style binary prefixes (KB/MB/GB...)\n"); printf("# 2 = SI decimal prefixes (kB/MB/GB...)\n"); defaultcomment(cfg.unitmode == UNITMODE); printf("UnitMode %d\n\n", cfg.unitmode); printf("# used rate unit (0 = bytes, 1 = bits)\n"); defaultcomment(cfg.rateunit == RATEUNIT); printf("RateUnit %d\n\n", cfg.rateunit); printf("# how units are prefixed when traffic rate is shown in bits\n"); printf("# 0 = IEC binary prefixes (Kibit/s...)\n"); printf("# 1 = SI decimal prefixes (kbit/s...)\n"); defaultcomment(cfg.rateunitmode == RATEUNITMODE); printf("RateUnitMode %d\n\n", cfg.rateunitmode); printf("# output style\n"); printf("# 0 = minimal & narrow, 1 = bar column visible\n"); printf("# 2 = same as 1 except rate in summary\n"); printf("# 3 = rate column visible\n"); defaultcomment(cfg.ostyle == OSTYLE); printf("OutputStyle %d\n", cfg.ostyle); defaultcomment(cfg.estimatebarvisible == ESTIMATEBARVISIBLE); printf("EstimateBarVisible %d\n\n", cfg.estimatebarvisible); printf("# number of decimals to use in outputs\n"); defaultcomment(cfg.defaultdecimals == DEFAULTDECIMALS); printf("DefaultDecimals %d\n", cfg.defaultdecimals); defaultcomment(cfg.hourlydecimals == HOURLYDECIMALS); printf("HourlyDecimals %d\n\n", cfg.hourlydecimals); printf("# spacer for separating hourly sections (0 = none, 1 = '|', 2 = '][', 3 = '[ ]')\n"); defaultcomment(cfg.hourlystyle == HOURLYSTYLE); printf("HourlySectionStyle %d\n\n", cfg.hourlystyle); printf("# how many seconds should sampling for -tr take by default\n"); defaultcomment(cfg.sampletime == DEFSAMPTIME); printf("Sampletime %d\n\n", cfg.sampletime); printf("# default query mode\n"); printf("# 0 = normal, 1 = days, 2 = months, 3 = top, 5 = short\n"); printf("# 7 = hours, 8 = xml, 9 = one line, 10 = json\n"); defaultcomment(cfg.qmode == DEFQMODE); printf("QueryMode %d\n\n", cfg.qmode); printf("# default list output entry limits (0 = all)\n"); defaultcomment(cfg.listfivemins == LISTFIVEMINS); printf("List5Mins %2d\n", cfg.listfivemins); defaultcomment(cfg.listhours == LISTHOURS); printf("ListHours %2d\n", cfg.listhours); defaultcomment(cfg.listdays == LISTDAYS); printf("ListDays %2d\n", cfg.listdays); defaultcomment(cfg.listmonths == LISTMONTHS); printf("ListMonths %2d\n", cfg.listmonths); defaultcomment(cfg.listyears == LISTYEARS); printf("ListYears %2d\n", cfg.listyears); defaultcomment(cfg.listtop == LISTTOP); printf("ListTop %2d\n\n", cfg.listtop); printf("# how to match interface given for query to interface in database\n"); printf("# 0 = case sensitive exact match to interface name\n"); printf("# 1 = method 0 followed by case sensitive exact match of alias\n"); printf("# 2 = method 1 followed by case insensitive exact match of alias\n"); printf("# 3 = method 2 followed by case insensitive beginning match of alias\n"); defaultcomment(cfg.ifacematchmethod == IFACEMATCHMETHOD); printf("InterfaceMatchMethod %d\n\n", cfg.ifacematchmethod); printf("\n"); /* vnstatd section */ printf("# vnstatd\n##\n\n"); printf("# switch to given user when started as root (leave empty to disable)\n"); defaultcomment(strlen(cfg.daemonuser) == 0); printf("DaemonUser \"%s\"\n\n", cfg.daemonuser); printf("# switch to given group when started as root (leave empty to disable)\n"); defaultcomment(strlen(cfg.daemongroup) == 0); printf("DaemonGroup \"%s\"\n\n", cfg.daemongroup); printf("# try to detect interface maximum bandwidth, 0 = disable feature\n"); printf("# MaxBandwidth will be used as fallback value when enabled\n"); defaultcomment(cfg.bwdetection == BWDETECT); printf("BandwidthDetection %d\n\n", cfg.bwdetection); printf("# maximum bandwidth (Mbit) for all interfaces, 0 = disable feature\n# (unless interface specific limit is given)\n"); defaultcomment(cfg.maxbw == DEFMAXBW); printf("MaxBandwidth %d\n\n", cfg.maxbw); printf("# interface specific limits\n"); printf("# example 8Mbit limit for eth0 (remove # to activate):\n"); printf("#MaxBWeth0 8\n"); while (p != NULL) { printf("MaxBW%s %u\n", p->interface, p->limit); p = p->next; } printf("\n"); printf("# data retention durations (-1 = unlimited, 0 = feature disabled)\n"); defaultcomment(cfg.fiveminutehours == FIVEMINUTEHOURS); printf("5MinuteHours %2d\n", cfg.fiveminutehours); defaultcomment(cfg.hourlydays == HOURLYDAYS); printf("HourlyDays %2d\n", cfg.hourlydays); defaultcomment(cfg.dailydays == DAILYDAYS); printf("DailyDays %2d\n", cfg.dailydays); defaultcomment(cfg.monthlymonths == MONTHLYMONTHS); printf("MonthlyMonths %2d\n", cfg.monthlymonths); defaultcomment(cfg.yearlyyears == YEARLYYEARS); printf("YearlyYears %2d\n", cfg.yearlyyears); defaultcomment(cfg.topdayentries == TOPDAYENTRIES); printf("TopDayEntries %2d\n\n", cfg.topdayentries); printf("# how often (in seconds) interface data is updated\n"); defaultcomment(cfg.updateinterval == UPDATEINTERVAL); printf("UpdateInterval %d\n\n", cfg.updateinterval); printf("# how often (in seconds) interface status changes are checked\n"); defaultcomment(cfg.pollinterval == POLLINTERVAL); printf("PollInterval %d\n\n", cfg.pollinterval); printf("# how often (in minutes) data is saved to database\n"); defaultcomment(cfg.saveinterval == SAVEINTERVAL); printf("SaveInterval %d\n\n", cfg.saveinterval); printf("# how often (in minutes) data is saved when all interface are offline\n"); defaultcomment(cfg.offsaveinterval == OFFSAVEINTERVAL); printf("OfflineSaveInterval %d\n\n", cfg.offsaveinterval); printf("# rescan database after save for new interfaces to be monitored (1 = enabled, 0 = disabled)\n"); defaultcomment(cfg.rescanonsave == RESCANONSAVE); printf("RescanDatabaseOnSave %d\n\n", cfg.rescanonsave); printf("# automatically start monitoring all interfaces not found in the database\n"); printf("# (1 = enabled, 0 = disabled)\n"); defaultcomment(cfg.alwaysadd == ALWAYSADD); printf("AlwaysAddNewInterfaces %d\n\n", cfg.alwaysadd); printf("# on which day should months change\n"); defaultcomment(cfg.monthrotate == MONTHROTATE); printf("MonthRotate %d\n", cfg.monthrotate); defaultcomment(cfg.monthrotateyears == MONTHROTATEYEARS); printf("MonthRotateAffectsYears %d\n\n", cfg.monthrotateyears); printf("# filesystem disk space check (1 = enabled, 0 = disabled)\n"); defaultcomment(cfg.spacecheck == USESPACECHECK); printf("CheckDiskSpace %d\n\n", cfg.spacecheck); printf("# how much the boot time can variate between updates (seconds)\n"); defaultcomment(cfg.bvar == BVAR); printf("BootVariation %d\n\n", cfg.bvar); printf("# create database entries even when there is no traffic (1 = enabled, 0 = disabled)\n"); defaultcomment(cfg.trafficlessentries == TRAFFICLESSENTRIES); printf("TrafficlessEntries %d\n\n", cfg.trafficlessentries); printf("# how many minutes to wait during daemon startup for system clock to\n"); printf("# sync time if most recent database update appears to be in the future\n"); defaultcomment(cfg.timesyncwait == TIMESYNCWAIT); printf("TimeSyncWait %d\n\n", cfg.timesyncwait); printf("# how often (in minutes) bandwidth detection is done when\n"); printf("# BandwidthDetection is enabled (0 = disabled)\n"); defaultcomment(cfg.bwdetectioninterval == BWDETECTINTERVAL); printf("BandwidthDetectionInterval %d\n\n", cfg.bwdetectioninterval); printf("# force data save when interface status changes (1 = enabled, 0 = disabled)\n"); defaultcomment(cfg.savestatus == SAVESTATUS); printf("SaveOnStatusChange %d\n\n", cfg.savestatus); printf("# enable / disable logging (0 = disabled, 1 = logfile, 2 = syslog)\n"); defaultcomment(cfg.uselogging == USELOGGING); printf("UseLogging %d\n\n", cfg.uselogging); printf("# create dirs if needed (1 = enabled, 0 = disabled)\n"); defaultcomment(cfg.createdirs == CREATEDIRS); printf("CreateDirs %d\n\n", cfg.createdirs); printf("# update ownership of files if needed (1 = enabled, 0 = disabled)\n"); defaultcomment(cfg.updatefileowner == UPDATEFILEOWNER); printf("UpdateFileOwner %d\n\n", cfg.updatefileowner); printf("# file used for logging if UseLogging is set to 1\n"); defaultcomment(strcmp(cfg.logfile, LOGFILE) == 0); printf("LogFile \"%s\"\n\n", cfg.logfile); printf("# file used as daemon pid / lock file\n"); defaultcomment(strcmp(cfg.pidfile, PIDFILE) == 0); printf("PidFile \"%s\"\n\n", cfg.pidfile); printf("# 1 = 64-bit, 0 = 32-bit, -1 = old style logic, -2 = automatic detection\n"); defaultcomment(cfg.is64bit == IS64BIT); printf("64bitInterfaceCounters %d\n\n", cfg.is64bit); printf("# use SQLite Write-Ahead Logging mode (1 = enabled, 0 = disabled)\n"); defaultcomment(cfg.waldb == WALDB); printf("DatabaseWriteAheadLogging %d\n\n", cfg.waldb); printf("# change the setting of the SQLite \"synchronous\" flag\n"); printf("# (-1 = auto, 0 = off, 1, = normal, 2 = full, 3 = extra)\n"); defaultcomment(cfg.dbsynchronous == DBSYNCHRONOUS); printf("DatabaseSynchronous %d\n\n", cfg.dbsynchronous); printf("# database uses UTC instead of local timezone (1 = enabled, 0 = disabled)\n"); defaultcomment(cfg.useutc == USEUTC); printf("UseUTC %d\n\n", cfg.useutc); printf("\n"); /* vnstati section */ printf("# vnstati\n##\n\n"); printf("# title timestamp format\n"); defaultcomment(strcmp(cfg.hformat, HFORMAT) == 0); printf("HeaderFormat \"%s\"\n\n", cfg.hformat); printf("# show hours with rate (1 = enabled, 0 = disabled)\n"); defaultcomment(cfg.hourlyrate == HOURLYRATE); printf("HourlyRate %d\n\n", cfg.hourlyrate); printf("# show rate in summary (1 = enabled, 0 = disabled)\n"); defaultcomment(cfg.summaryrate == SUMMARYRATE); printf("SummaryRate %d\n\n", cfg.summaryrate); printf("# transparent background (1 = enabled, 0 = disabled)\n"); defaultcomment(cfg.transbg == TRANSBG); printf("TransparentBg %d\n\n", cfg.transbg); printf("# image size control\n"); defaultcomment(cfg.largefonts == LARGEFONTS); printf("LargeFonts %d\n", cfg.largefonts); defaultcomment(cfg.linespaceadjust == LINESPACEADJUST); printf("LineSpacingAdjustment %d\n", cfg.linespaceadjust); defaultcomment(cfg.imagescale == IMAGESCALE); printf("ImageScale %d\n\n", cfg.imagescale); printf("# 5 minutes graph size control\n"); defaultcomment(cfg.fivegresultcount == FIVEGRESULTCOUNT); printf("5MinuteGraphResultCount %d\n", cfg.fivegresultcount); defaultcomment(cfg.fivegheight == FIVEGHEIGHT); printf("5MinuteGraphHeight %d\n\n", cfg.fivegheight); printf("# hourly graph mode (0 = 24 hour sliding window, 1 = begins from midnight)\n"); defaultcomment(cfg.hourlygmode == HOURLYGMODE); printf("HourlyGraphMode %d\n\n", cfg.hourlygmode); printf("# horizontal/vertical summary graph (0 = hours, 1 = 5 minutes)\n"); defaultcomment(cfg.summarygraph == SUMMARYGRAPH); printf("SummaryGraph %d\n\n", cfg.summarygraph); printf("# traffic estimate bar style\n"); printf("# (0 = not shown, 1 = continuation of existing bar, 2 = separate bar)\n"); defaultcomment(cfg.estimatestyle == ESTIMATESTYLE); printf("EstimateStyle %d\n\n", cfg.estimatestyle); printf("# bar column in list outputs shows rate if OutputStyle is 3\n"); printf("# (1 = enabled, 0 = disabled)\n"); defaultcomment(cfg.barshowsrate == BARSHOWSRATE); printf("BarColumnShowsRate %d\n\n", cfg.barshowsrate); printf("# image colors\n"); defaultcomment(strcmp(cfg.cbg, CBACKGROUND) == 0); printf("CBackground \"%s\"\n", cfg.cbg); defaultcomment(strcmp(cfg.cedge, CEDGE) == 0); printf("CEdge \"%s\"\n", cfg.cedge); defaultcomment(strcmp(cfg.cheader, CHEADER) == 0); printf("CHeader \"%s\"\n", cfg.cheader); defaultcomment(strcmp(cfg.cheadertitle, CHEADERTITLE) == 0); printf("CHeaderTitle \"%s\"\n", cfg.cheadertitle); defaultcomment(strcmp(cfg.cheaderdate, CHEADERDATE) == 0); printf("CHeaderDate \"%s\"\n", cfg.cheaderdate); defaultcomment(strcmp(cfg.ctext, CTEXT) == 0); printf("CText \"%s\"\n", cfg.ctext); defaultcomment(strcmp(cfg.cline, CLINE) == 0); printf("CLine \"%s\"\n", cfg.cline); defaultcomment(strcmp(cfg.clinel, CLINEL) == 0); printf("CLineL \"%s\"\n", cfg.clinel); defaultcomment(strcmp(cfg.crx, CRX) == 0); printf("CRx \"%s\"\n", cfg.crx); defaultcomment(strcmp(cfg.ctx, CTX) == 0); printf("CTx \"%s\"\n", cfg.ctx); defaultcomment(strcmp(cfg.crxd, CRXD) == 0); printf("CRxD \"%s\"\n", cfg.crxd); defaultcomment(strcmp(cfg.ctxd, CTXD) == 0); printf("CTxD \"%s\"\n", cfg.ctxd); } void defaultcomment(const int isdefault) { if (isdefault) { printf(";"); } } vnstat-2.9/src/dbxml.h0000644000000000000000000000055613255745443013471 0ustar rootroot#ifndef DBXML_H #define DBXML_H void showxml(const char *interface, const char mode, const char *databegin, const char *dataend); void xmldump(const interfaceinfo *interface, const char *tablename, const int datetype, const char *databegin, const char *dataend); void xmldate(const time_t *date, const int type); void xmlheader(void); void xmlfooter(void); #endif vnstat-2.9/src/ibw.h0000644000000000000000000000043213454462145013131 0ustar rootroot#ifndef IBW_H #define IBW_H int ibwloadcfg(const char *cfgfile); int ibwadd(const char *iface, const uint32_t limit); void ibwlist(void); int ibwget(const char *iface, uint32_t *limit); ibwnode *ibwgetnode(const char *iface); void ibwflush(void); int ibwcfgread(FILE *fd); #endif vnstat-2.9/src/dbjson.c0000644000000000000000000000642413465371162013631 0ustar rootroot#include "common.h" #include "dbsql.h" #include "dbjson.h" void showjson(const char *interface, const int ifcount, const char mode, const char *databegin, const char *dataend) { interfaceinfo info; timeused_debug(__func__, 1); if (!db_getinterfacecountbyname(interface)) { return; } if (!db_getinterfaceinfo(interface, &info)) { return; } if (ifcount) { printf(","); } printf("{"); printf("\"name\":\"%s\",", info.name); printf("\"alias\":\"%s\",", info.alias); printf("\"created\":{"); jsondate(&info.created, 1); printf("},"); printf("\"updated\":{"); jsondate(&info.updated, 2); printf("},"); printf("\"traffic\":"); printf("{\"total\":{\"rx\":%" PRIu64 ",\"tx\":%" PRIu64 "},", info.rxtotal, info.txtotal); switch (mode) { case 'd': jsondump(&info, "day", 1, databegin, dataend); break; case 'm': jsondump(&info, "month", 3, databegin, dataend); break; case 't': jsondump(&info, "top", 1, databegin, dataend); break; case 'h': jsondump(&info, "hour", 2, databegin, dataend); break; case 'y': jsondump(&info, "year", 4, databegin, dataend); break; case 'f': jsondump(&info, "fiveminute", 2, databegin, dataend); break; case 'a': default: jsondump(&info, "fiveminute", 2, databegin, dataend); printf(","); jsondump(&info, "hour", 2, databegin, dataend); printf(","); jsondump(&info, "day", 1, databegin, dataend); printf(","); jsondump(&info, "month", 3, databegin, dataend); printf(","); jsondump(&info, "year", 4, databegin, dataend); printf(","); jsondump(&info, "top", 1, databegin, dataend); break; } printf("}}"); timeused_debug(__func__, 0); } void jsondump(const interfaceinfo *interface, const char *tablename, const int datetype, const char *databegin, const char *dataend) { int first = 1; dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; if (!db_getdata_range(&datalist, &datainfo, interface->name, tablename, (uint32_t)cfg.listjsonxml, databegin, dataend)) { printf("Error: Failed to fetch %s data.\n", tablename); return; } printf("\"%s\":[", tablename); datalist_i = datalist; while (datalist_i != NULL) { if (!first) { printf(","); } else { first = 0; } printf("{\"id\":%" PRId64 ",", datalist_i->rowid); jsondate(&datalist_i->timestamp, datetype); printf(",\"rx\":%" PRIu64 ",\"tx\":%" PRIu64 "}", datalist_i->rx, datalist_i->tx); datalist_i = datalist_i->next; } dbdatalistfree(&datalist); printf("]"); } void jsondate(const time_t *date, const int type) { struct tm *d; d = localtime(date); switch (type) { case 1: printf("\"date\":{\"year\":%d,\"month\":%d,\"day\":%d}", 1900 + d->tm_year, 1 + d->tm_mon, d->tm_mday); break; case 2: printf("\"date\":{\"year\":%d,\"month\":%d,\"day\":%d},\"time\":{\"hour\":%d,\"minute\":%d}", 1900 + d->tm_year, 1 + d->tm_mon, d->tm_mday, d->tm_hour, d->tm_min); break; case 3: printf("\"date\":{\"year\":%d,\"month\":%d}", 1900 + d->tm_year, 1 + d->tm_mon); break; case 4: printf("\"date\":{\"year\":%d}", 1900 + d->tm_year); break; default: break; } } void jsonheader(void) { printf("{\"vnstatversion\":\"%s\",\"jsonversion\":\"%d\",\"interfaces\":[", getversion(), JSONVERSION); } void jsonfooter(void) { printf("]}\n"); } vnstat-2.9/src/fs.c0000644000000000000000000000772513537746277013004 0ustar rootroot#include "common.h" #include "id.h" #include "fs.h" int direxists(const char *dir) { return fileexists(dir); } int fileexists(const char *file) { struct stat statbuf; if (stat(file, &statbuf) != 0) { if (errno == ENOENT) { return 0; } if (debug) printf("Error (debug): stat() \"%s\": %s\n", file, strerror(errno)); } return 1; } int mkpath(const char *dir, const mode_t mode) { int ret = 1; size_t i = 0, len = 0; char *tmp = NULL; if (!strlen(dir)) { if (debug) printf("Error (debug): mkpath(), no directory given\n"); return 0; } if (direxists(dir)) { if (debug) printf("already exists: %s\n", dir); return 1; } if (!cfg.createdirs) { return 0; } tmp = strdup(dir); if (tmp == NULL) { return 0; } len = strlen(tmp); if (tmp[len - 1] == '/') { tmp[len - 1] = '\0'; } if (tmp[0] == '/') { i++; } for (; i < len; i++) { if (tmp[i] == '/') { tmp[i] = '\0'; if (!direxists(tmp)) { if (mkdir(tmp, mode) != 0) { if (debug) printf("Error (debug): mkdir() \"%s\": %s\n", tmp, strerror(errno)); ret = 0; break; } } tmp[i] = '/'; } } if (ret) { if (mkdir(tmp, mode) != 0) { if (debug) printf("Error (debug): mkdir() \"%s\": %s\n", tmp, strerror(errno)); ret = 0; } else if (debug) { printf("created: %s\n", tmp); } } free(tmp); return ret; } void preparevnstatdir(const char *dir, const char *user, const char *group) { size_t i, len, lastslash = 0; char *path, *base; if (dir == NULL) { return; } len = strlen(dir); if (len < 2) { return; } if (dir[len - 1] == '/') { return; } path = strdup(dir); if (path == NULL) { return; } /* verify that path ends with vnstat or vnstatd */ base = basename(dirname(path)); if (strcmp(base, "vnstat") != 0 && strcmp(base, "vnstatd") != 0) { free(path); return; } free(path); path = strdup(dir); if (path == NULL) { return; } /* extract path */ for (i = 0; i < len; i++) { if (path[i] == '/') { lastslash = i; } } if (lastslash == 0) { free(path); return; } path[lastslash] = '\0'; /* create & chmod if needed */ if (mkpath(path, 0775)) { updatedirowner(path, user, group); } free(path); } void updatedirowner(const char *dir, const char *user, const char *group) { uid_t uid; gid_t gid; if (!cfg.updatefileowner) { return; } if (!hasroot()) { if (debug) printf("user not root, skipping chmod\n"); return; } uid = getuser(user); gid = getgroup(group); updatedirownerid(dir, uid, gid); } void updatedirownerid(const char *dir, const uid_t uid, const gid_t gid) { DIR *d; struct dirent *di; struct stat statbuf; char entryname[512]; int dir_fd, file_fd; if (!cfg.updatefileowner) { return; } if (!hasroot()) { if (debug) printf("user not root, skipping chmod\n"); return; } if ((dir_fd = open(dir, FS_OPEN_RO_FLAGS)) == -1) return; if (fstat(dir_fd, &statbuf) != 0) { close(dir_fd); return; } if (statbuf.st_uid != uid || statbuf.st_gid != gid) { if (fchown(dir_fd, uid, gid) != 0) { if (debug) printf("Error (debug): updatedirowner() chown() \"%s\": %s\n", dir, strerror(errno)); close(dir_fd); return; } else { if (debug) printf("\"%s\" chown completed\n", dir); } } if ((d = fdopendir(dir_fd)) == NULL) { if (debug) printf("Error (debug): updatedirowner() diropen() \"%s\": %s\n", dir, strerror(errno)); close(dir_fd); return; } while ((di = readdir(d))) { if (di->d_type != DT_REG) { continue; } snprintf(entryname, 512, "%s/%s", dir, di->d_name); if ((file_fd = open(entryname, FS_OPEN_RO_FLAGS)) == -1) continue; if (fstat(file_fd, &statbuf) != 0) { close(file_fd); continue; } if (statbuf.st_uid != uid || statbuf.st_gid != gid) { if (fchown(file_fd, uid, gid) != 0) { if (debug) printf("Error (debug): chown() \"%s\": %s\n", entryname, strerror(errno)); } else { if (debug) printf("\"%s\" chown completed\n", entryname); } } close(file_fd); } closedir(d); } vnstat-2.9/src/image_support.c0000644000000000000000000003755614156427647015252 0ustar rootroot#include "common.h" #include "dbsql.h" #include "misc.h" #include "image.h" #include "image_support.h" #include "vnstati.h" void imageinit(IMAGECONTENT *ic, const int width, const int height) { int rgb[3]; ic->im = gdImageCreate(width, height); /* text, edge and header colors */ hextorgb(cfg.ctext, rgb); ic->ctext = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("ctext", ic->ctext, cfg.ctext, rgb); hextorgb(cfg.cedge, rgb); ic->cedge = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("cedge", ic->cedge, cfg.cedge, rgb); hextorgb(cfg.cheader, rgb); ic->cheader = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("cheader", ic->cheader, cfg.cheader, rgb); hextorgb(cfg.cheadertitle, rgb); ic->cheadertitle = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("cheadertitle", ic->cheadertitle, cfg.cheadertitle, rgb); hextorgb(cfg.cheaderdate, rgb); ic->cheaderdate = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("cheaderdate", ic->cheaderdate, cfg.cheaderdate, rgb); /* lines */ hextorgb(cfg.cline, rgb); ic->cline = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("cline", ic->cline, cfg.cline, rgb); if (cfg.clinel[0] == '-') { modcolor(rgb, 50, 1); } else { hextorgb(cfg.clinel, rgb); } ic->clinel = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("clinel", ic->clinel, cfg.clinel, rgb); /* background */ hextorgb(cfg.cbg, rgb); ic->cbackground = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("cbackground", ic->cbackground, cfg.cbg, rgb); modcolor(rgb, -35, 0); ic->cvnstat = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("cvnstat", ic->cvnstat, cfg.cbg, rgb); hextorgb(cfg.cbg, rgb); modcolor(rgb, -15, 0); ic->cbgoffset = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("cbgoffset", ic->cbgoffset, cfg.cbg, rgb); hextorgb(cfg.cbg, rgb); modcolor(rgb, -40, 0); ic->cbgoffsetmore = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("cbgoffsetmore", ic->cbgoffsetmore, cfg.cbg, rgb); /* rx */ hextorgb(cfg.crx, rgb); ic->crx = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("crx", ic->crx, cfg.crx, rgb); if (cfg.crxd[0] == '-') { modcolor(rgb, -50, 1); } else { hextorgb(cfg.crxd, rgb); } ic->crxd = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("crxd", ic->crxd, cfg.crxd, rgb); /* tx */ hextorgb(cfg.ctx, rgb); ic->ctx = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("ctx", ic->ctx, cfg.ctx, rgb); if (cfg.ctxd[0] == '-') { modcolor(rgb, -50, 1); } else { hextorgb(cfg.ctxd, rgb); } ic->ctxd = gdImageColorAllocate(ic->im, rgb[0], rgb[1], rgb[2]); colorinitcheck("ctxd", ic->ctxd, cfg.ctxd, rgb); } void colorinitcheck(const char *color, const int value, const char *cfgtext, const int *rgb) { if (value == -1) { printf("Error: ImageColorAllocate failed.\n"); printf(" C: \"%s\" T: \"%s\" RGB: %d/%d/%d\n", color, cfgtext, rgb[0], rgb[1], rgb[2]); exit(EXIT_FAILURE); } } void layoutinit(IMAGECONTENT *ic, const char *title, const int width, const int height) { struct tm *d; char datestring[64], buffer[512]; gdFontPtr datefont; if (ic->large) { datefont = gdFontGetSmall(); } else { datefont = gdFontGetTiny(); } /* get time in given format */ d = localtime(&ic->interface.updated); strftime(datestring, 64, cfg.hformat, d); /* background, edges */ gdImageFill(ic->im, 0, 0, ic->cbackground); if (ic->showedge) { gdImageRectangle(ic->im, 0, 0, width - 1, height - 1, ic->cedge); } /* titlebox with title */ if (ic->showheader) { if (strlen(ic->headertext)) { strncpy_nt(buffer, ic->headertext, 65); } else { if (strcmp(ic->interface.name, ic->interface.alias) == 0 || strlen(ic->interface.alias) == 0) { snprintf(buffer, 512, "%s%s", ic->interface.name, title); } else { snprintf(buffer, 512, "%s (%s)%s", ic->interface.alias, ic->interface.name, title); } } gdImageFilledRectangle(ic->im, 2 + ic->showedge, 2 + ic->showedge, width - 3 - ic->showedge, 24, ic->cheader); gdImageString(ic->im, gdFontGetGiant(), 12, 5 + ic->showedge, (unsigned char *)buffer, ic->cheadertitle); } /* date */ if (!ic->showheader || ic->altdate) { gdImageString(ic->im, datefont, 5 + ic->showedge, height - 12 - ic->showedge - (ic->large * 3), (unsigned char *)datestring, ic->cvnstat); } else { gdImageString(ic->im, datefont, width - (((int)strlen(datestring)) * datefont->w + 12), 9 + ic->showedge - (ic->large * 3), (unsigned char *)datestring, ic->cheaderdate); } /* generator */ gdImageString(ic->im, gdFontGetTiny(), width - 114 - ic->showedge, height - 12 - ic->showedge, (unsigned char *)"vnStat / Teemu Toivola", ic->cvnstat); } void drawlegend(IMAGECONTENT *ic, const int x, const int y, const short israte) { if (!ic->showlegend) { return; } if (!israte) { gdImageString(ic->im, ic->font, x, y, (unsigned char *)"rx tx", ic->ctext); gdImageFilledRectangle(ic->im, x - 12 - (ic->large * 2), y + 4, x - 12 + ic->font->w - (ic->large * 2), y + 4 + ic->font->w, ic->crx); gdImageRectangle(ic->im, x - 12 - (ic->large * 2), y + 4, x - 12 + ic->font->w - (ic->large * 2), y + 4 + ic->font->w, ic->ctext); gdImageFilledRectangle(ic->im, x + 30 + (ic->large * 12), y + 4, x + 30 + ic->font->w + (ic->large * 12), y + 4 + ic->font->w, ic->ctx); gdImageRectangle(ic->im, x + 30 + (ic->large * 12), y + 4, x + 30 + ic->font->w + (ic->large * 12), y + 4 + ic->font->w, ic->ctext); } else { gdImageString(ic->im, ic->font, x - 12, y, (unsigned char *)"rx tx rate", ic->ctext); gdImageFilledRectangle(ic->im, x - 22 - (ic->large * 3), y + 4, x - 22 + ic->font->w - (ic->large * 3), y + 4 + ic->font->w, ic->crx); gdImageRectangle(ic->im, x - 22 - (ic->large * 3), y + 4, x - 22 + ic->font->w - (ic->large * 3), y + 4 + ic->font->w, ic->ctext); gdImageFilledRectangle(ic->im, x + 8 + (ic->large * 7), y + 4, x + 8 + ic->font->w + (ic->large * 7), y + 4 + ic->font->w, ic->ctx); gdImageRectangle(ic->im, x + 8 + (ic->large * 7), y + 4, x + 8 + ic->font->w + (ic->large * 7), y + 4 + ic->font->w, ic->ctext); } } void drawbar(IMAGECONTENT *ic, const int x, const int y, const int len, const uint64_t rx, const uint64_t tx, const uint64_t max, const short isestimate) { int rxl, txl, width = len, overlap = 0; int crx = ic->crx, ctx = ic->ctx, crxd = ic->crxd, ctxd = ic->ctxd; int ybeginoffset = YBEGINOFFSET, yendoffset = YBEGINOFFSET + ic->font->h - 6 - ic->large; if (isestimate) { switch (cfg.estimatestyle) { case 0: return; case 1: crx = ic->cbgoffsetmore; ctx = ic->cbgoffsetmore; crxd = ic->cbgoffsetmore; ctxd = ic->cbgoffsetmore; break; case 2: ybeginoffset += 19; yendoffset += 19; crxd = ic->crx; ctxd = ic->ctx; crx = ic->cbgoffset; ctx = ic->cbgoffset; break; default: return; } } if ((rx + tx) < max) { width = (int)lrint(((double)(rx + tx) / (double)max) * len); } else if ((rx + tx) > max || max == 0) { if (debug && (rx + tx) > max) { printf("Warning: Bar rx + tx sum exceeds given maximum, no bar shown\n"); } return; } if (width <= 0) { return; } if (tx > rx) { rxl = (int)lrint(((double)rx / (double)(rx + tx) * width)); txl = width - rxl; } else { txl = (int)lrint(((double)tx / (double)(rx + tx) * width)); rxl = width - txl; } if (rxl) { if (txl > 0) { overlap = 1; } gdImageFilledRectangle(ic->im, x, y + ybeginoffset, x + rxl - 1 + overlap, y + yendoffset, crx); gdImageRectangle(ic->im, x, y + ybeginoffset, x + rxl - 1 + overlap, y + yendoffset, crxd); } if (txl) { gdImageFilledRectangle(ic->im, x + rxl, y + ybeginoffset, x + rxl + txl - 1, y + yendoffset, ctx); gdImageRectangle(ic->im, x + rxl, y + ybeginoffset, x + rxl + txl - 1, y + yendoffset, ctxd); } } void drawpoles(IMAGECONTENT *ic, const int x, const int y, const int len, const uint64_t rx, const uint64_t tx, const uint64_t max) { int l; if (rx > 0) { l = (int)lrint(((double)rx / (double)max) * len); if (l > 0) { gdImageFilledRectangle(ic->im, x - (ic->large * 2), y + (len - l), x + 7 + (ic->large * 0), y + len, ic->crx); } } if (tx > 0) { l = (int)lrint(((double)tx / (double)max) * len); if (l > 0) { gdImageFilledRectangle(ic->im, x + 5 - (ic->large * 0), y + (len - l), x + 12 + (ic->large * 2), y + len, ic->ctx); } } } void drawdonut(IMAGECONTENT *ic, const int x, const int y, const float rxp, const float txp, const int size, const int holesize) { // libgd versions 2.2.3 - 2.2.5 have bug in gdImageFilledArc() https://github.com/libgd/libgd/issues/351 // so workaround needs to be used, 2.2 version series ends with 2.2.5 and the bug is fixed starting from 2.3.0 if (GD_MAJOR_VERSION == 2 && GD_MINOR_VERSION == 2 && GD_RELEASE_VERSION >= 3) { drawdonut_libgd_bug_workaround(ic, x, y, rxp, txp, size, holesize); } else { drawdonut_libgd_native(ic, x, y, rxp, txp, size, holesize); } } void drawdonut_libgd_bug_workaround(IMAGECONTENT *ic, const int x, const int y, const float rxp, const float txp, const int size, const int holesize) { int rxarc = 0, txarc = 0; if ((int)(rxp + txp) > 0) { rxarc = (int)lrintf(360 * (rxp / (float)100)); if ((int)(rxp + txp) == 100) { txarc = 360 - rxarc; } else { txarc = (int)lrintf(360 * (txp / (float)100)); } } // background filled circle gdImageFilledArc(ic->im, x, y, size, size, 0, 360, ic->cbgoffset, 0); if (txarc) { gdImageFilledArc(ic->im, x, y, size, size, 270, 270 + txarc, ic->ctxd, gdEdged | gdNoFill); if (txarc >= 5) { gdImageFill(ic->im, x + 1, y - (size / 2 - 3), ic->ctx); } gdImageFilledArc(ic->im, x, y, holesize, holesize, 270, 270 + txarc, ic->ctxd, gdEdged | gdNoFill); } if (rxarc) { gdImageFilledArc(ic->im, x, y, size, size, 270 + txarc, 270 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill); if (rxarc >= 5) { gdImageFill(ic->im, (int)(x + (size / 2 - 3) * cos((int)((270 * 2 + 2 * txarc + rxarc) / 2) * M_PI / 180)), (int)(y + (size / 2 - 3) * sin((int)((270 * 2 + 2 * txarc + rxarc) / 2) * M_PI / 180)), ic->crx); } gdImageFilledArc(ic->im, x, y, holesize, holesize, 270 + txarc, 270 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill); } // remove center from background filled circle, making it a donut gdImageFilledArc(ic->im, x, y, holesize - 2, holesize - 2, 0, 360, ic->cbackground, 0); } void drawdonut_libgd_native(IMAGECONTENT *ic, const int x, const int y, const float rxp, const float txp, const int size, const int holesize) { int rxarc = 0, txarc = 0; if ((int)(rxp + txp) > 0) { rxarc = (int)(360 * (rxp / (float)100)); if ((int)(rxp + txp) == 100) { txarc = 360 - rxarc; } else { txarc = (int)(360 * (txp / (float)100)); } } // background filled circle gdImageFilledArc(ic->im, x, y, size, size, 0, 360, ic->cbgoffset, 0); if (txarc) { gdImageFilledArc(ic->im, x, y, size, size, 270, 270 + txarc, ic->ctx, 0); gdImageFilledArc(ic->im, x, y, size, size, 270, 270 + txarc, ic->ctxd, gdEdged | gdNoFill); gdImageFilledArc(ic->im, x, y, holesize, holesize, 270, 270 + txarc, ic->ctxd, gdEdged | gdNoFill); } if (rxarc) { gdImageFilledArc(ic->im, x, y, size, size, 270 + txarc, 270 + txarc + rxarc, ic->crx, 0); gdImageFilledArc(ic->im, x, y, size, size, 270 + txarc, 270 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill); gdImageFilledArc(ic->im, x, y, holesize, holesize, 270 + txarc, 270 + txarc + rxarc, ic->crxd, gdEdged | gdNoFill); } // remove center from background filled circle, making it a donut gdImageFilledArc(ic->im, x, y, holesize - 2, holesize - 2, 0, 360, ic->cbackground, 0); } void drawpole(IMAGECONTENT *ic, const int x, const int y, const int length, const int direction, const int color) { int len = length - 1; if (length > 0) { switch (direction) { case 1: gdImageLine(ic->im, x, y, x, y - len, color); break; case 2: gdImageLine(ic->im, x, y, x, y + len, color); break; default: break; } } } void drawarrowup(IMAGECONTENT *ic, const int x, const int y) { gdImageLine(ic->im, x, y, x + 2, y + 3, ic->ctext); gdImageLine(ic->im, x, y, x - 2, y + 3, ic->ctext); gdImageLine(ic->im, x - 2, y + 3, x + 2, y + 3, ic->ctext); gdImageLine(ic->im, x, y + 1, x, y - 1, ic->ctext); } void drawarrowright(IMAGECONTENT *ic, const int x, const int y) { gdImageLine(ic->im, x, y, x - 3, y - 2, ic->ctext); gdImageLine(ic->im, x, y, x - 3, y + 2, ic->ctext); gdImageLine(ic->im, x - 3, y - 2, x - 3, y + 2, ic->ctext); gdImageLine(ic->im, x + 1, y, x - 1, y, ic->ctext); } void hextorgb(const char *input, int *rgb) { int offset; char hex[3], dec[4]; if (input[0] == '#') { offset = 1; } else { offset = 0; } snprintf(hex, 3, "%c%c", input[(0 + offset)], input[(1 + offset)]); snprintf(dec, 4, "%d", (int)strtol(hex, NULL, 16)); rgb[0] = atoi(dec); snprintf(hex, 3, "%c%c", input[(2 + offset)], input[(3 + offset)]); snprintf(dec, 4, "%d", (int)strtol(hex, NULL, 16)); rgb[1] = atoi(dec); snprintf(hex, 3, "%c%c", input[(4 + offset)], input[(5 + offset)]); snprintf(dec, 4, "%d", (int)strtol(hex, NULL, 16)); rgb[2] = atoi(dec); if (debug) { printf("%s -> %d, %d, %d\n", input, rgb[0], rgb[1], rgb[2]); } } void modcolor(int *rgb, const int offset, const int force) { int i, overflow = 0; if (debug) { printf("m%d (%d): %d, %d, %d -> ", offset, force, rgb[0], rgb[1], rgb[2]); } for (i = 0; i < 3; i++) { if ((rgb[i] + offset) > 255 || (rgb[i] + offset) < 0) { overflow++; } } /* positive offset gives lighter color, negative darker if forced */ /* otherwise the direction is changed depending on possible overflows */ for (i = 0; i < 3; i++) { if (overflow < 2 || force) { if ((rgb[i] + offset) > 255) { rgb[i] = 255; } else if ((rgb[i] + offset) < 0) { rgb[i] = 0; } else { rgb[i] += offset; } } else { if ((rgb[i] - offset) < 0) { rgb[i] = 0; } else if ((rgb[i] - offset) > 255) { rgb[i] = 255; } else { rgb[i] -= offset; } } } if (debug) { printf("%d, %d, %d\n", rgb[0], rgb[1], rgb[2]); } } char *getimagevalue(const uint64_t b, const int len, const int rate) { static char buffer[64]; int i, declen = 0, unit = 0, p = 1024; uint64_t limit; if (b == 0) { snprintf(buffer, 64, "%*s", len, "--"); } else { if (rate && (getunit() == 2 || getunit() == 4)) { p = 1000; unit = getunit(); } for (i = UNITPREFIXCOUNT - 1; i > 0; i--) { limit = (uint64_t)(pow(p, i - 1)) * 1000; if (b >= limit) { snprintf(buffer, 64, "%*.*f", len, declen, (double)b / (double)(getunitdivisor(unit, i + 1))); return buffer; } } snprintf(buffer, 64, "%*" PRIu64 "", len, b); } return buffer; } char *getimagescale(const uint64_t b, const int rate) { static char buffer[8]; int unit, div = 1, p = 1024; unit = getunit(); if (b == 0) { snprintf(buffer, 8, "--"); } else { if (rate) { if (unit == 2 || unit == 4) { p = 1000; } while (div < UNITPREFIXCOUNT && (double)b >= (pow(p, div - 1) * 1000)) { div++; } snprintf(buffer, 8, "%s", getrateunitprefix(unit, div)); } else { while (div < UNITPREFIXCOUNT && (double)b >= (pow(p, div - 1) * 1000)) { div++; } snprintf(buffer, 8, "%s", getunitprefix(div)); } } return buffer; } uint64_t getscale(const uint64_t input, const int rate) { int i, unit; unsigned int div = 1024; uint64_t result = input; unit = getunit(); if (rate && (unit == 2 || unit == 4)) { div = 1000; } /* get unit */ for (i = 0; result >= div; i++) { result = result / div; } /* round result depending of scale */ if (result >= 300) { result = result / 4 + (100 - ((result / 4) % 100)); } else if (result > 20) { result = result / 4 + (10 - ((result / 4) % 10)); } else { result = result / 4; } /* put unit back */ if (i) { result = result * (uint64_t)(pow(div, i)); } /* make sure result isn't zero */ if (!result) { if (i) { result = (uint64_t)(pow(div, i)); } else { result = 1; } } return result; } vnstat-2.9/src/vnstati.h0000644000000000000000000000111314162104251014021 0ustar rootroot#ifndef VNSTATI_H #define VNSTATI_H typedef struct { int cache, help; int32_t limit; char interface[32], filename[512], cfgfile[512]; FILE *pngout; } IPARAMS; void initiparams(IPARAMS *p); void showihelp(IPARAMS *p); void parseargs(IPARAMS *p, IMAGECONTENT *ic, int argc, char **argv); void validateinput(IPARAMS *p); void handlecaching(IPARAMS *p, IMAGECONTENT *ic); void handledatabase(IPARAMS *p, IMAGECONTENT *ic); void validateoutput(IPARAMS *p); void writeoutput(IPARAMS *p, IMAGECONTENT *ic); #if HAVE_DECL_GDIMAGEFILE void showsupportedfileextensions(void); #endif #endif vnstat-2.9/src/iflist.c0000644000000000000000000000156513505511055013635 0ustar rootroot#include "common.h" #include "iflist.h" int iflistadd(iflist **ifl, const char *iface, const uint32_t bandwidth) { iflist *newif = NULL, *ifl_iterator = *ifl; newif = malloc(sizeof(iflist)); if (newif == NULL) { return 0; } newif->next = NULL; if (*ifl != NULL) { while (ifl_iterator->next != NULL) { ifl_iterator = ifl_iterator->next; } ifl_iterator->next = newif; } else { *ifl = newif; } strncpy_nt(newif->interface, iface, 32); newif->bandwidth = bandwidth; return 1; } int iflistsearch(iflist **ifl, const char *iface) { iflist *ifl_iterator = *ifl; while (ifl_iterator != NULL) { if (strcmp(iface, ifl_iterator->interface) == 0) { return 1; } ifl_iterator = ifl_iterator->next; } return 0; } void iflistfree(iflist **ifl) { iflist *ifl_prev; while (*ifl != NULL) { ifl_prev = *ifl; *ifl = (*ifl)->next; free(ifl_prev); } } vnstat-2.9/src/datacache.c0000644000000000000000000000616513510102250014226 0ustar rootroot#include "common.h" #include "datacache.h" int datacache_add(datacache **dc, const char *interface, const short sync) { datacache *newdc; newdc = malloc(sizeof(datacache)); if (newdc == NULL) { return 0; } newdc->next = *dc; *dc = newdc; strncpy_nt((*dc)->interface, interface, 32); (*dc)->active = 1; (*dc)->filled = 0; (*dc)->syncneeded = sync; (*dc)->currx = 0; (*dc)->curtx = 0; (*dc)->updated = time(NULL); (*dc)->log = NULL; return 1; } int datacache_remove(datacache **dc, const char *interface) { int ret = 0; datacache *dc_prev, *dc_head; dc_head = *dc; dc_prev = *dc; if (*dc == NULL) { return ret; } /* handle list head remove */ if (strcmp((*dc)->interface, interface) == 0) { *dc = (*dc)->next; xferlog_clear(&dc_prev->log); free(dc_prev); return 1; } *dc = (*dc)->next; /* handle other locations */ while (*dc != NULL) { if (strcmp((*dc)->interface, interface) == 0) { dc_prev->next = (*dc)->next; xferlog_clear(&(*dc)->log); free(*dc); ret = 1; break; } dc_prev = *dc; *dc = (*dc)->next; } *dc = dc_head; return ret; } void datacache_clear(datacache **dc) { datacache *dc_prev; while (*dc != NULL) { dc_prev = *dc; *dc = (*dc)->next; xferlog_clear(&dc_prev->log); free(dc_prev); } } int datacache_count(datacache **dc) { int count = 0; datacache *cacheiterator = *dc; while (cacheiterator != NULL) { count++; cacheiterator = cacheiterator->next; } return count; } int datacache_activecount(datacache **dc) { int count = 0; datacache *cacheiterator = *dc; while (cacheiterator != NULL) { if (cacheiterator->active) { count++; } cacheiterator = cacheiterator->next; } return count; } void datacache_debug(datacache **dc) { int i = 1; datacache *cacheiterator = *dc; if (cacheiterator == NULL) { printf("cache: empty\n"); return; } printf("cache: "); while (cacheiterator != NULL) { printf(" %d: \"%s\" (", i, cacheiterator->interface); xferlog_debug(&cacheiterator->log, 0); printf(") "); cacheiterator = cacheiterator->next; i++; } printf("\n"); } int xferlog_add(xferlog **log, const time_t timestamp, const uint64_t rx, const uint64_t tx) { xferlog *newlog; if (*log == NULL || (*log)->timestamp != timestamp) { newlog = malloc(sizeof(xferlog)); if (newlog == NULL) { return 0; } newlog->next = *log; *log = newlog; newlog->timestamp = timestamp; newlog->rx = 0; newlog->tx = 0; } (*log)->rx += rx; (*log)->tx += tx; return 1; } void xferlog_clear(xferlog **log) { xferlog *log_prev; while (*log != NULL) { log_prev = *log; *log = (*log)->next; free(log_prev); } } void xferlog_debug(xferlog **log, const int newline) { int i = 1; xferlog *logiterator = *log; if (newline && logiterator == NULL) { printf(" xferlog: empty\n"); return; } if (newline) { printf(" xferlog: "); } while (logiterator != NULL) { printf("%d: %" PRIu64 " - %" PRIu64 " / %" PRIu64 "", i, (uint64_t)logiterator->timestamp, logiterator->rx, logiterator->tx); if (logiterator->next != NULL) { printf(", "); } logiterator = logiterator->next; i++; } if (newline) { printf("\n"); } } vnstat-2.9/src/daemon.c0000644000000000000000000006557014112265045013614 0ustar rootroot#include "common.h" #include "ifinfo.h" #include "iflist.h" #include "dbsql.h" #include "dbaccess.h" #include "datacache.h" #include "misc.h" #include "cfg.h" #include "ibw.h" #include "fs.h" #include "id.h" #include "daemon.h" void daemonize(void) { int i; char str[10]; i = (int)fork(); if (i < 0) { /* fork error */ perror("Error: fork"); exit(EXIT_FAILURE); } if (i > 0) { /* parent exits */ exit(EXIT_SUCCESS); } /* child (daemon) continues */ setsid(); /* obtain a new process group */ if (!verifylogaccess()) { printf("Error: Unable to use logfile. Exiting.\n"); exit(EXIT_FAILURE); } /* lock / pid file */ pidfile = open(cfg.pidfile, O_RDWR | O_CREAT, 0644); if (pidfile < 0) { perror("Error: pidfile"); snprintf(errorstring, 1024, "opening pidfile \"%s\" failed (%s), exiting.", cfg.pidfile, strerror(errno)); printe(PT_Error); exit(EXIT_FAILURE); /* can't open */ } if (lockf(pidfile, F_TLOCK, 0) < 0) { perror("Error: pidfile lock"); snprintf(errorstring, 1024, "pidfile \"%s\" lock failed (%s), exiting.", cfg.pidfile, strerror(errno)); printe(PT_Error); exit(EXIT_FAILURE); /* can't lock */ } /* close all descriptors except lock file */ for (i = getdtablesize(); i >= 0; --i) { if (i != pidfile) { close(i); } } /* redirect standard i/o to null */ i = open("/dev/null", O_RDWR); /* stdin */ if (i < 0) { perror("Error: open() /dev/null"); snprintf(errorstring, 1024, "open() /dev/null failed, exiting."); printe(PT_Error); exit(EXIT_FAILURE); } /* stdout */ if (dup(i) < 0) { perror("Error: dup(stdout)"); snprintf(errorstring, 1024, "dup(stdout) failed, exiting."); printe(PT_Error); exit(EXIT_FAILURE); } /* stderr */ if (dup(i) < 0) { perror("Error: dup(stderr)"); snprintf(errorstring, 1024, "dup(stderr) failed, exiting."); printe(PT_Error); exit(EXIT_FAILURE); } close(i); umask(027); /* set newly created file permissions */ /* change running directory */ if (chdir("/") < 0) { perror("Error: chdir(/)"); snprintf(errorstring, 1024, "directory change to / failed, exiting."); printe(PT_Error); exit(EXIT_FAILURE); } /* first instance continues */ snprintf(str, 10, "%d\n", (int)getpid()); /* record pid to pidfile */ if (write(pidfile, str, strlen(str)) < 0) { perror("Error: write(pidfile)"); snprintf(errorstring, 1024, "writing to pidfile \"%s\" failed (%s), exiting.", cfg.pidfile, strerror(errno)); printe(PT_Error); exit(EXIT_FAILURE); } signal(SIGCHLD, SIG_IGN); /* ignore child */ signal(SIGTSTP, SIG_IGN); /* ignore tty signals */ signal(SIGTTOU, SIG_IGN); signal(SIGTTIN, SIG_IGN); } unsigned int addinterfaces(DSTATE *s) { iflist *ifl = NULL, *ifl_iterator = NULL; unsigned int count = 0; uint32_t bwlimit = 0; timeused_debug(__func__, 1); /* get list of currently visible interfaces */ if (getiflist(&ifl, 0, 1) == 0) { iflistfree(&ifl); return 0; } if (ifl == NULL) { return 0; } if (debug) { printf("Interface list:"); ifl_iterator = ifl; while (ifl_iterator != NULL) { printf(" \"%s\"", ifl_iterator->interface); ifl_iterator = ifl_iterator->next; } printf("\n"); } ifl_iterator = ifl; while (ifl_iterator != NULL) { if (debug) printf("Processing: \"%s\"\n", ifl_iterator->interface); /* skip already known interfaces */ if (db_getinterfacecountbyname(ifl_iterator->interface)) { if (debug) printf("already known\n"); ifl_iterator = ifl_iterator->next; continue; } /* create database for interface */ if (!db_addinterface(ifl_iterator->interface)) { if (debug) printf("add failed, skip\n"); ifl_iterator = ifl_iterator->next; continue; } if (!getifinfo(ifl_iterator->interface)) { if (debug) printf("getifinfo failed, skip\n"); /* remove empty entry from database since the interface can't provide data */ db_removeinterface(ifl_iterator->interface); ifl_iterator = ifl_iterator->next; continue; } db_setcounters(ifl_iterator->interface, ifinfo.rx, ifinfo.tx); count++; ibwget(ifl_iterator->interface, &bwlimit); if (bwlimit > 0) { snprintf(errorstring, 1024, "Interface \"%s\" added with %" PRIu32 " Mbit bandwidth limit.", ifl_iterator->interface, bwlimit); } else { snprintf(errorstring, 1024, "Interface \"%s\" added. Warning: no bandwidth limit has been set.", ifl_iterator->interface); } printe(PT_Infoless); if (s->running) { datacache_add(&s->dcache, ifl_iterator->interface, 1); } ifl_iterator = ifl_iterator->next; } if (count && !s->running) { if (count == 1) { printf("-> %u new interface found.\n", count); } else { printf("-> %u new interfaces found.\n", count); } printf("Limits can be modified using the configuration file. See \"man vnstat.conf\".\n"); printf("Unwanted interfaces can be removed from monitoring with \"vnstat --remove\".\n"); } iflistfree(&ifl); timeused_debug(__func__, 0); return count; } void detectboot(DSTATE *s) { char buffer[32]; char *btime_buffer; uint64_t current_btime, db_btime; current_btime = getbtime(); btime_buffer = db_getinfo("btime"); if (current_btime == 0) { return; } else if (strlen(btime_buffer) == 0) { snprintf(buffer, 32, "%" PRIu64 "", current_btime); db_setinfo("btime", buffer, 1); return; } db_btime = strtoull(btime_buffer, (char **)NULL, 0); if (db_btime < (current_btime - (uint32_t)cfg.bvar)) { s->bootdetected = 1; if (debug) printf("System has been booted, %" PRIu64 " < %" PRIu64 " - %d\n", db_btime, current_btime, cfg.bvar); } snprintf(buffer, 32, "%" PRIu64 "", current_btime); db_setinfo("btime", buffer, 1); } void debugtimestamp(void) { time_t now; char timestamp[22]; now = time(NULL); strftime(timestamp, 22, DATETIMEFORMAT, localtime(&now)); printf("%s\n", timestamp); } void initdstate(DSTATE *s) { db = NULL; noexit = 1; /* disable exits in functions */ debug = 0; /* debug disabled by default */ disableprints = 0; /* let prints be visible */ s->rundaemon = 0; /* daemon disabled by default */ s->running = 0; s->dbsaved = 1; s->showhelp = 1; s->sync = 0; s->forcesave = 0; s->noadd = 0; s->initdb = 0; s->iflisthash = 0; s->cfgfile[0] = '\0'; s->user[0] = '\0'; s->group[0] = '\0'; s->prevdbupdate = 0; s->prevdbsave = 0; s->dbifcount = 0; s->dodbsave = 0; s->bootdetected = 0; s->cleanuphour = getcurrenthour(); s->dbretrycount = 0; s->dcache = NULL; s->prevwaldbcheckpoint = time(NULL); } void preparedatabase(DSTATE *s) { s->dbifcount = db_getinterfacecount(); if (s->dbifcount > 0 && !cfg.alwaysadd) { s->dbifcount = 0; return; } if (debug) { printf("db if count: %" PRIu64 "\n", s->dbifcount); } if (s->noadd) { printf("No interfaces found in database, exiting.\n"); exit(EXIT_FAILURE); } if (!spacecheck(cfg.dbdir)) { printf("Error: Not enough free diskspace available, exiting.\n"); exit(EXIT_FAILURE); } if (s->dbifcount == 0) { if (importlegacydbs(s) && !cfg.alwaysadd) { s->dbifcount = 0; return; } printf("No interfaces found in database, adding available interfaces...\n"); } if (!addinterfaces(s) && s->dbifcount == 0) { printf("Nothing to do, exiting.\n"); exit(EXIT_FAILURE); } /* set counter back to zero so that dbs will be cached later */ s->dbifcount = 0; } unsigned int importlegacydbs(DSTATE *s) { DIR *dir; struct dirent *di; unsigned int importcount = 0; if ((dir = opendir(cfg.dbdir)) == NULL) { printf("Error: Unable to open database directory \"%s\": %s\n", cfg.dbdir, strerror(errno)); printf("Make sure it exists and is at least read enabled for current user.\n"); printf("Exiting...\n"); exit(EXIT_FAILURE); } s->dbifcount = 0; while ((di = readdir(dir))) { if ((di->d_name[0] != '.') && (strncmp(di->d_name, DATABASEFILE, strlen(DATABASEFILE)) != 0)) { /* ignore already known interfaces */ if (db_getinterfacecountbyname(di->d_name)) { continue; } if (importlegacydb(di->d_name, cfg.dbdir)) { importcount++; } } } closedir(dir); s->dbifcount += importcount; return importcount; } void setsignaltraps(void) { intsignal = 0; if (signal(SIGINT, sighandler) == SIG_ERR) { perror("Error: signal SIGINT"); exit(EXIT_FAILURE); } if (signal(SIGHUP, sighandler) == SIG_ERR) { perror("Error: signal SIGHUP"); exit(EXIT_FAILURE); } if (signal(SIGTERM, sighandler) == SIG_ERR) { perror("Error: signal SIGTERM"); exit(EXIT_FAILURE); } } void filldatabaselist(DSTATE *s) { iflist *dbifl = NULL, *dbifl_iterator = NULL; timeused_debug(__func__, 1); if (db_getiflist(&dbifl) < 0) { errorexitdaemon(s, 1); } dbifl_iterator = dbifl; while (dbifl_iterator != NULL) { if (debug) { printf("\nProcessing interface \"%s\"...\n", dbifl_iterator->interface); } if (!datacache_add(&s->dcache, dbifl_iterator->interface, s->sync)) { snprintf(errorstring, 1024, "Cache memory allocation failed (%s), exiting.", strerror(errno)); printe(PT_Error); errorexitdaemon(s, 1); } s->dbifcount++; dbifl_iterator = dbifl_iterator->next; } iflistfree(&dbifl); s->sync = 0; /* disable update interval check for one loop if database list was refreshed */ /* otherwise increase default update interval since there's nothing else to do */ if (s->dbifcount) { s->updateinterval = 0; intsignal = 42; s->prevdbsave = s->current; /* list monitored interfaces to log */ datacache_status(&s->dcache); } else { s->updateinterval = 120; } timeused_debug(__func__, 0); } void adjustsaveinterval(DSTATE *s) { /* modify active save interval if all interfaces are unavailable */ if (datacache_activecount(&s->dcache) > 0) { s->saveinterval = cfg.saveinterval * 60; } else { s->saveinterval = cfg.offsaveinterval * 60; } } void checkdbsaveneed(DSTATE *s) { if ((s->current - s->prevdbsave) >= (s->saveinterval) || s->forcesave) { s->dodbsave = 1; s->forcesave = 0; s->prevdbsave = s->current - (s->current % s->saveinterval); } else { s->dodbsave = 0; } } void processdatacache(DSTATE *s) { datacache *iterator = s->dcache; timeused_debug(__func__, 1); while (iterator != NULL) { if (debug) { printf("dc: processing %s (%d)...\n", iterator->interface, s->dodbsave); } if (!iterator->filled) { if (!initcachevalues(s, &iterator)) { iterator = iterator->next; continue; } s->iflisthash = 0; } if (iterator->active) { if (!getifinfo(iterator->interface)) { /* disable interface since we can't access its data */ iterator->active = 0; snprintf(errorstring, 1024, "Interface \"%s\" not available, disabling.", iterator->interface); printe(PT_Info); } else { if (!processifinfo(s, &iterator)) { iterator = iterator->next; continue; } } } else { if (debug) printf("dc: interface is disabled\n"); } iterator = iterator->next; } if (s->bootdetected) { s->bootdetected = 0; } timeused_debug(__func__, 0); if (s->dodbsave) { flushcachetodisk(s); cleanremovedinterfaces(s); if (s->cleanuphour != getcurrenthour()) { db_removeoldentries(); s->cleanuphour = getcurrenthour(); } if (cfg.rescanonsave) { rescandatabaseforinterfaces(s); } s->dodbsave = 0; } } int initcachevalues(DSTATE *s, datacache **dc) { interfaceinfo info; if (!db_getinterfaceinfo((*dc)->interface, &info)) { return 0; } if (s->bootdetected) { (*dc)->currx = 0; (*dc)->curtx = 0; } else { (*dc)->currx = info.rxcounter; (*dc)->curtx = info.txcounter; } (*dc)->updated = info.updated; (*dc)->filled = 1; return 1; } int processifinfo(DSTATE *s, datacache **dc) { uint64_t rxchange, txchange; uint64_t maxtransfer; uint32_t maxbw; time_t interval; short detected64bit = 0; if ((*dc)->syncneeded) { /* if --sync was used during startup */ (*dc)->currx = ifinfo.rx; (*dc)->curtx = ifinfo.tx; (*dc)->syncneeded = 0; return 1; } if ((*dc)->updated > ifinfo.timestamp) { /* skip update if previous update is less than a day in the future */ /* otherwise exit with error message since the clock is probably messed */ if ((*dc)->updated > (ifinfo.timestamp + 86400)) { snprintf(errorstring, 1024, "Interface \"%s\" has previous update date too much in the future, exiting. (%u / %u)", (*dc)->interface, (unsigned int)(*dc)->updated, (unsigned int)ifinfo.timestamp); printe(PT_Error); errorexitdaemon(s, 1); } return 0; } interval = ifinfo.timestamp - (*dc)->updated; /* maximum configurable update interval is 5 minutes, limit here is set to 6 minutes (360 seconds) */ /* in order to be on the safe side and avoid discarding data in case there's some random extra delay */ if ((interval >= 1) && (interval <= 360)) { if ((*dc)->currx > MAX32 || (*dc)->curtx > MAX32 || ifinfo.rx > MAX32 || ifinfo.tx > MAX32) { ifinfo.is64bit = 1; detected64bit = 1; } rxchange = countercalc(&(*dc)->currx, &ifinfo.rx, ifinfo.is64bit); txchange = countercalc(&(*dc)->curtx, &ifinfo.tx, ifinfo.is64bit); /* workaround for interface drivers using only 32-bit range with 64-bit interface counters, */ /* active only when automatic detection is enabled and all values are within 32-bit range */ if (cfg.is64bit == -2 || !detected64bit) { if ((rxchange / (uint64_t)interval / 1024 / 1024 * 8) > BWMAX || (txchange / (uint64_t)interval / 1024 / 1024 * 8) > BWMAX) { ifinfo.is64bit = 0; rxchange = countercalc(&(*dc)->currx, &ifinfo.rx, 0); txchange = countercalc(&(*dc)->curtx, &ifinfo.tx, 0); } } /* get bandwidth limit for current interface */ ibwget((*dc)->interface, &maxbw); if (maxbw > 0) { /* calculate maximum possible transfer since last update based on set maximum rate */ /* and add 2% in order to be on the safe side */ maxtransfer = (uint64_t)(ceilf(((float)maxbw / (float)8) * (float)interval * (float)1.02)) * 1024 * 1024; if (debug) printf("interval: %" PRIu64 " maxbw: %" PRIu32 " maxrate: %" PRIu64 " rxc: %" PRIu64 " txc: %" PRIu64 "\n", (uint64_t)interval, maxbw, maxtransfer, rxchange, txchange); /* sync counters if traffic is greater than set maximum */ if ((rxchange > maxtransfer) || (txchange > maxtransfer)) { snprintf(errorstring, 1024, "Traffic rate for \"%s\" higher than set maximum %" PRIu32 " Mbit (%" PRIu64 "s->%" PRIu64 ", r%" PRIu64 " t%" PRIu64 ", 64bit:%d), syncing.", (*dc)->interface, maxbw, (uint64_t)interval, maxtransfer, rxchange, txchange, ifinfo.is64bit); printe(PT_Info); rxchange = txchange = 0; } } if (rxchange || txchange || cfg.trafficlessentries) { xferlog_add(&(*dc)->log, (*dc)->updated - ((*dc)->updated % 300), rxchange, txchange); } } (*dc)->currx = ifinfo.rx; (*dc)->curtx = ifinfo.tx; (*dc)->updated = ifinfo.timestamp; return 1; } void flushcachetodisk(DSTATE *s) { int ret; double used_secs = 0.0; uint32_t logcount = 0; datacache *iterator = s->dcache; xferlog *logiterator; interfaceinfo info; timeused(__func__, 1); if (!db_begintransaction()) { handledatabaseerror(s); return; } db_errcode = 0; while (iterator != NULL) { /* ignore interface no longer in database */ if (!db_getinterfacecountbyname(iterator->interface)) { if (db_errcode) { handledatabaseerror(s); break; } else { iterator = iterator->next; continue; } } /* flush interface specific log to database */ logcount = 0; logiterator = iterator->log; while (logiterator != NULL) { if (!db_addtraffic_dated(iterator->interface, logiterator->rx, logiterator->tx, (uint64_t)logiterator->timestamp)) { handledatabaseerror(s); break; } logiterator = logiterator->next; logcount++; } if (db_errcode) { break; } /* update database counters if new data was inserted */ if (logcount) { if (!db_setcounters(iterator->interface, iterator->currx, iterator->curtx)) { handledatabaseerror(s); break; } } if (!iterator->active && !logcount) { /* throw away if interface hasn't seen any data and is disabled */ if (!iterator->currx && !iterator->curtx) { ret = db_getinterfaceinfo(iterator->interface, &info); if (!ret || (!info.rxtotal && !info.txtotal)) { snprintf(errorstring, 1024, "Removing interface \"%s\" from database as it is disabled and has seen no data.", iterator->interface); printe(PT_Info); if (!db_removeinterface(iterator->interface)) { if (db_errcode) { handledatabaseerror(s); } } break; } } } /* update interface timestamp in database */ if (!db_setupdated(iterator->interface, iterator->updated)) { handledatabaseerror(s); break; } /* update interface activity status in database */ if (!db_setactive(iterator->interface, iterator->active)) { handledatabaseerror(s); break; } iterator = iterator->next; } if (db_intransaction && !db_errcode) { if (!db_committransaction()) { handledatabaseerror(s); } else { /* clear xferlog now that everything is in database */ iterator = s->dcache; while (iterator != NULL) { xferlog_clear(&iterator->log); iterator = iterator->next; } s->dbretrycount = 0; } } else { db_rollbacktransaction(); } used_secs = timeused(__func__, 0); if (used_secs > SLOWDBWARNLIMIT) { snprintf(errorstring, 1024, "Writing cached data to database took %.1f seconds.", used_secs); printe(PT_Warning); } } void handledatabaseerror(DSTATE *s) { if (db_iserrcodefatal(db_errcode)) { snprintf(errorstring, 1024, "Fatal database error detected, exiting."); printe(PT_Error); errorexitdaemon(s, 1); } else { if (db_isdiskfull(db_errcode)) { snprintf(errorstring, 1024, "Disk is full, continuing with data caching."); printe(PT_Error); } else { s->dbretrycount++; if (s->dbretrycount > DBRETRYLIMIT) { snprintf(errorstring, 1024, "Database error retry limit of %d reached, exiting.", DBRETRYLIMIT); printe(PT_Error); errorexitdaemon(s, 1); } } } } void cleanremovedinterfaces(DSTATE *s) { datacache *iterator = s->dcache; iflist *dbifl = NULL, *dbifl_iterator = NULL; timeused_debug(__func__, 1); while (iterator != NULL) { if (!db_getinterfacecountbyname(iterator->interface)) { iflistadd(&dbifl, iterator->interface, 0); } iterator = iterator->next; } if (dbifl != NULL) { dbifl_iterator = dbifl; while (dbifl_iterator != NULL) { snprintf(errorstring, 1024, "Interface \"%s\" no longer in database, stopping monitoring.", dbifl_iterator->interface); printe(PT_Info); datacache_remove(&s->dcache, dbifl_iterator->interface); if (s->dbifcount > 0) { s->dbifcount--; } dbifl_iterator = dbifl_iterator->next; } datacache_status(&s->dcache); iflistfree(&dbifl); } timeused_debug(__func__, 0); } void rescandatabaseforinterfaces(DSTATE *s) { short interface_already_monitored = 0; uint64_t dbifcount = s->dbifcount; datacache *iterator = NULL; iflist *dbifl = NULL, *dbifl_iterator = NULL; timeused_debug(__func__, 1); if (db_getiflist(&dbifl) > 0 && dbifl != NULL) { dbifl_iterator = dbifl; while (dbifl_iterator != NULL) { iterator = s->dcache; interface_already_monitored = 0; while (iterator != NULL) { if (strcmp(iterator->interface, dbifl_iterator->interface) == 0) { interface_already_monitored = 1; break; } iterator = iterator->next; } if (!interface_already_monitored) { snprintf(errorstring, 1024, "Interface \"%s\" found from database, starting monitoring.", dbifl_iterator->interface); printe(PT_Info); if (!datacache_add(&s->dcache, dbifl_iterator->interface, 1)) { snprintf(errorstring, 1024, "Cache memory allocation failed (%s), exiting.", strerror(errno)); printe(PT_Error); errorexitdaemon(s, 1); } s->dbifcount++; } dbifl_iterator = dbifl_iterator->next; } if (s->dbifcount != dbifcount) { datacache_status(&s->dcache); } iflistfree(&dbifl); } timeused_debug(__func__, 0); } void handleintsignals(DSTATE *s) { switch (intsignal) { case SIGHUP: snprintf(errorstring, 1024, "SIGHUP received, flushing data to disk and reloading config."); printe(PT_Info); flushcachetodisk(s); datacache_clear(&s->dcache); s->dbifcount = 0; ibwflush(); db_close(); loadcfg(s->cfgfile, CT_Daemon); ibwloadcfg(s->cfgfile); if (!db_open_rw(1)) { snprintf(errorstring, 1024, "Opening database after SIGHUP failed (%s), exiting.", strerror(errno)); printe(PT_Error); if (s->rundaemon && !debug) { close(pidfile); unlink(cfg.pidfile); } exit(EXIT_FAILURE); } break; case SIGINT: snprintf(errorstring, 1024, "SIGINT received, exiting."); printe(PT_Info); s->running = 0; break; case SIGTERM: snprintf(errorstring, 1024, "SIGTERM received, exiting."); printe(PT_Info); s->running = 0; break; /* from filldatabaselist() */ case 42: break; case 0: break; default: snprintf(errorstring, 1024, "Unknown signal %d received, ignoring.", intsignal); printe(PT_Info); break; } intsignal = 0; } void preparedirs(DSTATE *s) { /* database directory */ if (mkpath(cfg.dbdir, 0775)) { updatedirowner(cfg.dbdir, s->user, s->group); } if (!cfg.createdirs || !s->rundaemon) { return; } /* possible pid/lock and log directory */ preparevnstatdir(cfg.pidfile, s->user, s->group); if (cfg.uselogging == 1) { preparevnstatdir(cfg.logfile, s->user, s->group); } } void datacache_status(datacache **dc) { char buffer[1024], bwtemp[32]; unsigned int b = 0, count = 0; uint32_t bwlimit = 0; datacache *iterator = *dc; timeused_debug(__func__, 1); snprintf(buffer, 1024, "Monitoring (%d): ", datacache_count(dc)); b = (unsigned int)strlen(buffer) + 1; while (iterator != NULL) { if ((b + strlen(iterator->interface) + 32) < 1020) { if (!ibwget(iterator->interface, &bwlimit) || bwlimit == 0) { snprintf(bwtemp, 32, " (no limit) "); } else { snprintf(bwtemp, 32, " (%" PRIu32 " Mbit) ", bwlimit); } strcat(buffer, iterator->interface); strcat(buffer, bwtemp); b += strlen(iterator->interface) + strlen(bwtemp); } else { strcat(buffer, "..."); break; } count++; iterator = iterator->next; } if (count) { strncpy_nt(errorstring, buffer, 1024); } else { snprintf(errorstring, 1024, "Nothing to monitor"); } printe(PT_Info); timeused_debug(__func__, 0); } void interfacechangecheck(DSTATE *s) { char *ifacelist, interface[32]; datacache *iterator = s->dcache; uint32_t newhash; int offset, found; timeused_debug(__func__, 1); /* get list of currently visible interfaces */ if (getifliststring(&ifacelist, 0) == 0) { free(ifacelist); s->iflisthash = 0; return; } newhash = simplehash(ifacelist, (int)strlen(ifacelist)); if (s->iflisthash == newhash) { free(ifacelist); return; } /* search for changes if hash doesn't match */ if (debug) { printf("ifacelist changed: '%s' %u <> %u\n", ifacelist, s->iflisthash, newhash); } while (iterator != NULL) { if (!iterator->filled) { iterator = iterator->next; continue; } found = offset = 0; while (offset <= (int)strlen(ifacelist)) { sscanf(ifacelist + offset, "%31s", interface); if (strcmp(iterator->interface, interface) == 0) { found = 1; break; } offset += (int)strlen(interface) + 1; } if (iterator->active == 1 && found == 0) { iterator->active = 0; iterator->currx = 0; iterator->curtx = 0; if (cfg.savestatus) { s->forcesave = 1; } snprintf(errorstring, 1024, "Interface \"%s\" disabled.", iterator->interface); printe(PT_Info); } else if (iterator->active == 0 && found == 1) { iterator->active = 1; iterator->currx = 0; iterator->curtx = 0; if (cfg.savestatus) { s->forcesave = 1; } snprintf(errorstring, 1024, "Interface \"%s\" enabled.", iterator->interface); printe(PT_Info); } iterator = iterator->next; } free(ifacelist); s->iflisthash = newhash; timeused_debug(__func__, 0); } uint32_t simplehash(const char *data, int len) { uint32_t hash; if (len <= 0 || data == NULL) { return 0; } hash = (uint32_t)len; for (len--; len >= 0; len--) { if (len > 0) { hash += (uint32_t)data[len] * (uint32_t)len; } else { hash += (uint32_t)data[len]; } } return hash; } __attribute__((noreturn)) void errorexitdaemon(DSTATE *s, const int fataldberror) { if (!fataldberror) { flushcachetodisk(s); } db_close(); datacache_clear(&s->dcache); ibwflush(); if (s->rundaemon && !debug) { close(pidfile); unlink(cfg.pidfile); } exit(EXIT_FAILURE); } short getcurrenthour(void) { int ret = 0; time_t current; struct tm *stm; char buffer[4]; current = time(NULL); stm = localtime(¤t); if (stm == NULL) { return 0; } if (!strftime(buffer, sizeof(buffer), "%H", stm)) { return 0; } ret = atoi(buffer); if (ret > 23 || ret < 0) { ret = 0; } return (short)ret; } int waittimesync(DSTATE *s) { datacache *iterator = s->dcache; char timestamp[22], timestamp2[22]; if (cfg.timesyncwait == 0) { return 0; } if (s->prevdbupdate == 0 && s->prevdbsave == 0) { while (iterator != NULL) { if (debug) { printf("w: processing %s...\n", iterator->interface); } if (!iterator->filled) { if (!initcachevalues(s, &iterator)) { iterator = iterator->next; continue; } s->iflisthash = 0; } if (debug) { strftime(timestamp, 22, DATETIMEFORMAT, localtime(&iterator->updated)); printf("w: has %s\n", timestamp); } if (iterator->updated > s->prevdbsave) { s->prevdbsave = iterator->updated; } iterator = iterator->next; } if (s->prevdbsave == 0) { snprintf(errorstring, 1024, "Couldn't define when database was last updated. Continuing, some errors may follow."); printe(PT_Info); return 0; } } s->current = time(NULL); if (debug) { strftime(timestamp, 22, DATETIMEFORMAT, localtime(&s->current)); printf("current time: %s\n", timestamp); strftime(timestamp2, 22, DATETIMEFORMAT, localtime(&s->prevdbsave)); printf("latest db update: %s\n", timestamp2); } if (s->current < s->prevdbsave) { if (s->prevdbupdate == 0) { s->prevdbupdate = s->current; strftime(timestamp, 22, DATETIMEFORMAT, localtime(&s->current)); strftime(timestamp2, 22, DATETIMEFORMAT, localtime(&s->prevdbsave)); snprintf(errorstring, 1024, "Latest database update is in the future (db: %s > now: %s). Giving the system clock up to %d minutes to sync before continuing.", timestamp2, timestamp, cfg.timesyncwait); printe(PT_Info); } if (s->current - s->prevdbupdate >= cfg.timesyncwait * 60) { strftime(timestamp, 22, DATETIMEFORMAT, localtime(&s->current)); strftime(timestamp2, 22, DATETIMEFORMAT, localtime(&s->prevdbsave)); snprintf(errorstring, 1024, "Latest database update is still in the future (db: %s > now: %s), continuing. Some errors may follow.", timestamp2, timestamp); printe(PT_Info); return 0; } } else { if (s->prevdbupdate != 0) { strftime(timestamp, 22, DATETIMEFORMAT, localtime(&s->current)); strftime(timestamp2, 22, DATETIMEFORMAT, localtime(&s->prevdbsave)); snprintf(errorstring, 1024, "Latest database update is no longer in the future (db: %s <= now: %s), continuing.", timestamp2, timestamp); printe(PT_Info); } s->prevdbsave = s->current; s->prevdbupdate = 0; if (debug) { printf("time sync ok\n\n"); } return 0; } return 1; } vnstat-2.9/src/ifinfo.h0000644000000000000000000000150714077625105013625 0ustar rootroot#ifndef IFINFO_H #define IFINFO_H #include "iflist.h" #if defined(BSD_VNSTAT) #include #endif int getifinfo(const char *iface); int getifliststring(char **ifacelist, int showspeed); int getiflist(iflist **ifl, const int getspeed, const int validate); #if defined(__linux__) || defined(CHECK_VNSTAT) int getiflist_linux(iflist **ifl, const int getspeed, const int validate); #elif defined(BSD_VNSTAT) int getiflist_bsd(iflist **ifl, const int getspeed, const int validate); #endif int readproc(const char *iface); int readsysclassnet(const char *iface); #if defined(BSD_VNSTAT) int getifdata(const char *iface, struct if_data *ifd); int readifaddrs(const char *iface); #endif uint32_t getifspeed(const char *iface); int isifavailable(const char *iface); int isifvalid(const char *iface); int istun(const char *iface); #endif vnstat-2.9/src/daemon.h0000644000000000000000000000261614106255051013610 0ustar rootroot#ifndef DAEMON_H #define DAEMON_H typedef struct { int updateinterval, saveinterval; short running, dodbsave, rundaemon; short dbsaved, showhelp, sync, forcesave, noadd, initdb; short bootdetected, cleanuphour, dbretrycount; uint32_t iflisthash; uint64_t dbifcount; char cfgfile[512]; char user[33], group[33]; time_t current, prevdbupdate, prevdbsave, prevwaldbcheckpoint; datacache *dcache; } DSTATE; void daemonize(void); void debugtimestamp(void); unsigned int addinterfaces(DSTATE *s); void initdstate(DSTATE *s); void preparedatabase(DSTATE *s); unsigned int importlegacydbs(DSTATE *s); void setsignaltraps(void); void filldatabaselist(DSTATE *s); void adjustsaveinterval(DSTATE *s); void checkdbsaveneed(DSTATE *s); void processdatacache(DSTATE *s); void processdatalist(DSTATE *s); void handleintsignals(DSTATE *s); void preparedirs(DSTATE *s); void detectboot(DSTATE *s); int initcachevalues(DSTATE *s, datacache **dc); int processifinfo(DSTATE *s, datacache **dc); void flushcachetodisk(DSTATE *s); void handledatabaseerror(DSTATE *s); void cleanremovedinterfaces(DSTATE *s); void rescandatabaseforinterfaces(DSTATE *s); void datacache_status(datacache **dc); void interfacechangecheck(DSTATE *s); uint32_t simplehash(const char *data, int len); void errorexitdaemon(DSTATE *s, const int fataldberror) __attribute__((noreturn)); short getcurrenthour(void); int waittimesync(DSTATE *s); #endif vnstat-2.9/src/id.c0000644000000000000000000000407413465371162012745 0ustar rootroot#include "common.h" #include "id.h" uid_t getuser(const char *user) { struct passwd *pw; uid_t uid; if (!strlen(user)) { return getuid(); } if (isnumeric(user)) { uid = (uid_t)atoi(user); pw = getpwuid(uid); } else { pw = getpwnam(user); } if (pw == NULL) { printf("Error: No such user: \"%s\".\n", user); exit(EXIT_FAILURE); } uid = pw->pw_uid; if (debug) printf("getuser(%s / %d): %s (%d)\n", user, atoi(user), pw->pw_name, (int)uid); return uid; } gid_t getgroup(const char *group) { struct group *gr; gid_t gid; if (!strlen(group)) { return getgid(); } if (isnumeric(group)) { gid = (gid_t)atoi(group); gr = getgrgid(gid); } else { gr = getgrnam(group); } if (gr == NULL) { printf("Error: No such group: \"%s\".\n", group); exit(EXIT_FAILURE); } gid = gr->gr_gid; if (debug) printf("getgroup(%s / %d): %s (%d)\n", group, atoi(group), gr->gr_name, (int)gid); return gid; } void setuser(const char *user) { uid_t uid; if (!strlen(user)) { return; } if (isnumeric(user) && atoi(user) == 0) { return; } uid = getuser(user); if (uid == getuser("")) { if (debug) printf("no user switching needed, already as requested user \"%s\"\n", user); return; } if (!hasroot()) { printf("Error: User can only be set as root.\n"); exit(EXIT_FAILURE); } if (debug) printf("switching to user id %d.\n", uid); if (setuid(uid) != 0) { perror("Error: setuid"); exit(EXIT_FAILURE); } } void setgroup(const char *group) { gid_t gid; if (!strlen(group)) { return; } if (isnumeric(group) && atoi(group) == 0) { return; } gid = getgroup(group); if (gid == getgroup("")) { if (debug) printf("no group switching needed, already as requested group \"%s\"\n", group); return; } if (!hasroot()) { printf("Error: Group can only be set as root.\n"); exit(EXIT_FAILURE); } if (debug) printf("switching to group id %d.\n", gid); if (setgid(gid) != 0) { perror("Error: setgid"); exit(EXIT_FAILURE); } } int hasroot(void) { if (getuid() != 0 && geteuid() != 0) { return 0; } return 1; } vnstat-2.9/src/dbshow.h0000644000000000000000000000242314172632410013630 0ustar rootroot#ifndef DBSHOW_H #define DBSHOW_H #define DATEBUFFLEN 64 #define HGLINES 15 #define ALERTUSAGELEN 59 typedef struct { time_t date; uint64_t rx, tx; } HOURDATA; typedef enum AlertOutput { AO_No_Output = 0, AO_Always_Output, AO_Output_On_Estimate, AO_Output_On_Limit } AlertOutput; typedef enum AlertExit { AE_Always_Exit_0 = 0, AE_Always_Exit_1, AE_Exit_1_On_Estimate, AE_Exit_1_On_Limit } AlertExit; typedef enum AlertType { AT_None = 0, AT_Hour, AT_Day, AT_Month, AT_Year } AlertType; typedef enum AlertCondition { AC_None = 0, AC_RX, AC_TX, AC_Total, AC_RX_Estimate, AC_TX_Estimate, AC_Total_Estimate } AlertCondition; void showdb(const char *interface, int qmode, const char *databegin, const char *dataend); void showsummary(const interfaceinfo *interface, const int shortmode); void showlist(const interfaceinfo *interface, const char *listname, const char *databegin, const char *dataend); void showoneline(const interfaceinfo *interface); void showhours(const interfaceinfo *interface); int showbar(const uint64_t rx, const uint64_t tx, const uint64_t max, const int len); void indent(int i); int showalert(const char *interface, const AlertOutput output, const AlertExit exit, const AlertType type, const AlertCondition condition, const uint64_t limit); #endif vnstat-2.9/src/image.h0000644000000000000000000000331114100245655013423 0ustar rootroot#ifndef IMAGE_H #define IMAGE_H #include /* libgd2-dev libgd2 */ #include /* gdFontGetTiny() */ #include /* gdFontGetSmall() */ #include /* gdFontGetMediumBold() */ #include /* gdFontGetLarge() */ #include /* gdFontGetGiant() */ /* rectangle size */ #define YBEGINOFFSET (-1) #define FIVEMINHEIGHTOFFSET 4 #define FIVEMINWIDTHFULLPADDING 10 #define FIVEMINWIDTHPADDING 2 #define FIVEMINEXTRASPACE 78 #define SCALEMINPIXELS 25 typedef struct { gdImagePtr im; gdFontPtr font; interfaceinfo interface; int cbackground, cedge, cheader, cheadertitle, cheaderdate, ctext, cline, clinel, cvnstat; int crx, crxd, ctx, ctxd, cbgoffset, cbgoffsetmore, showheader, showedge, showlegend, altdate; int lineheight, large; char headertext[65], databegin[18], dataend[18]; time_t current; } IMAGECONTENT; typedef struct { time_t date; uint64_t rx, tx; } HOURDATA; void initimagecontent(IMAGECONTENT *ic); void drawimage(IMAGECONTENT *ic); #if HAVE_DECL_GD_NEAREST_NEIGHBOUR void scaleimage(IMAGECONTENT *ic); #endif int drawhours(IMAGECONTENT *ic, const int xpos, const int ypos, const int rate); void drawhourly(IMAGECONTENT *ic, const int rate); void drawlist(IMAGECONTENT *ic, const char *listname); void drawsummary(IMAGECONTENT *ic, const int layout, const int rate); void drawsummary_alltime(IMAGECONTENT *ic, const int x, const int y); void drawsummary_digest(IMAGECONTENT *ic, const int x, const int y, const char *mode); void drawfivegraph(IMAGECONTENT *ic, const int rate, const int resultcount, const int height); int drawfiveminutes(IMAGECONTENT *ic, const int xpos, const int ypos, const int rate, const int resultcount, const int height); #endif vnstat-2.9/src/dbxml.c0000644000000000000000000000640713467042201013450 0ustar rootroot#include "common.h" #include "dbsql.h" #include "dbxml.h" void showxml(const char *interface, const char mode, const char *databegin, const char *dataend) { interfaceinfo info; timeused_debug(__func__, 1); if (!db_getinterfacecountbyname(interface)) { return; } if (!db_getinterfaceinfo(interface, &info)) { return; } printf(" \n", info.name); printf(" %s\n", info.name); printf(" %s\n", info.alias); printf(" "); xmldate(&info.created, 1); printf("\n"); printf(" "); xmldate(&info.updated, 2); printf("\n"); printf(" \n"); printf(" %" PRIu64 "%" PRIu64 "\n", info.rxtotal, info.txtotal); switch (mode) { case 'd': xmldump(&info, "day", 1, databegin, dataend); break; case 'm': xmldump(&info, "month", 3, databegin, dataend); break; case 't': xmldump(&info, "top", 1, databegin, dataend); break; case 'h': xmldump(&info, "hour", 2, databegin, dataend); break; case 'y': xmldump(&info, "year", 4, databegin, dataend); break; case 'f': xmldump(&info, "fiveminute", 2, databegin, dataend); break; case 'a': default: xmldump(&info, "fiveminute", 2, databegin, dataend); xmldump(&info, "hour", 2, databegin, dataend); xmldump(&info, "day", 1, databegin, dataend); xmldump(&info, "month", 3, databegin, dataend); xmldump(&info, "year", 2, databegin, dataend); xmldump(&info, "top", 1, databegin, dataend); break; } printf(" \n"); printf(" \n"); timeused_debug(__func__, 0); } void xmldump(const interfaceinfo *interface, const char *tablename, const int datetype, const char *databegin, const char *dataend) { dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalistinfo datainfo; if (!db_getdata_range(&datalist, &datainfo, interface->name, tablename, (uint32_t)cfg.listjsonxml, databegin, dataend)) { printf("Error: Failed to fetch %s data.\n", tablename); return; } printf(" <%ss>\n", tablename); datalist_i = datalist; while (datalist_i != NULL) { printf(" <%s id=\"%" PRId64 "\">", tablename, datalist_i->rowid); xmldate(&datalist_i->timestamp, datetype); printf("%" PRIu64 "%" PRIu64 "\n", datalist_i->rx, datalist_i->tx, tablename); datalist_i = datalist_i->next; } dbdatalistfree(&datalist); printf(" \n", tablename); } void xmldate(const time_t *date, const int type) { struct tm *d; d = localtime(date); switch (type) { case 1: printf("%d%02d%02d", 1900 + d->tm_year, 1 + d->tm_mon, d->tm_mday); break; case 2: printf("%d%02d%02d", 1900 + d->tm_year, 1 + d->tm_mon, d->tm_mday, d->tm_hour, d->tm_min); break; case 3: printf("%d%02d", 1900 + d->tm_year, 1 + d->tm_mon); break; case 4: printf("%d", 1900 + d->tm_year); break; default: break; } } void xmlheader(void) { printf("\n", getversion(), XMLVERSION); } void xmlfooter(void) { printf("\n"); } vnstat-2.9/src/common.c0000644000000000000000000001441214164120314013622 0ustar rootroot#include "common.h" /* global variables */ CFG cfg; IFINFO ifinfo; char errorstring[1024]; ibwnode *ifacebw; int debug; int noexit; /* = running as daemon if 2 */ int intsignal; int pidfile; int disableprints; int printe(const PrintType type) { int result = 1; char timestamp[22]; time_t current; if (disableprints) { return 1; /* daemon running but log not enabled */ } else if (noexit == 2 && cfg.uselogging == 0) { return 1; /* daemon running, log enabled */ } else if (noexit == 2) { switch (type) { case PT_Multiline: break; case PT_Info: case PT_Infoless: case PT_Warning: case PT_Error: case PT_Config: case PT_ShortMultiline: result = logprint(type); break; } /* daemon isn't running or is running attached to a terminal */ } else { if (cfg.timestampprints && type != PT_ShortMultiline) { current = time(NULL); strftime(timestamp, 22, DATETIMEFORMAT, localtime(¤t)); printf("[%s] ", timestamp); } switch (type) { case PT_Info: printf("Info: %s\n", errorstring); break; case PT_Infoless: printf("%s\n", errorstring); break; case PT_Warning: printf("Warning: %s\n", errorstring); break; case PT_Error: printf("Error: %s\n", errorstring); break; case PT_Config: printf("Config: %s\n", errorstring); break; case PT_Multiline: printf("%s\n", errorstring); break; case PT_ShortMultiline: break; } fflush(stdout); } return result; } int logprint(const PrintType type) { /* buffer needs some extra space for timestamp + info compared to errorstring */ char timestamp[22], buffer[1060]; time_t current; FILE *logfile; buffer[0] = '\0'; /* logfile */ if (cfg.uselogging == 1) { if (type == PT_Multiline) { return 0; } if ((logfile = fopen(cfg.logfile, "a")) == NULL) { return 0; } current = time(NULL); strftime(timestamp, 22, DATETIMEFORMAT, localtime(¤t)); switch (type) { case PT_Info: case PT_Infoless: snprintf(buffer, 1060, "[%s] %s\n", timestamp, errorstring); break; case PT_Warning: snprintf(buffer, 1060, "[%s] Warning: %s\n", timestamp, errorstring); break; case PT_Error: snprintf(buffer, 1060, "[%s] Error: %s\n", timestamp, errorstring); break; case PT_Config: snprintf(buffer, 1060, "[%s] Config: %s\n", timestamp, errorstring); break; case PT_Multiline: break; case PT_ShortMultiline: snprintf(buffer, 1060, "[%s] %s\n", timestamp, errorstring); break; } if (fwrite(buffer, strlen(buffer), 1, logfile) != 1) { fclose(logfile); return 0; } fclose(logfile); return 1; /* syslog */ } else if (cfg.uselogging == 2) { openlog("vnstatd", LOG_PID, LOG_DAEMON); switch (type) { case PT_Multiline: break; case PT_Warning: syslog(LOG_WARNING, "Warning: %s", errorstring); break; case PT_Error: syslog(LOG_ERR, "Error: %s", errorstring); break; case PT_Config: syslog(LOG_ERR, "Config: %s", errorstring); break; case PT_Info: case PT_Infoless: case PT_ShortMultiline: syslog(LOG_NOTICE, "%s", errorstring); break; } closelog(); return 1; } return 0; } int verifylogaccess(void) { FILE *logfile; /* only logfile logging can be verified */ if (cfg.uselogging == 1) { if ((logfile = fopen(cfg.logfile, "a")) == NULL) { return 0; } fclose(logfile); } return 1; } int dmonth(const int month) { static int dmon[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int year; time_t current; /* handle leap years */ if (month == 1) { current = time(NULL); year = localtime(¤t)->tm_year + 1900; if (isleapyear(year)) { return 29; } else { return 28; } } else { return dmon[month]; } } int isleapyear(const int year) { if (year % 4 != 0) { return 0; } else if (year % 100 != 0) { return 1; } else if (year % 400 != 0) { return 0; } return 1; } time_t mosecs(time_t month, time_t updated) { struct tm d; if (localtime_r(&month, &d) == NULL) { return 1; } d.tm_mday = cfg.monthrotate; d.tm_hour = d.tm_min = d.tm_sec = 0; if ((updated - month) > 0) { return updated - mktime(&d); } else { return 1; } } uint64_t countercalc(const uint64_t *a, const uint64_t *b, const short is64bit) { /* no rollover */ if (*b >= *a) { if (debug) printf("cc (%d): %" PRIu64 " - %" PRIu64 " = %" PRIu64 "\n", is64bit, *b, *a, *b - *a); return *b - *a; /* rollover exists */ } else { /* counter is 64bit */ if (*a > MAX32 || *b > MAX32 || is64bit == 1) { if (debug) printf("cc64 (%d): uint64 - %" PRIu64 " + %" PRIu64 " = %" PRIu64 "\n", is64bit, *a, *b, (uint64_t)MAX64 - *a + *b); return MAX64 - *a + *b; /* counter is 32bit */ } else { if (debug) printf("cc32 (%d): uint32 - %" PRIu64 " + %" PRIu64 " = %" PRIu64 "\n", is64bit, *a, *b, (uint64_t)MAX32 - *a + *b); return MAX32 - *a + *b; } } } /* strncpy with ensured null termination */ char *strncpy_nt(char *dest, const char *src, size_t n) { strncpy(dest, src, n); dest[n - 1] = '\0'; return dest; } int isnumeric(const char *s) { size_t i, len = strlen(s); if (!len) { return 0; } for (i = 0; i < len; i++) { if (!isdigit(s[i])) { return 0; } } return 1; } __attribute__((noreturn)) void panicexit(const char *sourcefile, const int sourceline) { snprintf(errorstring, 1024, "Unexpected error (%s), exiting. (%s:%d)", strerror(errno), sourcefile, sourceline); fprintf(stderr, "%s\n", errorstring); printe(PT_Error); exit(EXIT_FAILURE); } char *getversion(void) { int i; static char versionbuffer[16]; strncpy_nt(versionbuffer, VERSION, 16); for (i = 0; i < (int)strlen(versionbuffer); i++) { if (versionbuffer[i] == '_') { versionbuffer[i] = ' '; } } return versionbuffer; } double timeused(const char *func, const int reset) { static struct timeval starttime; struct timeval endtime; double used_secs; if (reset) { gettimeofday(&starttime, NULL); return 0.0; } if (gettimeofday(&endtime, NULL) != 0) { return 0.0; } used_secs = (double)(endtime.tv_usec - starttime.tv_usec) / 1000000 + (double)(endtime.tv_sec - starttime.tv_sec); if (debug) { printf("%s() in %f s\n", func, used_secs); } return used_secs; } void timeused_debug(const char *func, const int reset) { if (!debug) { return; } timeused(func, reset); } vnstat-2.9/src/vnstat_func.h0000644000000000000000000000221614167077460014710 0ustar rootroot#ifndef VNSTAT_FUNC__H #define VNSTAT_FUNC__H typedef struct { int query, setalias; int addiface, force, traffic; int livetraffic, defaultiface, removeiface, renameiface, livemode; int32_t limit; uint64_t dbifcount; char interface[32], alias[32], newifname[32], filename[512]; char definterface[32], cfgfile[512], *ifacelist, jsonmode, xmlmode; char databegin[18], dataend[18]; unsigned int alert, alertoutput, alertexit, alerttype, alertcondition; uint64_t alertlimit; } PARAMS; void initparams(PARAMS *p); void showhelp(PARAMS *p); void showlonghelp(PARAMS *p); void parseargs(PARAMS *p, const int argc, char **argv); int parsealertargs(PARAMS *p, char **argv); void showalerthelp(void); void showstylehelp(void); void handleshowalert(PARAMS *p); void handleremoveinterface(PARAMS *p); void handlerenameinterface(PARAMS *p); void handleaddinterface(PARAMS *p); void handlesetalias(PARAMS *p); void handleshowdata(PARAMS *p); void showoneinterface(PARAMS *p); void handletrafficmeters(PARAMS *p); void handleifselection(PARAMS *p); void showiflist(const int parseable); void showdbiflist(const int parseable); void validateinterface(PARAMS *p); #endif vnstat-2.9/UNINSTALL0000644000000000000000000000053214114516557012706 0ustar rootroot# Uninstall 1. Stop the daemon (`vnstatd`) if it is still running 2. Remove any manually installed service files or file entries used to start the daemon 3. Run `make uninstall` and follow the instructions 4. Remove the database directory if it is no longer needed, the command of the previous step will not touch any collected data vnstat-2.9/test-driver0000755000000000000000000001027713030336157013607 0ustar rootroot#! /bin/sh # test-driver - basic testsuite driver script. scriptversion=2013-07-13.22; # UTC # Copyright (C) 2011-2013 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # This file is maintained in Automake, please report # bugs to or send patches to # . # Make unconditional expansion of undefined variables an error. This # helps a lot in preventing typo-related bugs. set -u usage_error () { echo "$0: $*" >&2 print_usage >&2 exit 2 } print_usage () { cat <$log_file 2>&1 estatus=$? if test $enable_hard_errors = no && test $estatus -eq 99; then estatus=1 fi case $estatus:$expect_failure in 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 0:*) col=$grn res=PASS recheck=no gcopy=no;; 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; *:*) col=$red res=FAIL recheck=yes gcopy=yes;; esac # Report outcome to console. echo "${col}${res}${std}: $test_name" # Register the test result, and other relevant metadata. echo ":test-result: $res" > $trs_file echo ":global-test-result: $res" >> $trs_file echo ":recheck: $recheck" >> $trs_file echo ":copy-in-global-log: $gcopy" >> $trs_file # Local Variables: # mode: shell-script # sh-indentation: 2 # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC" # time-stamp-end: "; # UTC" # End: vnstat-2.9/compile0000755000000000000000000001624513037475074013001 0ustar rootroot#! /bin/sh # Wrapper for compilers which do not understand '-c -o'. scriptversion=2012-10-14.11; # UTC # Copyright (C) 1999-2013 Free Software Foundation, Inc. # Written by Tom Tromey . # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # This file is maintained in Automake, please report # bugs to or send patches to # . nl=' ' # We need space, tab and new line, in precisely that order. Quoting is # there to prevent tools from complaining about whitespace usage. IFS=" "" $nl" file_conv= # func_file_conv build_file lazy # Convert a $build file to $host form and store it in $file # Currently only supports Windows hosts. If the determined conversion # type is listed in (the comma separated) LAZY, no conversion will # take place. func_file_conv () { file=$1 case $file in / | /[!/]*) # absolute file, and not a UNC file if test -z "$file_conv"; then # lazily determine how to convert abs files case `uname -s` in MINGW*) file_conv=mingw ;; CYGWIN*) file_conv=cygwin ;; *) file_conv=wine ;; esac fi case $file_conv/,$2, in *,$file_conv,*) ;; mingw/*) file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` ;; cygwin/*) file=`cygpath -m "$file" || echo "$file"` ;; wine/*) file=`winepath -w "$file" || echo "$file"` ;; esac ;; esac } # func_cl_dashL linkdir # Make cl look for libraries in LINKDIR func_cl_dashL () { func_file_conv "$1" if test -z "$lib_path"; then lib_path=$file else lib_path="$lib_path;$file" fi linker_opts="$linker_opts -LIBPATH:$file" } # func_cl_dashl library # Do a library search-path lookup for cl func_cl_dashl () { lib=$1 found=no save_IFS=$IFS IFS=';' for dir in $lib_path $LIB do IFS=$save_IFS if $shared && test -f "$dir/$lib.dll.lib"; then found=yes lib=$dir/$lib.dll.lib break fi if test -f "$dir/$lib.lib"; then found=yes lib=$dir/$lib.lib break fi if test -f "$dir/lib$lib.a"; then found=yes lib=$dir/lib$lib.a break fi done IFS=$save_IFS if test "$found" != yes; then lib=$lib.lib fi } # func_cl_wrapper cl arg... # Adjust compile command to suit cl func_cl_wrapper () { # Assume a capable shell lib_path= shared=: linker_opts= for arg do if test -n "$eat"; then eat= else case $1 in -o) # configure might choose to run compile as 'compile cc -o foo foo.c'. eat=1 case $2 in *.o | *.[oO][bB][jJ]) func_file_conv "$2" set x "$@" -Fo"$file" shift ;; *) func_file_conv "$2" set x "$@" -Fe"$file" shift ;; esac ;; -I) eat=1 func_file_conv "$2" mingw set x "$@" -I"$file" shift ;; -I*) func_file_conv "${1#-I}" mingw set x "$@" -I"$file" shift ;; -l) eat=1 func_cl_dashl "$2" set x "$@" "$lib" shift ;; -l*) func_cl_dashl "${1#-l}" set x "$@" "$lib" shift ;; -L) eat=1 func_cl_dashL "$2" ;; -L*) func_cl_dashL "${1#-L}" ;; -static) shared=false ;; -Wl,*) arg=${1#-Wl,} save_ifs="$IFS"; IFS=',' for flag in $arg; do IFS="$save_ifs" linker_opts="$linker_opts $flag" done IFS="$save_ifs" ;; -Xlinker) eat=1 linker_opts="$linker_opts $2" ;; -*) set x "$@" "$1" shift ;; *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) func_file_conv "$1" set x "$@" -Tp"$file" shift ;; *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) func_file_conv "$1" mingw set x "$@" "$file" shift ;; *) set x "$@" "$1" shift ;; esac fi shift done if test -n "$linker_opts"; then linker_opts="-link$linker_opts" fi exec "$@" $linker_opts exit 1 } eat= case $1 in '') echo "$0: No command. Try '$0 --help' for more information." 1>&2 exit 1; ;; -h | --h*) cat <<\EOF Usage: compile [--help] [--version] PROGRAM [ARGS] Wrapper for compilers which do not understand '-c -o'. Remove '-o dest.o' from ARGS, run PROGRAM with the remaining arguments, and rename the output as expected. If you are trying to build a whole package this is not the right script to run: please start by reading the file 'INSTALL'. Report bugs to . EOF exit $? ;; -v | --v*) echo "compile $scriptversion" exit $? ;; cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) func_cl_wrapper "$@" # Doesn't return... ;; esac ofile= cfile= for arg do if test -n "$eat"; then eat= else case $1 in -o) # configure might choose to run compile as 'compile cc -o foo foo.c'. # So we strip '-o arg' only if arg is an object. eat=1 case $2 in *.o | *.obj) ofile=$2 ;; *) set x "$@" -o "$2" shift ;; esac ;; *.c) cfile=$1 set x "$@" "$1" shift ;; *) set x "$@" "$1" shift ;; esac fi shift done if test -z "$ofile" || test -z "$cfile"; then # If no '-o' option was seen then we might have been invoked from a # pattern rule where we don't need one. That is ok -- this is a # normal compilation that the losing compiler can handle. If no # '.c' file was seen then we are probably linking. That is also # ok. exec "$@" fi # Name of file we expect compiler to create. cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` # Create the lock directory. # Note: use '[/\\:.-]' here to ensure that we don't use the same name # that we are using for the .o file. Also, base the name on the expected # object file name, since that is what matters with a parallel build. lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d while true; do if mkdir "$lockdir" >/dev/null 2>&1; then break fi sleep 1 done # FIXME: race condition here if user kills between mkdir and trap. trap "rmdir '$lockdir'; exit 1" 1 2 15 # Run the compile. "$@" ret=$? if test -f "$cofile"; then test "$cofile" = "$ofile" || mv "$cofile" "$ofile" elif test -f "${cofile}bj"; then test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" fi rmdir "$lockdir" exit $ret # Local Variables: # mode: shell-script # sh-indentation: 2 # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC" # time-stamp-end: "; # UTC" # End: vnstat-2.9/configure.ac0000644000000000000000000001026514173305704013677 0ustar rootroot# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_INIT([vnstat], [2.9]) AM_INIT_AUTOMAKE([foreign subdir-objects std-options -Wall -Werror]) AM_MAINTAINER_MODE AC_CONFIG_SRCDIR([src/vnstatd.c]) AC_CONFIG_HEADERS([src/config.h]) # Checks for programs. AC_PROG_CC AM_PROG_CC_C_O AC_PROG_MAKE_SET AC_PROG_MKDIR_P # Extra options AC_ARG_ENABLE([image-output], [ AS_HELP_STRING([--disable-image-output], [disable PNG image output])]) CFLAG_EXTRAS="" AC_ARG_ENABLE([werror], [ AS_HELP_STRING([--enable-werror], [add -Werror to CFLAGS])], [CFLAG_EXTRAS="-Werror"]) AC_SUBST([CFLAG_EXTRAS]) AC_ARG_ENABLE([extra-paths], [ AS_HELP_STRING([--disable-extra-paths], [do not add extra paths to CFLAGS and LDFLAGS])], [], [ CFLAGS="$CFLAGS -I/usr/local/include" LDFLAGS="$LDFLAGS -L/usr/local/lib"]) # Checks for libraries. AC_CHECK_LIB([m], [pow], [], [AC_MSG_ERROR([could not find required math library])]) AC_CHECK_LIB([sqlite3], [sqlite3_prepare_v2], [], [AC_MSG_ERROR([could not find required sqlite3 library])]) AS_IF([test "x$enable_image_output" != "xno"], [ AC_CHECK_LIB([gd], [gdImagePng], [IMAGELIBS=-lgd]) AC_CHECK_DECLS([GD_NEAREST_NEIGHBOUR, gdImageFile], [], [], [[#include ]]) AC_SUBST([IMAGELIBS])]) AM_CONDITIONAL([HAVE_LIBGD], [test "$IMAGELIBS" = "-lgd"]) PKG_CHECK_MODULES([CHECK], [check >= 0.9.6], [], [AC_MSG_NOTICE([testcases can not be execute without check installed])]) AM_CONDITIONAL([HAVE_CHECK], [test "$CHECK_LIBS"]) # Checks for header files. AC_CHECK_HEADERS([fcntl.h inttypes.h locale.h stdint.h stdlib.h string.h sys/file.h sys/mount.h sys/param.h sys/socket.h sys/statvfs.h sys/time.h syslog.h unistd.h wchar.h linux/rtnetlink.h]) # Check if being cross-compiled AC_CANONICAL_BUILD AC_CANONICAL_HOST AM_CONDITIONAL([IS_CROSSCOMPILED], [test "$host" != "$build"]) # Check if 64-bit interface counters are used in Linux AC_CHECK_DECLS([IFLA_STATS64], [], [], [[#include ]]) # Check if O_CLOEXEC can be used AC_CHECK_DECLS([O_CLOEXEC], [], [], [[#include ]]) # Check availability and level of SQLite WAL mode support AC_CHECK_DECLS([SQLITE_CHECKPOINT_RESTART, SQLITE_CHECKPOINT_TRUNCATE], [], [], [[#include ]]) # Checks for typedefs, structures, and compiler characteristics. AC_TYPE_UID_T AC_TYPE_INT32_T AC_TYPE_MODE_T AC_TYPE_SIZE_T AC_TYPE_UINT32_T AC_TYPE_UINT64_T # Checks for library functions. AC_FUNC_CHOWN AC_FUNC_FORK AC_FUNC_MKTIME AC_CHECK_FUNCS([dup2 localtime_r memset mkdir pow rmdir setlocale strcasecmp strchr strdup strerror strncasecmp strstr strtol strtoul strtoull tzset mbstowcs wcswidth]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT # Resolve install paths for output. msg_bindir=$bindir while expr match "${msg_bindir}" '^.*\$.*$' 1>/dev/null; do msg_bindir="$(eval echo ${msg_bindir})" done msg_sbindir=$sbindir while expr match "${msg_sbindir}" '^.*\$.*$' 1>/dev/null; do msg_sbindir="$(eval echo ${msg_sbindir})" done msg_sysconfdir=$sysconfdir while expr match "${msg_sysconfdir}" '^.*\$.*$' 1>/dev/null; do msg_sysconfdir="$(eval echo ${msg_sysconfdir})" done # Output configuration. AC_MSG_NOTICE() AC_MSG_NOTICE([ ============================================== ]) AC_MSG_NOTICE() AC_MSG_NOTICE([ host: $host ]) AC_MSG_NOTICE([ build: $build ]) AC_MSG_NOTICE() AC_MSG_NOTICE([ prefix: $prefix ]) AC_MSG_NOTICE([ exec_prefix: $exec_prefix ]) AC_MSG_NOTICE([ bindir: $bindir ]) AC_MSG_NOTICE([ sbindir: $sbindir ]) AC_MSG_NOTICE([ sysconfdir: $sysconfdir ]) AC_MSG_NOTICE() AC_MSG_NOTICE([ Install paths ]) AC_MSG_NOTICE() AC_MSG_NOTICE([ vnstat: $msg_bindir/vnstat ]) AM_COND_IF([HAVE_LIBGD], [ AC_MSG_NOTICE([ vnstati: $msg_bindir/vnstati ])]) AC_MSG_NOTICE([ vnstatd: $msg_sbindir/vnstatd ]) AC_MSG_NOTICE([ config: $msg_sysconfdir/vnstat.conf ]) AC_MSG_NOTICE() AM_COND_IF([HAVE_CHECK], [ AC_MSG_NOTICE([ Tests: available ])], [ AC_MSG_NOTICE([ Tests: unavailable ])]) AM_COND_IF([HAVE_LIBGD], [ AC_MSG_NOTICE([ Image output: enabled ])], [ AC_MSG_NOTICE([ Image output: disabled ])]) AC_MSG_NOTICE() AC_MSG_NOTICE([ ============================================== ]) AC_MSG_NOTICE() vnstat-2.9/cfg/0000755000000000000000000000000014164604450012144 5ustar rootrootvnstat-2.9/cfg/vnstat.conf0000644000000000000000000001366414164652766014361 0ustar rootroot# vnStat 2.9 configuration file # # lines starting with # or ; are comments, everything has default # values, remove ; before each option to change its value # default interface (leave empty for automatic selection) ;Interface "" # location of the database directory ;DatabaseDir "/var/lib/vnstat" # locale (LC_ALL) ("-" = use system locale) ;Locale "-" # date output formats for -d, -m, -t and -w ;DayFormat "%Y-%m-%d" ;MonthFormat "%Y-%m" ;TopFormat "%Y-%m-%d" # characters used for visuals ;RXCharacter "%" ;TXCharacter ":" ;RXHourCharacter "r" ;TXHourCharacter "t" # how units are prefixed when traffic is shown # 0 = IEC standard prefixes (KiB/MiB/GiB...) # 1 = old style binary prefixes (KB/MB/GB...) # 2 = SI decimal prefixes (kB/MB/GB...) ;UnitMode 0 # used rate unit (0 = bytes, 1 = bits) ;RateUnit 1 # how units are prefixed when traffic rate is shown in bits # 0 = IEC binary prefixes (Kibit/s...) # 1 = SI decimal prefixes (kbit/s...) ;RateUnitMode 1 # output style # 0 = minimal & narrow, 1 = bar column visible # 2 = same as 1 except rate in summary # 3 = rate column visible ;OutputStyle 3 ;EstimateBarVisible 1 # number of decimals to use in outputs ;DefaultDecimals 2 ;HourlyDecimals 1 # spacer for separating hourly sections (0 = none, 1 = '|', 2 = '][', 3 = '[ ]') ;HourlySectionStyle 2 # how many seconds should sampling for -tr take by default ;Sampletime 5 # default query mode # 0 = normal, 1 = days, 2 = months, 3 = top, 5 = short # 7 = hours, 8 = xml, 9 = one line, 10 = json ;QueryMode 0 # default list output entry limits (0 = all) ;List5Mins 24 ;ListHours 24 ;ListDays 30 ;ListMonths 12 ;ListYears 0 ;ListTop 10 # how to match interface given for query to interface in database # 0 = case sensitive exact match to interface name # 1 = method 0 followed by case sensitive exact match of alias # 2 = method 1 followed by case insensitive exact match of alias # 3 = method 2 followed by case insensitive beginning match of alias ;InterfaceMatchMethod 3 # vnstatd ## # switch to given user when started as root (leave empty to disable) ;DaemonUser "" # switch to given group when started as root (leave empty to disable) ;DaemonGroup "" # try to detect interface maximum bandwidth, 0 = disable feature # MaxBandwidth will be used as fallback value when enabled ;BandwidthDetection 1 # maximum bandwidth (Mbit) for all interfaces, 0 = disable feature # (unless interface specific limit is given) ;MaxBandwidth 1000 # interface specific limits # example 8Mbit limit for eth0 (remove # to activate): #MaxBWeth0 8 # data retention durations (-1 = unlimited, 0 = feature disabled) ;5MinuteHours 48 ;HourlyDays 4 ;DailyDays 62 ;MonthlyMonths 25 ;YearlyYears -1 ;TopDayEntries 20 # how often (in seconds) interface data is updated ;UpdateInterval 20 # how often (in seconds) interface status changes are checked ;PollInterval 5 # how often (in minutes) data is saved to database ;SaveInterval 5 # how often (in minutes) data is saved when all interface are offline ;OfflineSaveInterval 30 # rescan database after save for new interfaces to be monitored (1 = enabled, 0 = disabled) ;RescanDatabaseOnSave 1 # automatically start monitoring all interfaces not found in the database # (1 = enabled, 0 = disabled) ;AlwaysAddNewInterfaces 0 # on which day should months change ;MonthRotate 1 ;MonthRotateAffectsYears 0 # filesystem disk space check (1 = enabled, 0 = disabled) ;CheckDiskSpace 1 # how much the boot time can variate between updates (seconds) ;BootVariation 15 # create database entries even when there is no traffic (1 = enabled, 0 = disabled) ;TrafficlessEntries 1 # how many minutes to wait during daemon startup for system clock to # sync time if most recent database update appears to be in the future ;TimeSyncWait 5 # how often (in minutes) bandwidth detection is done when # BandwidthDetection is enabled (0 = disabled) ;BandwidthDetectionInterval 5 # force data save when interface status changes (1 = enabled, 0 = disabled) ;SaveOnStatusChange 1 # enable / disable logging (0 = disabled, 1 = logfile, 2 = syslog) ;UseLogging 2 # create dirs if needed (1 = enabled, 0 = disabled) ;CreateDirs 1 # update ownership of files if needed (1 = enabled, 0 = disabled) ;UpdateFileOwner 1 # file used for logging if UseLogging is set to 1 ;LogFile "/var/log/vnstat/vnstat.log" # file used as daemon pid / lock file ;PidFile "/var/run/vnstat/vnstat.pid" # 1 = 64-bit, 0 = 32-bit, -1 = old style logic, -2 = automatic detection ;64bitInterfaceCounters -2 # use SQLite Write-Ahead Logging mode (1 = enabled, 0 = disabled) ;DatabaseWriteAheadLogging 0 # change the setting of the SQLite "synchronous" flag # (-1 = auto, 0 = off, 1, = normal, 2 = full, 3 = extra) ;DatabaseSynchronous -1 # database uses UTC instead of local timezone (1 = enabled, 0 = disabled) ;UseUTC 0 # vnstati ## # title timestamp format ;HeaderFormat "%Y-%m-%d %H:%M" # show hours with rate (1 = enabled, 0 = disabled) ;HourlyRate 1 # show rate in summary (1 = enabled, 0 = disabled) ;SummaryRate 1 # transparent background (1 = enabled, 0 = disabled) ;TransparentBg 0 # image size control ;LargeFonts 0 ;LineSpacingAdjustment 0 ;ImageScale 100 # 5 minutes graph size control ;5MinuteGraphResultCount 576 ;5MinuteGraphHeight 300 # hourly graph mode (0 = 24 hour sliding window, 1 = begins from midnight) ;HourlyGraphMode 0 # horizontal/vertical summary graph (0 = hours, 1 = 5 minutes) ;SummaryGraph 0 # traffic estimate bar style # (0 = not shown, 1 = continuation of existing bar, 2 = separate bar) ;EstimateStyle 1 # bar column in list outputs shows rate if OutputStyle is 3 # (1 = enabled, 0 = disabled) ;BarColumnShowsRate 0 # image colors ;CBackground "FFFFFF" ;CEdge "AEAEAE" ;CHeader "606060" ;CHeaderTitle "FFFFFF" ;CHeaderDate "FFFFFF" ;CText "000000" ;CLine "B0B0B0" ;CLineL "-" ;CRx "92CF00" ;CTx "606060" ;CRxD "-" ;CTxD "-" vnstat-2.9/README0000644000000000000000000000365314161740233012271 0ustar rootroot # What is vnStat vnStat is a console-based network traffic monitor that uses the network interface statistics provided by the kernel as information source. This means that vnStat won't actually be sniffing any traffic and also ensures light use of system resources regardless of network traffic rate. By default, traffic statistics are stored on a five minute level for the last 48 hours, on a hourly level for the last 4 days, on a daily level for the last 2 full months and on a yearly level forever. The data retention durations are fully user configurable. Total seen traffic and a top days listing is also provided. Optional image output is available in systems with the GD library installed. See the webpage https://humdi.net/vnstat/ for output examples. # Getting started vnStat works best when installed. See the INSTALL or INSTALL_BSD file depending on used operating system. These files contain all needed information for the installing process. Instructions for upgrading from a previous version are included in the UPGRADE file. Release notes can be found from the CHANGES file. # Available options and documentation A list of commonly used options is available with `vnstat --help`. The complete list can be accessed with `vnstat --longhelp`. The following man pages are available with more detailed descriptions of each option including some usage examples: vnstat general documentation and console query parameters vnstatd daemon documentation vnstati image output documentation vnstat.conf configuration file # Contacting the author email: Teemu Toivola irc: Vergo (IRCNet) git: https://github.com/vergoh/vnstat The current version of vnStat is always available from https://humdi.net/vnstat/ Bug reports, improvement ideas, feature requests and pull requests should be sent using the matching features on GitHub as those are harder to miss or forget. vnstat-2.9/missing0000755000000000000000000001533013030336157013003 0ustar rootroot#! /bin/sh # Common wrapper for a few potentially missing GNU programs. scriptversion=2013-10-28.13; # UTC # Copyright (C) 1996-2013 Free Software Foundation, Inc. # Originally written by Fran,cois Pinard , 1996. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. if test $# -eq 0; then echo 1>&2 "Try '$0 --help' for more information" exit 1 fi case $1 in --is-lightweight) # Used by our autoconf macros to check whether the available missing # script is modern enough. exit 0 ;; --run) # Back-compat with the calling convention used by older automake. shift ;; -h|--h|--he|--hel|--help) echo "\ $0 [OPTION]... PROGRAM [ARGUMENT]... Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due to PROGRAM being missing or too old. Options: -h, --help display this help and exit -v, --version output version information and exit Supported PROGRAM values: aclocal autoconf autoheader autom4te automake makeinfo bison yacc flex lex help2man Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and 'g' are ignored when checking the name. Send bug reports to ." exit $? ;; -v|--v|--ve|--ver|--vers|--versi|--versio|--version) echo "missing $scriptversion (GNU Automake)" exit $? ;; -*) echo 1>&2 "$0: unknown '$1' option" echo 1>&2 "Try '$0 --help' for more information" exit 1 ;; esac # Run the given program, remember its exit status. "$@"; st=$? # If it succeeded, we are done. test $st -eq 0 && exit 0 # Also exit now if we it failed (or wasn't found), and '--version' was # passed; such an option is passed most likely to detect whether the # program is present and works. case $2 in --version|--help) exit $st;; esac # Exit code 63 means version mismatch. This often happens when the user # tries to use an ancient version of a tool on a file that requires a # minimum version. if test $st -eq 63; then msg="probably too old" elif test $st -eq 127; then # Program was missing. msg="missing on your system" else # Program was found and executed, but failed. Give up. exit $st fi perl_URL=http://www.perl.org/ flex_URL=http://flex.sourceforge.net/ gnu_software_URL=http://www.gnu.org/software program_details () { case $1 in aclocal|automake) echo "The '$1' program is part of the GNU Automake package:" echo "<$gnu_software_URL/automake>" echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:" echo "<$gnu_software_URL/autoconf>" echo "<$gnu_software_URL/m4/>" echo "<$perl_URL>" ;; autoconf|autom4te|autoheader) echo "The '$1' program is part of the GNU Autoconf package:" echo "<$gnu_software_URL/autoconf/>" echo "It also requires GNU m4 and Perl in order to run:" echo "<$gnu_software_URL/m4/>" echo "<$perl_URL>" ;; esac } give_advice () { # Normalize program name to check for. normalized_program=`echo "$1" | sed ' s/^gnu-//; t s/^gnu//; t s/^g//; t'` printf '%s\n' "'$1' is $msg." configure_deps="'configure.ac' or m4 files included by 'configure.ac'" case $normalized_program in autoconf*) echo "You should only need it if you modified 'configure.ac'," echo "or m4 files included by it." program_details 'autoconf' ;; autoheader*) echo "You should only need it if you modified 'acconfig.h' or" echo "$configure_deps." program_details 'autoheader' ;; automake*) echo "You should only need it if you modified 'Makefile.am' or" echo "$configure_deps." program_details 'automake' ;; aclocal*) echo "You should only need it if you modified 'acinclude.m4' or" echo "$configure_deps." program_details 'aclocal' ;; autom4te*) echo "You might have modified some maintainer files that require" echo "the 'autom4te' program to be rebuilt." program_details 'autom4te' ;; bison*|yacc*) echo "You should only need it if you modified a '.y' file." echo "You may want to install the GNU Bison package:" echo "<$gnu_software_URL/bison/>" ;; lex*|flex*) echo "You should only need it if you modified a '.l' file." echo "You may want to install the Fast Lexical Analyzer package:" echo "<$flex_URL>" ;; help2man*) echo "You should only need it if you modified a dependency" \ "of a man page." echo "You may want to install the GNU Help2man package:" echo "<$gnu_software_URL/help2man/>" ;; makeinfo*) echo "You should only need it if you modified a '.texi' file, or" echo "any other file indirectly affecting the aspect of the manual." echo "You might want to install the Texinfo package:" echo "<$gnu_software_URL/texinfo/>" echo "The spurious makeinfo call might also be the consequence of" echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might" echo "want to install GNU make:" echo "<$gnu_software_URL/make/>" ;; *) echo "You might have modified some files without having the proper" echo "tools for further handling them. Check the 'README' file, it" echo "often tells you about the needed prerequisites for installing" echo "this package. You may also peek at any GNU archive site, in" echo "case some other package contains this missing '$1' program." ;; esac } give_advice "$1" | sed -e '1s/^/WARNING: /' \ -e '2,$s/^/ /' >&2 # Propagate the correct exit status (expected to be 127 for a program # not found, 63 for a program that failed due to version mismatch). exit $st # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC" # time-stamp-end: "; # UTC" # End: vnstat-2.9/FAQ0000644000000000000000000000510313666557725011760 0ustar rootrootThe latest version of this FAQ is available at https://humdi.net/vnstat/FAQ ---- A snapshot of the FAQ (updated 13.4.2019): I managed to get invalid data into the database after ... playing around with the system clock / doing some strange network experiments / having the cron entry not properly configured. Is there a database editor available? Nothing vnStat specific is available. The sqlite3 command can be used to read and modify the database. How do I stop monitoring an interface? Execute "vnstat --remove -i interfacename" with correct permissions. How do I uninstall vnStat? You only need to run 'make uninstall' in the directory that comes when the .tar.gz is extracted. Just make sure it's the same version you have installed. If you've used a binary package included with the distribution then refer to instructions provided by the package manager. What is this KiB/MiB/GiB/TiB thing? See http://en.wikipedia.org/wiki/Binary_prefix#Prefixes and UnitMode option in the configuration file. Is the MB value reported by vnStat 10^6 or 2^20 bytes? 2^20 bytes. The prefix can be configured to show MiB from the configuration file instead of MB if that looks better. What does the 'estimated' value mean? The estimated value is an calculated average that tries to predict the total traffic for the current day/month based on previous traffic. This estimate works fairly well if the monitored interface has constant traffic of the same magnitude (like game servers). It can't predic peaks but the accuracy usually gets better by the end of the day/month. Why isn't the estimated value shown with --json or xml outputs? Those features only dump the database and since the estimate is always calculated in real time, there's no reason to write it into the database. How is the estimated value calculated? estimate = ( x / y ) * z x = traffic so far for the day/month y = passed minutes/hours ... z = total minutes/hours ... About bug reports If the latest version isn't being used then test if the issue can still be replicated with the latest or latest development version. If the issue can still be reproduced, check if there's already an issue open in GitHub. If not then using https://github.com/vergoh/vnstat/issues for reporting new issues is suggested. Any bug report should at least include an explanation about how the bug can be reproduced. Also include information about the used distribution, kernel (uname -a), compiler (gcc --version) and network interface card. Read the report again before sending it. :) vnstat-2.9/INSTALL_BSD0000644000000000000000000001167414114723166013140 0ustar rootroot # tl;dr ./configure && make && make install # Prerequisites - make or gmake - C compiler - user with access to kernel interface statistics - usually available by default but may be restricted by security settings - databases/sqlite3 - graphics/gd (optional, image output) - devel/check (optional, test suite) - devel/pkg-config (optional, for check detection) - devel/autotools (optional, for recreating configure and makefiles) # Compiling the binaries This source package contains the required source files for vnStat including the daemon (`vnstatd`) and image output (`vnstati`). Executing ./configure && make will compile `vnstat` and `vnstatd` without requiring additional libraries. The optional image output capable binary `vnstati` will also be compiled if the required additional libgd2 library is found to be available and `--disable-image-output` isn't given as parameter for `./configure`. An example cgi (`vnstat.cgi`) to be used with a http server with the image output support has been provided in the `examples` directory. Configuration options for the cgi are in the beginning of the file. Additional examples for using the json output are also available in the same directory. For executing the optional test suite, see the appendix at the end of this file. # Installing as root Login as root and run the following command: make install If there were no errors, vnStat binaries, man pages and a configuration file should now be installed. The configuration file will be upgraded using previously configured values if it is found already to exist. A backup of the previous configuration file will be named as `vnstat.conf.old` in the current directory. The configuration file `/usr/local/etc/vnstat.conf` should be checked at this point. See the `vnstat.conf` man page for documentation about available options. Finally make vnStat monitor the selected interface(s). Configure init scripts so that the following command is executed once during system startup: /usr/local/sbin/vnstatd -d One suitable place is for example `/etc/rc.local`. During first startup, the daemon (`vnstatd`) should list and add all available interfaces for monitoring. The command can also be executed manually at this point in order to avoid having to reboot the system Depending on configuration, it may take some minutes for the `vnstat` command to begin showing results as the entries in the database aren't updated constantly. Monitoring of unwanted interfaces can be stopped with: vnstat --remove -i ethunwanted # Installing without root access Copy all needed binaries to some directory included in your PATH (`~/bin/` is used here as an example) and create the database directory. cp -v vnstat vnstatd vnstati ~/bin/ cp -v cfg/vnstat.conf ~/.vnstatrc mkdir ~/.vnstat Next open the configuration file `~/.vnstatrc` with your favorite text editor and locate the following line: DatabaseDir "/var/lib/vnstat" and replace it with DatabaseDir "/pathtomyhomedir/.vnstat" Next, locate the following lines: UseLogging 2 LogFile "/var/log/vnstat/vnstat.log" PidFile "/var/run/vnstat/vnstat.pid" and replace them with UseLogging 1 LogFile "/pathtomyhomedir/.vnstat/.log" PidFile "/pathtomyhomedir/.vnstat/.pid" Finally, save the file. If you are unsure about your home directory path, execute cd ; pwd The output should tell your home directory. Now it's time to add a crontab entry for vnStat. Do that by executing the command `crontab -e` and add the following line (without leading spaces, remember to change the path): @reboot ~/bin/vnstatd -d If you found yourself using a strange editor then `man vi` may help. Make sure the configuration file (`~/.vnstatrc`) has the log option either disabled or set to a file that is located in a place where you have write permissions, such as your home dir. Then try starting the daemon with vnstatd -d After that wait for (or generate) at least 1 byte of network traffic (and 5 min for the next database file save). vnstat Now you should get some statistics about your network usage. See the config file `~/.vnstatrc` for interface and other settings. # Appendix: Running the test suite This step isn't mandatory for using vnStat. The source package includes a test suite for validating many of the functionalities provided and used by the executables. The test suite requires the Check unit testing framework ( https://libcheck.github.io/check/ ) to be installed and available (usually `devel/check` in ports). The configure script also assumes that the `pkg-config` command is installed. That command is usually part of the `devel/pkgconf` package. After the `./configure` script has been executed the test suite can be executed with: make check The output should show a non-zero number of tests executed if all the necessary packages were available. A more detailed list of executed tests can be seen from the `check_vnstat.log` file after execution. vnstat-2.9/INSTALL0000644000000000000000000001467114114515605012445 0ustar rootroot # tl;dr ./configure --prefix=/usr --sysconfdir=/etc && make && make install # Prerequisites - make - C compiler - user with access to kernel interface statistics - usually available by default but can be restricted for example by grsecurity and similar security enhancement suites or settings - sqlite3 (library and development files) - libgd (optional, image output) - check (optional, test suite) - pkg-config (optional, for check detection) - autotools (optional, for recreating configure and makefiles) # Compiling the binaries This source package contains the required source files for vnStat including the daemon (`vnstatd`) and image output (`vnstati`). Executing ./configure --prefix=/usr --sysconfdir=/etc && make will compile `vnstat` and `vnstatd`. The optional image output capable binary `vnstati` will also be compiled if the required additional libgd library is found to be available and `--disable-image-output` isn't given as parameter for `./configure`. An example cgi (`vnstat.cgi`) to be used with a http server with the image output support has been provided in the `examples` directory. Configuration options for the cgi are in the beginning of the file. Additional examples for using the json output are also available in the same directory. For executing the optional test suite, see the appendix at the end of this file. # Installing as root Log in as root and run the following command: make install If there were no errors, vnStat binaries, man pages and a configuration file should now be installed. The configuration file will be upgraded using previously configured values if it is found already to exist. A backup of the previous configuration file will be named as `vnstat.conf.old` in the current directory. The configuration file `/etc/vnstat.conf` should be checked at this point. See the `vnstat.conf` man page for documentation about available options. Finally, make vnStat monitor available interfaces. Configure init scripts so that the following command is executed once during system startup: vnstatd -d The `examples` directory contains suitable files for most commonly used service managers. Refer to your operating system / distribution documentation if unsure which service manager is being used. * systemd * option 1: hardened - requires a more recent systemd version ~~~ cp -v examples/systemd/vnstat.service /etc/systemd/system/ systemctl enable vnstat systemctl start vnstat ~~~ * option 2: simple - works also with older systemd versions ~~~ cp -v examples/systemd/simple/vnstat.service /etc/systemd/system/ systemctl enable vnstat systemctl start vnstat ~~~ * init.d * Debian ~~~ cp -v examples/init.d/debian/vnstat /etc/init.d/ update-rc.d vnstat defaults service vnstat start ~~~ * Red Hat / CentOS ~~~ cp -v examples/init.d/redhat/vnstat /etc/init.d/ chkconfig vnstat on service vnstat start ~~~ * upstart ~~~ cp -v examples/upstart/vnstat.conf /etc/init/ initctl start vnstat ~~~ An alternative method is to add the command to an already existing script that gets executed during system startup. In many distributions `/etc/rc.local` can be used if nothing else suitable can be found. Note that the full path to the executable may need to be included instead of only the command itself. During first startup, the daemon (`vnstatd`) should list and add all available interfaces for monitoring. Depending on configuration, it may take some minutes for the `vnstat` command to begin showing results as the entries in the database aren't updated constantly. Monitoring of unwanted interfaces can be stopped with: vnstat --remove -i ethunwanted # Installing without root access Copy all needed binaries to some directory included in your PATH (`~/bin/` is used here as an example) and create the database directory. cp -v vnstat vnstatd vnstati ~/bin/ cp -v cfg/vnstat.conf ~/.vnstatrc mkdir ~/.vnstat Check that the binaries got installed to a suitable location and are of the correct version: vnstat --version If this gives a `command not found` error or a different than expected version then check the content of the PATH variable and try again. Next open the configuration file `~/.vnstatrc` with your favorite text editor and locate the following line: DatabaseDir "/var/lib/vnstat" and replace it with DatabaseDir "/pathtomyhomedir/.vnstat" Next, locate the following lines: UseLogging 2 LogFile "/var/log/vnstat/vnstat.log" PidFile "/var/run/vnstat/vnstat.pid" and replace them with UseLogging 1 LogFile "/pathtomyhomedir/.vnstat/.log" PidFile "/pathtomyhomedir/.vnstat/.pid" Finally, save the file. If you are unsure about your home directory path, execute cd ; pwd The output should tell your home directory. Now it's time to add a crontab entry for vnStat in order to get the daemon running automatically after a system startup. Do that by executing the command `crontab -e` and add the following line (without leading spaces, remember to change the path): @reboot ~/bin/vnstatd -d If you found yourself using a strange editor then `man vi` may help. Make sure the configuration file (`~/.vnstatrc`) has the log option either disabled or set to a file that is located in a place where you have write permissions, such as your home dir. Then try starting the daemon with vnstatd -d After that wait for (or generate) at least 1 byte of network traffic (and 5 min for the next database file save). vnstat Now you should get some statistics about your network usage. See the config file `~/.vnstatrc` for interface and other settings. # Appendix: Running the test suite This step isn't mandatory for using vnStat. The source package includes a test suite for validating many of the functionalities provided and used by the executables. The test suite requires the Check unit testing framework ( https://libcheck.github.io/check/ ) to be installed and available. Depending on the used distribution, the necessary package to be installed is usually called `check` and may also require `check-devel` to be installed if available. After the `./configure` script has been executed the test suite can be executed with: make check The output should show a non-zero number of tests executed if all the necessary packages were available. A more detailed list of executed tests can be seen from the `check_vnstat.log` file after execution.