projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
10075e6
)
qmail plugin: Use `readdir_r' instead of `readdir'.
author
Florian Forster
<octo@leeloo.lan.home.verplant.org>
Sun, 6 Jul 2008 14:40:33 +0000
(16:40 +0200)
committer
Florian Forster
<octo@leeloo.lan.home.verplant.org>
Sun, 6 Jul 2008 14:40:33 +0000
(16:40 +0200)
src/qmail.c
patch
|
blob
|
history
diff --git
a/src/qmail.c
b/src/qmail.c
index
74386c3
..
063eee9
100644
(file)
--- a/
src/qmail.c
+++ b/
src/qmail.c
@@
-58,8
+58,15
@@
static void qmail_submit (const char *plugin_instance, gauge_t value)
static int count_files_in_subtree (const char *path, int depth)
{
static int count_files_in_subtree (const char *path, int depth)
{
+#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 *dh;
struct dirent *de;
DIR *dh;
struct dirent *de;
+ char dirent_buffer[DIRENT_BUFFER_SIZE];
int status;
char **subdirs;
int status;
char **subdirs;
@@
-79,11
+86,27
@@
static int count_files_in_subtree (const char *path, int depth)
subdirs_num = 0;
count = 0;
subdirs_num = 0;
count = 0;
- while (
(de = readdir (dh)) != NULL
)
+ while (
42
)
{
char abs_path[PATH_MAX];
struct stat statbuf;
{
char abs_path[PATH_MAX];
struct stat statbuf;
+ de = NULL;
+ status = readdir_r (dh, (struct dirent *) dirent_buffer, &de);
+ if (status != 0)
+ {
+ char errbuf[4096];
+ ERROR ("qmail plugin: readdir_r failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ closedir (dh);
+ return (-1);
+ }
+ else if (de == NULL)
+ {
+ /* end of directory */
+ break;
+ }
+
if (de->d_name[0] == '.')
continue;
if (de->d_name[0] == '.')
continue;