[ntp:hackers] Replacement of hardcoded file paths.

Brian Utterback brian.utterback at oracle.com
Thu Jul 28 21:52:14 UTC 2011


As you may know, Solaris has a few paths that are slightly different
than the standard paths used in the distro. For instance, the default
location for ntp.conf is /etc/inet and the ntpstats directory is in
/var/ntp rather than /var/NTP. In the past I have created patch files
that are applied before building as part of the Solaris Userland build
procedure (see http://hg.openindiana.org/userland-gate/ )

Anyway, everytime I update a rev, I have to regenerate the patch files.
Now, some of these paths are already defined as preprocessor macros and
the ones that are not could easily be changed to match. This would allow
them to be easily set by simply setting -D flags on the compiler command
line (although /etc/inet should follow the configure flag sysconfdir,
but it does not currently.)

One problem I ran into is that the macros are all currently defined to
include the quotes around the string:

#  define NTP_VAR "/var/NTP/"                /* NOTE the trailing '/' */

This means that simply setting the value in -d does not work because the
quotes are missing or stripped out, depending on how you do it.

Setting the macro to not use the quotes does not work because doing this:

#define NTP_VAR /var/NTP/
char statsdir[MAXFILENAME] = "NTP_VAR";

because the preprocessor does not expand macros in quotes.

The usual way to do this is to use the pre-processor "#" operator, which
automatically places quotes around the argument. You need to use two
levels of expansion to make sure the argument expands properly:

#define XSTR(a) #a
#define STR(a) XSTR(a)
#define NTP_VAR /var/NTP

char statsdir[MAXFILENAME] = STR(NTP_VAR)

The question I have is, does anybody know any reason not to do this,
like do we support a compiler that does not support this idiom? Or, does
anybody know a better way to accomplish this?


-- 
blu

Always code as if the guy who ends up maintaining your code will be a
violent psychopath who knows where you live. - Martin Golding
-----------------------------------------------------------------------|
Brian Utterback - Solaris RPE, Oracle Corporation.
Ph:603-262-3916, Em:brian.utterback at oracle.com


More information about the hackers mailing list