From aa8c94c4344f4d856700f58624e50d304bcc96b9 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 23 Jun 2016 14:37:26 +0100 Subject: [PATCH] [Fix] Disable fts as it is completely broken in bloody linux --- src/client/rspamc.c | 64 +++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/src/client/rspamc.c b/src/client/rspamc.c index d51da024d..638ccedfe 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -20,9 +20,6 @@ #include "rspamdclient.h" #include "utlist.h" #include "unix-std.h" - -#include - #ifdef HAVE_SYS_WAIT_H #include #endif @@ -1379,39 +1376,56 @@ static void rspamc_process_dir (struct event_base *ev_base, struct rspamc_command *cmd, const gchar *name, GQueue *attrs) { - FTS *fts; - FTSENT *entry; + DIR *d; + struct dirent entry, *pentry = NULL; gint cur_req = 0; + gchar fpath[PATH_MAX]; FILE *in; + struct stat st; - gchar * const names[] = { - (gchar *)name, - NULL - }; + memset (&entry, 0, sizeof (entry)); + d = opendir (name); - fts = fts_open (&names[0], FTS_LOGICAL|FTS_XDEV, NULL); + if (d != NULL) { + while (readdir_r (d, &entry, &pentry) == 0) { + if (pentry == NULL) { + break; + } - if (fts != NULL) { - while ((entry = fts_read (fts))) { - if (entry->fts_info != FTS_F) { + if (pentry->d_name[0] == '.') { continue; } - in = fopen (entry->fts_path, "r"); - if (in == NULL) { - rspamd_fprintf (stderr, "cannot open file %s: %s\n", - entry->fts_path, strerror (errno)); + rspamd_snprintf (fpath, sizeof (fpath), "%s%c%s", + name, G_DIR_SEPARATOR, pentry->d_name); + + if (lstat (fpath, &st) == -1) { + rspamd_fprintf (stderr, "cannot stat file %s: %s\n", + fpath, strerror (errno)); + continue; + } + + if (S_ISDIR (st.st_mode)) { + rspamc_process_dir (ev_base, cmd, fpath, attrs); continue; } + else if (S_ISREG (st.st_mode)) { + in = fopen (fpath, "r"); + if (in == NULL) { + rspamd_fprintf (stderr, "cannot open file %s: %s\n", + fpath, strerror (errno)); + continue; + } - rspamc_process_input (ev_base, cmd, in, entry->fts_path, attrs); - cur_req++; - fclose (in); + rspamc_process_input (ev_base, cmd, in, fpath, attrs); + cur_req++; + fclose (in); - if (cur_req >= max_requests) { - cur_req = 0; - /* Wait for completion */ - event_base_loop (ev_base, 0); + if (cur_req >= max_requests) { + cur_req = 0; + /* Wait for completion */ + event_base_loop (ev_base, 0); + } } } } @@ -1420,7 +1434,7 @@ rspamc_process_dir (struct event_base *ev_base, struct rspamc_command *cmd, exit (EXIT_FAILURE); } - fts_close (fts); + closedir (d); event_base_loop (ev_base, 0); } -- 2.39.5