-/* $OpenBSD: radiusd.c,v 1.9 2015/10/19 22:07:37 yasuoka Exp $ */
+/* $OpenBSD: radiusd.c,v 1.10 2015/10/27 04:18:36 yasuoka Exp $ */
/*
* Copyright (c) 2013 Internet Initiative Japan Inc.
{
struct radiusd_module *module = NULL;
pid_t pid;
- int on, pairsock[] = { -1, -1 };
+ int ival, pairsock[] = { -1, -1 };
const char *av[3];
ssize_t n;
struct imsg imsg;
close(pairsock[1]);
module->fd = pairsock[0];
- on = 1;
- if (fcntl(module->fd, O_NONBLOCK, &on) == -1) {
- log_warn("Could not load module `%s': fcntl(,O_NONBLOCK)",
+ if ((ival = fcntl(module->fd, F_GETFL, 0)) < 0) {
+ log_warn("Could not load module `%s': fcntl(F_GETFL)",
+ name);
+ goto on_error;
+ }
+ if (fcntl(module->fd, F_SETFL, ival | O_NONBLOCK) < 0) {
+ log_warn("Could not load module `%s': fcntl(F_SETFL,O_NONBLOCK)",
name);
goto on_error;
}
-/* $OpenBSD: radiusd_module.c,v 1.6 2015/10/19 09:47:37 yasuoka Exp $ */
+/* $OpenBSD: radiusd_module.c,v 1.7 2015/10/27 04:18:36 yasuoka Exp $ */
/*
* Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
module_start(struct module_base *base)
{
#ifdef USE_LIBEVENT
- int on;
+ int ival;
- on = 1;
- if (fcntl(base->ibuf.fd, O_NONBLOCK, &on) == -1)
+ if ((ival = fcntl(base->ibuf.fd, F_GETFL, 0)) < 0)
+ err(1, "Failed to F_GETFL");
+ if (fcntl(base->ibuf.fd, F_SETFL, ival | O_NONBLOCK) < 0)
err(1, "Failed to setup NONBLOCK");
event_set(&base->ev, base->ibuf.fd, EV_READ, module_on_event, base);
event_add(&base->ev, NULL);