~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to client/cs_platforms.cpp

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "boinc_win.h"
25
25
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
26
26
LPFN_ISWOW64PROCESS fnIsWow64Process;
27
 
#endif
28
 
 
29
 
#ifndef _WIN32
 
27
#else
30
28
#include "config.h"
31
 
#include <stdio.h>
32
 
#ifdef HAVE_SIGNAL_H
 
29
#include <cstdio>
 
30
#include <cstdlib>
33
31
#include <signal.h>
34
 
#endif
35
32
#ifdef HAVE_UNISTD_H
36
33
#include <unistd.h>
37
34
#endif
47
44
#include "client_state.h"
48
45
#include "error_numbers.h"
49
46
#include "log_flags.h"
 
47
#include "filesys.h"
50
48
#include "str_util.h"
 
49
#include "str_replace.h"
51
50
#include "util.h"
52
51
 
 
52
#if (defined (__APPLE__) && (defined(__i386__) || defined(__x86_64__)))
 
53
#include <sys/sysctl.h>
 
54
#include <Carbon/Carbon.h>
 
55
 
 
56
char *HOSTTYPE = "";
 
57
#endif
53
58
 
54
59
// return the primary platform id.
55
60
//
93
98
#endif
94
99
 
95
100
#elif defined(__APPLE__)
96
 
#if defined(__x86_64__)
97
 
    add_platform("x86_64-apple-darwin");
98
 
#endif
99
101
 
100
102
#if defined(__i386__) || defined(__x86_64__)
101
 
    // Supported on both Mac Intel architectures
 
103
    OSStatus err = noErr;
 
104
    SInt32 version = 0;
 
105
    int response = 0;
 
106
    int retval = 0;
 
107
    size_t len = sizeof(response);
 
108
 
 
109
    err = Gestalt(gestaltSystemVersion, &version);
 
110
    retval = sysctlbyname("hw.optional.x86_64", &response, &len, NULL, 0);
 
111
    if ((err == noErr) && (version >= 0x1050) && response && (!retval)) {
 
112
        HOSTTYPE = "x86_64-apple-darwin";
 
113
        add_platform("x86_64-apple-darwin");
 
114
    } else {
 
115
        HOSTTYPE = "i686-apple-darwin";
 
116
    }
 
117
 
 
118
    // Supported on both Mac Intel architectures    
102
119
    add_platform("i686-apple-darwin");
103
120
#endif
104
121
    // Supported on all 3 Mac architectures
105
122
    add_platform("powerpc-apple-darwin");
 
123
 
 
124
#elif defined(__linux__) && ( defined(__i386__) || defined(__x86_64__) )
 
125
    // Let's try to support both 32 and 64 bit applications in one client
 
126
    // regardless of whether it is a 32 or 64 bit client
 
127
    const char *uname[]={"/bin/uname","/usr/bin/uname",0};
 
128
    int eno=0, support64=0, support32=0;
 
129
    FILE *f;
 
130
    char cmdline[256];
 
131
    cmdline[0]=0;
 
132
 
 
133
    // find the 'uname' executable
 
134
    do {
 
135
        if (boinc_file_exists(uname[eno])) break; 
 
136
    } while (uname[++eno] != 0);
 
137
 
 
138
    // run it and check the kernel machine architecture.
 
139
    if ( uname[eno] != 0 ) {
 
140
        strlcpy(cmdline,uname[eno],256);
 
141
        strlcat(cmdline," -m",256);
 
142
        if ((f=popen(cmdline,"r"))) {
 
143
            while (!std::feof(f)) {
 
144
                fgets(cmdline,256,f);
 
145
                if (strstr(cmdline,"x86_64")) support64=1;
 
146
            }
 
147
            pclose(f);
 
148
        }
 
149
 
 
150
        if (!support64) {
 
151
                // we're running on a 32 bit kernel, so we will assume
 
152
                // we are i686-pc-linux-gnu only.
 
153
                support32=1;
 
154
            } else {
 
155
                // we're running on a 64 bit kernel.
 
156
                // Now comes the hard part.  How to tell whether we can run
 
157
                // 32-bit binaries.
 
158
#if defined(__i386__) && !defined(__x86_64__)
 
159
            // If we're a 32 bit binary, then we obviously can.
 
160
                support32=1;
 
161
#else
 
162
            // If we're a 64 bit binary, the check is a bit harder.
 
163
                // We'll use the file command to check installation of
 
164
                // 32 bit libraries or executables.
 
165
                const char *file[]={"/usr/bin/file","/bin/file",0};
 
166
                const char *libdir[]={"/lib","/lib32","/lib/32","/usr/lib","/usr/lib32","/usr/lib/32"};
 
167
                const int nlibdirs=sizeof(libdir)/sizeof(char *);
 
168
            
 
169
            // find 'file'
 
170
            eno=0;
 
171
            do {
 
172
                if (boinc_file_exists(file[eno])) break; 
 
173
            } while (file[++eno] != 0);
 
174
            
 
175
            // now try to find a 32-bit C library.
 
176
                if (file[eno] != 0) {
 
177
                    int i;
 
178
                    for (i=0; i < nlibdirs; i++) {
 
179
                        struct dirent *entry;
 
180
                        DIR *a = opendir(libdir[i]);
 
181
                    // if dir doesn't exist, do to the next one
 
182
                    if (a == 0) continue;
 
183
                    // dir exists. read each entry until you find a 32bit lib
 
184
                    while ((support32 == 0) && ((entry=readdir(a)) != 0)) {
 
185
                        strlcpy(cmdline, file[eno], 256);
 
186
                        strlcat(cmdline, " -L ", 256);
 
187
                        strlcat(cmdline, libdir[i], 256);
 
188
                        strlcat(cmdline, "/", 256);
 
189
                        strlcat(cmdline, entry->d_name, 256);
 
190
                        f = popen(cmdline, "r");
 
191
                        if (f) {
 
192
                            while (!std::feof(f)) {
 
193
                                    fgets(cmdline,256,f);
 
194
                                // If the library is 32-bit ELF, then we're
 
195
                                // golden.
 
196
                                        if (strstr(cmdline, "ELF") && strstr(cmdline, "32-bit")) support32=1;
 
197
                                }
 
198
                                        pclose(f);
 
199
                        }  
 
200
                    }
 
201
                    closedir(a);
 
202
                    if (support32) break;
 
203
                }
 
204
                }
 
205
#endif
 
206
        }
 
207
    }
 
208
 
 
209
    if (support64) {
 
210
        add_platform("x86_64-pc-linux-gnu");
 
211
    }
 
212
    if (support32) {
 
213
        add_platform("i686-pc-linux-gnu");
 
214
    }
 
215
 
 
216
    if (!(support64 || support32)) {
 
217
        // Something went wrong. Assume HOSTTYPE and HOSTTYPEALT
 
218
        // are correct
 
219
        add_platform(HOSTTYPE);
 
220
#ifdef HOSTTYPEALT
 
221
        add_platform(HOSTTYPEALT);
 
222
#endif
 
223
    }
 
224
 
106
225
#elif defined(sun)
107
 
    // Check if we can run 64 bit binaries...
 
226
    // Check if we can run 64-bit binaries...
 
227
    // this assumes there isn't a 64-bit only solaris.  (Every 64-bit solaris can run 32 bit binaries)
108
228
 
109
229
#if defined(__sparc) || defined(sparc)
110
 
    FILE *f=fopen("/usr/bin/sparcv9/ls","r");
 
230
    char *exe64=const_cast<char *>("/usr/bin/sparcv9/ls");
 
231
    char *platform64=const_cast<char *>("sparc64-sun-solaris");
 
232
    char *platform32=const_cast<char *>("sparc-sun-solaris");
 
233
#elif defined(__i386) || defined(i386) || defined(__amd64) || defined(__x86_64__)
 
234
    char *exe64=const_cast<char *>("/usr/bin/amd64/ls");
 
235
    char *platform64=const_cast<char *>("x86_64-pc-solaris");
 
236
    char *platform32=const_cast<char *>("i686-pc-solaris");
 
237
#else
 
238
#define UNKNOWN_SOLARIS_PROCESSOR
 
239
#endif
 
240
 
 
241
#ifndef UNKNOWN_SOLARIS_PROCESSOR
 
242
    FILE *f=fopen(exe64,"r"); 
111
243
    char *argv[3];
112
244
    pid_t pid;
113
245
    int rv=0;
114
 
    argv[0]="/usr/bin/sparcv9/ls";
 
246
    argv[0]=exe64;
115
247
    argv[1]=argv[0];
116
248
    argv[2]=NULL;
117
249
    if (f) {
138
270
            }
139
271
            // if we exited with success add the 64 bit platform
140
272
            if ((done == pid) && (rv == 0)) {
141
 
               add_platform("sparc64-sun-solaris");
 
273
               add_platform(platform64);
142
274
            }
143
275
        }
144
276
    }
145
 
    add_platform("sparc-sun-solaris");
 
277
    add_platform(platform32);
146
278
    // the following platform is obsolete, but we'll add it anyway.
 
279
#if defined(__sparc) || defined(sparc) 
147
280
    add_platform("sparc-sun-solaris2.7");
148
 
#else // defined sparc
 
281
#endif
 
282
#else  // !defined(UNKNOWN_SOLARIS_PROCESSOR)
 
283
 
149
284
    add_platform(HOSTTYPE);
150
285
#ifdef HOSTTYPEALT
151
286
    add_platform(HOSTTYPEALT);
152
287
#endif
153
 
#endif // else defined sparc      
154
 
 
155
 
#else
 
288
 
 
289
#endif  // !defined(UNKNOWN_SOLARIS_PROCESSOR)
 
290
 
 
291
#else                   
 
292
 
156
293
    // Any other platform, fall back to the previous method
157
294
    add_platform(HOSTTYPE);
158
295
#ifdef HOSTTYPEALT