From owner-freebsd-hackers@FreeBSD.ORG Thu Dec 5 15:17:08 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6F24AB02 for ; Thu, 5 Dec 2013 15:17:08 +0000 (UTC) Received: from mail.embedded-brains.de (host-82-135-62-35.customer.m-online.net [82.135.62.35]) by mx1.freebsd.org (Postfix) with ESMTP id 0EEB11378 for ; Thu, 5 Dec 2013 15:17:05 +0000 (UTC) Received: by mail.embedded-brains.de (Postfix, from userid 65534) id 21A82652CFE; Thu, 5 Dec 2013 16:07:47 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on fidibusdmz X-Spam-Level: X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from [192.168.96.64] (eb0024.eb.z [192.168.96.64]) by mail.embedded-brains.de (Postfix) with ESMTP id B660B65253A; Thu, 5 Dec 2013 16:07:45 +0100 (CET) Message-ID: <52A096C1.9090400@embedded-brains.de> Date: Thu, 05 Dec 2013 16:07:45 +0100 From: Sebastian Huber User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Subject: Re: Global variables in system programs References: <525D5A35.4040005@embedded-brains.de> In-Reply-To: <525D5A35.4040005@embedded-brains.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Cc: Eitan Adler X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Dec 2013 15:17:08 -0000 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.