From e8991ff8286f151d109bb4f98d885a583e198f83 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Thu, 28 Oct 2010 00:43:26 -0400 Subject: [PATCH] vol: Use OSI_NULLSOCKET and not -1 to indicate invalid fssync fd The FSync file descriptor is an osi_socket which has an invalid value of OSI_NULLSOCKET which is not necessarily -1. Be sure to compare against OSI_NULLSOCKET and not -1 when checking an invalid value. Change-Id: I5b7531e690ea06046b337222b52a5013c7f8802e Reviewed-on: http://gerrit.openafs.org/3179 Reviewed-by: Derrick Brashear Reviewed-by: Andrew Deason Tested-by: Derrick Brashear --- src/vol/daemon_com.c | 12 ++++++------ src/vol/fssync-server.c | 14 +++++++------- src/vol/salvsync-server.c | 19 +++++++++++-------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/vol/daemon_com.c b/src/vol/daemon_com.c index c532b8623..26d5cb7c8 100644 --- a/src/vol/daemon_com.c +++ b/src/vol/daemon_com.c @@ -156,7 +156,7 @@ SYNC_connect(SYNC_client_state * state) { 3, 3, 3, 5, 5, 5, 7, 15, 16, 24, 32, 40, 48, 0 }; time_t *timeout = &backoff[0]; - if (state->fd >= 0) { + if (state->fd != OSI_NULLSOCKET) { return 1; } @@ -194,7 +194,7 @@ SYNC_disconnect(SYNC_client_state * state) #else close(state->fd); #endif - state->fd = -1; + state->fd = OSI_NULLSOCKET; return 0; } @@ -213,7 +213,7 @@ SYNC_closeChannel(SYNC_client_state * state) SYNC_response res; SYNC_PROTO_BUF_DECL(ores); - if (state->fd == -1) + if (state->fd == OSI_NULLSOCKET) return SYNC_OK; memset(&com, 0, sizeof(com)); @@ -279,11 +279,11 @@ SYNC_ask(SYNC_client_state * state, SYNC_command * com, SYNC_response * res) return SYNC_COM_ERROR; } - if (state->fd == -1) { + if (state->fd == OSI_NULLSOCKET) { SYNC_connect(state); } - if (state->fd == -1) { + if (state->fd == OSI_NULLSOCKET) { state->fatal_error = 1; return SYNC_COM_ERROR; } @@ -352,7 +352,7 @@ SYNC_ask_internal(SYNC_client_state * state, SYNC_command * com, SYNC_response * struct iovec iov[2]; #endif - if (state->fd == -1) { + if (state->fd == OSI_NULLSOCKET) { Log("SYNC_ask: invalid sync file descriptor on circuit '%s'\n", state->proto_name); res->hdr.response = SYNC_COM_ERROR; diff --git a/src/vol/fssync-server.c b/src/vol/fssync-server.c index d08791006..acd2e6c66 100644 --- a/src/vol/fssync-server.c +++ b/src/vol/fssync-server.c @@ -114,7 +114,7 @@ static struct offlineInfo OfflineVolumes[MAXHANDLERS][MAXOFFLINEVOLUMES]; * fssync server socket handle. */ static SYNC_server_state_t fssync_server_state = - { -1, /* file descriptor */ + { OSI_NULLSOCKET, /* file descriptor */ FSSYNC_ENDPOINT_DECL, /* server endpoint */ FSYNC_PROTO_VERSION, /* protocol version */ 5, /* bind() retry limit */ @@ -442,7 +442,7 @@ FSYNC_newconnection(osi_socket afd) socklen_t junk; junk = sizeof(other); fd = accept(afd, (struct sockaddr *)&other, &junk); - if (fd == -1) { + if (fd == OSI_NULLSOCKET) { Log("FSYNC_newconnection: accept failed, errno==%d\n", errno); osi_Assert(1 == 2); } else if (!AddHandler(fd, FSYNC_com)) { @@ -1971,7 +1971,7 @@ InitHandler(void) int i; ObtainWriteLock(&FSYNC_handler_lock); for (i = 0; i < MAXHANDLERS; i++) { - HandlerFD[i] = -1; + HandlerFD[i] = OSI_NULLSOCKET; HandlerProc[i] = 0; } ReleaseWriteLock(&FSYNC_handler_lock); @@ -2017,7 +2017,7 @@ AddHandler(osi_socket afd, void (*aproc) (osi_socket)) int i; ObtainWriteLock(&FSYNC_handler_lock); for (i = 0; i < MAXHANDLERS; i++) - if (HandlerFD[i] == -1) + if (HandlerFD[i] == OSI_NULLSOCKET) break; if (i >= MAXHANDLERS) { ReleaseWriteLock(&FSYNC_handler_lock); @@ -2060,7 +2060,7 @@ static int RemoveHandler(osi_socket afd) { ObtainWriteLock(&FSYNC_handler_lock); - HandlerFD[FindHandler_r(afd)] = -1; + HandlerFD[FindHandler_r(afd)] = OSI_NULLSOCKET; ReleaseWriteLock(&FSYNC_handler_lock); return 1; } @@ -2073,7 +2073,7 @@ GetHandler(struct pollfd *fds, int maxfds, int events, int *nfds) int fdi = 0; ObtainReadLock(&FSYNC_handler_lock); for (i = 0; i < MAXHANDLERS; i++) - if (HandlerFD[i] != -1) { + if (HandlerFD[i] != OSI_NULLSOCKET) { osi_Assert(fdi= MAXHANDLERS) { ReleaseWriteLock(&SALVSYNC_handler_lock); @@ -868,7 +868,7 @@ static int RemoveHandler(osi_socket afd) { ObtainWriteLock(&SALVSYNC_handler_lock); - HandlerFD[FindHandler_r(afd)] = -1; + HandlerFD[FindHandler_r(afd)] = OSI_NULLSOCKET; ReleaseWriteLock(&SALVSYNC_handler_lock); return 1; } @@ -881,10 +881,13 @@ GetHandler(fd_set * fdsetp, int *maxfdp) FD_ZERO(fdsetp); ObtainReadLock(&SALVSYNC_handler_lock); /* just in case */ for (i = 0; i < MAXHANDLERS; i++) - if (HandlerFD[i] != -1) { + if (HandlerFD[i] != OSI_NULLSOCKET) { FD_SET(HandlerFD[i], fdsetp); - if (maxfd < HandlerFD[i]) +#ifndef AFS_NT40_ENV + /* On Windows the nfds parameter to select() is ignored */ + if (maxfd < HandlerFD[i] || maxfd == (int)-1) maxfd = HandlerFD[i]; +#endif } *maxfdp = maxfd; ReleaseReadLock(&SALVSYNC_handler_lock); /* just in case */ -- 2.39.5