From owner-svn-src-projects@FreeBSD.ORG Sun Aug 22 19:57:42 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 131761065672; Sun, 22 Aug 2010 19:57:42 +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 01CDF8FC18; Sun, 22 Aug 2010 19:57:42 +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 o7MJvfGb013150; Sun, 22 Aug 2010 19:57:41 GMT (envelope-from attilio@svn.freebsd.org) Received: (from attilio@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o7MJvfgO013148; Sun, 22 Aug 2010 19:57:41 GMT (envelope-from attilio@svn.freebsd.org) Message-Id: <201008221957.o7MJvfgO013148@svn.freebsd.org> From: Attilio Rao Date: Sun, 22 Aug 2010 19:57:41 +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: r211637 - 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 19:57:42 -0000 Author: attilio Date: Sun Aug 22 19:57:41 2010 New Revision: 211637 URL: http://svn.freebsd.org/changeset/base/211637 Log: Fix style fot the alloc_client() function. 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:09:18 2010 (r211636) +++ projects/sv/usr.sbin/netdumpsrv/netdump_server.c Sun Aug 22 19:57:41 2010 (r211637) @@ -133,162 +133,148 @@ usage(const char *cmd) cmd); } -static struct netdump_client *alloc_client(struct sockaddr_in *sip) +static struct netdump_client * +alloc_client(struct sockaddr_in *sip) { - struct sockaddr_in saddr; - struct netdump_client *client; - struct in_addr *ip; - char *firstdot; - int i, ecode, fd, bufsz; + struct sockaddr_in saddr; + struct netdump_client *client; + struct in_addr *ip; + char *firstdot; + int i, ecode, fd, bufsz; + + assert(sip != NULL); + + client = calloc(1, sizeof(*client)); + if (client == NULL) { + LOGERR_PERROR("calloc()"); + return (NULL); + } + ip = &sip->sin_addr; + bcopy(ip, &client->ip, sizeof(*ip)); + client->corefd = -1; + client->sock = -1; + client->last_msg = now; - assert(sip != NULL); - - client = calloc(1, sizeof(*client)); - if (!client) - { - LOGERR_PERROR("calloc()"); - return NULL; - } - ip = &sip->sin_addr; - bcopy(ip, &client->ip, sizeof(*ip)); - client->corefd = -1; - client->sock = -1; - client->last_msg = now; - - ecode = getnameinfo((struct sockaddr *)sip, sip->sin_len, client->hostname, - sizeof(client->hostname), NULL, 0, NI_NAMEREQD); - if (ecode != 0) { - - /* Can't resolve, try with a numeric IP. */ ecode = getnameinfo((struct sockaddr *)sip, sip->sin_len, - client->hostname, sizeof(client->hostname), NULL, 0, 0); + client->hostname, sizeof(client->hostname), NULL, 0, NI_NAMEREQD); if (ecode != 0) { - LOGERR("getnameinfo(): %s\n", gai_strerror(ecode)); - free(client); - return NULL; + + /* Can't resolve, try with a numeric IP. */ + ecode = getnameinfo((struct sockaddr *)sip, sip->sin_len, + client->hostname, sizeof(client->hostname), NULL, 0, 0); + if (ecode != 0) { + LOGERR("getnameinfo(): %s\n", gai_strerror(ecode)); + free(client); + return (NULL); + } + } else { + + /* Strip off the domain name */ + firstdot = strchr(client->hostname, '.'); + if (firstdot) + *firstdot = '\0'; } - } else { - /* Strip off the domain name */ - firstdot = strchr(client->hostname, '.'); - if (firstdot) - { - *firstdot='\0'; + client->sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (client->sock == -1) { + LOGERR_PERROR("socket()"); + free(client); + return (NULL); + } + if (fcntl(client->sock, F_SETFL, O_NONBLOCK) == -1) { + LOGERR_PERROR("fcntl()"); + close(client->sock); + free(client); + return (NULL); + } + bzero(&saddr, sizeof(saddr)); + saddr.sin_len = sizeof(saddr); + saddr.sin_family = AF_INET; + saddr.sin_addr.s_addr = bindip.s_addr; + saddr.sin_port = htons(0); + if (bind(client->sock, (struct sockaddr *)&saddr, sizeof(saddr))) { + LOGERR_PERROR("bind()"); + close(client->sock); + free(client); + return (NULL); + } + bzero(&saddr, sizeof(saddr)); + saddr.sin_len = sizeof(saddr); + saddr.sin_family = AF_INET; + saddr.sin_addr.s_addr = ip->s_addr; + saddr.sin_port = htons(NETDUMP_ACKPORT); + if (connect(client->sock, (struct sockaddr *)&saddr, sizeof(saddr))) { + LOGERR_PERROR("connect()"); + close(client->sock); + free(client); + return (NULL); } - } - /* Set up the client socket */ - if ((client->sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) - { - LOGERR_PERROR("socket()"); - free(client); - return NULL; - } - if (fcntl(client->sock, F_SETFL, O_NONBLOCK) == -1) { - LOGERR_PERROR("fcntl()"); - close(client->sock); - free(client); - return NULL; - } - bzero(&saddr, sizeof(saddr)); - saddr.sin_len = sizeof(saddr); - saddr.sin_family = AF_INET; - saddr.sin_addr.s_addr = bindip.s_addr; - saddr.sin_port = htons(0); - if (bind(client->sock, (struct sockaddr *)&saddr, sizeof(saddr))) { - LOGERR_PERROR("bind()"); - close(client->sock); - free(client); - return NULL; - } - bzero(&saddr, sizeof(saddr)); - saddr.sin_len = sizeof(saddr); - saddr.sin_family = AF_INET; - saddr.sin_addr.s_addr = ip->s_addr; - saddr.sin_port = htons(NETDUMP_ACKPORT); - if (connect(client->sock, (struct sockaddr *)&saddr, sizeof(saddr))) { - LOGERR_PERROR("connect()"); - close(client->sock); - free(client); - return NULL; - } - bufsz=131072; /* XXX: Enough to hold approx twice the chunk size. Should be - * plenty for any 1 client. */ - if (setsockopt(client->sock, SOL_SOCKET, SO_RCVBUF, &bufsz, sizeof(bufsz))) - { - LOGERR_PERROR("setsockopt()"); + /* It should be enough to hold approximatively twize the chunk size. */ + bufsz = 131072; + if (setsockopt(client->sock, SOL_SOCKET, SO_RCVBUF, &bufsz, + sizeof(bufsz))) { + LOGERR_PERROR("setsockopt()"); LOGWARN("May drop packets from %s due to small receive buffer\n", - client->hostname); - } - - /* Try info.host.0 through info.host.255 in sequence */ - for (i=0; i < MAX_DUMPS; i++) - { - snprintf(client->infofilename, sizeof(client->infofilename), - "%s/info.%s.%d", dumpdir, client->hostname, i); - snprintf(client->corefilename, sizeof(client->corefilename), - "%s/vmcore.%s.%d", dumpdir, client->hostname, i); - - /* Try the info file first */ - if ((fd = open(client->infofilename, O_WRONLY|O_CREAT|O_EXCL, - DEFFILEMODE)) == -1) - { - if (errno == EEXIST) - { - continue; - } - LOGERR("open(\"%s\"): %s\n", client->infofilename, strerror(errno)); - continue; - } - if (!(client->infofile = fdopen(fd, "w"))) - { - LOGERR_PERROR("fdopen()"); - close(fd); - unlink(client->infofilename); - continue; + client->hostname); } - /* Next make the core file */ - if ((fd = open(client->corefilename, O_RDWR|O_CREAT|O_EXCL, - DEFFILEMODE)) == -1) - { - /* Failed. Keep the numbers in sync. */ - fclose(client->infofile); - unlink(client->infofilename); - client->infofile = NULL; + /* Try info.host.0 through info.host.255 in sequence. */ + for (i = 0; i < MAX_DUMPS; i++) { + snprintf(client->infofilename, sizeof(client->infofilename), + "%s/info.%s.%d", dumpdir, client->hostname, i); + snprintf(client->corefilename, sizeof(client->corefilename), + "%s/vmcore.%s.%d", dumpdir, client->hostname, i); + + /* Try the info file first. */ + fd = open(client->infofilename, O_WRONLY|O_CREAT|O_EXCL, + DEFFILEMODE); + if (fd == -1) { + if (errno != EEXIST) + LOGERR("open(\"%s\"): %s\n", + client->infofilename, strerror(errno)); + continue; + } + client->infofile = fdopen(fd, "w"); + if (client->infofile == NULL) { + LOGERR_PERROR("fdopen()"); + close(fd); + unlink(client->infofilename); + continue; + } - if (errno == EEXIST) - { - continue; - } - LOGERR("open(\"%s\"): %s\n", client->corefilename, strerror(errno)); - continue; + /* Next make the core file. */ + fd = open(client->corefilename, O_RDWR|O_CREAT|O_EXCL, + DEFFILEMODE); + if (fd == -1) { + + /* Failed. Keep the numbers in sync. */ + fclose(client->infofile); + unlink(client->infofilename); + client->infofile = NULL; + if (errno != EEXIST) + LOGERR("open(\"%s\"): %s\n", + client->corefilename, strerror(errno)); + continue; + } + client->corefd = fd; + break; } - client->corefd = fd; - break; - } - if (!client->infofile || client->corefd == -1) - { - LOGERR("Can't create output files for new client %s [%s]\n", - client->hostname, client_ntoa(client)); - if (client->infofile) - { - fclose(client->infofile); - } - if (client->corefd != -1) - { - close(client->corefd); - } - if (client->sock != -1) - { - close(client->sock); + if (client->infofile == NULL || client->corefd == -1) { + LOGERR("Can't create output files for new client %s [%s]\n", + client->hostname, client_ntoa(client)); + if (client->infofile) + fclose(client->infofile); + if (client->corefd != -1) + close(client->corefd); + if (client->sock != -1) + close(client->sock); + free(client); + return (NULL); } - free(client); - return NULL; - } - SLIST_INSERT_HEAD(&clients, client, iter); - return client; + SLIST_INSERT_HEAD(&clients, client, iter); + return (client); } static void free_client(struct netdump_client *client)