X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fvserver.c;h=54b3623f4b02758df80473207744b8754224fa0a;hb=a2e870fa005e4612ed126a49fbebd8618e50da6f;hp=d80717cd3349e6a684e977375604209e7d05b775;hpb=b61a03b05c1f4040a6599334b65141aa3bd134f5;p=collectd.git diff --git a/src/vserver.c b/src/vserver.c index d80717cd..54b3623f 100644 --- a/src/vserver.c +++ b/src/vserver.c @@ -3,22 +3,27 @@ * 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" @@ -126,15 +131,7 @@ 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); @@ -148,6 +145,7 @@ static int vserver_read (void) while (42) { + struct dirent *dent; int len; char file[BUFSIZE]; @@ -159,20 +157,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;