From: Florian Forster Date: Wed, 23 Jul 2008 15:18:13 +0000 (+0200) Subject: Merge branch 'master' of git://git.verplant.org/collectd X-Git-Tag: collectd-4.5.0~91 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0421d0d777f6df3cf78fd5366c82b0ed7adb9684;hp=c71b8d22d731098030a81dd974f2f76ac7f7b32e;p=collectd.git Merge branch 'master' of git://git.verplant.org/collectd --- diff --git a/ChangeLog b/ChangeLog index 0f0f2571..35e8b36c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2008-07-15, Version 4.4.2 + * build system: Use pkg-config to detect the upsclient library. + * collectd: Try even harder to determine the endianess of the + architecture collectd is being built on. + * disk plugin: Fix for Linux 2.4: A wrong field was used as the name + of disks. + * dns plugin: Fix compilation errors with BIND versions 19991001 + through 19991005. + * network plugin: Bugfix in the init routine: The init function + cleared a buffer regardless of its contents. This could lead to lost + values under Solaris. + * nginx plugin: Remove usage of the thread-unsafe `strtok' function. + * vserver plugin: Remove usage of the thread-unsafe `readdir' + function. + * wireless plugin: Work around incorrect noise and power values + returned by some broken drivers. + 2008-06-03, Version 4.4.1 * collectd: Fix the `DataSource' option within `Type' blocks. Thanks to kyrone for reporting this. diff --git a/src/Makefile.am b/src/Makefile.am index 9962c0d0..c4e7d69f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -523,7 +523,7 @@ pkglib_LTLIBRARIES += perl.la perl_la_SOURCES = perl.c # Despite C99 providing the "bool" type thru stdbool.h, Perl defines its own # version of that type if HAS_BOOL is not defined... *sigh* -perl_la_CPPFLAGS = -DHAS_BOOL=1 +perl_la_CPPFLAGS = $(AM_CPPFLAGS) -DHAS_BOOL=1 perl_la_CFLAGS = $(AM_CFLAGS) \ $(PERL_CFLAGS) \ -DXS_VERSION=\"$(VERSION)\" -DVERSION=\"$(VERSION)\" @@ -550,7 +550,7 @@ endif if BUILD_PLUGIN_POSTGRESQL pkglib_LTLIBRARIES += postgresql.la postgresql_la_SOURCES = postgresql.c -postgresql_la_CPPFLAGS = $(BUILD_WITH_LIBPQ_CPPFLAGS) +postgresql_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBPQ_CPPFLAGS) postgresql_la_LDFLAGS = -module -avoid-version \ $(BUILD_WITH_LIBPQ_LDFLAGS) -lpq collectd_LDADD += "-dlopen" postgresql.la diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 884298dc..1a52ae5c 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -30,7 +30,11 @@ section-start or -end. Empty lines and everything after the hash-symbol `#' is ignored. Values are either string, enclosed in double-quotes, (floating-point-)numbers or a boolean expression, i.Ee. either B or B. String containing of only alphanumeric characters and underscores do -not need to be quoted. +not need to be quoted. Lines may be wrapped by using `\' as the last character +before the newline. This allows long lines to be split into multiple lines. +Quoted strings may be wrapped as well. However, those are treated special in +that whitespace at the beginning of the following lines will be ignored, which +allows for nicely indenting the wrapped lines. The configuration is read and processed in order, i.Ee. from top to bottom. So the plugins are loaded in the order listed in this config file. It diff --git a/src/collectd.h b/src/collectd.h index 5912fe6f..a262bf1d 100644 --- a/src/collectd.h +++ b/src/collectd.h @@ -203,9 +203,6 @@ # include #endif -#if HAVE_PTH_H -# include -#endif #if HAVE_SENSORS_SENSORS_H # include #endif @@ -254,7 +251,19 @@ #endif #if __GNUC__ -# pragma GCC poison strcpy strcat sprintf strtok +# pragma GCC poison strcpy strcat strtok +#endif + +/* + * Special hack for the perl plugin: Because the later included perl.h defines + * a macro which is never used, but contains `sprintf', we cannot poison that + * identifies just yet. The parl plugin will do that itself once perl.h is + * included. + */ +#ifndef DONT_POISON_SPRINTF_YET +# if __GNUC__ +# pragma GCC poison sprintf +# endif #endif extern char hostname_g[]; diff --git a/src/configfile.c b/src/configfile.c index 2afef4f0..d483032a 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -327,7 +327,7 @@ static int dispatch_block_plugin (oconfig_item_t *ci) if (ci->children[i].children == NULL) dispatch_value_plugin (name, ci->children + i); else - {DEBUG ("No nested config blocks allow for this plugin.");} + {DEBUG ("No nested config blocks allowed for this plugin.");} } return (0); diff --git a/src/liboconfig/scanner.l b/src/liboconfig/scanner.l index 4d9fc3de..b559e863 100644 --- a/src/liboconfig/scanner.l +++ b/src/liboconfig/scanner.l @@ -1,6 +1,7 @@ /** * oconfig - src/scanner.l * Copyright (C) 2007 Florian octo Forster + * Copyright (C) 2008 Sebastian tokkee Harl * * 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 @@ -21,11 +22,30 @@ #include "oconfig.h" #include "aux_types.h" #include "parser.h" + +/* multiline string buffer */ +static char *ml_buffer = NULL; +static int ml_pos = 0; +static int ml_len = 0; + +#define ml_free (ml_len - ml_pos) + +static void ml_append (char *); + +#ifdef yyterminate +# undef yyterminate +#endif +#define yyterminate() \ + do { free (ml_buffer); ml_buffer = NULL; ml_pos = 0; ml_len = 0; \ + return YY_NULL; } while (0) %} %option yylineno %option noyywrap +%x ML WHITE_SPACE [\ \t\b] -QUOTED_STRING \"([^\\"]+|\\.)*\" +NON_WHITE_SPACE [^\ \t\b] +EOL (\r\n|\n) +QUOTED_STRING ([^\\"]+|\\.)* UNQUOTED_STRING [0-9A-Za-z_]+ HEX_NUMBER 0[xX][0-9a-fA-F]+ OCT_NUMBER 0[0-7]+ @@ -43,7 +63,9 @@ IPV4_ADDR {IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}(:{PORT})? {WHITE_SPACE} | {COMMENT} {/* ignore */} -\n {return (EOL);} +\\{EOL} {/* continue line */} + +{EOL} {return (EOL);} "/" {return (SLASH);} "<" {return (OPENBRAC);} ">" {return (CLOSEBRAC);} @@ -54,6 +76,62 @@ IPV4_ADDR {IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}(:{PORT})? {NUMBER} {yylval.number = strtod (yytext, NULL); return (NUMBER);} -{QUOTED_STRING} {yylval.string = yytext; return (QUOTED_STRING);} +\"{QUOTED_STRING}\" {yylval.string = yytext; return (QUOTED_STRING);} {UNQUOTED_STRING} {yylval.string = yytext; return (UNQUOTED_STRING);} + +\"{QUOTED_STRING}\\{EOL} { + int len = strlen (yytext); + + ml_pos = 0; + + /* remove "\\" */ + if ('\r' == yytext[len - 2]) + len -= 3; + else + len -= 2; + yytext[len] = '\0'; + + ml_append (yytext); + BEGIN (ML); +} +^{WHITE_SPACE}+ {/* remove leading white-space */} +{NON_WHITE_SPACE}{QUOTED_STRING}\\{EOL} { + int len = strlen (yytext); + + /* remove "\\" */ + if ('\r' == yytext[len - 2]) + len -= 3; + else + len -= 2; + yytext[len] = '\0'; + + ml_append(yytext); +} +{NON_WHITE_SPACE}{QUOTED_STRING}\" { + ml_append(yytext); + yylval.string = ml_buffer; + + BEGIN (INITIAL); + return (QUOTED_STRING); +} %% +static void ml_append (char *string) +{ + int len = strlen (string); + int s; + + if (ml_free <= len) { + ml_len += len - ml_free + 1; + ml_buffer = (char *)realloc (ml_buffer, ml_len); + if (NULL == ml_buffer) + YY_FATAL_ERROR ("out of dynamic memory in ml_append"); + } + + s = snprintf (ml_buffer + ml_pos, ml_free, "%s", string); + if ((0 > s) || (ml_free <= s)) + YY_FATAL_ERROR ("failed to write to multiline buffer"); + + ml_pos += s; + return; +} /* ml_append */ + diff --git a/src/ntpd.c b/src/ntpd.c index 1a0a07dd..44964bb5 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -68,7 +68,7 @@ static char ntpd_port[16]; #define MAXFILENAME 128 #define MAXSEQ 127 #define MODE_PRIVATE 7 -#define NTP_OLDVERSION ((u_char) 1) /* oldest credible version */ +#define NTP_OLDVERSION ((uint8_t) 1) /* oldest credible version */ #define IMPL_XNTPD 3 #define FP_FRAC 65536.0 @@ -117,27 +117,27 @@ struct resp_pkt #define ISRESPONSE(rm_vn_mode) (((rm_vn_mode)&RESP_BIT)!=0) #define ISMORE(rm_vn_mode) (((rm_vn_mode)&MORE_BIT)!=0) -#define INFO_VERSION(rm_vn_mode) ((u_char)(((rm_vn_mode)>>3)&0x7)) +#define INFO_VERSION(rm_vn_mode) ((uint8_t)(((rm_vn_mode)>>3)&0x7)) #define INFO_MODE(rm_vn_mode) ((rm_vn_mode)&0x7) #define RM_VN_MODE(resp, more, version) \ - ((u_char)(((resp)?RESP_BIT:0)\ + ((uint8_t)(((resp)?RESP_BIT:0)\ |((more)?MORE_BIT:0)\ |((version?version:(NTP_OLDVERSION+1))<<3)\ |(MODE_PRIVATE))) #define INFO_IS_AUTH(auth_seq) (((auth_seq) & 0x80) != 0) #define INFO_SEQ(auth_seq) ((auth_seq)&0x7f) -#define AUTH_SEQ(auth, seq) ((u_char)((((auth)!=0)?0x80:0)|((seq)&0x7f))) +#define AUTH_SEQ(auth, seq) ((uint8_t)((((auth)!=0)?0x80:0)|((seq)&0x7f))) -#define INFO_ERR(err_nitems) ((u_short)((ntohs(err_nitems)>>12)&0xf)) -#define INFO_NITEMS(err_nitems) ((u_short)(ntohs(err_nitems)&0xfff)) -#define ERR_NITEMS(err, nitems) (htons((u_short)((((u_short)(err)<<12)&0xf000)\ - |((u_short)(nitems)&0xfff)))) +#define INFO_ERR(err_nitems) ((uint16_t)((ntohs(err_nitems)>>12)&0xf)) +#define INFO_NITEMS(err_nitems) ((uint16_t)(ntohs(err_nitems)&0xfff)) +#define ERR_NITEMS(err, nitems) (htons((uint16_t)((((uint16_t)(err)<<12)&0xf000)\ + |((uint16_t)(nitems)&0xfff)))) #define INFO_MBZ(mbz_itemsize) ((ntohs(mbz_itemsize)>>12)&0xf) -#define INFO_ITEMSIZE(mbz_itemsize) ((u_short)(ntohs(mbz_itemsize)&0xfff)) -#define MBZ_ITEMSIZE(itemsize) (htons((u_short)(itemsize))) +#define INFO_ITEMSIZE(mbz_itemsize) ((uint16_t)(ntohs(mbz_itemsize)&0xfff)) +#define MBZ_ITEMSIZE(itemsize) (htons((uint16_t)(itemsize))) /* negate a long float type */ #define M_NEG(v_i, v_f) \ diff --git a/src/perl.c b/src/perl.c index 541826fb..268e1d14 100644 --- a/src/perl.c +++ b/src/perl.c @@ -27,13 +27,19 @@ /* do not automatically get the thread specific perl interpreter */ #define PERL_NO_GET_CONTEXT +#define DONT_POISON_SPRINTF_YET 1 #include "collectd.h" +#undef DONT_POISON_SPRINTF_YET #include "configfile.h" #include #include +#if __GNUC__ +# pragma GCC poison sprintf +#endif + #include /* Some versions of Perl define their own version of DEBUG... :-/ */ diff --git a/src/snmp.c b/src/snmp.c index 05612576..07465ddd 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -708,14 +708,14 @@ static value_t csnmp_value_list_to_value (struct variable_list *vl, int type, || (vl->type == ASN_GAUGE)) { temp = (uint32_t) *vl->val.integer; - DEBUG ("snmp plugin: Parsed int32 value is %llu.", temp); + DEBUG ("snmp plugin: Parsed int32 value is %"PRIu64".", temp); } else if (vl->type == ASN_COUNTER64) { temp = (uint32_t) vl->val.counter64->high; temp = temp << 32; temp += (uint32_t) vl->val.counter64->low; - DEBUG ("snmp plugin: Parsed int64 value is %llu.", temp); + DEBUG ("snmp plugin: Parsed int64 value is %"PRIu64".", temp); } else if (vl->type == ASN_OCTET_STR) { @@ -1424,8 +1424,8 @@ static int csnmp_read_host (host_definition_t *host) if ((time_end - time_start) > host->interval) { WARNING ("snmp plugin: Host `%s' should be queried every %i seconds, " - "but reading all values takes %lu seconds.", - host->name, host->interval, (unsigned long)(time_end - time_start)); + "but reading all values takes %u seconds.", + host->name, host->interval, (unsigned int) (time_end - time_start)); } return (0); diff --git a/src/vserver.c b/src/vserver.c index 413674b0..dac43926 100644 --- a/src/vserver.c +++ b/src/vserver.c @@ -120,11 +120,19 @@ static inline long long __get_sock_bytes(const char *s) static int vserver_read (void) { +#if NAME_MAX < 1024 +# define DIRENT_BUFFER_SIZE (sizeof (struct dirent) + 1024 + 1) +#else +# define DIRENT_BUFFER_SIZE (sizeof (struct dirent) + NAME_MAX + 1) +#endif + DIR *proc; struct dirent *dent; /* 42 */ + char dirent_buffer[DIRENT_BUFFER_SIZE]; errno = 0; - if (NULL == (proc = opendir (PROCDIR))) + proc = opendir (PROCDIR); + if (proc == NULL) { char errbuf[1024]; ERROR ("vserver plugin: fopen (%s): %s", PROCDIR, @@ -132,21 +140,51 @@ static int vserver_read (void) return (-1); } - while (NULL != (dent = readdir (proc))) + while (42) { - int len; + size_t len; char file[BUFSIZE]; FILE *fh; char buffer[BUFSIZE]; + struct stat statbuf; char *cols[4]; + int status; + + status = readdir_r (proc, (struct dirent *) dirent_buffer, &dent); + if (status != 0) + { + char errbuf[4096]; + ERROR ("vserver plugin: readdir_r failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + closedir (proc); + return (-1); + } + else if (dent == NULL) + { + /* end of directory */ + break; + } + if (dent->d_name[0] == '.') continue; - /* This is not a directory */ - if (dent->d_type != DT_DIR) + len = snprintf (file, sizeof (file), PROCDIR "/%s", dent->d_name); + if ((len < 0) || (len >= BUFSIZE)) + continue; + + status = stat (file, &statbuf); + if (status != 0) + { + char errbuf[4096]; + WARNING ("vserver plugin: stat (%s) failed: %s", + file, sstrerror (errno, errbuf, sizeof (errbuf))); + continue; + } + + if (!S_ISDIR (statbuf.st_mode)) continue; /* socket message accounting */ diff --git a/version-gen.sh b/version-gen.sh index 755e1168..0049f7de 100755 --- a/version-gen.sh +++ b/version-gen.sh @@ -1,6 +1,6 @@ #!/bin/sh -DEFAULT_VERSION="4.4.1.git" +DEFAULT_VERSION="4.4.2.git" VERSION="$( git describe 2> /dev/null | sed -e 's/^collectd-//' )"