-/* $OpenBSD: radiusd.c,v 1.10 2015/10/27 04:18:36 yasuoka Exp $ */
+/* $OpenBSD: radiusd.c,v 1.11 2015/10/27 04:27:01 yasuoka Exp $ */
/*
* Copyright (c) 2013 Internet Initiative Japan Inc.
{
struct radiusd_listen *l;
struct radiusd_module *module;
- int s;
+ int s, ival;
char hbuf[NI_MAXHOST];
TAILQ_FOREACH(l, &radiusd->listen, next) {
close(s);
goto on_error;
}
+ if ((ival = fcntl(s, F_GETFL, 0)) < 0) {
+ log_warn("fcntl(F_GETFL) failed at %s()", __func__);
+ close(s);
+ goto on_error;
+ }
+ if (fcntl(s, F_SETFL, ival | O_NONBLOCK) < 0) {
+ log_warn("fcntl(F_SETFL,O_NONBLOCK) failed at %s()", __func__);
+ close(s);
+ goto on_error;
+ }
if (l->addr.ipv4.sin_family == AF_INET)
log_info("Start listening on %s:%d/udp", hbuf,
(int)ntohs(l->addr.ipv4.sin_port));
peersz = sizeof(peer);
if ((sz = recvfrom(listn->sock, buf, sizeof(buf), 0,
(struct sockaddr *)&peer, &peersz)) < 0) {
+ if (errno == EAGAIN)
+ return;
log_warn("%s: recvfrom() failed", __func__);
goto on_error;
}
-/* $OpenBSD: radiusd_radius.c,v 1.8 2015/10/19 22:07:37 yasuoka Exp $ */
+/* $OpenBSD: radiusd_radius.c,v 1.9 2015/10/27 04:27:01 yasuoka Exp $ */
/*
* Copyright (c) 2013 Internet Initiative Japan Inc.
#include <netinet/in.h>
#include <err.h>
+#include <errno.h>
#include <event.h>
+#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
static int
radius_server_start(struct radius_server *server)
{
+ int ival;
socklen_t locallen;
char buf0[NI_MAXHOST + NI_MAXSERV + 32];
char buf1[NI_MAXHOST + NI_MAXSERV + 32];
server->addr.sin4.sin_len, buf1, sizeof(buf1)));
goto on_error;
}
+ if ((ival = fcntl(server->sock, F_GETFL, 0)) < 0) {
+ module_radius_log(server->module, LOG_WARNING,
+ "%s: fcntl(F_GETFL) failed", __func__);
+ goto on_error;
+ }
+ if (fcntl(server->sock, F_SETFL, ival | O_NONBLOCK) < 0) {
+ module_radius_log(server->module, LOG_WARNING,
+ "%s: fcntl(F_SETFL) failed", __func__);
+ goto on_error;
+ }
locallen = sizeof(server->local);
if (getsockname(server->sock, (struct sockaddr *)&server->local,
&locallen) != 0) {
struct sockaddr *peer;
peer = (struct sockaddr *)&server->addr;
- if ((sz = recv(server->sock, pkt, sizeof(pkt), 0)) <= 0) {
+ if ((sz = recv(server->sock, pkt, sizeof(pkt), 0)) == -1) {
+ if (errno == EAGAIN)
+ return;
module_radius_log(server->module, LOG_WARNING,
"server=%s recv() failed: %m",
addrport_tostring(peer, peer->sa_len, buf, sizeof(buf)));