From 6804d2324ff2524cdf9ac013cb2b6b72c2295117 Mon Sep 17 00:00:00 2001
From: Rob Landley <rob@landley.net>
Date: Tue, 5 Aug 2014 19:41:36 -0500
Subject: find.c: Posix wants loop detection.

---
 toys/posix/find.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/toys/posix/find.c b/toys/posix/find.c
index b1aa6845..0ea5271e 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -189,7 +189,17 @@ static int do_find(struct dirtree *new)
     }
     if (S_ISDIR(new->st.st_mode)) {
       if (!new->again) {
+        struct dirtree *n;
+
         if (TT.depth) return recurse;
+        for (n = new->parent; n; n = n->parent) {
+          if (n->st.st_ino==new->st.st_ino && n->st.st_dev==new->st.st_dev) {
+            error_msg("'%s': loop detected", s = dirtree_path(new, 0));
+            free(s);
+
+            return 0;
+          }
+        }
       } else {
         struct double_list *dl;
 
-- 
cgit v1.2.3