djberg96 / sys-proctable

A cross-platform Ruby interface for gathering process information on your operating system
Apache License 2.0
150 stars 33 forks source link

Test failure on Big Sur #89

Closed djberg96 closed 3 years ago

djberg96 commented 3 years ago

I noticed a test failure after upgrading to Big Sur.

Ruby 3.0.1 Big Sur Darwin Daniels-iMac.local 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64 x86_64

Failures:

  1) Sys::ProcTable ProcTable::Struct members contains an environ member and returns the expected value
     Failure/Error: expect(subject.environ['A']).to eq('B')

       expected: "B"
            got: nil

       (compared using ==)
     # ./spec/sys_proctable_darwin_spec.rb:116:in `block (3 levels) in <top (required)>'

Finished in 2.27 seconds (files took 0.14925 seconds to load)
55 examples, 1 failure

Failed examples:

rspec ./spec/sys_proctable_darwin_spec.rb:113 # Sys::ProcTable ProcTable::Struct members contains an environ member and returns the expected value
djberg96 commented 3 years ago

I'm just not seeing the environment information in the buffer. Maybe there's been an API change?

Below is the buffer from a Process.spawn({'A' => 'B', 'Z' => nil}, "sleep 60") call. I don't see it present in the buffer. It should be somewhere between the "\x0060" and the "\xFF\xBF".

"/bin/sleep\x00\x00\x00\x00\x00\x00sleep\x0060\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xBF\x00\x 00\x00\x00/bin/sleep\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"

Fryguy commented 3 years ago

I see the same error on my Big Sur machine.

Fryguy commented 3 years ago

Strangely if you grab other processes they do have the information - I only see it missing from ones spawned as children.

djberg96 commented 3 years ago

@Fryguy I could only find a single reference to what we're seeing:

https://forums.freebsd.org/threads/port-freebsd-sysctl-library-to-mac.77486/

This could just be a fundamental change in Big Sur. Maybe for security reasons? Or a bug?

djberg96 commented 3 years ago

Relevant? https://github.com/apple/darwin-xnu/blob/main/bsd/kern/kern_sysctl.c#L1315-L1321

Fryguy commented 3 years ago

Yes that looks very relevant.

djberg96 commented 3 years ago

Yep, I think it's a change in the OS. I'll have to update the test and add a comment.

djberg96 commented 3 years ago

My solution for now - skip it: https://github.com/djberg96/sys-proctable/pull/90