Skip to content

Commit fd5070d

Browse files
committed
Fixed tests on osx.
1 parent 4c2958c commit fd5070d

File tree

5 files changed

+17
-22
lines changed

5 files changed

+17
-22
lines changed

Lib/module.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "poll_priv.h"
33
#include <string.h>
44
#include <stdarg.h>
5-
#include <errno.h>
65

76
static module_ret_code init_ctx(const char *ctx_name, m_context **context);
87
static void destroy_ctx(const char *ctx_name, m_context *context);
@@ -13,7 +12,6 @@ static int tell_if(void *data, void *m);
1312
static pubsub_msg_t *create_pubsub_msg(const unsigned char *message, const self_t *sender, const char *topic, enum msg_type type, const size_t size);
1413
static module_ret_code tell_pubsub_msg(pubsub_msg_t *m, module *mod, m_context *c);
1514
static int manage_fds(module *mod, m_context *c, int flag, int stop);
16-
static int _poll_set_new_evt(module_poll_t *t, m_context *c, int flag);
1715
static module_ret_code start(const self_t *self, const enum module_states mask, const char *err_str);
1816
static module_ret_code stop(const self_t *self, const enum module_states mask, const char *err_str, int stop);
1917

@@ -198,7 +196,7 @@ module_ret_code module_register_fd(const self_t *self, const int fd, const bool
198196

199197
/* If a fd is registered at runtime, start polling on it */
200198
if (module_is(self, RUNNING)) {
201-
int ret = _poll_set_new_evt(tmp, c, ADD);
199+
int ret = poll_set_new_evt(tmp, c, ADD);
202200
return !ret ? MOD_OK : MOD_ERR;
203201
}
204202
return MOD_OK;
@@ -218,7 +216,7 @@ module_ret_code module_deregister_fd(const self_t *self, const int fd) {
218216
*tmp = (*tmp)->prev;
219217
/* If a fd is deregistered for a RUNNING module, stop polling on it */
220218
if (module_is(self, RUNNING)) {
221-
ret = _poll_set_new_evt(t, c, RM);
219+
ret = poll_set_new_evt(t, c, RM);
222220
}
223221
if (t->autoclose) {
224222
close(t->fd);
@@ -447,26 +445,12 @@ static int manage_fds(module *mod, m_context *c, int flag, int stop) {
447445
if (flag == RM && stop) {
448446
ret = module_deregister_fd(&mod->self, t->fd);
449447
} else {
450-
ret = _poll_set_new_evt(t, c, flag);
448+
ret = poll_set_new_evt(t, c, flag);
451449
}
452450
}
453451
return ret;
454452
}
455453

456-
/*
457-
* Just a call to poll_set_new_evt + some filtering:
458-
* STDIN_FILENO returns EPERM but it is actually pollable
459-
*/
460-
static int _poll_set_new_evt(module_poll_t *t, m_context *c, int flag) {
461-
int ret = poll_set_new_evt(t, c, flag);
462-
printf("Ret: %d, errno: %d\n", ret, errno);
463-
/* Workaround for STDIN_FILENO */
464-
if (ret == -1 && t->fd == STDIN_FILENO && errno == EPERM) {
465-
ret = 0;
466-
}
467-
return ret;
468-
}
469-
470454
static module_ret_code start(const self_t *self, const enum module_states mask, const char *err_str) {
471455
GET_MOD_IN_STATE(self, mask);
472456

Lib/poll_plugins/epoll_priv.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ int poll_set_new_evt(module_poll_t *tmp, m_context *c, enum op_type flag) {
1616
struct epoll_event *ev = (struct epoll_event *)tmp->ev;
1717
ev->data.ptr = tmp;
1818
ev->events = EPOLLIN;
19-
return epoll_ctl(c->fd, f, tmp->fd, (struct epoll_event *)tmp->ev);
19+
int ret = epoll_ctl(c->fd, f, tmp->fd, (struct epoll_event *)tmp->ev);
20+
/* Workaround for STDIN_FILENO: it returns EPERM but it is actually pollable */
21+
if (ret == -1 && tmp->fd == STDIN_FILENO && errno == EPERM) {
22+
ret = 0;
23+
}
24+
return ret;
2025
}
2126

2227
int poll_init_pevents(void **pevents, int max_events) {

Lib/poll_plugins/kqueue_priv.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ int poll_set_new_evt(module_poll_t *tmp, m_context *c, enum op_type flag) {
2424
int f = flag == ADD ? EV_ADD : EV_DELETE;
2525
struct kevent *_ev = (struct kevent *)tmp->ev;
2626
EV_SET(_ev, tmp->fd, EVFILT_READ, f, 0, 0, (void *)tmp);
27-
return kevent(c->fd, _ev, 1, NULL, 0, NULL);
27+
int ret = kevent(c->fd, _ev, 1, NULL, 0, NULL);
28+
/* Workaround for STDIN_FILENO: it returns EINVAL but it is actually pollable */
29+
if (ret == -1 && tmp->fd == STDIN_FILENO && errno == EINVAL) {
30+
ret = 0;
31+
}
32+
return ret;
2833
}
2934

3035
int poll_init_pevents(void **pevents, int max_events) {

Lib/poll_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "module_cmn.h"
44
#include "module_priv.h"
55
#include <fcntl.h>
6+
#include <errno.h>
67

78
/* Useful macros to smooth away differences between supported OS */
89
enum op_type { ADD, RM };

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
- [x] Fix CMakeLists to runt tests even if valgrind could not be found
1212

13-
- [ ] Fix tests on osx? module_register_fd fails
13+
- [x] Fix tests on osx? module_register_fd fails
1414
- [x] Special handling of STDIN_FILENO in poll_set_new_evt: it returns EPERM but it is actually pollable.
1515

1616
## 3.1.0

0 commit comments

Comments
 (0)