Skip to content

Commit b346ca9

Browse files
committed
Fix xsetfd, close eloop fd with epoll and correct a diagnositic message.
1 parent f18a138 commit b346ca9

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ xsetfd(int fd, int flags)
473473
if (oflags == -1)
474474
return -1;
475475
if (!(oflags & FD_CLOEXEC) &&
476-
fcntl(fd, F_SETFD, oflags | O_NONBLOCK) == -1)
476+
fcntl(fd, F_SETFD, oflags | FD_CLOEXEC) == -1)
477477
return -1;
478478
}
479479
#endif

src/eloop.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,11 @@ eloop_forked(struct eloop *eloop, unsigned short flags)
700700
unsigned short events;
701701
int err;
702702

703-
/* The fd is invalid after a fork, no need to close it. */
703+
/* kqueue invalidates the fd on fork.
704+
* epoll shares state across fork, so we close the old and create a new one. */
705+
#ifdef USE_EPOLL
706+
close(eloop->fd);
707+
#endif
704708
eloop->fd = -1;
705709
if (flags && eloop_open(eloop) == -1)
706710
return -1;

src/service.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ srv_recv(struct srv_ctx *sctx, unsigned short e)
102102

103103
nread = recvmsg(sctx->srv_fd, &msg, MSG_WAITALL);
104104
if (nread == -1) {
105-
logerr("%s: recvmsg cmd", __func__);
105+
logerr("%s: recvmsg data", __func__);
106106
return -1;
107107
}
108108
if ((size_t)nread != cmd.sc_datalen) {
109-
logerrx("%s: read datalen mismatch: %zd != %zd",
110-
__func__, nread, cmd.sc_datalen);
109+
logerrx("%s: read datalen mismatch: %zu != %zu",
110+
__func__, (size_t)nread, cmd.sc_datalen);
111111
return -1;
112112
}
113113
}

0 commit comments

Comments
 (0)