Global variables in system programs
Sebastian Huber
sebastian.huber at embedded-brains.de
Thu Dec 5 15:17:08 UTC 2013
Hello,
a small status update since some of my ROUTE(8) patches have been committed to
FreeBSD HEAD recently.
A library interface to the core network commands and utilities is useful, but
it turned out that the ROUTE(8) program was just the most simple one to
convert. I tried to do this also with IFCONFIG(8), but gave up (it uses some
sort of module registry via linker sets, etc.). I use now a different
approach. I initialize/destroy all global variables in a custom
set-up/tear-down routine and protect the commands with a global mutex. Calls
to the error and exit functions are wrapped to use a long jump. This works
well so far with ROUTE(8), IFCONFIG(8), NETSTAT(1), PING(8) and PING6(8).
What really helps is adding static and const qualifiers whenever possible.
Function static variables are a problem since they cannot be initialized with a
single set-up/tear-down routine for a module. Signals are also a problem in a
multi-threaded environment (used by PING6(8)).
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber at embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
More information about the freebsd-hackers
mailing list