Uploaded image for project: 'Facter'
  1. Facter
  2. FACT-2934

Facter::Core::Execution does not set status variables in Facter 4

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • FACT 4.0.49
    • FACT 4.0.50
    • None
    • Needs Assessment
    • Bug Fix
    • Hide
      Description of the problem: The exec and execute methods of the Facter::Core::Execution module are commonly used to execute external processes in custom facts. In Facter 4, these methods no longer set the global Ruby variables $CHILD_STATUS or $? because Open3 is used and it consumes the exit status of the child process.

      Description of the fix: Reimplement Open3.popen3 to not use Process.detach but Process.wait instead.
      Show
      Description of the problem: The exec and execute methods of the Facter::Core::Execution module are commonly used to execute external processes in custom facts. In Facter 4, these methods no longer set the global Ruby variables $CHILD_STATUS or $? because Open3 is used and it consumes the exit status of the child process. Description of the fix: Reimplement Open3.popen3 to not use Process.detach but Process.wait instead.
    • Needs Assessment

    Description

      The exec and execute methods of the Facter::Core::Execution module are commonly used to execute external processes in custom facts. In Facter 4, these methods no longer set the global Ruby variables $CHILD_STATUS or $?.

      This is a regression of FACT-1284 which was its self a regression of behavior present in Facter 2.x and 1.x.

      Reproduction Case

      • Install puppet-agent 7 on CentOS 7:

      yum install -y http://yum.puppetlabs.com/puppet7-release-el-7.noarch.rpm
      yum install -y puppet-agent
       
      source /etc/profile.d/puppet-agent.sh
      

      • Create a directory containing a custom fact that uses the $? variable:

      mkdir exit_code_test
       
      cat <<'EOF' > exit_code_test/exit_code_test.rb
      Facter.add("exit_code_test") do
        setcode do
          Facter::Util::Resolution.exec('/usr/bin/false')
          "/usr/bin/false exited with code: %{status}" % {status: $?.exitstatus}
        end
      end
      EOF
      

      • Run Facter:

      env FACTERLIB=$PWD/exit_code_test facter exit_code_test
      

      Outcome

      The fact fails to resolve, logging an error from a `nil` reference:

      # facter --version
      4.0.49
       
      # env FACTERLIB=$PWD/exit_code_test facter exit_code_test
      [2021-02-02 21:33:19.961928 ] ERROR Facter - Error while resolving custom fact fact='exit_code_test', resolution='<anonymous>': undefined method `exitstatus' for nil:NilClass
      

      Expected Outcome

      The exit status resolves to 1 as it does in Facter 3:

      # facter --version
      3.14.14 (commit e36657bea27254f003c8fc71d8ef57454db643e2)
       
      # env FACTERLIB=$PWD/exit_code_test facter exit_code_test
      /usr/bin/false exited with code: 1
      

      And in Facter 2:

      # facter --version
      2.5.7
       
      # env FACTERLIB=$PWD/exit_code_test facter exit_code_test
      /usr/bin/false exited with code: 1
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              chuck Charlie Sharpsteen
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support