Skip to content

Commit

Permalink
[server] allow loop restart after select() sets EINTR (since we handl…
Browse files Browse the repository at this point in the history
…e signals) - fixes cmd execution through UDP on FreeBSD
  • Loading branch information
mrash committed Nov 5, 2014
1 parent c5f0389 commit e7942f4
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions server/udp_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,19 @@ run_udp_server(fko_srv_options_t *opts)
if(set_sig_handlers() > 0)
log_msg(LOG_ERR, "Errors encountered when setting signal handlers.");

FD_ZERO(&sfd_set);

/* Now loop and receive SPA packets
*/
while(1)
{
if(sig_do_stop())
{
if(opts->verbose)
log_msg(LOG_INFO,
"udp_server: terminating signal received, will stop.");
break;
}

/* Check for any expired firewall rules and deal with them.
*/
Expand All @@ -145,7 +152,6 @@ run_udp_server(fko_srv_options_t *opts)

/* Initialize and setup the socket for select.
*/
FD_ZERO(&sfd_set);
FD_SET(s_sock, &sfd_set);

/* Set our select timeout to (500ms by default).
Expand All @@ -157,17 +163,28 @@ run_udp_server(fko_srv_options_t *opts)

if(selval == -1)
{
/* Select error so bail
*/
log_msg(LOG_ERR, "run_udp_server: select error socket: %s",
strerror(errno));
rv = -1;
break;
if(errno == EINTR)
{
/* restart loop but only after we check for a terminating
* signal above in sig_do_stop()
*/
continue;
}
else
{
log_msg(LOG_ERR, "run_udp_server: select error socket: %s",
strerror(errno));
rv = -1;
break;
}
}

if(selval == 0)
continue;

if(! FD_ISSET(s_sock, &sfd_set))
continue;

/* If we make it here then there is a datagram to process
*/
clen = sizeof(caddr);
Expand Down

0 comments on commit e7942f4

Please sign in to comment.