Package: linuxinfo / 1.1.8-34

10_linuxinfo-option-handling Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Description: Add standard options and improve output on already present 
#  options
#  Fail if /proc/cpuinfo is unreadable and support > 9 CPUs
# Author: Erick Kinnee <cerb@debian.org>
# Author: Helge Kreutzmann <debian@helgefjell.de>
# Last-Update: 2006-07-30

Index: linuxinfo-1.1.8-29/linuxinfo.c
===================================================================
--- linuxinfo-1.1.8-29.orig/linuxinfo.c	2010-02-01 21:27:32.780064347 +0100
+++ linuxinfo-1.1.8-29/linuxinfo.c	2010-02-01 21:27:00.668550000 +0100
@@ -20,7 +20,11 @@
 	1.1.4	AIB	1999????	Added -v for versioning
 	1.1.6	AIB	20000405	Updates & changes to linuxinfo
 	1.1.7	AIB	20000406	Changed to file descriptors
-	
+
+	1.1.8   KRE     20051118        Include <string.h>
+        1.1.9   KRE     20060730        Support more than 9 CPUs and bail out
+                                        if /proc/cpuinfo is unreadable
+
 	Modelled on Vince Weaver's Linux_logo 2.10
 	
 	Prints out a line of information about your system.
@@ -32,12 +36,13 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <string.h>
 
 #include "linuxinfo.h"
 
 int main(int argc, char *argv[])
 {
-	char ordinals[10][10] = { "Unknown", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };
+	char ordinals[13][10] = { "Unknown", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve" };
 
 	struct os_stat os;
 	struct hw_stat hw;
@@ -47,29 +52,55 @@
 
 	if (argc > 1)
 	{
-		if (strcmp(argv[1], "-v") == 0)
+		if (strcmp(argv[1], ("-v")) == 0)
 		{
 			printf("%s %s\n", argv[0], VERSION);
-			return -1;
+			return 0;
 		}
+		if (strcmp(argv[1], ("-h")) == 0)
+		{
+			printf("%s %s\n", argv[0], VERSION);
+			printf(" -h   print this help\n");
+	    printf(" -v   print linuxinfo version\n");
+			return 0;
+		}
+		
 		cpuinfo_fd = open(argv[1], O_RDONLY);
+                if (cpuinfo_fd < 0)
+		{
+                    fprintf(stderr,"Unsupported option or file %s not found.\n",argv[1]);
+                    return -1;
+		}
 	}
 	else
+	{
 		cpuinfo_fd = open(CPUINFO_FILE, O_RDONLY);
+                if (cpuinfo_fd < 0)
+		{
+                    fprintf(stderr,"Could not open %s.\n",CPUINFO_FILE);
+                    return -2;
+		}
+	}
 
 	GetOperatingSystemInfo(&os);
 	GetHardwareInfo(cpuinfo_fd, &hw);
 	GetSystemLibcInfo(&lib);
 
 	printf("%s %s %s %s\n", os.os_name, os.os_hostname, os.os_version, os.os_revision);
+	if (hw.hw_processors > 12)
+	{
+	    printf("%i %s ", hw.hw_processors, hw.hw_cpuinfo);
+	}
+	else
+	{
+	    printf("%s %s ", ordinals[hw.hw_processors], hw.hw_cpuinfo);
+	}
 
 	if (strncmp(hw.hw_megahertz, "?", strlen("?")) == 0)
-		printf("%s %s processor%s, %s total bogomips, %sM RAM\n", ordinals[hw.hw_processors], \
-			hw.hw_cpuinfo, (hw.hw_processors > 1) ? "s" : "", hw.hw_bogomips, hw.hw_memory);
+		printf("processor%s, %s total bogomips, %sM RAM\n", (hw.hw_processors > 1) ? "s" : "", hw.hw_bogomips, hw.hw_memory);
 	else
 	{
-		printf("%s %s %sMHz processor%s, %s total bogomips, %sM RAM\n", ordinals[hw.hw_processors], \
-			hw.hw_cpuinfo, hw.hw_megahertz, (hw.hw_processors > 1) ? "s" : "", hw.hw_bogomips, hw.hw_memory);
+		printf("%sMHz processor%s, %s total bogomips, %sM RAM\n", hw.hw_megahertz, (hw.hw_processors > 1) ? "s" : "", hw.hw_bogomips, hw.hw_memory);
 	}
 	printf("System library %s\n", lib.lib_version);