Skip to content

Commit

Permalink
Fix fcntl(FD_CLOEXEC) call to be future proof (confluentinc#3467)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhill committed Apr 8, 2022
1 parent 6759e13 commit 3694a00
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/rdkafka_broker.c
Original file line number Diff line number Diff line change
Expand Up @@ -1946,13 +1946,21 @@ int rd_kafka_socket_cb_generic(int domain,
int type,
int protocol,
void *opaque) {
int s;
int on = 1;
s = (int)socket(domain, type, protocol);
int s = (int)socket(domain, type, protocol);
#ifdef FD_CLOEXEC
int flags;
#endif

if (s == -1)
return -1;

#ifdef FD_CLOEXEC
if (fcntl(s, F_SETFD, FD_CLOEXEC, &on) == -1)
if ((flags = fcntl(s, F_GETFD)) == -1)
fprintf(stderr,
"WARNING: librdkafka: %s: "
"fnctl(F_GETFD) for FD_CLOEXEC failed: %s: ignoring\n",
__FUNCTION__, rd_strerror(errno));
else if (fcntl(s, F_SETFD, flags | FD_CLOEXEC) == -1)
fprintf(stderr,
"WARNING: librdkafka: %s: "
"fcntl(FD_CLOEXEC) failed: %s: ignoring\n",
Expand Down

0 comments on commit 3694a00

Please sign in to comment.