~ubuntu-branches/ubuntu/lucid/boinc/lucid-backports

« back to all changes in this revision

Viewing changes to client/hostinfo_unix_test.C

  • Committer: Bazaar Package Importer
  • Author(s): Rene Mayorga
  • Date: 2009-05-23 13:29:17 UTC
  • mfrom: (1.3.1 upstream) (9.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090523132917-3rvmkmkxbw17181o
Tags: 6.4.5+dfsg-2
* Uploaded to unstable
* Include a patch picked from Upstream SVN
   to avoid FTBFSs whith gcc 4.4 (Closes: #526666)
* remove CUDA dir that contais binary-only non DFSG software
* change section from boinc-dbg to debug
* set orig +dfsg since we remove non-dfsg software 
  when we pull the tag from upstream
  + Add Comments about this on README.Source
* Move schedtool to Recommends, (Closes: #532133)
* Add ru debconf templates translation, thanks
  to Yuri Kozlov <yuray@komyakino.ru> (Closes: #531205)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <stdio.h>
2
 
#include <string.h>
3
 
 
4
 
#define false 0
5
 
#define true 1
6
 
#define bool int
7
 
#define strlcpy strncpy
8
 
 
9
 
int main(void)
10
 
{
11
 
    char buf[256], features[1024], model_buf[1024];
12
 
    bool vendor_found=false, model_found=false;
13
 
    bool cache_found=false, features_found=false;
14
 
    bool icache_found=false,dcache_found=false;
15
 
    bool model_hack=false, vendor_hack=false;
16
 
    int n;
17
 
    int family=-1, model=-1, stepping=-1;
18
 
    char  p_vendor[256], p_model[256];
19
 
    char buf2[256];
20
 
    int m_cache=-1;
21
 
 
22
 
 
23
 
    FILE* f = fopen("/proc/cpuinfo", "r");
24
 
    if (!f) return;
25
 
 
26
 
#ifdef __mips__
27
 
    strcpy(p_model, "MIPS ");
28
 
    model_hack = true;
29
 
#elif __alpha__
30
 
    strcpy(p_vendor, "HP (DEC) ");
31
 
    vendor_hack = true;
32
 
#elif __hppa__
33
 
    strcpy(p_vendor, "HP ");
34
 
    vendor_hack = true;
35
 
#elif __ia64__
36
 
    strcpy(p_model, "IA-64 ");
37
 
    model_hack = true;
38
 
#endif
39
 
 
40
 
    strcpy(features, "");
41
 
    while (fgets(buf, 256, f)) {
42
 
        //strip_whitespace(buf);
43
 
        if (
44
 
                /* there might be conflicts if we dont #ifdef */
45
 
#ifdef __ia64__
46
 
                strstr(buf, "vendor     : ")
47
 
#elif __hppa__          
48
 
                strstr(buf, "cpu\t\t: ")
49
 
#elif __powerpc__
50
 
                strstr(buf, "machine\t\t: ")
51
 
#elif __sparc__
52
 
                strstr(buf, "type\t\t: ")
53
 
#elif __alpha__
54
 
                strstr(buf, "cpu\t\t\t: ")
55
 
#else
56
 
        strstr(buf, "vendor_id\t: ") || strstr(buf, "system type\t\t: ")
57
 
#endif
58
 
                ) {
59
 
            if (!vendor_hack && !vendor_found) {
60
 
                vendor_found = true;
61
 
                strlcpy(p_vendor, strchr(buf, ':') + 2, sizeof(p_vendor));
62
 
            } else if (!vendor_found) {
63
 
                vendor_found = true;
64
 
                strlcpy(buf2, strchr(buf, ':') + 2, sizeof(p_vendor) - strlen(p_vendor) - 1);
65
 
                strcat(p_vendor, buf2);
66
 
            }
67
 
        }
68
 
 
69
 
        if (
70
 
#ifdef __ia64__
71
 
                strstr(buf, "family     : ") || strstr(buf, "model name : ")
72
 
#elif __powerpc__ || __sparc__
73
 
                strstr(buf, "cpu\t\t: ")
74
 
#else
75
 
        strstr(buf, "model name\t: ") || strstr(buf, "cpu model\t\t: ")
76
 
#endif
77
 
                ) {
78
 
            if (!model_hack && !model_found) {
79
 
                model_found = true;
80
 
#ifdef __powerpc__
81
 
            char *coma = NULL;
82
 
            if ((coma = strrchr(buf, ','))) {   /* we have ", altivec supported" */
83
 
                *coma = '\0';   /* strip the unwanted line */
84
 
                strcpy(features, "altivec");
85
 
                features_found = true;
86
 
            }
87
 
#endif
88
 
                strlcpy(p_model, strchr(buf, ':') + 2, sizeof(p_model));
89
 
            } else if (!model_found) {
90
 
#ifdef __ia64__
91
 
                /* depending on kernel version, family can be either
92
 
                a number or a string. If number, we have a model name,
93
 
                else we don't */
94
 
                char *testc = NULL;
95
 
                testc = strrchr(buf, ':')+2;
96
 
                if (isdigit(*testc)) {
97
 
                        family = atoi(testc);
98
 
                        continue;       /* skip this line */
99
 
                }
100
 
#endif
101
 
                model_found = true;
102
 
                strlcpy(buf2, strchr(buf, ':') + 2, sizeof(p_model) - strlen(p_model) - 1);
103
 
                strcat(p_model, buf2);
104
 
            }           
105
 
        }
106
 
 
107
 
#ifndef __hppa__
108
 
        /* XXX: hppa: "cpu family       : PA-RISC 2.0" */
109
 
        if (strstr(buf, "cpu family\t: ") && family<0) {
110
 
                family = atoi(buf+strlen("cpu family\t: "));
111
 
        }
112
 
        /* XXX: hppa: "model            : 9000/785/J6000" */
113
 
        if (strstr(buf, "model\t\t: ") && model<0) {
114
 
            model = atoi(buf+strlen("model\t\t: "));
115
 
        }
116
 
        /* ia64 */
117
 
        if (strstr(buf, "model      : ") && model<0) {
118
 
            model = atoi(buf+strlen("model     : "));
119
 
        }
120
 
#endif
121
 
        if (strstr(buf, "stepping\t: ") && stepping<0) {
122
 
            stepping = atoi(buf+strlen("stepping\t: "));
123
 
        }
124
 
#ifdef __hppa__
125
 
        if (!icache_found && strstr(buf, "I-cache\t\t: ")) {
126
 
            icache_found = true;
127
 
            sscanf(buf, "I-cache\t\t: %d", &n);
128
 
            m_cache += n*1024;
129
 
        }
130
 
        if (!dcache_found && strstr(buf, "D-cache\t\t: ")) {
131
 
            dcache_found = true;
132
 
            sscanf(buf, "D-cache\t\t: %d", &n);
133
 
            m_cache += n*1024;
134
 
        }
135
 
#elif __powerpc__
136
 
        if (!cache_found && strstr(buf, "L2 cache\t: ")) {
137
 
            cache_found = true;
138
 
            sscanf(buf, "L2 cache\t: %d", &n);
139
 
            m_cache = n*1024;
140
 
        }
141
 
#else
142
 
        if (!cache_found && (strstr(buf, "cache size\t: ") == buf)) {
143
 
            cache_found = true;
144
 
            sscanf(buf, "cache size\t: %d", &n);
145
 
            m_cache = n*1024;
146
 
        }
147
 
#endif
148
 
        if (!features_found) {
149
 
            // Some versions of the linux kernel call them flags,
150
 
            // others call them features, so look for both.
151
 
            if ((strstr(buf, "flags\t\t: ") == buf)) {
152
 
                strlcpy(features, strchr(buf, ':') + 2, sizeof(features));
153
 
            } else if ((strstr(buf, "features\t\t: ") == buf)) {
154
 
                strlcpy(features, strchr(buf, ':') + 2, sizeof(features));
155
 
            } else if ((strstr(buf, "features   : ") == buf)) { /* ia64 */
156
 
                strlcpy(features, strchr(buf, ':') + 2, sizeof(features));
157
 
            }
158
 
            if (strlen(features)) {
159
 
                features_found = true;
160
 
            }
161
 
        }
162
 
    }
163
 
    strcpy(model_buf, p_model);
164
 
    if (family>=0 || model>=0 || stepping>0) {
165
 
        strcat(model_buf, " [");
166
 
        if (family>=0) {
167
 
            sprintf(buf, "Family %d ", family);
168
 
            strcat(model_buf, buf);
169
 
        }
170
 
        if (model>=0) {
171
 
            sprintf(buf, "Model %d ", model);
172
 
            strcat(model_buf, buf);
173
 
        }
174
 
        if (stepping>=0) {
175
 
            sprintf(buf, "Stepping %d", stepping);
176
 
            strcat(model_buf, buf);
177
 
        }
178
 
        strcat(model_buf, "]");
179
 
    }
180
 
    if (strlen(features)) {
181
 
        strcat(model_buf, "[");
182
 
        strcat(model_buf, features);
183
 
        strcat(model_buf, "]");
184
 
    }
185
 
 
186
 
 
187
 
    printf("p_vendor: %s\nm_cache: %d\nmodel_buf: %s\n", p_vendor, m_cache, model_buf);
188
 
    return 0;
189
 
}