diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2020-01-31 10:44:23 -0500 | 
|---|---|---|
| committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2020-02-04 08:10:52 -0500 | 
| commit | 19d95d40c08d96b8b6ba6c7d224701db339893ab (patch) | |
| tree | 44c500348142373382f417b267999fcf7909578f /lib/agentx.c | |
| parent | 698ba8d02688ef7b9532c9a6dc441f841b9357ee (diff) | |
lib: Test return of fcntl in agentx.c
The agentx.c code was calling fcntl but not testing return
code and handling it, thus making SA unhappy.
Fix.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'lib/agentx.c')
| -rw-r--r-- | lib/agentx.c | 24 | 
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/agentx.c b/lib/agentx.c index 2c6a43d1a7..b479b5ea4c 100644 --- a/lib/agentx.c +++ b/lib/agentx.c @@ -55,28 +55,42 @@ static int agentx_timeout(struct thread *t)  static int agentx_read(struct thread *t)  {  	fd_set fds; -	int flags; +	int flags, new_flags = 0;  	int nonblock = false;  	struct listnode *ln = THREAD_ARG(t);  	list_delete_node(events, ln);  	/* fix for non blocking socket */  	flags = fcntl(THREAD_FD(t), F_GETFL, 0); -	if (-1 == flags) +	if (-1 == flags) { +		flog_err(EC_LIB_SYSTEM_CALL, "Failed to get FD settings fcntl: %s(%d)", +			 strerror(errno), errno);  		return -1; +	}  	if (flags & O_NONBLOCK)  		nonblock = true;  	else -		fcntl(THREAD_FD(t), F_SETFL, flags | O_NONBLOCK); +		new_flags = fcntl(THREAD_FD(t), F_SETFL, flags | O_NONBLOCK); + +	if (new_flags == -1) +		flog_err(EC_LIB_SYSTEM_CALL, "Failed to set snmp fd non blocking: %s(%d)", +			 strerror(errno), errno);  	FD_ZERO(&fds);  	FD_SET(THREAD_FD(t), &fds);  	snmp_read(&fds);  	/* Reset the flag */ -	if (!nonblock) -		fcntl(THREAD_FD(t), F_SETFL, flags); +	if (!nonblock) { +		new_flags = fcntl(THREAD_FD(t), F_SETFL, flags); + +		if (new_flags == -1) +			flog_err( +				EC_LIB_SYSTEM_CALL, +				"Failed to set snmp fd back to original settings: %s(%d)", +				strerror(errno), errno); +	}  	netsnmp_check_outstanding_agent_requests();  	agentx_events_update();  | 
