#include "socket_unix.h"
-
+#define sane_close(_it) if (_it > 0) {close(_it) ; _it = -1; }
typedef struct {
int interruptorFd;
static void
-initInterruptPipe(interruptPipe * const pipeP,
+initInterruptPipe(interruptPipe * pipeP,
const char ** const errorP) {
- int pipeFd[2];
+ int pipeFd[2] = {-1, -1};
int rc;
rc = pipe(pipeFd);
- if (rc != 0)
+ if (rc != 0) {
xmlrpc_asprintf(errorP, "Unable to create a pipe to use to interrupt "
"waits. pipe() failed with errno %d (%s)",
errno, strerror(errno));
- else {
+ } else {
*errorP = NULL;
pipeP->interruptorFd = pipeFd[1];
pipeP->interrupteeFd = pipeFd[0];
static void
-termInterruptPipe(interruptPipe const pipe) {
-
- close(pipe.interruptorFd);
- close(pipe.interrupteeFd);
+termInterruptPipe(interruptPipe pipe) {
+
+ if (pipe.interruptorFd) {
+ sane_close(pipe.interruptorFd);
+ }
+ if (pipe.interrupteeFd) {
+ sane_close(pipe.interrupteeFd);
+ }
}
termInterruptPipe(socketUnixP->interruptPipe);
if (!socketUnixP->userSuppliedFd)
- close(socketUnixP->fd);
+ sane_close(socketUnixP->fd);
free(socketUnixP);
}
struct socketUnix * socketUnixP;
MALLOCVAR(socketUnixP);
-
+
if (socketUnixP == NULL)
xmlrpc_asprintf(errorP, "Unable to allocate memory for Unix "
"channel descriptor");
else {
TChannel * channelP;
-
+
socketUnixP->fd = fd;
socketUnixP->userSuppliedFd = TRUE;
if (!*errorP) {
ChannelCreate(&channelVtbl, socketUnixP, &channelP);
-
if (channelP == NULL)
xmlrpc_asprintf(errorP, "Unable to allocate memory for "
"channel descriptor.");
termInterruptPipe(socketUnixP->interruptPipe);
if (!socketUnixP->userSuppliedFd)
- close(socketUnixP->fd);
+ sane_close(socketUnixP->fd);
free(socketUnixP);
}
rc = accept(listenSocketP->fd, &peerAddr, &size);
if (rc >= 0) {
- int const acceptedFd = rc;
+ int acceptedFd = rc;
createChannelForAccept(acceptedFd, peerAddr,
&channelP, channelInfoPP, errorP);
if (*errorP)
- close(acceptedFd);
+ sane_close(acceptedFd);
} else if (errno == EINTR)
interrupted = TRUE;
else
xmlrpc_asprintf(errorP, "socket() failed with errno %d (%s)",
errno, strerror(errno));
else {
- int const socketFd = rc;
+ int socketFd = rc;
setSocketOptions(socketFd, errorP);
if (!*errorP) {
}
}
if (*errorP)
- close(socketFd);
+ sane_close(socketFd);
}
}