use SOCK_CLOEXEC

This commit is contained in:
Alexandre Ratchov 2015-02-16 11:52:36 +01:00
parent 8dd18742f2
commit 98027ba688
1 changed files with 2 additions and 6 deletions

View File

@ -342,7 +342,7 @@ aucat_connect_tcp(struct aucat *hdl, char *host, unsigned int unit)
}
s = -1;
for (ai = ailist; ai != NULL; ai = ai->ai_next) {
s = socket(ai->ai_family, ai->ai_socktype,
s = socket(ai->ai_family, ai->ai_socktype | SOCK_CLOEXEC,
ai->ai_protocol);
if (s < 0) {
DPERROR("socket");
@ -384,7 +384,7 @@ aucat_connect_un(struct aucat *hdl, unsigned int unit)
snprintf(ca.sun_path, sizeof(ca.sun_path),
"/tmp/aucat-%u/%s%u", uid, AUCAT_PATH, unit);
ca.sun_family = AF_UNIX;
s = socket(AF_UNIX, SOCK_STREAM, 0);
s = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (s < 0)
return 0;
while (connect(s, (struct sockaddr *)&ca, len) < 0) {
@ -498,10 +498,6 @@ _aucat_open(struct aucat *hdl, const char *str, unsigned int mode,
if (!aucat_connect_un(hdl, unit))
return 0;
}
if (fcntl(hdl->fd, F_SETFD, FD_CLOEXEC) < 0) {
DPERROR("FD_CLOEXEC");
goto bad_connect;
}
hdl->rstate = RSTATE_MSG;
hdl->rtodo = sizeof(struct amsg);
hdl->wstate = WSTATE_IDLE;