]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Disable fts as it is completely broken in bloody linux
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 23 Jun 2016 13:37:26 +0000 (14:37 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 23 Jun 2016 13:37:26 +0000 (14:37 +0100)
src/client/rspamc.c

index d51da024d9729887b7c0fe42e584f3bb78268440..638ccedfe5c2d5c11d5d767bf0f2b0d5e93928f2 100644 (file)
@@ -20,9 +20,6 @@
 #include "rspamdclient.h"
 #include "utlist.h"
 #include "unix-std.h"
-
-#include <fts.h>
-
 #ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
 #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);
 }