sysctl text definitions.

Alfred Perlstein alfred at freebsd.org
Thu Jan 24 14:41:18 PST 2008


Hey guys, something that I've always wanted to do was actually somehow
export those handy description strings from the kernel SYSCTL macros
in the least obtrusive method possible.

The only thing I could come up with that didn't require compiling the
files twice was to basically do some tricks where the text strings
wound up in some throw-away section of the object files.

Any suggestions on how to do this?

In "psuedo-code" what I would do is something like change SYSCTL_*
and add the following:

SYSCTL_INT(...., text) \
   ...old define...\
   SYSCTL_COMMENT(parent, node, text)

Also, add the following struct someplace:

struct sysctl_comment {
  const char *parent;
  const char *node;
  const char *comment;
};

Then SYSCTL_COMMENT does something like (more psuedocode):

#define SYSCTL_COMMENT(parent, node, comment) \
.set sysctl_comments { \
struct sysctl_comment uniquifier = { \
  .parent = parent; \
  .node = node; \
  .comment = comment; \
}; 


Then after building the kernel one should be able to do:
for file in kernel ${modules} ; do
  strip --section=sysctl_comments file > file.install
  objdump --section=sysctl_comment file > file.sysctl.out
  sysctl_help_database_builder file.sysctl.out > file.sysctl.db
done

Then these would be copied into /boot or maybe some other place
as part of the install process.

Sysctl or some other util could then read these db files to give
help with sysctls.

Any ideas/pointers on how to do this linker magic?

-- 
- Alfred Perlstein


More information about the freebsd-hackers mailing list