Bug 202726 - rcorder: Circular dependency on provision `mountcritremote' in file `/etc/rc.d/ldconfig'.
Summary: rcorder: Circular dependency on provision `mountcritremote' in file `/etc/rc....
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: conf (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: Enji Cooper
URL:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2015-08-28 18:46 UTC by Jan Beich
Modified: 2016-05-30 20:00 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer freebsd_triage 2015-08-28 18:46:50 UTC
Regressed since base r282145.

$ rcorder /etc/rc.d/* >/dev/null
rcorder: Circular dependency on provision `mountcritremote' in file `/etc/rc.d/ldconfig'.
Comment 1 Jilles Tjoelker freebsd_committer freebsd_triage 2015-08-30 15:59:46 UTC
Having a cyclic dependency in rc.d is bad because it makes it hard to predict in what order things are started.

The cycle here is:

* ldconfig depends on mountcritremote via REQUIRE: line in ldconfig. This is needed to allow /usr/local etc to be NFS-mounted on systems that aren't "diskless". Perhaps that can be dropped. The actual access happens to allow for libdata/ldconfig files and aout libraries; if those didn't exist, it would be possible to change ldconfig to write pathnames into /var/run/ld-elf.so.hints without checking for existence.

* mountcritremote depends on devd via BEFORE: line in devd. This is clearly correct, to allow mounting filesystems via devices that need devd to load their driver or do other setup.

* devd depends on ldconfig via REQUIRE: line in devd. This is new, to allow calling /usr/local binaries from devd actions.

There seem valid use cases for all three dependencies, but not all at the same time. The static dependency system is too crude to handle it.

Doing it dynamically seems hard as well -- how should devd know that it needs to wait for ldconfig before running a particular action?

Alternatively, we could run ldconfig twice and satisfy all three dependencies to some degree (obviously, an action to bring up a device needed for some filesystem cannot use libraries on that filesystem).
Comment 2 Enji Cooper freebsd_committer freebsd_triage 2015-10-25 05:17:20 UTC
Giving bug to glebius@. I can confirm that reverting the commit fixes the circular dependency.

Having ldconfig REQUIRE just FILESYSTEMS instead of mountcritremote fixes the circular dependency, but I'm not sure if people are using NFS for ldconfig directories (seems like a really bad idea under some circumstances, but maybe not under diskless boots):

$ svn diff etc/rc.d/ldconfig 
Index: etc/rc.d/ldconfig
===================================================================
--- ../../../etc/rc.d/ldconfig  (revision 289914)
+++ ../../../etc/rc.d/ldconfig  (working copy)
@@ -4,7 +4,7 @@
 #
 
 # PROVIDE: ldconfig
-# REQUIRE: mountcritremote FILESYSTEMS
+# REQUIRE: FILESYSTEMS
 # BEFORE:  DAEMON
 
 . /etc/rc.subr
Comment 3 Enji Cooper freebsd_committer freebsd_triage 2015-10-25 05:35:48 UTC
Here's another alternative to this problem that would work with remote
file systems. The key difference to this patch is that it would only
regenerate the linker hints if a `remote` file system was mounted.

I think this is risky with a parallel boot mechanism like we have at
$work because it might break the ldconfig hints, but it's worth a shot
for general use.

ldconfig is started last because I wanted to make sure it's clean
before regenerating the hints file.

This patch needs to be tested.

Index: etc/rc.d/ldconfig
===================================================================
--- etc/rc.d/ldconfig  (revision 289914)
+++ etc/rc.d/ldconfig  (working copy)
@@ -4,7 +4,7 @@
 #
 
 # PROVIDE: ldconfig
-# REQUIRE: mountcritremote FILESYSTEMS
+# REQUIRE: FILESYSTEMS
 # BEFORE:  DAEMON
 
 . /etc/rc.subr
Index: etc/rc.d/mountcritremote
===================================================================
--- etc/rc.d/mountcritremote   (revision 289914)
+++ etc/rc.d/mountcritremote   (working copy)
@@ -34,6 +34,8 @@
 
 mountcritremote_start()
 {
+       local mounted_remote_filesystem=false
+
        # Mount nfs filesystems.
        #
        case "`/sbin/mount -d -a -t nfs`" in
@@ -40,6 +42,7 @@
        '')
                ;;
        *)
+               mounted_remote_filesystem=true
                echo -n 'Mounting NFS file systems:'
                mount -a -t nfs
                echo '.'
@@ -63,6 +66,7 @@
 
                case "`mount -d -a -t ${fstype}`" in
                *mount_${fstype}*)
+                       mounted_remote_filesystem=true
                        echo -n "Mounting ${fsdecr} file systems:"
                        mount -a -t ${fstype}
                        echo '.'
@@ -70,9 +74,15 @@
                esac
        done
 
-       # Cleanup /var again just in case it's a network mount.
-       /etc/rc.d/cleanvar quietreload
-       rm -f /var/run/clean_var /var/spool/lock/clean_var
+       if $mounted_remote_filesystem; then
+               # Cleanup /var again just in case it's a network mount.
+               /etc/rc.d/cleanvar quietreload
+               rm -f /var/run/clean_var /var/spool/lock/clean_var
+
+               # Regenerate the ldconfig hints in case there are additional
+               # library paths on remote file systems
+               /etc/rc.d/ldconfig quietstart
+       fi
 }
 
 load_rc_config $name
Comment 4 Enji Cooper freebsd_committer freebsd_triage 2015-10-25 21:40:41 UTC
Taking since I have a patch in progress on ^/user/ngie/detangle-rc .
Comment 5 commit-hook freebsd_committer freebsd_triage 2016-05-30 20:00:22 UTC
A commit references this bug:

Author: ngie
Date: Mon May 30 19:59:51 UTC 2016
New revision: 301004
URL: https://svnweb.freebsd.org/changeset/base/301004

Log:
  Fix circular dependency created after r287197 between ldconfig and mountcritremote

  ldconfig is already required by mountcritremote indirectly, as noted by rcorder:

  > rcorder: Circular dependency on provision `mountcritremote' in file `ldconfig'.

  Having mountcritremote REQUIRE ldconfig breaks dependency ordering.

  Making the ldconfig hints be conditionally regenerated from mountcritremote when
  remote filesystems are mounted is done after this change, similar to cleanvar
  being conditionally called after the change.

  Differential Revision: https://reviews.freebsd.org/D6621
  PR: 202726
  Reviewed by: jilles
  Sponsored by: EMC / Isilon Storage Division

Changes:
  head/etc/rc.d/ldconfig
  head/etc/rc.d/mountcritremote