From mboxrd@z Thu Jan 1 00:00:00 1970 From: teigland@sourceware.org Date: 31 Aug 2006 18:46:25 -0000 Subject: [Cluster-devel] cluster/group/gfs_controld main.c Message-ID: <20060831184625.6878.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: cluster Changes by: teigland at sourceware.org 2006-08-31 18:46:24 Modified files: group/gfs_controld: main.c Log message: tidy up a couple style things Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/group/gfs_controld/main.c.diff?cvsroot=cluster&r1=1.11&r2=1.12 --- cluster/group/gfs_controld/main.c 2006/08/31 18:17:32 1.11 +++ cluster/group/gfs_controld/main.c 2006/08/31 18:46:24 1.12 @@ -89,8 +89,8 @@ { int i; - while (1) { /* I hate gotos */ - /* This is expected to fail the first time, with nothing allocated: */ + while (1) { + /* This fails the first time with client_size of zero */ for (i = 0; i < client_size; i++) { if (client[i].fd == -1) { client[i].fd = fd; @@ -98,22 +98,25 @@ pollfd[i].events = POLLIN; if (i > *maxi) *maxi = i; - /* log_debug("client %d fd %d added", i, fd); */ return i; } } + /* We didn't find an empty slot, so allocate more. */ client_size += MAX_CLIENTS; + if (!client) { client = malloc(client_size * sizeof(struct client)); pollfd = malloc(client_size * sizeof(struct pollfd)); - } - else { - client = realloc(client, client_size * sizeof(struct client)); - pollfd = realloc(pollfd, client_size * sizeof(struct pollfd)); + } else { + client = realloc(client, client_size * + sizeof(struct client)); + pollfd = realloc(pollfd, client_size * + sizeof(struct pollfd)); } if (!client || !pollfd) log_error("Can't allocate client memory."); + for (i = client_size - MAX_CLIENTS; i < client_size; i++) { client[i].fd = -1; pollfd[i].fd = -1; @@ -129,14 +132,6 @@ pollfd[ci].fd = -1; } -static void client_init(void) -{ - int i; - - for (i = 0; i < client_size; i++) - client[i].fd = -1; -} - int client_send(int ci, char *buf, int len) { return write(client[ci].fd, buf, len); @@ -586,7 +581,6 @@ prog_name = argv[0]; INIT_LIST_HEAD(&mounts); INIT_LIST_HEAD(&withdrawn_mounts); - client_init(); decode_arguments(argc, argv);