X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fvserver.c;h=0e58a9710c7800e974b2c415ec886c216f232235;hb=f46301fdc32e9cd13a757dbc005d2b66d5188193;hp=d80717cd3349e6a684e977375604209e7d05b775;hpb=affac33e83584e7538c358e3bd0a587d0c692bc3;p=collectd.git diff --git a/src/vserver.c b/src/vserver.c index d80717cd..0e58a971 100644 --- a/src/vserver.c +++ b/src/vserver.c @@ -3,25 +3,31 @@ * Copyright (C) 2006,2007 Sebastian Harl * Copyright (C) 2007-2010 Florian octo Forster * - * 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; only version 2 of the license is applicable. + * 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: * - * 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. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * 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 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Sebastian Harl - * Florian octo Forster + * Florian octo Forster **/ #include "collectd.h" + #include "common.h" #include "plugin.h" @@ -50,15 +56,14 @@ static int vserver_init (void) static void traffic_submit (const char *plugin_instance, const char *type_instance, derive_t rx, derive_t tx) { - value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - - values[0].derive = rx; - values[1].derive = tx; + value_t values[] = { + { .derive = rx }, + { .derive = tx }, + }; vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); sstrncpy (vl.type, "if_octets", sizeof (vl.type)); @@ -70,16 +75,15 @@ static void traffic_submit (const char *plugin_instance, static void load_submit (const char *plugin_instance, gauge_t snum, gauge_t mnum, gauge_t lnum) { - value_t values[3]; value_list_t vl = VALUE_LIST_INIT; - - values[0].gauge = snum; - values[1].gauge = mnum; - values[2].gauge = lnum; + value_t values[] = { + { .gauge = snum }, + { .gauge = mnum }, + { .gauge = lnum }, + }; vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); sstrncpy (vl.type, "load", sizeof (vl.type)); @@ -91,14 +95,10 @@ static void submit_gauge (const char *plugin_instance, const char *type, const char *type_instance, gauge_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; - vl.values_len = STATIC_ARRAY_SIZE (values); - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + vl.values = &(value_t) { .gauge = value }; + vl.values_len = 1; sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); sstrncpy (vl.type, type, sizeof (vl.type)); @@ -126,28 +126,21 @@ static derive_t vserver_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]; + DIR *proc; errno = 0; proc = opendir (PROCDIR); if (proc == NULL) { char errbuf[1024]; - ERROR ("vserver plugin: fopen (%s): %s", PROCDIR, + ERROR ("vserver plugin: fopen (%s): %s", PROCDIR, sstrerror (errno, errbuf, sizeof (errbuf))); return (-1); } while (42) { + struct dirent *dent; int len; char file[BUFSIZE]; @@ -159,20 +152,20 @@ static int vserver_read (void) int status; - status = readdir_r (proc, (struct dirent *) dirent_buffer, &dent); - if (status != 0) + errno = 0; + dent = readdir (proc); + if (dent == NULL) { char errbuf[4096]; - ERROR ("vserver plugin: readdir_r failed: %s", - sstrerror (errno, errbuf, sizeof (errbuf))); + + if (errno == 0) /* end of directory */ + break; + + ERROR ("vserver plugin: failed to read directory %s: %s", + PROCDIR, sstrerror (errno, errbuf, sizeof (errbuf))); closedir (proc); return (-1); } - else if (dent == NULL) - { - /* end of directory */ - break; - } if (dent->d_name[0] == '.') continue; @@ -180,7 +173,7 @@ static int vserver_read (void) len = ssnprintf (file, sizeof (file), PROCDIR "/%s", dent->d_name); if ((len < 0) || (len >= BUFSIZE)) continue; - + status = stat (file, &statbuf); if (status != 0) { @@ -189,7 +182,7 @@ static int vserver_read (void) file, sstrerror (errno, errbuf, sizeof (errbuf))); continue; } - + if (!S_ISDIR (statbuf.st_mode)) continue; @@ -210,7 +203,7 @@ static int vserver_read (void) { derive_t rx; derive_t tx; - char *type_instance; + const char *type_instance; if (strsplit (buffer, cols, 4) < 4) continue; @@ -260,7 +253,7 @@ static int vserver_read (void) if (2 == n) { - char *type_instance; + const char *type_instance; gauge_t value; if (0 == strcmp (cols[0], "nr_threads:")) @@ -309,8 +302,8 @@ static int vserver_read (void) while ((fh != NULL) && (NULL != fgets (buffer, BUFSIZE, fh))) { - char *type = "vs_memory"; - char *type_instance; + const char *type = "vs_memory"; + const char *type_instance; gauge_t value; if (strsplit (buffer, cols, 2) < 2)