FreeBSD/usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.c
/*
 * Input from the control socket.
 */
Input from the control socket.
Input from the control socket .
static struct ng_mesg *
csock_read(char *path)
{
	struct ng_mesg *mesg;
	int ret, err;
	if ((mesg = malloc(resbufsiz + 1)) == NULL) {
		stats[LEAF_begemotNgNoMems]++;
		syslog(LOG_CRIT, "out of memory");
		errno = ENOMEM;
		return (NULL);
	}
	if ((ret = NgRecvMsg(csock, mesg, resbufsiz + 1, path)) < 0) {
		err = errno;
		free(mesg);
		if (errno == EWOULDBLOCK) {
			errno = err;
			return (NULL);
		}
		stats[LEAF_begemotNgMsgReadErrs]++;
		syslog(LOG_WARNING, "read from csock: %m");
		errno = err;
		return (NULL);
	}
	if (ret == 0) {
		syslog(LOG_DEBUG, "node closed -- exiting");
		exit(0);
	}
	if ((size_t)ret > resbufsiz) {
		stats[LEAF_begemotNgTooLargeMsgs]++;
		syslog(LOG_WARNING, "ng message too large");
		free(mesg);
		errno = EFBIG;
		return (NULL);
	}
	return (mesg);
}
static struct ng_mesg * csock_read ( char * path ) { struct ng_mesg * mesg ; int ret , err ; if ( ( mesg = malloc ( resbufsiz + 1 ) ) == NULL ) { stats [ LEAF_begemotNgNoMems ] ++ ; syslog ( LOG_CRIT , " " ) ; errno = ENOMEM ; return ( NULL ) ; } if ( ( ret = NgRecvMsg ( csock , mesg , resbufsiz + 1 , path ) ) < 0 ) { err = errno ; free ( mesg ) ; if ( errno == EWOULDBLOCK ) { errno = err ; return ( NULL ) ; } stats [ LEAF_begemotNgMsgReadErrs ] ++ ; syslog ( LOG_WARNING , " " ) ; errno = err ; return ( NULL ) ; } if ( ret == 0 ) { syslog ( LOG_DEBUG , " " ) ; exit ( 0 ) ; } if ( ( size_t ) ret > resbufsiz ) { stats [ LEAF_begemotNgTooLargeMsgs ] ++ ; syslog ( LOG_WARNING , " " ) ; free ( mesg ) ; errno = EFBIG ; return ( NULL ) ; } return ( mesg ) ; }
Input from the control socket.
Input from the control socket .