PERFORCE change 82880 for review

Victor Cruceru soc-victor at FreeBSD.org
Tue Aug 30 23:51:21 GMT 2005


http://perforce.freebsd.org/chv.cgi?CH=82880

Change 82880 by soc-victor at soc-victor_82.76.158.176 on 2005/08/30 23:51:05

	More cleanup for HR-MIB.

Affected files ...

.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_diskstorage_tbl.c#11 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c#6 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_network_tbl.c#5 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_partition_tbl.c#5 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_printer_tbl.c#5 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_processor_tbl.c#4 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c#11 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#22 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_storage_tbl.c#10 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swinstalled_tbl.c#3 edit

Differences ...

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_diskstorage_tbl.c#11 (text+ko) ====

@@ -518,10 +518,12 @@
 		return;
 	}	
 	for (unit = 0; unit < mdio.md_pad[0] && unit < MDNPAD - 1; unit++) {
+		struct md_ioctl u_mdio;
 		char mddev[64] = "";
+		
 		(void)snprintf(mddev, sizeof(mddev) - 1, "%s%d", 
 			MD_NAME, mdio.md_pad[unit + 1]);
-		struct md_ioctl u_mdio;
+
 
 		memset(&u_mdio, 0, sizeof(u_mdio));
 		u_mdio.md_version = MDIOVERSION;

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c#6 (text+ko) ====

@@ -32,8 +32,6 @@
 #include "hostres_snmp.h"
 #include "hostres_oid.h"
 #include "hostres_tree.h"
-
-#include <sys/types.h>
 #include <sys/sysctl.h>
 #include <stdlib.h>
 #include <assert.h>
@@ -57,10 +55,15 @@
 		return (NULL);
 	}
 	memset(entry, 0, sizeof(*entry));
-	strncpy(entry->mountPoint, name, sizeof(entry->mountPoint)-1);
+	
+	strncpy((char *)entry->mountPoint, name, 
+		sizeof(entry->mountPoint)-1);
 
 	STAILQ_FOREACH(map, &hrState_g.fs_name_map, link)
-		if (strncmp(map->a_name, entry->mountPoint, sizeof(map->a_name) - 1) == 0) {
+		if (strncmp((const char*)map->a_name, 
+			(const char*)entry->mountPoint, 
+			sizeof(map->a_name) - 1) == 0) {
+			
 			entry->index = map->hrIndex;
 			map->entry_p = entry;
 			break;
@@ -80,7 +83,9 @@
 		}
 		map->hrIndex = hrState_g.next_hrFS_index ++;
 		map->a_name[sizeof(map->a_name)-1]='\0';
-		strncpy(map->a_name, entry->mountPoint, sizeof(map->a_name)-1);
+		strncpy((char*)map->a_name, 
+			(const char*)entry->mountPoint, 
+			sizeof(map->a_name) - 1);
 		map->entry_p = entry;
 		STAILQ_INSERT_TAIL(&hrState_g.fs_name_map, map, link);
 		HR_DPRINTF((stderr, "%s  added into hrFSMap at index=%d\n ", 
@@ -120,7 +125,9 @@
 	struct hrFSTblEntry *entry =  NULL;
 
 	TAILQ_FOREACH(entry, &hrState_g.hr_fs_tbl, link)
-		if (strncmp(entry->mountPoint, name, sizeof(entry->mountPoint) - 1) == 0)
+		if (strncmp((const char*)entry->mountPoint, 
+			name, 
+			sizeof(entry->mountPoint) - 1) == 0)
 			return (entry);
 	return (NULL);
 }
@@ -289,13 +296,14 @@
 		entry->flags |= HR_FS_FOUND;
 		
 		entry->mountPoint[0]='\0'; 
-		strncpy(&entry->mountPoint[0], &fs_p->f_mntonname[0], 
+		strncpy((char *)&entry->mountPoint[0], &fs_p->f_mntonname[0], 
 			sizeof(entry->mountPoint) - 1 );
 		
 		
 		if( !(fs_p->f_flags &  MNT_LOCAL) ) {
 			/*this remote mount*/
-			strncpy(&entry->remoteMountPoint[0], &fs_p->f_mntfromname[0], 
+			strncpy((char*)&entry->remoteMountPoint[0], 
+				&fs_p->f_mntfromname[0], 
 				sizeof(entry->remoteMountPoint)-1);
 		} else {
 			entry->remoteMountPoint[0]='\0';	
@@ -304,16 +312,16 @@
 		get_FS_type_v(fs_p, &entry->type);
 		
 		if( (fs_p->f_flags &  MNT_RDONLY) == MNT_RDONLY ) {
-			entry->access = FS_READ_ONLY;
+			entry->access = (int32_t)FS_READ_ONLY;
 		} else {
-			entry->access = FS_READ_WRITE;		
+			entry->access = (int32_t)FS_READ_WRITE;		
 		}
 		
 		/*FIX ME - bootable fs ?! */
 		if( ( fs_p->f_flags &  MNT_ROOTFS ) == MNT_ROOTFS ) {
-			entry->bootable = SNMP_TRUE; 
+			entry->bootable = (int32_t)SNMP_TRUE; 
 		} else {
-			entry->bootable = SNMP_FALSE; 
+			entry->bootable = (int32_t)SNMP_FALSE; 
 		}
 		
 		entry->storageIndex = storage_idx;
@@ -337,13 +345,13 @@
 		
 		memset(&entry->mountPoint[0], '\0',  sizeof(entry->mountPoint));
 		
-		strncpy(&entry->mountPoint[0], &fs_p->f_mntonname[0], 
+		strncpy((char *)&entry->mountPoint[0], &fs_p->f_mntonname[0], 
 			sizeof(entry->mountPoint) - 1 );
 		
 		
 		if( !(fs_p->f_flags &  MNT_LOCAL) ) {
 			/*this remote mount*/
-			strncpy(&entry->remoteMountPoint[0], &fs_p->f_mntfromname[0], 
+			strncpy((char *)&entry->remoteMountPoint[0], &fs_p->f_mntfromname[0], 
 				sizeof(entry->remoteMountPoint)-1);
 		} else {
 			entry->remoteMountPoint[0]='\0';	
@@ -352,16 +360,16 @@
 		get_FS_type_v(fs_p, &entry->type);
 		
 		if( ( fs_p->f_flags &  MNT_RDONLY ) == MNT_RDONLY ) {
-			entry->access = FS_READ_ONLY;
+			entry->access = (int32_t)FS_READ_ONLY;
 		} else {
-			entry->access = FS_READ_WRITE;		
+			entry->access = (int32_t)FS_READ_WRITE;		
 		}
 
 		/*FIX ME - bootable fs ?! */
 		if( ( fs_p->f_flags &  MNT_ROOTFS ) == MNT_ROOTFS ) {
-			entry->bootable = SNMP_TRUE; 
+			entry->bootable = (int32_t)SNMP_TRUE; 
 		} else {
-			entry->bootable = SNMP_FALSE; 
+			entry->bootable = (int32_t)SNMP_FALSE; 
 		}
 				
 		

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_network_tbl.c#5 (text+ko) ====

@@ -76,19 +76,13 @@
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <sys/types.h>
 #include <assert.h>	
 #include <err.h>
 #include <sys/fcntl.h>
-#include <sys/param.h>
-#include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <sys/errno.h>
-#include <sys/time.h>
-#include <net/if.h>
 #include <net/if_var.h>
 #include <net/if_dl.h>
-#include <netinet/in.h>
 #include <netinet/in_var.h>
 #include <arpa/inet.h>
 #include <ctype.h>
@@ -183,7 +177,7 @@
 	
 
 	STAILQ_FOREACH(map, &hrState_g.device_name_map, link)
-		if (strcmp(map->name_key, dev_name) == 0) {
+		if (strcmp((const char*)map->name_key, dev_name) == 0) {
 			entry->index = map->hrIndex;
 			map->entry_p = entry;
 			break;
@@ -204,10 +198,15 @@
 		map->hrIndex = hrState_g.next_hrDevice_index ++;
 		
 		memset(&map->name_key[0], 0, sizeof(map->name_key));
-		strncpy(map->name_key, dev_name, sizeof(map->name_key) - 1);
+		
+		strncpy((char *)map->name_key, 
+			dev_name, 
+			sizeof(map->name_key) - 1);
 		
 		memset(&map->location_key[0], 0, sizeof(map->location_key));
-		snprintf(map->location_key, sizeof(map->location_key) - 1, "net_device:%s", dev_name);
+		(void)snprintf((char*)map->location_key, 
+			sizeof(map->location_key) - 1, 
+			"net_device:%s", dev_name);
 
 
 		map->entry_p = entry;
@@ -224,10 +223,13 @@
 	
 	entry->index = map->hrIndex;
 	memset(&entry->name[0], 0, sizeof(entry->name));
-	strncpy(entry->name, dev_name, sizeof(entry->name) - 1);
+	strncpy((char *)entry->name, dev_name, 
+		sizeof(entry->name) - 1);
 		
 	memset(&entry->location[0], 0, sizeof(entry->location));
-	snprintf(entry->location, sizeof(entry->location) - 1, "net_device:%s", dev_name);
+	(void)snprintf((char *)entry->location, 
+		sizeof(entry->location) - 1,
+		"net_device:%s", dev_name);
 					
 	INSERT_OBJECT_INT(entry, &hrState_g.hr_device_tbl);
 	
@@ -323,9 +325,10 @@
 			dev_entry->flags |= HR_DEVICE_IMMUTABLE;
 			dev_entry->type = (struct asn_oid)OIDX_hrDeviceNetwork;
 			dev_entry->id = oid_zeroDotZero; /*unknown id - FIX ME*/
-			dev_entry->status = DS_RUNNING;
+			dev_entry->status = (int32_t)DS_RUNNING;
 			dev_entry->errors = 0; /*FIX ME*/
-			snprintf(dev_entry->descr, sizeof(dev_entry->descr) - 1, 
+			(void)snprintf((char *)dev_entry->descr, 
+				sizeof(dev_entry->descr) - 1, 
 				"%s: Network device",
 				ifptr->ifr_name);
 		}else{

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_partition_tbl.c#5 (text+ko) ====

@@ -31,7 +31,6 @@
 #include "hostres_snmp.h"
 #include "hostres_oid.h"
 #include "hostres_tree.h"
-#include <sys/types.h>
 #include <libdisk.h>
 #include <assert.h>
 #include <stdlib.h>
@@ -80,7 +79,7 @@
 	
 
 	STAILQ_FOREACH(map, &hrState_g.partition_name_map, link)
-		if (strcmp(map->id, curr_chunk->name) == 0 ) {
+		if (strcmp((const char*)map->id, curr_chunk->name) == 0 ) {
 			map->entry_p = entry;
 			break;
 		}
@@ -100,7 +99,7 @@
 		map->index = hrState_g.next_hrPartition_index ++;
 		
 		memset(&map->id[0], 0, sizeof(map->id));
-		strncpy(map->id, curr_chunk->name, sizeof(map->id) - 1);
+		strncpy((char *)map->id, curr_chunk->name, sizeof(map->id) - 1);
 		
 
 		map->entry_p = entry;
@@ -119,7 +118,7 @@
 	entry->index.subs[1] = map->index;
 
 	memset(&entry->id[0], 0, sizeof(entry->id));
-	strncpy(entry->id, curr_chunk->name, sizeof(entry->id) - 1);
+	strncpy((char*)entry->id, curr_chunk->name, sizeof(entry->id) - 1);
 		
 	INSERT_OBJECT_OID_LINK_INDEX(entry, &hrState_g.hr_partition_tbl, link, index);
 
@@ -150,7 +149,7 @@
 	struct hrPartitionTblEntry *entry =  NULL;
 
 	TAILQ_FOREACH(entry, &hrState_g.hr_partition_tbl, link)
-		if (strncmp(entry->id, name, sizeof(entry->id) - 1) == 0)
+		if (strncmp((const char *)entry->id, name, sizeof(entry->id) - 1) == 0)
 			return (entry);
 	return (NULL);
 }
@@ -161,7 +160,7 @@
 	struct hrPartitionTblEntry *entry =  NULL;
 
 	TAILQ_FOREACH(entry, &hrState_g.hr_partition_tbl, link)
-		if (strncmp(entry->label, name, sizeof(entry->label) - 1) == 0)
+		if (strncmp((const char *)entry->label, name, sizeof(entry->label) - 1) == 0)
 			return (entry);
 	return (NULL);
 }
@@ -169,6 +168,8 @@
 static
 void handleChunk(int32_t ds_index, const struct chunk* chunk_p) {
 	struct hrPartitionTblEntry* entry = NULL;
+	daddr_t k_size;
+	
 	assert(chunk_p != NULL); 
 	if (chunk_p == NULL)
 		return;
@@ -184,8 +185,10 @@
 	}
 	assert(entry != NULL);
 	entry->flags |= HR_PARTITION_FOUND;
-	snprintf(entry->label, sizeof(entry->label) - 1, "%s%s", _PATH_DEV, chunk_p->name );
-	daddr_t k_size= chunk_p->size/2;
+	(void)snprintf((char* )entry->label, 
+		sizeof(entry->label) - 1, "%s%s",
+		 _PATH_DEV, chunk_p->name );
+	k_size = chunk_p->size/2;
 	/*may overflow the SNMP type*/
 	entry->size =  ( k_size > (daddr_t)INT_MAX ? INT_MAX : 	k_size ); 
 }

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_printer_tbl.c#5 (text+ko) ====

@@ -71,7 +71,6 @@
 #include "hostres_oid.h"
 #include "hostres_tree.h" 
 #include <errno.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h> 
@@ -169,9 +168,9 @@
 		len = MAXPATHLEN;
 
 	if (pp->status_file[0] == '/')
-		strlcpy(buf, pp->status_file, len);
+		(void)strlcpy(buf, pp->status_file, len);
 	else
-		snprintf(buf, len, "%s/%s", pp->spool_dir, pp->status_file);
+		(void)snprintf(buf, len, "%s/%s", pp->spool_dir, pp->status_file);
 
 	return buf;
 }
@@ -188,9 +187,9 @@
 		len = MAXPATHLEN;
 
 	if (pp->lock_file[0] == '/')
-		strlcpy(buf, pp->lock_file, len);
+		(void)strlcpy(buf, pp->lock_file, len);
 	else
-		snprintf(buf, len, "%s/%s", pp->spool_dir, pp->lock_file);
+		(void)snprintf(buf, len, "%s/%s", pp->spool_dir, pp->lock_file);
 
 	return buf;
 }
@@ -301,7 +300,9 @@
 void
 lastprinter(void)
 {
-	cgetclose();
+	if (cgetclose() != 0) {
+		syslog(LOG_ERR, "cgetclose() failed: %m");
+	}
 }
 
 
@@ -577,7 +578,7 @@
 
 
 	STAILQ_FOREACH(map, &hrState_g.device_name_map, link) {
-		if (strcmp(map->name_key, dev_name) == 0) {
+		if (strcmp((const char*)map->name_key, dev_name) == 0) {
 			entry->index = map->hrIndex;
 			map->entry_p = entry;
 			break;
@@ -599,10 +600,12 @@
 		map->hrIndex = hrState_g.next_hrDevice_index ++;
 		
 		memset(&map->name_key[0], 0, sizeof(map->name_key));
-		strncpy(map->name_key, dev_name, sizeof(map->name_key) - 1);
+		strncpy((char *)map->name_key, dev_name, sizeof(map->name_key) - 1);
 		
 		memset(&map->location_key[0], 0, sizeof(map->location_key));
-		snprintf(map->location_key, sizeof(map->location_key) - 1, "printer:%s", dev_name);
+		(void)snprintf((char *)map->location_key, 
+			sizeof(map->location_key) - 1, 
+			"printer:%s", dev_name);
 
 
 		map->entry_p = entry;
@@ -619,10 +622,12 @@
 	
 	entry->index = map->hrIndex;
 	memset(&entry->name[0], 0, sizeof(entry->name));
-	strncpy(entry->name, dev_name, sizeof(entry->name) - 1);
+	strncpy((char *)entry->name, dev_name, sizeof(entry->name) - 1);
 		
 	memset(&entry->location[0], 0, sizeof(entry->location));
-	snprintf(entry->location, sizeof(entry->location) - 1, "printer:%s", dev_name);
+	(void)snprintf((char *)entry->location, 
+		sizeof(entry->location) - 1, 
+		"printer:%s", dev_name);
 					
 	INSERT_OBJECT_INT(entry, &hrState_g.hr_device_tbl);
 	
@@ -641,7 +646,7 @@
 	FILE* f = NULL;
 	enum PrinterStatus ps = PS_UNKNOWN;
 
-	lock_file_name(pp, lockfile, sizeof lockfile);
+	(void)lock_file_name(pp, lockfile, sizeof lockfile);
 	fd = open(lockfile, O_RDONLY);
 	if (fd < 0 || flock(fd, LOCK_SH|LOCK_NB) == 0) {
 		(void) close(fd);	/* unlocks as well */
@@ -651,10 +656,11 @@
 	}
 	
 			
-	status_file_name(pp, statfile, sizeof(statfile));
+	(void)status_file_name(pp, statfile, sizeof(statfile));
 	f = fopen(statfile, "r");
 	if (f == NULL) {
-		syslog(LOG_ERR, "cannot open status file: %s\n", strerror(errno));
+		syslog(LOG_ERR, "cannot open status file: %s\n", 
+			strerror(errno));
 		ps = PS_UNKNOWN;
 		goto  LABEL_DONE;		
 	}
@@ -712,7 +718,8 @@
 	
 	}
 	memset(&dev_only[0], '\0', sizeof(dev_only));
-	snprintf(dev_only, sizeof(dev_only) - 1, "%s", pp->lp + strlen(_PATH_DEV));
+	(void)snprintf(dev_only, sizeof(dev_only) - 1, 
+		"%s", pp->lp + strlen(_PATH_DEV));
 	
 	HR_DPRINTF((stderr,
 		"hrPrinterTable: printer %s has device %s\n",
@@ -748,9 +755,10 @@
 		dev_entry->flags |= HR_DEVICE_IMMUTABLE;
 		dev_entry->type = (struct asn_oid)OIDX_hrDevicePrinter;
 		dev_entry->id = oid_zeroDotZero; /*unknown id - FIX ME*/
-		dev_entry->status = DS_RUNNING;
+		dev_entry->status = (int32_t)DS_RUNNING;
 		dev_entry->errors = 0; /*FIX ME*/
-		snprintf(dev_entry->descr, sizeof(dev_entry->descr) - 1, 
+		(void)snprintf((char *)dev_entry->descr, 
+			sizeof(dev_entry->descr) - 1, 
 			"printer %s: %s ",
 			pp->printer ,
 			pp->lp);
@@ -769,8 +777,9 @@
 	}
 	assert(printer_entry != NULL);
 	printer_entry->flags |= HR_PRINTER_FOUND;
-	printer_entry->status = getPrinterSatus(pp);
-	memset(printer_entry->detectedErrorState, 0, sizeof(printer_entry->detectedErrorState));
+	printer_entry->status = (int32_t)getPrinterSatus(pp);
+	memset(printer_entry->detectedErrorState, 0, 
+		sizeof(printer_entry->detectedErrorState));
 
 
 }

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_processor_tbl.c#4 (text+ko) ====

@@ -36,10 +36,7 @@
 #include <string.h>
 #include <syslog.h>
 #include <stdarg.h>
-#include <sys/types.h>
 #include <sys/sysctl.h>
-#include <kvm.h>
-#include <sys/param.h>
 #include <sys/user.h>
 #include <math.h>
 
@@ -51,9 +48,7 @@
 	for( i = 0; i < MAX_CPU_SAMPLES; i++ ){
 		sum += entry->samples[i];
 	}
-	return floor((double)sum/(double)MAX_CPU_SAMPLES);
-	
-	
+	return ((int)floor((double)sum/(double)MAX_CPU_SAMPLES));
 }
 
 
@@ -147,7 +142,7 @@
 
 			entry->samples[entry->cur_sample_idx] = (double)100.0 - hrProcessor_getpcpu(plist);
 			/*this is fisrt time, thus no previous samples*/
-			entry->load = floor(entry->samples[entry->cur_sample_idx]); 
+			entry->load = (int)floor(entry->samples[entry->cur_sample_idx]); 
 			entry->cur_sample_idx = (entry->cur_sample_idx + 1) % MAX_CPU_SAMPLES;
 			
 		}
@@ -173,38 +168,38 @@
 	 * If not, no entries will be present in the hrProcessor Table
 	 */ 
 	STAILQ_FOREACH(map, &hrState_g.device_name_map, link) {
-		if (strncmp(map->name_key, "cpu", strlen("cpu")) == 0 && 
-		    strstr(map->location_key, ".CPU") != NULL) {
-			if (sscanf(map->name_key,"cpu%d", &cpu_no) != 1) {
-				syslog(LOG_ERR, 
-				"hrProcessorTable: Failed to get cpu no. from device named \"%s\"",
-				map->name_key);
-				continue;
-			}
-			
-			entry = (struct	hrProcessorTblEntry *)malloc(sizeof(*entry));		
-			if (entry == NULL) {
-				syslog(LOG_ERR, 
-				"hrProcessorTable: %s malloc failed: %m", __func__);
-				continue; /*next time?*/
-			}
-			memset(entry, 0, sizeof(*entry));
-			
-			entry->index = map->hrIndex;
-			entry->load = 0;
-			entry->cpu_no = (u_char)cpu_no; 
-			entry->idle_pid = 0;
-			entry->frwId = oid_zeroDotZero; /*unknown id - FIX ME*/
+	if (strncmp((const char*)map->name_key, "cpu", strlen("cpu")) == 0 && 
+	    strstr((const char*)map->location_key, ".CPU") != NULL) {
+		if (sscanf((const char*)map->name_key,"cpu%d", &cpu_no) != 1) {
+			syslog(LOG_ERR, 
+			"hrProcessorTable: Failed to get cpu no. from device named \"%s\"",
+			map->name_key);
+			continue;
+		}
+		
+		entry = (struct	hrProcessorTblEntry *)malloc(sizeof(*entry));		
+		if (entry == NULL) {
+			syslog(LOG_ERR, 
+			"hrProcessorTable: %s malloc failed: %m", __func__);
+			continue; /*next time?*/
+		}
+		memset(entry, 0, sizeof(*entry));
+		
+		entry->index = map->hrIndex;
+		entry->load = 0;
+		entry->cpu_no = (u_char)cpu_no; 
+		entry->idle_pid = 0;
+		entry->frwId = oid_zeroDotZero; /*unknown id - FIX ME*/
 
-			INSERT_OBJECT_INT(entry, &hrState_g.hr_processor_tbl);
-			
-			hrState_g.detected_processor_count++;
-			
-			HR_DPRINTF((stderr, "CPU %d added with SNMP index=%d\n ", 
-				entry->cpu_no, 
-				entry->index));
-			
-		}
+		INSERT_OBJECT_INT(entry, &hrState_g.hr_processor_tbl);
+		
+		hrState_g.detected_processor_count++;
+		
+		HR_DPRINTF((stderr, "CPU %d added with SNMP index=%d\n ", 
+			entry->cpu_no, 
+			entry->index));
+		
+	}
 	}
 	HR_DPRINTF((stderr, "%s: %d CPUs detected\n", __func__, 
 		hrState_g.detected_processor_count));
@@ -238,7 +233,7 @@
 static 
 void hrProcessor_refill_tbl(void) {
 	if(hrState_g.hw_ncpu <= 0){
-		int size = sizeof(hrState_g.hw_ncpu);
+		size_t size = sizeof(hrState_g.hw_ncpu);
 		if (sysctlbyname("hw.ncpu", &hrState_g.hw_ncpu, &size, NULL, 0) < 0 ||
 		    size != sizeof(hrState_g.hw_ncpu)) {
 			syslog(LOG_ERR, "hrProcessorTable: sysctl(hw.ncpu) failed");

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c#11 (text+ko) ====

@@ -33,7 +33,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
-#include <sys/types.h>
 #include <sys/sysctl.h>
 #include <syslog.h>
 #include <utmp.h>
@@ -433,9 +432,14 @@
 	        size_t buf_len = 0;
 		
 		
-		sysctl(mib, 2, NULL, &buf_len, NULL, 0); /*got the needed buffer len */
+		/*get the needed buffer len */
+		if(sysctl(mib, 2, NULL, &buf_len, NULL, 0) != 0){
+			syslog(LOG_ERR, "sysctl({CTL_KERN,KERN_BOOTFILE}) failed: %m ");
+			return (NULL); /*error*/		
+		
+		}
 		
-		buf = (u_char*)malloc(buf_len);
+		buf = (char*)malloc(buf_len);
 		
 		if(buf == NULL){
 			syslog(LOG_ERR, "malloc failed ");
@@ -459,7 +463,7 @@
 int OS_getSystemNumUsers(void) {
 	int user_counter = 0;
 	struct utmp utmp_entry;
-	struct passwd *pw;
+
 	if( hrState_g.utmp_fp == (FILE*)NULL ) {
 		assert(0);
 		return (-1); /*error*/
@@ -469,7 +473,7 @@
 	
 	while (fread(&utmp_entry, sizeof(utmp_entry), 1,  hrState_g.utmp_fp) == 1 ) {
         	if (utmp_entry.ut_name[0] && utmp_entry.ut_line[0]) {
-			if( (pw = getpwnam(utmp_entry.ut_name)) == NULL ) {
+			if(  getpwnam(utmp_entry.ut_name) == NULL ) {
 				continue;
 			}	
 			user_counter++;

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#22 (text+ko) ====

@@ -55,7 +55,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/mdioctl.h>
-#include <sys/param.h>
 #include <sys/linker.h>
 #include <sys/module.h>
 
@@ -154,7 +153,7 @@
 	mdmaybeload();
 	
 	hrState_g.md_fd = -1;		
-	snprintf(mddev, sizeof(mddev) - 1, "%s%s", _PATH_DEV, MDCTL_NAME);
+	(void)snprintf(mddev, sizeof(mddev) - 1, "%s%s", _PATH_DEV, MDCTL_NAME);
 	if ((hrState_g.md_fd = open(mddev, O_RDWR)) < 0) {
 		syslog(LOG_ERR, "open %s failed: %m", mddev);
 	}

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_storage_tbl.c#10 (text+ko) ====

@@ -31,7 +31,6 @@
 #include "hostres_snmp.h"
 #include "hostres_oid.h"
 #include "hostres_tree.h"
-#include <sys/types.h>
 #include <sys/sysctl.h>
 #include <stdlib.h>
 #include <assert.h>
@@ -57,10 +56,11 @@
 		return (NULL);
 	}
 	memset(entry, 0, sizeof(*entry));
-	strncpy(entry->descr, name, sizeof(entry->descr) - 1);
+	strncpy((char *)entry->descr, name, sizeof(entry->descr) - 1);
 
 	STAILQ_FOREACH(map, &hrState_g.storage_name_map, link)
-		if (strcmp(map->a_name, entry->descr) == 0) {
+		if (strcmp((const char*)map->a_name, 
+			(const char*)entry->descr) == 0) {
 			entry->index = map->hrIndex;
 			map->entry_p = entry;
 			break;
@@ -79,7 +79,8 @@
 			return (NULL);
 		}
 		map->hrIndex = hrState_g.next_hrStorage_index ++;
-		strncpy(map->a_name, entry->descr, sizeof(map->a_name) - 1);
+		strncpy((char *)map->a_name, (char *)entry->descr, 
+			sizeof(map->a_name) - 1);
 		map->entry_p = entry;
 		STAILQ_INSERT_TAIL(&hrState_g.storage_name_map, map, link);
 		HR_DPRINTF((stderr, "%s  added into hrStorageMap at index=%d\n ", name, map->hrIndex));
@@ -118,7 +119,8 @@
 	struct hrStorageTblEntry *entry =  NULL;
 
 	TAILQ_FOREACH(entry, &hrState_g.hr_storage_tbl, link)
-		if (strncmp(entry->descr, name, sizeof(entry->descr) - 1) == 0)
+		if (strncmp((const char*)entry->descr, name, 
+			sizeof(entry->descr) - 1) == 0)
 			return (entry);
 	return (NULL);
 }
@@ -146,7 +148,7 @@
 void hrStorage_OS_get_vm_v(void) {
 	/*FIX ME*/
 	int mib[2] = { CTL_VM, VM_TOTAL };
-	int len = sizeof(hrState_g.mem_stats);
+	size_t len = sizeof(hrState_g.mem_stats);
 	int page_size_bytes;
 	struct hrStorageTblEntry *entry = NULL;
 	if ( sysctl(mib, 2, &hrState_g.mem_stats, &len, NULL, 0) < 0 ) {
@@ -197,12 +199,13 @@
 static
 void hrStorage_OS_get_swap_v(void) {
         int nswapdev = 0;
-	int len  = sizeof(nswapdev);
+	size_t len  = sizeof(nswapdev);
 	struct hrStorageTblEntry *entry;
 	char swap_w_prefix[255+1];
 	
-	if ( sysctlbyname("vm.nswapdev", &nswapdev,&len, NULL,0 ) < 0 ) {
-		syslog(LOG_ERR, "hrStorageTable: sysctlbyname(\"vm.nswapdev\") failed. %m \n");
+	if ( sysctlbyname("vm.nswapdev", &nswapdev, &len, NULL,0 ) < 0 ) {
+		syslog(LOG_ERR, 
+		"hrStorageTable: sysctlbyname(\"vm.nswapdev\") failed. %m \n");
 		assert(0);
 		return;
 	}
@@ -235,9 +238,9 @@
 	
 
 	
-	for (len = 0; len < nswapdev; len++ ) {
+	for (len = 0; len < (size_t)nswapdev; len++ ) {
 		memset(&swap_w_prefix[0], '\0', sizeof(swap_w_prefix) );
-		snprintf(swap_w_prefix, sizeof(swap_w_prefix) - 1, 
+		(void)snprintf(swap_w_prefix, sizeof(swap_w_prefix) - 1, 
 			"Swap:%s%s", _PATH_DEV, hrState_g.swap_devs[len].ksw_devname);
 		entry = hrStorageTblEntry_find_by_name(swap_w_prefix);
 		if (entry != NULL) {
@@ -353,7 +356,9 @@
 		
 		
 		memset(&fs_string[0], '\0', sizeof(fs_string) );
-		snprintf(fs_string, sizeof(fs_string) - 1, "%s, type: %s, dev: %s", hrState_g.fs_buf[i].f_mntonname, 
+		(void)snprintf(fs_string, sizeof(fs_string) - 1, 
+			"%s, type: %s, dev: %s", 
+			hrState_g.fs_buf[i].f_mntonname, 
 			hrState_g.fs_buf[i].f_fstypename,
 			hrState_g.fs_buf[i].f_mntfromname);
 		

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swinstalled_tbl.c#3 (text+ko) ====

@@ -32,7 +32,6 @@
 #include "hostres_snmp.h"
 #include "hostres_oid.h"
 #include "hostres_tree.h"
-#include <sys/types.h>
 #include <sys/sysctl.h>
 #include <stdlib.h>
 #include <assert.h>
@@ -41,7 +40,6 @@
 #include <err.h>
 #include <sys/utsname.h>
 #include <sys/stat.h>
-#include <sys/syslimits.h>
 #include <dirent.h>
 
 extern
@@ -58,10 +56,13 @@
 		return (NULL);
 	}
 	memset(entry, 0, sizeof(*entry));
-	strncpy(entry->name, name, sizeof(entry->name)-1);
+	strncpy((char*)entry->name, name, sizeof(entry->name)-1);
 
 	STAILQ_FOREACH(map, &hrState_g.sw_installed_name_map, link)
-		if (strncmp(map->name, entry->name, sizeof(map->name) - 1) == 0) {
+		if (strncmp((const char*)map->name, 
+			(const char*)entry->name, 
+			sizeof(map->name) - 1) == 0) {
+			
 			entry->index = map->hrIndex;
 			map->entry_p = entry;
 			break;
@@ -81,7 +82,7 @@
 		}
 		map->hrIndex = hrState_g.next_hrSWInstalled_index ++;
 		map->name[sizeof(map->name)-1]='\0';
-		strncpy(map->name, entry->name, sizeof(map->name) - 1);
+		strncpy((char *)map->name, (const char *)entry->name, sizeof(map->name) - 1);
 		map->entry_p = entry;
 		STAILQ_INSERT_TAIL(&hrState_g.sw_installed_name_map, map, link);
 		HR_DPRINTF((stderr, "%s  added into hrSWInstalled at index=%d\n ", 
@@ -121,7 +122,9 @@
 	struct hrSWInstalledTblEntry *entry =  NULL;
 
 	TAILQ_FOREACH(entry, &hrState_g.hr_sw_installed_tbl, link)
-		if (strncmp(entry->name, name, sizeof(entry->name) - 1) == 0)
+		if (strncmp((const char*)entry->name, name, 
+			sizeof(entry->name) - 1) == 0)
+			
 			return (entry);
 	return (NULL);
 }
@@ -175,7 +178,7 @@
 		return;
 	}
 	
-	snprintf(os_string, sizeof(os_string) - 1, "%s: %s", 
+	(void)snprintf(os_string, sizeof(os_string) - 1, "%s: %s", 
 		os_id.sysname, os_id.version);
 	
 	entry = hrSWInstalledTblEntry_find_by_name(os_string);		
@@ -189,7 +192,7 @@
 			
 			entry->flags |= (HR_SWINSTALLED_FOUND | HR_SWINSTALLED_IMMUTABLE);
 			entry->id = oid_zeroDotZero;
-			entry->type= SWI_OPERATING_SYSTEM;
+			entry->type = (int32_t)SWI_OPERATING_SYSTEM;
 			memset(&entry->date[0], 0, sizeof(entry->date));
 			
 			(void)OS_getSystemInitialLoadParameters();
@@ -232,7 +235,8 @@
 #define LOG_DIR         (getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : DEF_LOG_DIR)
 #define CONTENTS_FNAME          "+CONTENTS"
 
-	char 	pkg_dir[PATH_MAX]; /*1024, for sure it's too much for this situation*/
+	char 	pkg_dir[PATH_MAX]; /*1024, for sure it's too much f
+					or this situation*/
 	struct stat sb;
 	DIR *p_dir = NULL;	
 	struct dirent dir_entry;
@@ -243,18 +247,22 @@
 	memset(&pkg_dir[0], 0, sizeof(pkg_dir));
 	memset(&sb, 0, sizeof(sb));
 	
-	snprintf(pkg_dir, sizeof(pkg_dir) - 1, "%s", LOG_DIR);
+	(void)snprintf(pkg_dir, sizeof(pkg_dir) - 1, "%s", LOG_DIR);
 	if (stat(pkg_dir, &sb) != 0) {
-		syslog(LOG_ERR, "hrSWInstalledTable: stat(\"%s\") failed: %m ", pkg_dir);
+		syslog(LOG_ERR, 
+		"hrSWInstalledTable: stat(\"%s\") failed: %m ", pkg_dir);
 		return;
 	}
 	if (!S_ISDIR(sb.st_mode)) {
-		syslog(LOG_ERR, "hrSWInstalledTable: \"%s\" is not a directory! ", pkg_dir);
+		syslog(LOG_ERR, 
+		"hrSWInstalledTable: \"%s\" is not a directory! ", pkg_dir);
 		return;
 	}
 	if (sb.st_ctime <= hrState_g.os_pkg_last_change) {
-		HR_DPRINTF((stderr, "%s: no need to rescan installed packages, directory time-stamp unmodified \n ",
-			__func__));
+		HR_DPRINTF((stderr, 
+		 "%s: no need to rescan installed packages, directory time-stamp unmodified \n ",
+		 __func__));
+		 
 		TAILQ_FOREACH(entry, &hrState_g.hr_sw_installed_tbl, link)
 			entry->flags |= HR_SWINSTALLED_FOUND;			
 		return;
@@ -286,7 +294,7 @@
       		
       		
       		
-      		snprintf(pkg_file, sizeof(pkg_file) - 1, "%s/%s/%s",
+      		(void)snprintf(pkg_file, sizeof(pkg_file) - 1, "%s/%s/%s",
       		 		 pkg_dir,
       		 		 dir_entry.d_name, 
       		 		 CONTENTS_FNAME);
@@ -317,10 +325,11 @@
 			
 		entry->flags |= HR_SWINSTALLED_FOUND;
 		entry->id = oid_zeroDotZero;
-		entry->type= SWI_APPLICATION;
+		entry->type = (int32_t)SWI_APPLICATION;
 		memset(&entry->date[0], 0, sizeof(entry->date));
 			
-		snprintf(pkg_file, sizeof(pkg_file) - 1, "%s/%s", pkg_dir, dir_entry.d_name);
+		(void)snprintf(pkg_file, sizeof(pkg_file) - 1, "%s/%s", 
+			pkg_dir, dir_entry.d_name);
 			
 	
 		if(stat(pkg_file, &sb) == 0) {
@@ -352,7 +361,8 @@
         }/*end for*/
      	
 	if (return_code != 0) {
-		syslog(LOG_ERR, "hrSWInstalledTable: readdir_r(\"%s\") failed: %m ", pkg_dir);
+		syslog(LOG_ERR, 
+		"hrSWInstalledTable: readdir_r(\"%s\") failed: %m ", pkg_dir);
 	} else {
 		/*save the timestamp of directory
 	 	to avoid any further scanning*/
@@ -361,7 +371,10 @@
 	
 PKG_LOOP_END:
 	if ( p_dir != NULL ) {
-		closedir(p_dir);
+		if (closedir(p_dir) != 0) {
+		  syslog(LOG_ERR, 
+		 "hrSWInstalledTable: closedir failed: %m ");
+		}
 	}
 	
 


More information about the p4-projects mailing list