2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2007-10-24 00:44:42 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2007-10-24 00:44:42 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2007-10-24 00:44:42 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2007-10-24 00:44:42 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-24 00:44:42 +00:00
|
|
|
|
|
|
|
// Determine which platforms are supported and provide a way
|
|
|
|
// of exposing that information to the rest of the client.
|
|
|
|
|
|
|
|
#include "cpp.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
2008-11-25 19:04:27 +00:00
|
|
|
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
|
|
|
|
LPFN_ISWOW64PROCESS fnIsWow64Process;
|
2010-05-11 19:10:29 +00:00
|
|
|
#else
|
2007-10-24 00:44:42 +00:00
|
|
|
#include "config.h"
|
2009-02-26 00:23:23 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
2008-07-08 23:51:54 +00:00
|
|
|
#include <signal.h>
|
2011-09-27 19:45:27 +00:00
|
|
|
#if HAVE_UNISTD_H
|
2008-07-08 23:51:54 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2011-09-27 19:45:27 +00:00
|
|
|
#if HAVE_SYS_TYPES_H
|
2008-07-08 23:51:54 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
2011-09-27 19:45:27 +00:00
|
|
|
#if HAVE_SYS_WAIT_H
|
2008-07-08 23:51:54 +00:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
2007-10-24 00:44:42 +00:00
|
|
|
#endif
|
|
|
|
|
2011-09-27 19:45:27 +00:00
|
|
|
#if defined(__APPLE__) && (defined(__i386__) || defined(__x86_64__))
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#endif
|
|
|
|
|
2007-10-24 00:44:42 +00:00
|
|
|
#include "error_numbers.h"
|
2009-03-17 18:41:35 +00:00
|
|
|
#include "filesys.h"
|
2007-10-24 00:44:42 +00:00
|
|
|
#include "str_util.h"
|
2009-06-16 20:54:44 +00:00
|
|
|
#include "str_replace.h"
|
2007-10-24 00:44:42 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2012-04-30 21:00:28 +00:00
|
|
|
#include "client_types.h"
|
|
|
|
#include "client_state.h"
|
|
|
|
#include "log_flags.h"
|
|
|
|
#include "project.h"
|
|
|
|
|
2007-10-24 00:44:42 +00:00
|
|
|
// return the primary platform id.
|
|
|
|
//
|
|
|
|
const char* CLIENT_STATE::get_primary_platform() {
|
|
|
|
return platforms[0].name.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// add a platform to the vector.
|
|
|
|
//
|
|
|
|
void CLIENT_STATE::add_platform(const char* platform) {
|
|
|
|
PLATFORM pp;
|
|
|
|
pp.name = platform;
|
|
|
|
platforms.push_back(pp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// determine the list of supported platforms.
|
|
|
|
//
|
|
|
|
void CLIENT_STATE::detect_platforms() {
|
|
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN32__)
|
|
|
|
#if defined(_WIN64) && defined(_M_X64)
|
|
|
|
add_platform("windows_x86_64");
|
|
|
|
add_platform("windows_intelx86");
|
|
|
|
#else
|
2008-11-25 19:04:27 +00:00
|
|
|
// see if 32-bit client is running on 64-bit machine
|
|
|
|
//
|
|
|
|
BOOL bIsWow64 = FALSE;
|
|
|
|
fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
|
|
|
|
GetModuleHandle(TEXT("kernel32")),"IsWow64Process"
|
|
|
|
);
|
|
|
|
if (fnIsWow64Process) {
|
|
|
|
if (fnIsWow64Process(GetCurrentProcess(), &bIsWow64)) {
|
|
|
|
if (bIsWow64) {
|
|
|
|
add_platform("windows_x86_64");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-24 00:44:42 +00:00
|
|
|
add_platform("windows_intelx86");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#elif defined(__APPLE__)
|
2009-02-26 00:23:23 +00:00
|
|
|
|
2014-09-02 10:54:10 +00:00
|
|
|
#ifdef __x86_64__
|
|
|
|
add_platform("x86_64-apple-darwin");
|
2007-10-24 00:44:42 +00:00
|
|
|
add_platform("i686-apple-darwin");
|
2011-04-22 09:21:30 +00:00
|
|
|
#else
|
2014-09-02 10:54:10 +00:00
|
|
|
#error Mac client now requires a 64-bit system
|
2011-04-22 09:21:30 +00:00
|
|
|
#endif
|
2009-02-26 00:23:23 +00:00
|
|
|
|
2009-03-17 18:41:35 +00:00
|
|
|
#elif defined(__linux__) && ( defined(__i386__) || defined(__x86_64__) )
|
|
|
|
// Let's try to support both 32 and 64 bit applications in one client
|
|
|
|
// regardless of whether it is a 32 or 64 bit client
|
|
|
|
const char *uname[]={"/bin/uname","/usr/bin/uname",0};
|
|
|
|
int eno=0, support64=0, support32=0;
|
|
|
|
FILE *f;
|
|
|
|
char cmdline[256];
|
|
|
|
cmdline[0]=0;
|
|
|
|
|
|
|
|
// find the 'uname' executable
|
|
|
|
do {
|
2011-01-06 23:09:13 +00:00
|
|
|
if (boinc_file_exists(uname[eno])) break;
|
2009-03-17 18:41:35 +00:00
|
|
|
} while (uname[++eno] != 0);
|
2009-10-27 03:01:23 +00:00
|
|
|
|
2009-03-17 18:41:35 +00:00
|
|
|
// run it and check the kernel machine architecture.
|
|
|
|
if ( uname[eno] != 0 ) {
|
|
|
|
strlcpy(cmdline,uname[eno],256);
|
|
|
|
strlcat(cmdline," -m",256);
|
|
|
|
if ((f=popen(cmdline,"r"))) {
|
|
|
|
while (!std::feof(f)) {
|
2013-07-09 17:34:32 +00:00
|
|
|
if (!fgets(cmdline,256,f)) break;
|
2009-11-04 16:28:56 +00:00
|
|
|
if (strstr(cmdline,"x86_64")) support64=1;
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
}
|
2009-10-27 03:01:23 +00:00
|
|
|
|
2009-11-04 16:21:52 +00:00
|
|
|
if (!support64) {
|
2011-01-06 23:09:13 +00:00
|
|
|
// we're running on a 32 bit kernel, so we will assume
|
|
|
|
// we are i686-pc-linux-gnu only.
|
|
|
|
support32=1;
|
|
|
|
} else {
|
|
|
|
// we're running on a 64 bit kernel.
|
|
|
|
// Now comes the hard part. How to tell whether we can run
|
|
|
|
// 32-bit binaries.
|
2009-03-17 18:41:35 +00:00
|
|
|
#if defined(__i386__) && !defined(__x86_64__)
|
2009-11-04 16:21:52 +00:00
|
|
|
// If we're a 32 bit binary, then we obviously can.
|
2011-01-06 23:09:13 +00:00
|
|
|
support32=1;
|
2009-03-17 18:41:35 +00:00
|
|
|
#else
|
2009-11-04 16:21:52 +00:00
|
|
|
// If we're a 64 bit binary, the check is a bit harder.
|
2011-01-06 23:09:13 +00:00
|
|
|
// We'll use the file command to check installation of
|
|
|
|
// 32 bit libraries or executables.
|
|
|
|
const char *file[]={"/usr/bin/file","/bin/file",0};
|
|
|
|
const char *libdir[]={"/lib","/lib32","/lib/32","/usr/lib","/usr/lib32","/usr/lib/32"};
|
|
|
|
const int nlibdirs=sizeof(libdir)/sizeof(char *);
|
|
|
|
|
2009-11-04 16:21:52 +00:00
|
|
|
// find 'file'
|
|
|
|
eno=0;
|
|
|
|
do {
|
2011-01-06 23:09:13 +00:00
|
|
|
if (boinc_file_exists(file[eno])) break;
|
2009-11-04 16:21:52 +00:00
|
|
|
} while (file[++eno] != 0);
|
2011-01-06 23:09:13 +00:00
|
|
|
|
2009-11-04 16:21:52 +00:00
|
|
|
// now try to find a 32-bit C library.
|
2011-01-06 23:09:13 +00:00
|
|
|
if (file[eno] != 0) {
|
|
|
|
int i;
|
|
|
|
for (i=0; i < nlibdirs; i++) {
|
|
|
|
struct dirent *entry;
|
|
|
|
DIR *a = opendir(libdir[i]);
|
2013-05-22 20:56:48 +00:00
|
|
|
// if dir doesn't exist, do the next one
|
2009-11-04 16:21:52 +00:00
|
|
|
if (a == 0) continue;
|
|
|
|
// dir exists. read each entry until you find a 32bit lib
|
|
|
|
while ((support32 == 0) && ((entry=readdir(a)) != 0)) {
|
|
|
|
strlcpy(cmdline, file[eno], 256);
|
|
|
|
strlcat(cmdline, " -L ", 256);
|
|
|
|
strlcat(cmdline, libdir[i], 256);
|
|
|
|
strlcat(cmdline, "/", 256);
|
|
|
|
strlcat(cmdline, entry->d_name, 256);
|
|
|
|
f = popen(cmdline, "r");
|
|
|
|
if (f) {
|
|
|
|
while (!std::feof(f)) {
|
2013-07-09 17:34:32 +00:00
|
|
|
if (!fgets(cmdline,256,f)) break;
|
2009-11-04 16:21:52 +00:00
|
|
|
// If the library is 32-bit ELF, then we're
|
|
|
|
// golden.
|
2011-01-06 23:09:13 +00:00
|
|
|
if (strstr(cmdline, "ELF") && strstr(cmdline, "32-bit")) support32=1;
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
}
|
2009-11-04 16:21:52 +00:00
|
|
|
}
|
|
|
|
closedir(a);
|
|
|
|
if (support32) break;
|
2009-10-27 03:01:23 +00:00
|
|
|
}
|
2011-01-06 23:09:13 +00:00
|
|
|
}
|
2009-03-17 18:41:35 +00:00
|
|
|
#endif
|
2009-11-04 16:21:52 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-17 18:41:35 +00:00
|
|
|
|
|
|
|
if (support64) {
|
2009-10-27 03:01:23 +00:00
|
|
|
add_platform("x86_64-pc-linux-gnu");
|
2009-03-17 18:41:35 +00:00
|
|
|
}
|
|
|
|
if (support32) {
|
2009-10-27 03:01:23 +00:00
|
|
|
add_platform("i686-pc-linux-gnu");
|
2009-03-17 18:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(support64 || support32)) {
|
|
|
|
// Something went wrong. Assume HOSTTYPE and HOSTTYPEALT
|
2009-10-27 03:01:23 +00:00
|
|
|
// are correct
|
2009-03-17 18:41:35 +00:00
|
|
|
add_platform(HOSTTYPE);
|
|
|
|
#ifdef HOSTTYPEALT
|
|
|
|
add_platform(HOSTTYPEALT);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-07-08 23:51:54 +00:00
|
|
|
#elif defined(sun)
|
2009-02-26 00:23:23 +00:00
|
|
|
// Check if we can run 64-bit binaries...
|
|
|
|
// this assumes there isn't a 64-bit only solaris. (Every 64-bit solaris can run 32 bit binaries)
|
2008-07-08 23:51:54 +00:00
|
|
|
|
|
|
|
#if defined(__sparc) || defined(sparc)
|
2009-02-26 00:23:23 +00:00
|
|
|
char *exe64=const_cast<char *>("/usr/bin/sparcv9/ls");
|
|
|
|
char *platform64=const_cast<char *>("sparc64-sun-solaris");
|
|
|
|
char *platform32=const_cast<char *>("sparc-sun-solaris");
|
|
|
|
#elif defined(__i386) || defined(i386) || defined(__amd64) || defined(__x86_64__)
|
|
|
|
char *exe64=const_cast<char *>("/usr/bin/amd64/ls");
|
|
|
|
char *platform64=const_cast<char *>("x86_64-pc-solaris");
|
|
|
|
char *platform32=const_cast<char *>("i686-pc-solaris");
|
|
|
|
#else
|
|
|
|
#define UNKNOWN_SOLARIS_PROCESSOR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef UNKNOWN_SOLARIS_PROCESSOR
|
2011-01-06 23:09:13 +00:00
|
|
|
FILE *f=fopen(exe64,"r");
|
2008-07-08 23:51:54 +00:00
|
|
|
char *argv[3];
|
|
|
|
pid_t pid;
|
|
|
|
int rv=0;
|
2009-02-26 00:23:23 +00:00
|
|
|
argv[0]=exe64;
|
2008-07-08 23:51:54 +00:00
|
|
|
argv[1]=argv[0];
|
|
|
|
argv[2]=NULL;
|
|
|
|
if (f) {
|
2008-07-10 21:57:18 +00:00
|
|
|
fclose(f);
|
|
|
|
if (0==(pid=fork())) {
|
|
|
|
// we are in child process
|
|
|
|
freopen("/dev/null","a",stderr);
|
|
|
|
freopen("/dev/null","a",stdout);
|
|
|
|
rv=execv(argv[0],argv);
|
|
|
|
exit(rv);
|
|
|
|
} else {
|
|
|
|
// we are in the parent process.
|
|
|
|
time_t start=time(0);
|
|
|
|
int done;
|
|
|
|
// wait 5 seconds or until the process exits.
|
|
|
|
do {
|
|
|
|
done=waitpid(pid,&rv,WNOHANG);
|
|
|
|
sleep(1);
|
|
|
|
} while (!done && ((time(0)-start)<5));
|
2011-01-06 23:09:13 +00:00
|
|
|
// if we timed out, kill the process
|
2008-07-10 21:57:18 +00:00
|
|
|
if ((time(0)-start)>=5) {
|
2011-01-06 23:09:13 +00:00
|
|
|
kill(pid,SIGKILL);
|
2008-07-10 21:57:18 +00:00
|
|
|
done=-1;
|
|
|
|
}
|
|
|
|
// if we exited with success add the 64 bit platform
|
|
|
|
if ((done == pid) && (rv == 0)) {
|
2009-02-26 00:23:23 +00:00
|
|
|
add_platform(platform64);
|
2008-07-10 21:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-08 23:51:54 +00:00
|
|
|
}
|
2009-02-26 00:23:23 +00:00
|
|
|
add_platform(platform32);
|
2008-07-08 23:51:54 +00:00
|
|
|
// the following platform is obsolete, but we'll add it anyway.
|
2011-01-06 23:09:13 +00:00
|
|
|
#if defined(__sparc) || defined(sparc)
|
2008-07-08 23:51:54 +00:00
|
|
|
add_platform("sparc-sun-solaris2.7");
|
2009-02-26 00:23:23 +00:00
|
|
|
#endif
|
|
|
|
#else // !defined(UNKNOWN_SOLARIS_PROCESSOR)
|
|
|
|
|
2008-07-08 23:51:54 +00:00
|
|
|
add_platform(HOSTTYPE);
|
|
|
|
#ifdef HOSTTYPEALT
|
|
|
|
add_platform(HOSTTYPEALT);
|
|
|
|
#endif
|
|
|
|
|
2009-02-26 00:23:23 +00:00
|
|
|
#endif // !defined(UNKNOWN_SOLARIS_PROCESSOR)
|
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
#else
|
2009-11-04 16:21:52 +00:00
|
|
|
|
2007-10-24 00:44:42 +00:00
|
|
|
// Any other platform, fall back to the previous method
|
|
|
|
add_platform(HOSTTYPE);
|
|
|
|
#ifdef HOSTTYPEALT
|
|
|
|
add_platform(HOSTTYPEALT);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-05-08 07:51:18 +00:00
|
|
|
if (cc_config.no_alt_platform) {
|
2007-10-24 00:44:42 +00:00
|
|
|
PLATFORM p = platforms[0];
|
|
|
|
platforms.clear();
|
|
|
|
platforms.push_back(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add platforms listed in cc_config.xml AFTER the above.
|
|
|
|
//
|
2014-05-08 07:51:18 +00:00
|
|
|
for (unsigned int i=0; i<cc_config.alt_platforms.size(); i++) {
|
|
|
|
add_platform(cc_config.alt_platforms[i].c_str());
|
2007-10-24 00:44:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// write XML list of supported platforms
|
|
|
|
//
|
|
|
|
void CLIENT_STATE::write_platforms(PROJECT* p, MIOFILE& mf) {
|
2012-11-22 18:12:51 +00:00
|
|
|
if (p->anonymous_platform) {
|
|
|
|
mf.printf(" <platform_name>anonymous</platform_name>\n");
|
|
|
|
} else {
|
2007-10-24 00:44:42 +00:00
|
|
|
mf.printf(
|
2012-11-22 18:12:51 +00:00
|
|
|
" <platform_name>%s</platform_name>\n", get_primary_platform()
|
2007-10-24 00:44:42 +00:00
|
|
|
);
|
2012-11-22 18:12:51 +00:00
|
|
|
for (unsigned int i=1; i<platforms.size(); i++) {
|
|
|
|
PLATFORM& platform = platforms[i];
|
|
|
|
mf.printf(
|
|
|
|
" <alt_platform>\n"
|
|
|
|
" <name>%s</name>\n"
|
|
|
|
" </alt_platform>\n",
|
|
|
|
platform.name.c_str()
|
|
|
|
);
|
|
|
|
}
|
2007-10-24 00:44:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CLIENT_STATE::is_supported_platform(const char* p) {
|
|
|
|
for (unsigned int i=0; i<platforms.size(); i++) {
|
|
|
|
PLATFORM& platform = platforms[i];
|
|
|
|
if (!strcmp(p, platform.name.c_str())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|