https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112014-05-15T13:38:58ZRuby Issue Tracking SystemRuby master - Feature #9842: system configuration variables (sysconf(), confstr(), pathconf() and fpathconf())https://redmine.ruby-lang.org/issues/9842?journal_id=467432014-05-15T13:38:58Zkosaki (Motohiro KOSAKI)kosaki.motohiro@gmail.com
<ul></ul><p>On Thu, May 15, 2014 at 7:45 AM, <a href="mailto:akr@fsij.org" class="email">akr@fsij.org</a> wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: system configuration variables (sysconf(), confstr(), pathconf() and fpathconf()) (Closed)" href="https://redmine.ruby-lang.org/issues/9842">#9842</a> has been reported by Akira Tanaka.</p>
<hr>
<p>Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: system configuration variables (sysconf(), confstr(), pathconf() and fpathconf()) (Closed)" href="https://redmine.ruby-lang.org/issues/9842">#9842</a>: system configuration variables (sysconf(), confstr(), pathconf() and fpathconf())<br>
<a href="https://bugs.ruby-lang.org/issues/9842" class="external">https://bugs.ruby-lang.org/issues/9842</a></p>
<ul>
<li>Author: Akira Tanaka</li>
<li>Status: Open</li>
<li>Priority: Normal</li>
<li>Assignee:</li>
<li>Category:</li>
<li>Target version:</li>
</ul>
<hr>
<p>How about providing methods to obtain system configuration variables?</p>
<p>POSIX defines sysconf(), confstr(), pathconf() and fpathconf().<br>
I implemented following methods in ext/etc.</p>
<ul>
<li>Etc.sysconf(name)</li>
<li>Etc.confstr(name)</li>
<li>IO.pathconf(name)</li>
<li>IO#pathconf(name)</li>
</ul>
<p>POSIX defines some names.<br>
Various operating sysmtems define additional names.</p>
<p>They can be used as follows:</p>
<pre><code>Etc.sysconf(Etc::SC_ARG_MAX) #=> 2097152
Etc.sysconf(Etc::SC_NPROCESSORS_ONLN) #=> 4
Etc.confstr(Etc::CS_PATH) #=> "/bin:/usr/bin"
Etc.confstr(Etc::CS_GNU_LIBC_VERSION) #=> "glibc 2.18"
IO.pathconf("/", Etc::PC_NAME_MAX) #=> 255
</code></pre>
</blockquote>
<p>Please drop this. This is broken by design. If an attacker create a<br>
symlink which point<br>
to FAT file system on the same place, IO.patchconf(PC_NAME_MAX) may return very<br>
small size and might lead to security issue.</p>
<p><a href="http://womble.decadent.org.uk/readdir_r-advisory.html" class="external">http://womble.decadent.org.uk/readdir_r-advisory.html</a></p>
<p>Or, at least, we need loooong document why you need much care about IO.pathconf.</p>
<blockquote>
<p>open("/") {|f| p f.pathconf(Etc::PC_TIMESTAMP_RESOLUTION) } #=> 1</p>
<pre><code>
I implemented them in ext/etc because I interpreted "etc" as
system configuration.
Any idea?
---Files--------------------------------
sysconf-confstr-pathconf.patch (13 KB)
--
https://bugs.ruby-lang.org/
</code></pre>
</blockquote> Ruby master - Feature #9842: system configuration variables (sysconf(), confstr(), pathconf() and fpathconf())https://redmine.ruby-lang.org/issues/9842?journal_id=467442014-05-15T14:06:21Zakr (Akira Tanaka)akr@fsij.org
<ul></ul><p>Motohiro KOSAKI wrote:</p>
<blockquote>
<blockquote>
<p>Etc.sysconf(Etc::SC_ARG_MAX) #=> 2097152<br>
Etc.sysconf(Etc::SC_NPROCESSORS_ONLN) #=> 4<br>
Etc.confstr(Etc::CS_PATH) #=> "/bin:/usr/bin"<br>
Etc.confstr(Etc::CS_GNU_LIBC_VERSION) #=> "glibc 2.18"<br>
IO.pathconf("/", Etc::PC_NAME_MAX) #=> 255</p>
</blockquote>
<p>Please drop this. This is broken by design. If an attacker create a<br>
symlink which point<br>
to FAT file system on the same place, IO.patchconf(PC_NAME_MAX) may return very<br>
small size and might lead to security issue.</p>
</blockquote>
<p>I see. I agree to drop IO.pathconf.</p>
<p>Is there a problem with sysconf(), confstr() and fpathconf()?</p> Ruby master - Feature #9842: system configuration variables (sysconf(), confstr(), pathconf() and fpathconf())https://redmine.ruby-lang.org/issues/9842?journal_id=467552014-05-16T13:23:32Zakr (Akira Tanaka)akr@fsij.org
<ul><li><strong>File</strong> <a href="/attachments/4437">sysconf-confstr-fpathconf.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/4437/sysconf-confstr-fpathconf.patch">sysconf-confstr-fpathconf.patch</a> added</li></ul><p>Updated patch attached.<br>
It doesn't define IO.pathconf.</p> Ruby master - Feature #9842: system configuration variables (sysconf(), confstr(), pathconf() and fpathconf())https://redmine.ruby-lang.org/issues/9842?journal_id=467592014-05-16T15:55:33Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul></ul><p>I don't disagree with this feature, but can't you design a little more abstract interface?</p> Ruby master - Feature #9842: system configuration variables (sysconf(), confstr(), pathconf() and fpathconf())https://redmine.ruby-lang.org/issues/9842?journal_id=467612014-05-16T16:15:24Zakr (Akira Tanaka)akr@fsij.org
<ul></ul><p>Usaku NAKAMURA wrote:</p>
<blockquote>
<p>I don't disagree with this feature, but can't you design a little more abstract interface?</p>
</blockquote>
<p>What the purpose of the abstraction?</p>
<p>For example, we can define Etc.getconf as a unified version of Etc.sysconf and Etc.confstr.<br>
It is exepected to work as POSIX getconf command which can invoke sysconf and confstr.<br>
getconf is an abstraction of sysconf and confstr because it includes the both functions.<br>
Does this abstration help you?</p> Ruby master - Feature #9842: system configuration variables (sysconf(), confstr(), pathconf() and fpathconf())https://redmine.ruby-lang.org/issues/9842?journal_id=467622014-05-16T16:35:38Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul></ul><p>POSIX is the standard which should be respected obviously, but Ruby is operating not only on POSIX environment.</p>
<p>Real needs is not revealing the items which getconf (or etc.) provides but the information along to a user's purpose, isn't it?<br>
Whether do you want the information along to some use cases or getconf itself?<br>
If the latter case, you can simply call getconf via system, `` or etc.<br>
If the former case, I believe that you can determine a natural interface.</p> Ruby master - Feature #9842: system configuration variables (sysconf(), confstr(), pathconf() and fpathconf())https://redmine.ruby-lang.org/issues/9842?journal_id=467652014-05-16T16:56:07Zakr (Akira Tanaka)akr@fsij.org
<ul></ul><p>I intend this feature (Etc.sysconf, etc.) as low level API.</p>
<p>One of the feature I want is <code>Etc.confstr(Etc::CS_GNU_LIBC_VERSION)</code>.<br>
I feel it is not a good idea to define a high level interface for it.</p>
<p>I like functions over command invocation.<br>
Command invocation depends various fragile factors (PATH, etc.) and difficult to treat errors.</p>
<p>Of course, I agree some feature may be appropriate to be defined as high level interface.<br>
People will find such feature more easily because<br>
this feature makes low level features more visible.</p> Ruby master - Feature #9842: system configuration variables (sysconf(), confstr(), pathconf() and fpathconf())https://redmine.ruby-lang.org/issues/9842?journal_id=467862014-05-18T00:33:53Zakr (Akira Tanaka)akr@fsij.org
<ul></ul><p>matz accepted this issue at <a href="https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20140517Japan" class="external">https://bugs.ruby-lang.org/projects/ruby/wiki/DevelopersMeeting20140517Japan</a></p> Ruby master - Feature #9842: system configuration variables (sysconf(), confstr(), pathconf() and fpathconf())https://redmine.ruby-lang.org/issues/9842?journal_id=467902014-05-18T01:48:54Zakr (Akira Tanaka)akr@fsij.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>Applied in changeset r45984.</p>
<hr>
<ul>
<li>
<p>ext/etc/etc.c: Etc.sysconf, Etc.confstr and IO#pathconf implemented.</p>
</li>
<li>
<p>ext/etc/extconf.rb: Check sysconf(), confstr() and fpathconf().</p>
</li>
<li>
<p>ext/etc/mkconstants.rb: New file.</p>
</li>
</ul>
<p><a href="/issues/9842">[ruby-core:62600]</a> [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: system configuration variables (sysconf(), confstr(), pathconf() and fpathconf()) (Closed)" href="https://redmine.ruby-lang.org/issues/9842">#9842</a>]</p> Ruby master - Feature #9842: system configuration variables (sysconf(), confstr(), pathconf() and fpathconf())https://redmine.ruby-lang.org/issues/9842?journal_id=468012014-05-19T02:18:09Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul></ul><p>Akira Tanaka wrote:</p>
<blockquote>
<p>I intend this feature (Etc.sysconf, etc.) as low level API.</p>
<p>One of the feature I want is <code>Etc.confstr(Etc::CS_GNU_LIBC_VERSION)</code>.<br>
I feel it is not a good idea to define a high level interface for it.</p>
</blockquote>
<p>I see.</p>
<blockquote>
<p>I like functions over command invocation.<br>
Command invocation depends various fragile factors (PATH, etc.) and difficult to treat errors.</p>
</blockquote>
<p>Almost I can agree it.</p>
<blockquote>
<p>Of course, I agree some feature may be appropriate to be defined as high level interface.<br>
People will find such feature more easily because<br>
this feature makes low level features more visible.</p>
</blockquote>
<p>I was convinced by this explanation. Thank you.</p>