From owner-svn-src-projects@FreeBSD.ORG Sun Aug 22 20:04:48 2010 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 96FD510656A5; Sun, 22 Aug 2010 20:04:48 +0000 (UTC) (envelope-from attilio@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 869E28FC1A; Sun, 22 Aug 2010 20:04:48 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o7MK4m2W013345; Sun, 22 Aug 2010 20:04:48 GMT (envelope-from attilio@svn.freebsd.org) Received: (from attilio@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o7MK4mrP013343; Sun, 22 Aug 2010 20:04:48 GMT (envelope-from attilio@svn.freebsd.org) Message-Id: <201008222004.o7MK4mrP013343@svn.freebsd.org> From: Attilio Rao Date: Sun, 22 Aug 2010 20:04:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r211638 - projects/sv/usr.sbin/netdumpsrv X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Aug 2010 20:04:48 -0000 Author: attilio Date: Sun Aug 22 20:04:48 2010 New Revision: 211638 URL: http://svn.freebsd.org/changeset/base/211638 Log: More style cleanups for other functions. Modified: projects/sv/usr.sbin/netdumpsrv/netdump_server.c Modified: projects/sv/usr.sbin/netdumpsrv/netdump_server.c ============================================================================== --- projects/sv/usr.sbin/netdumpsrv/netdump_server.c Sun Aug 22 19:57:41 2010 (r211637) +++ projects/sv/usr.sbin/netdumpsrv/netdump_server.c Sun Aug 22 20:04:48 2010 (r211638) @@ -50,6 +50,7 @@ #define MAX_DUMPS 256 /* Dumps per IP before to be cleaned out. */ #define CLIENT_TIMEOUT 120 /* Clients timeout (secs). */ +#define CLIENT_TPASS 10 /* Clients timeout pass (secs). */ #define PFLAGS_ABIND 0x01 #define PFLAGS_DDIR 0x02 @@ -95,6 +96,7 @@ static struct in_addr bindip; /* Miscellaneous handlers. */ static struct pidfh *pfh; static time_t now; +static time_t last_timeout_check; static int do_shutdown; static int sock; @@ -277,88 +279,78 @@ alloc_client(struct sockaddr_in *sip) return (client); } -static void free_client(struct netdump_client *client) +static void +free_client(struct netdump_client *client) { - assert(client != NULL); + assert(client != NULL); - /* Remove from the list. Ignore errors from close() routines. */ - SLIST_REMOVE(&clients, client, netdump_client, iter); - fclose(client->infofile); - close(client->corefd); - close(client->sock); - free(client); + /* Remove from the list. Ignore errors from close() routines. */ + SLIST_REMOVE(&clients, client, netdump_client, iter); + fclose(client->infofile); + close(client->corefd); + close(client->sock); + free(client); } -static void exec_handler(struct netdump_client *client, const char *reason) +static void +exec_handler(struct netdump_client *client, const char *reason) { - int pid; + int pid; - assert(client != NULL); + assert(client != NULL); - /* If no script is specified this is a no-op. */ - if ((pflags & PFLAGS_SCRIPT) == 0) - return; + /* If no script is specified this is a no-op. */ + if ((pflags & PFLAGS_SCRIPT) == 0) + return; - pid=fork(); + pid = fork(); - /* - * The function is invoked in critical conditions, thus just exiting - * without reporting errors is fine. - */ - if (pid == -1) - { - LOGERR_PERROR("fork()"); - return; - } - else if (pid) - { - return; - } - else - { - close(sock); - pidfile_close(pfh); - if (execl(handler_script, handler_script, reason, client_ntoa(client), - client->hostname, client->infofilename, client->corefilename, - NULL) == -1) { + /* + * The function is invoked in critical conditions, thus just exiting + * without reporting errors is fine. + */ + if (pid == -1) { LOGERR_PERROR("fork()"); - _exit(1); + return; + } else if (pid != 0) { + close(sock); + pidfile_close(pfh); + if (execl(handler_script, handler_script, reason, + client_ntoa(client), client->hostname, + client->infofilename, client->corefilename, NULL) == -1) { + LOGERR_PERROR("fork()"); + _exit(1); + } } - } } -static void handle_timeout(struct netdump_client *client) +static void +handle_timeout(struct netdump_client *client) { - assert(client != NULL); + assert(client != NULL); - LOGINFO("Client %s timed out\n", client_ntoa(client)); - client_pinfo(client, "Dump incomplete: client timed out\n"); - exec_handler(client, "timeout"); - free_client(client); + LOGINFO("Client %s timed out\n", client_ntoa(client)); + client_pinfo(client, "Dump incomplete: client timed out\n"); + exec_handler(client, "timeout"); + free_client(client); } -static void timeout_clients() +static void +timeout_clients() { - static time_t last_timeout_check; - struct netdump_client *client, *tmp; + struct netdump_client *client, *tmp; - /* Only time out clients every 10 seconds */ - if (now - last_timeout_check < 10) - { - return; - } - - last_timeout_check = now; - - /* Traverse the list looking for stale clients */ - SLIST_FOREACH_SAFE(client, &clients, iter, tmp) { - if (client->last_msg+CLIENT_TIMEOUT < now) - { - handle_timeout(client); - } - } + /* Only time out clients every 10 seconds. */ + if (now - last_timeout_check < CLIENT_TPASS) + return; + last_timeout_check = now; + + /* Traverse the list looking for stale clients. */ + SLIST_FOREACH_SAFE(client, &clients, iter, tmp) + if (client->last_msg + CLIENT_TIMEOUT < now) + handle_timeout(client); } static void send_ack(struct netdump_client *client, struct netdump_msg *msg)