From 06a2ac2c209976aab9ade33d7d5a5a86ceb7e107 Mon Sep 17 00:00:00 2001 From: cperciva Date: Sat, 17 Sep 2005 15:43:40 +0000 Subject: [PATCH] MFC revision 1.3: Log: Handle circular dependencies properly (via errx(3)) rather than dumping core. This bug was made visible by a recent change to the audio/timidity++ port, which now has itself as a run dependency. Approved by: re (scottl) --- usr.sbin/portsnap/make_index/make_index.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/usr.sbin/portsnap/make_index/make_index.c b/usr.sbin/portsnap/make_index/make_index.c index fbb8dd916864..c02bba8b0deb 100644 --- a/usr.sbin/portsnap/make_index/make_index.c +++ b/usr.sbin/portsnap/make_index/make_index.c @@ -305,15 +305,28 @@ recurse_one(DEP * d, size_t * nd) static void recurse(PORT * p) { - if (p->recursed != 0) + switch (p->recursed) { + case 0: + /* First time we've seen this port */ + p->recursed = 1; + break; + case 1: + /* We're in the middle of recursing this port */ + errx(1, "Circular dependency loop found: %s" + " depends upon itself.\n", p->pkgname); + case 2: + /* This port has already been recursed */ return; - p->recursed = 1; + } p->edep = recurse_one(p->edep, &p->n_edep); p->pdep = recurse_one(p->pdep, &p->n_pdep); p->fdep = recurse_one(p->fdep, &p->n_fdep); p->bdep = recurse_one(p->bdep, &p->n_bdep); p->rdep = recurse_one(p->rdep, &p->n_rdep); + + /* Finished recursing on this port */ + p->recursed = 2; } /* Heapify an element in a package list */