Convert to use socket wrappers. Aside from the header file
include change, this requires changing close -> closesocket
since our portability isn't trying to replace the close
function.
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
# include <selinux/selinux.h>
#endif
+#include "virsocket.h"
#include "virnetsocket.h"
#include "virutil.h"
#include "viralloc.h"
goto error;
}
bindErrno = errno;
- VIR_FORCE_CLOSE(fd);
+ closesocket(fd);
+ fd = -1;
runp = runp->ai_next;
continue;
}
virObjectUnref(socks[i]);
VIR_FREE(socks);
freeaddrinfo(ai);
- VIR_FORCE_CLOSE(fd);
+ if (fd != -1)
+ closesocket(fd);
return -1;
}
error:
if (path[0] != '@')
unlink(path);
- VIR_FORCE_CLOSE(fd);
+ if (fd != -1)
+ closesocket(fd);
return -1;
}
#else
break;
savedErrno = errno;
- VIR_FORCE_CLOSE(fd);
+ closesocket(fd);
+ fd = -1;
runp = runp->ai_next;
}
error:
freeaddrinfo(ai);
- VIR_FORCE_CLOSE(fd);
+ if (fd != -1)
+ closesocket(fd);
return -1;
}
VIR_FREE(lockpath);
VIR_FREE(rundir);
- if (ret < 0)
- VIR_FORCE_CLOSE(fd);
+ if (ret < 0 && fd != -1)
+ closesocket(fd);
return ret;
}
virObjectUnref(sock->libsshSession);
#endif
- if (sock->ownsFd)
- VIR_FORCE_CLOSE(sock->fd);
+ if (sock->ownsFd && sock->fd != -1) {
+ closesocket(sock->fd);
+ sock->fd = -1;
+ }
VIR_FORCE_CLOSE(sock->errfd);
virProcessAbort(sock->pid);
ret = 0;
cleanup:
- VIR_FORCE_CLOSE(fd);
+ if (fd != -1)
+ closesocket(fd);
virObjectUnlock(sock);
return ret;
}
virObjectLock(sock);
- VIR_FORCE_CLOSE(sock->fd);
+ if (sock->fd != -1) {
+ closesocket(sock->fd);
+ sock->fd = -1;
+ }
#ifdef HAVE_SYS_UN_H
/* If a server socket, then unlink UNIX path */
#include <config.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-
+#include "virsocket.h"
#include "viralloc.h"
#include "virbitmap.h"
#include "virportallocator.h"
ret = 0;
cleanup:
- VIR_FORCE_CLOSE(fd);
+ if (fd != -1)
+ closesocket(fd);
return ret;
}