Blame numactl-2.0.3-rc3-distance_parsing.patch

Neil Horman 8749d6
diff -up numactl-2.0.3-rc3/distance.c.orig numactl-2.0.3-rc3/distance.c
Neil Horman 8749d6
--- numactl-2.0.3-rc3/distance.c.orig	2009-05-08 10:10:06.000000000 -0400
Neil Horman 8749d6
+++ numactl-2.0.3-rc3/distance.c	2009-05-08 10:13:01.000000000 -0400
Neil Horman 8749d6
@@ -50,6 +50,7 @@ static int read_distance_table(void) 
Neil Horman 8749d6
 	int numnodes = 0; 
Neil Horman 8749d6
 	int *table = NULL; 
Neil Horman 8749d6
 	int err = -1;
Neil Horman 8749d6
+	int found_nodes = 0;
Neil Horman 8749d6
 	
Neil Horman 8749d6
 	for (nd = 0;; nd++) { 
Neil Horman 8749d6
 		char fn[100]; 
Neil Horman 8749d6
@@ -57,7 +58,7 @@ static int read_distance_table(void) 
Neil Horman 8749d6
 		sprintf(fn, "/sys/devices/system/node/node%d/distance", nd);
Neil Horman 8749d6
 		dfh = fopen(fn, "r"); 
Neil Horman 8749d6
 		if (!dfh) { 
Neil Horman 8749d6
-			if (errno == ENOENT && nd > 0)
Neil Horman 8749d6
+			if (errno == ENOENT)
Neil Horman 8749d6
 				err = 0;
Neil Horman 8749d6
 			if (!err && nd
Neil Horman 8749d6
 				continue;
Neil Horman 8749d6
@@ -79,14 +80,15 @@ static int read_distance_table(void) 
Neil Horman 8749d6
 		} 
Neil Horman 8749d6
 
Neil Horman 8749d6
 		parse_numbers(line, table + nd * numnodes, numnodes);
Neil Horman 8749d6
+		found_nodes++;
Neil Horman 8749d6
 	}
Neil Horman 8749d6
 	free(line); 
Neil Horman 8749d6
-	if (err)  { 
Neil Horman 8749d6
+	if (!found_nodes)  { 
Neil Horman 8749d6
 		numa_warn(W_distance,
Neil Horman 8749d6
 			  "Cannot parse distance information in sysfs: %s",
Neil Horman 8749d6
 			  strerror(errno));
Neil Horman 8749d6
 		free(table); 
Neil Horman 8749d6
-		return err;
Neil Horman 8749d6
+		return -1;
Neil Horman 8749d6
 	}
Neil Horman 8749d6
 	/* Update the global table pointer.  Race window here with
Neil Horman 8749d6
 	   other threads, but in the worst case we leak one distance