What to use for OS-specific module namespaces?

From: Joe Wreschnig [mailto:piman@sacredchao.net]
I’m working on a Ruby module to parse/write to files in the
Linux /proc
filesystem (ACPI interfaces), and I was wondering if there’s
a preferred
naming convention or namespace for things that are
OS-specific.

You’re going to write to the /proc filesystem?!

Yeah; a number of files in /proc do things when you write to them;
notably the ACPI stuff that I’m interested in. To change your speedstep
state, for instance, you write a “1” or “0” to
/proc/acpi/processor/CPU0/performance; to go into sleep mode, write a
"1" (for S1 state) to /proc/acpi/sleep. There are other things too, like
I think you need to write a 1 to start IP forwarding and khttpd and a
few other things.

Note that parsing /proc
won’t be cross-platform at all. Linux stores kernel info in /proc as flat
files but other flavors of *nix don’t. Solaris, for example, stores at
least some of the /proc data as binary data and you’re expected to use a C
library function to get at the data. This means that you’re better off
writing this as an extension, unless you only care about Linux. :slight_smile:

ATM, I really only care about Linux; AFAIK none of the BSDs seem to have
as good ACPI support as Linux, and I’m not familiar with Solaris at all.
See my comment to Nobu Nakada about “shorthanding” the interface
namespace though; it would be easy to plug in SysInfo extensions to do.

But yeah, I know that /proc is significantly different across OSs; I
prefer to think of it as Linux being right and the rest being broken,
but that’s not a very pragmatic approach. So, I’m going to try the
namespace shorthand trick for now.

Have you seen some of the Sys:: modules that I have out on the RAA? Rather
than create a separate namespace for each platform, consider using the trick
I used (which I borrowed from Dan Urist) with Sys::ProcTable. In that
module, I let the extconf.rb file create a common file called “ProcTable.c”.
That file is actually just a symbolic link to an os-specific file (linux.c
or solaris.c), depending on the platform you’re building on.

I’d prefer to avoid a C extension library if possible; Linux lets me do
this by reading all the data from /proc. In fact, I’m not sure if there
is any other way to get a lot of the hardware information. How do other
UNIXes let you get things like processor model/speed, memory
information, etc?

I’d like to put the model under the Sys:: namespace for consistency; if
you think it’s a good idea; then I’m left with the question of what to
call it again. :slight_smile: Sys::Hardware? Sys::Info seems too generic a name
(since Uptime, ProcTable, and Uname are both “Info” too).

···

On Mon, 2002-07-08 at 07:41, Berger, Daniel wrote: