Skip to content

facter/util/linux/dhcp.rb spamming logs #9589

Open

Description

@rwsmith61

Describe the Bug

During any puppet agent run, when facts are gathered, or when running puppet facts, on some systems, the system log will show:
Oct 7 10:58:51 san01p.bob.home dhcpcd[410158]: dhcpcd is not running
Oct 7 10:58:51 san01p.bob.home dhcpcd[410159]: dhcpcd is not running
Oct 7 10:58:51 san01p.bob.home dhcpcd[410163]: dhcpcd is not running
Oct 7 10:58:51 san01p.bob.home dhcpcd[410164]: dhcpcd is not running
Oct 7 14:58:51 san01p.bob.home dhcpcd[412370]: dhcpcd is not running
Oct 7 14:58:51 san01p.bob.home dhcpcd[412371]: dhcpcd is not running
Oct 7 14:58:51 san01p.bob.home dhcpcd[412375]: dhcpcd is not running
Oct 7 14:58:51 san01p.bob.home dhcpcd[412376]: dhcpcd is not running

On a single Ethernet interfaces system this generates four log per run.

This occurs on systems where the package dhcpcd is installed, the dhcpcd executable is found, and dhcpcd is not being run in master mode.

Expected Behavior

While the issue does stem from the fact that dhcpcd logs any errors through syslog and this can't be turned off, the fact that Puppet blindly runs the command on systems which the executable is found but may not be running, should itself not cause these logs by simply running the dhcpcd command in the ruby code.

The systems logs do not specify that the source is in fact from a puppet run or the ruby code. I had to infer this over multiple days of investigation then by inference that these messages were also just before the expected puppet run log output. I then had to infer that since the dhcpcd command has something to do with networking, that this must be coming from the puppet fact checking code and whence the source offending code. It was a bit harder in the beginning looking through Elastic/OpenSearch to get to this initial revelation.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Ensure that the package dhcpcd is installed and the executable /usr/sbin/dhcpcd exists and is executable.
  2. Ensure that the system is NOT running dhcpcd
  3. Run the command: $ puppet facts
  4. check the system log file, per distro, for the lines: dhcpcd[\d+]: dhcpcd is not running
  5. There will be four or lines, usually four per interface and/or run, in the system logs

Environment

  • tested with puppet 7 and puppet 8
  • On RHEL and Debian/Ubuntu that provide package dhcpcd and/or dhcp-client and the executable dhcpcd.

Additional Context

The source of this problem is found in the ruby module: /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/facter/util/linux/dhcp.rb, aka module Facter::Util::Linux::Dhcp in the function def search_with_dhcpcd_command().

The fix to keep this ruby code/facter from generating the excessive logs is to for example add the following code to this function def:

       @dhcpcd_command ||= Facter::Core::Execution.which('dhcpcd')
        return unless @dhcpcd_command
  •        # test if the dhcpcd proesss is running before executing dump command
    
  •        proc = Facter::Core::Execution.execute('pgrep -x dhcpcd')
    
  •        return if proc.empty?
          output = Facter::Core::Execution.execute("#{@dhcpcd_command} -U #{interface_name}", logger: @log)
    

Activity

  1. added
    bug
    on Oct 7, 2026
  2. rwsmith61 commented on Oct 8, 2026

    @rwsmith61
    Author

    This is a duplicate of a bug report under puppetlabs/facter, bug #2780. However, I don't see any solutions within the affected code.

  3. rwsmith61 commented on Oct 8, 2026

    @rwsmith61
    Author

    As of this writing there is no patch in the offending code so here is my suggestion until such time as there is.

    Edit thsi file: /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/facter/util/linux/dhcp.rb

    Replace def search_with_dhcpcd_command(interface_name) with the following:

              def search_with_dhcpcd_command(interface_name)
                @log.debug("Attempt to get DHCP for interface #{interface_name}, from dhcpcd command")
    
                @dhcpcd_command ||= Facter::Core::Execution.which('dhcpcd')
                return unless @dhcpcd_command
    
                dhcpcd_pids = ["/run/dhcpcd.pid", "/run/dhcpcd/pid", "/run/dhcpcd-#{interface_name}.pid", "/run/dhcpcd/#{interface_name}.pid"]
                return unless dhcpcd_pids.any? { |pid| File.exists?(pid) }
    
                output = Facter::Core::Execution.execute("#{@dhcpcd_command} -U #{interface_name}", logger: @log)
                dhcp = output.match(/dhcp_server_identifier='(.*)'/)
                dhcp[1] if dhcp
              end
    

    Note the two lines with 'dhcpcd_pids' that have been added to this def.

    Alternatively, if you have statically or manually assigned your IP addresses then you do not need dhcpcd. If so, then just uninstall package dhcpcd.

    HTH.
    rwsmith

  4. fragrantauto commented on Oct 26, 2026

    @fragrantauto

    The issue appears to be that dhcpcd -U is being executed even when no daemon is present, triggering the stderr output that gets captured by syslog. Instead of simply wrapping the command in a suppression block, we should verify the existence of the dhcpcd socket or check systemctl is-active dhcpcd before calling the utility to prevent the unnecessary subprocess overhead. Does this behavior persist if we add a guard clause to check for the presence of the dhcpcd process, or is the intention to support environments where dhcpcd might only be run in one-shot mode?

  5. rwsmith61 commented on Oct 27, 2026

    @rwsmith61
    Author

    The solution should be general in nature without making to many assumptions about the environment, for example relying on systemctl is-active dhcpcd will not work on some distros and when dhcpcd is run in 'one-shot mode'. And to minimize the processing overhead, for example checking if dhcpcd is running when the module is initialized and storing the result for when the class is called.

    As an example, as I have now updated for my Puppet environment I have modified dhcp.rb with the following:

              # One Time: Search all processes to check if running dhcpcd
              DHCPCD_RUNNING = Dir.glob('/proc/{[1-9]*}').any? do |proc|
                # Filter out kernel threads
                next unless File.symlink?("#{proc}/exe") and File.exists?("#{proc}/exe")
                Facter::Util::FileHelper.safe_read("#{proc}/comm", nil).strip == 'dhcpcd'
              end
    
              def dhcp(interface_name, interface_index, logger)
                @log = logger
                @log.debug("Get DHCP for interface #{interface_name}")
    
                dhcp = search_systemd_netif_leases(interface_index, interface_name)
                dhcp ||= search_dhclient_leases(interface_name)
                dhcp ||= search_internal_leases(interface_name)
                dhcp ||= search_with_dhcpcd_command(interface_name) if DHCPCD_RUNNING # only call if dhcpcd is known to be running
                dhcp
              end
     
    

    YMMV, and the code maintainers may have a completely different solution.

  6. jadayaanaliah26 commented on Nov 1, 2026

    @jadayaanaliah26

    Instead of checking systemd or executing dhcpcd, search_with_dhcpcd_command could

  7. christianfrei791 commented on Nov 7, 2026

    @christianfrei791

    The issue stems from the fact that dhcpcd -U writes to stderr/syslog when the daemon is unreachable, so we should redirect stderr to /dev/null when executing this command within search_with_dhcpcd_command. Since relying on systemd or specific daemon states introduces platform coupling, a simple shell redirection 2>/dev/null inside the backticks or Open3.capture3 call would suppress the unwanted logging while still allowing us to check the exit status. Can we confirm if the exit code of dhcpcd -U remains reliable for our logic if we suppress the error output stream?

  8. naeemgwendlyn26 commented on Nov 12, 2026

    @naeemgwendlyn26

    Checking for the PID file or reading the lease files in /var/lib/dhcpcd/ directly in `

  9. dredonjaquana26 commented on Nov 19, 2026

    @dredonjaquana26

    Instead of relying on external service managers or executing dhcpcd -U, can we check for the existence of the expected control socket in /run/dhcpcd/ or the pidfile path before triggering the command in search_with_dhcpcd_command?

  10. absolutegar commented on Nov 22, 2026

    @absolutegar

    Instead of relying on external service managers or potentially noisy executions, we could check for the existence of the dhcpcd control socket in /run/dhcpcd/ before calling search_with_dhcpcd_command. Does the current implementation allow for a lightweight file existence check on that socket path to determine if a daemon instance is actually listening before triggering the command?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions