Date: Thu, 05 Dec 2013 16:07:45 +0100 From: Sebastian Huber <sebastian.huber@embedded-brains.de> To: freebsd-hackers@freebsd.org Cc: Eitan Adler <lists@eitanadler.com> Subject: Re: Global variables in system programs Message-ID: <52A096C1.9090400@embedded-brains.de> In-Reply-To: <525D5A35.4040005@embedded-brains.de> References: <525D5A35.4040005@embedded-brains.de>
next in thread | previous in thread | raw e-mail | index | archive | help
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@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?52A096C1.9090400>