Skip to content

(#14522) Don't read /proc/self/status on Solaris#421

Closed
haus wants to merge 1 commit intopuppetlabs:1.7.xfrom
haus:ticket/1.7.x/14522_dont_read_proc_on_solaris
Closed

(#14522) Don't read /proc/self/status on Solaris#421
haus wants to merge 1 commit intopuppetlabs:1.7.xfrom
haus:ticket/1.7.x/14522_dont_read_proc_on_solaris

Conversation

@haus
Copy link

@haus haus commented Apr 5, 2013

/proc/self/status isn't a standard file on Solaris and can't be read as such.
Attempting to read it when using ruby 1.9.3 produces errors such as 'invalid
byte sequence in US-ASCII'. According to
http://www.ruby-forum.com/topic/163804, /proc/self/status is a sparse file with
a map at /proc/self/map to indicate which parts of the file to read. As a
stopgap measure, this commit simply returns false on Solaris, rather than
trying to read the file.

/proc/self/status isn't a standard file on Solaris and can't be read as such.
Attempting to read it when using ruby 1.9.3 produces errors such as 'invalid
byte sequence in US-ASCII'. According to
http://www.ruby-forum.com/topic/163804, /proc/self/status is a sparse file with
a map at /proc/self/map to indicate which parts of the file to read. As a
stopgap measure, this commit simply returns false on Solaris, rather than
trying to read the file.
@puppetcla
Copy link

CLA Signed by haus on 2011-07-19 21:00:00 -0700

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haus and I looked at this together and it's not the File.open that's the problem, but rather the comparison of raw data inside of a string Ruby thinks is encoded as UTF-8 being compared against a regular expression that is also UTF-8. When this happens the invalid UTF-8 sequence in the raw data causes the exception.

I think we can filter the raw data and make this work in a general way if we do this:

txt = File.open("/proc/self/status", "rb").read
txt.encode!('UTF-8', 'UTF-8', :invalid => :replace)
return true if txt =~ /^(s_context|VxID):[[:blank:]]*[0-9]/

@joshcooper
Copy link
Contributor

@jeffmccune @haus make sure to check if the encode! method is available, as it won't be in ruby 1.8

@jeffmccune jeffmccune closed this in 2cadc7c Apr 5, 2013
@jeffmccune
Copy link

summary: Merged into master as 2cadc7c. This should be released in Facter 1.7. Thanks again for the contribution!

-Jeff

florindragos pushed a commit that referenced this pull request Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants