Skip to content

Commit

Permalink
Make client socket non-blocking & close on exec.
Browse files Browse the repository at this point in the history
Also log which version packet we've received.
  • Loading branch information
dougnazar committed Dec 28, 2024
1 parent 4f21d9b commit 2c274e2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/nrpe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,9 @@ void wait_for_connections(void)
break; /* else handle the error later */
}

/* ensure socket is non-blocking & close on exec */
fcntl(new_sd, F_SETFD, fcntl(new_sd, F_GETFD) | FD_CLOEXEC);
fcntl(new_sd, F_SETFL, fcntl(new_sd, F_GETFL) | O_NONBLOCK);

rc = wait_conn_fork(new_sd);
if (rc == TRUE)
Expand Down Expand Up @@ -2023,6 +2026,8 @@ int read_packet(int sock, void *ssl_ptr, v2_packet * v2_pkt, v3_packet ** v3_pkt
logit(LOG_ERR, "Error: (use_ssl == false): Request packet version was invalid!");
return -1;
}
if (debug)
logit(LOG_DEBUG, "Received v%i packet", packet_ver);

if (packet_ver == NRPE_PACKET_VERSION_2) {
buffer_size = sizeof(v2_packet) - common_size;
Expand Down Expand Up @@ -2087,6 +2092,8 @@ int read_packet(int sock, void *ssl_ptr, v2_packet * v2_pkt, v3_packet ** v3_pkt
logit(LOG_ERR, "Error: (use_ssl == true): Request packet version was invalid!");
return -1;
}
if (debug)
logit(LOG_DEBUG, "Received v%i packet", packet_ver);

if (packet_ver == NRPE_PACKET_VERSION_2) {
buffer_size = sizeof(v2_packet) - common_size;
Expand Down

0 comments on commit 2c274e2

Please sign in to comment.