[torquedev] OS-Specific #define's

Garrick Staples garrick at usc.edu
Tue Feb 12 13:06:30 MST 2008

On Tue, Feb 12, 2008 at 12:45:10PM -0700, Joshua Butikofer alleged:
> Everyone,
> A colleague and I have been making small changes to TORQUE 2.3--in a branch off of the trunk for a
> specific customer. Some of these changes have been operating system specific, but the code has not
> been in one of the resmom directories. Most of our changes have been in mom_main and start_exec.
> Once these changes are fully tested, we will be merging them back into the main trunk.
> I've noticed that TORQUE does define a macro named "PBS_MACH" that contains the name for the
> operating system detected at configure time. This is useful information, but this macro can't be
> easily used in an #ifdef to include/exclude code at compile time. (Unless there is a standard way to
> do string comparisons with an #ifdef that I don't know about.) So here is my question to the
> development community: would it be worthwhile to have configure add an OS-specific macro in
> pbs_config.h, along with the PBS_MACH? (It would be something like __LINUX, __SOLARIS, __FREEBSD,
> etc.) Or would it be better to simply refactor the code so it points to a new routine contained in
> the resmom directories? If the latter is preferable, we still may need a way to determine between OS
> versions--like between FreeBSD5 and FreeBSD6; code for both versions are contained in the "freebsd5"
> resmom directory, but there may be code changes depending on which version is actually being used.

First off, don't create a macro that starts with 2 underscores.  That
violates POSIX because 2 leading underscores is reserved for the
C implementation.

The resmom/arch directories are for truely platform-specific stuff.  Stuff that
is outside the realm of POSIX.  This mostly includes finding process

OS-specific defines are evil.  They are impossible to reliably maintain over
time.  After moving from openpbs, many of the patches that got into torque were
often OS-specific with a litany of OS-specific defines.  A year later, many of
the changes were invalid because the OS fixed a bug.  

I've done my best to remove these.

You never want to compile based on the OS name.  What you want to do is test
for the feature, bug, or reason for the code in configure and then define for
the feature.

Test for the actual difference between the OSes and then compile the right

If it is a difference that could occur within the same OS (like enabling some
feature), either test for the feature at run-time or provide a run-time
configure option.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.supercluster.org/pipermail/torquedev/attachments/20080212/7011863b/attachment.bin

More information about the torquedev mailing list