2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-11-14 08:29:32 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This 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 2.1 of the License, or (at your option) any later version.
|
2003-07-02 20:57:59 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// 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.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-07-02 02:02:18 +00:00
|
|
|
#ifndef UTIL_H
|
|
|
|
#define UTIL_H
|
|
|
|
|
2003-06-09 23:50:49 +00:00
|
|
|
#include <cstdlib>
|
2003-08-21 23:27:57 +00:00
|
|
|
#include <ctime>
|
|
|
|
#include <cmath>
|
2003-08-22 18:51:53 +00:00
|
|
|
#include <cctype>
|
2003-08-21 23:27:57 +00:00
|
|
|
#include <cstring>
|
2003-08-27 23:35:44 +00:00
|
|
|
#include <algorithm>
|
2003-09-02 23:26:38 +00:00
|
|
|
#include <string>
|
2007-01-23 22:29:19 +00:00
|
|
|
#include <vector>
|
2003-06-10 18:50:43 +00:00
|
|
|
|
2006-06-15 18:19:06 +00:00
|
|
|
#ifdef HAVE_PTHREAD
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
|
|
|
|
2006-08-01 12:36:19 +00:00
|
|
|
// Ideally, we would access this using wxGetApp().m_use_sandbox in the Manager
|
|
|
|
// and gstate.m_use_sandbox in the Client, but it is used by some source files
|
|
|
|
// (filesys.C, check_security.C) that are linked with both Manager and Client
|
|
|
|
// so the most practical solution is to use a global.
|
|
|
|
extern int g_use_sandbox;
|
|
|
|
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
extern double dtime();
|
2005-04-04 06:02:36 +00:00
|
|
|
extern double dday();
|
2003-03-11 22:18:01 +00:00
|
|
|
extern void boinc_sleep(double);
|
2004-12-10 19:17:32 +00:00
|
|
|
extern int read_file_string(const char* pathname, std::string& result);
|
2006-07-18 01:46:55 +00:00
|
|
|
extern void escape_project_url(char *in, char* out);
|
2007-01-23 22:29:19 +00:00
|
|
|
extern void push_unique(std::string, std::vector<std::string>&);
|
2006-09-26 16:22:36 +00:00
|
|
|
|
2003-07-03 00:48:43 +00:00
|
|
|
// NOTE: use #include <functional> to get max,min
|
2002-08-09 21:43:19 +00:00
|
|
|
|
2002-09-16 20:11:52 +00:00
|
|
|
#define SECONDS_PER_DAY 86400
|
2003-06-09 23:50:49 +00:00
|
|
|
|
|
|
|
static inline double drand() {
|
|
|
|
return (double)rand()/(double)RAND_MAX;
|
|
|
|
}
|
|
|
|
|
2004-02-04 19:14:39 +00:00
|
|
|
#ifdef _WIN32
|
2004-07-09 10:34:26 +00:00
|
|
|
#include <windows.h>
|
2006-05-16 21:14:18 +00:00
|
|
|
|
2004-12-10 19:17:32 +00:00
|
|
|
extern char* windows_error_string(char* pszBuf, int iSize);
|
|
|
|
extern char* windows_format_error_string(
|
2004-05-24 17:51:08 +00:00
|
|
|
unsigned long dwError, char* pszBuf, int iSize
|
|
|
|
);
|
2004-12-10 19:17:32 +00:00
|
|
|
extern int boinc_thread_cpu_time(HANDLE thread_handle, double& cpu);
|
2006-05-01 05:54:52 +00:00
|
|
|
extern int boinc_process_cpu_time(double& cpu);
|
2007-03-20 19:55:53 +00:00
|
|
|
#else
|
|
|
|
extern int lookup_group(char*, gid_t& gid);
|
|
|
|
extern int check_security(int use_sandbox, int isManager);
|
2004-12-10 19:17:32 +00:00
|
|
|
|
2007-03-20 19:55:53 +00:00
|
|
|
// setpriority(2) arg to run in background
|
|
|
|
// (don't use 20 because
|
|
|
|
static const int PROCESS_IDLE_PRIORITY = 19;
|
2007-03-20 23:12:22 +00:00
|
|
|
extern double linux_cpu_time(int pid);
|
2004-02-04 19:14:39 +00:00
|
|
|
#endif
|
|
|
|
|
2004-04-07 06:51:42 +00:00
|
|
|
extern void update_average(double, double, double, double&, double&);
|
|
|
|
|
2004-12-05 23:52:17 +00:00
|
|
|
extern int boinc_calling_thread_cpu_time(double&);
|
2004-11-05 19:52:19 +00:00
|
|
|
|
2004-12-27 21:14:18 +00:00
|
|
|
// convert UNIX time to MySQL timestamp (yyyymmddhhmmss)
|
|
|
|
//
|
|
|
|
extern void mysql_timestamp(double, char*);
|
|
|
|
|
2006-06-15 18:19:06 +00:00
|
|
|
#ifdef HAVE_PTHREAD
|
|
|
|
extern pthread_mutex_t getrusage_mutex;
|
|
|
|
#endif
|
|
|
|
|
2007-04-09 02:17:26 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
extern int run_program(
|
|
|
|
char* path, char* cdir, int argc, char** argv, double, HANDLE&
|
|
|
|
);
|
|
|
|
extern void kill_program(HANDLE);
|
|
|
|
extern int get_exit_status(HANDLE);
|
|
|
|
#else
|
|
|
|
extern int run_program(
|
|
|
|
char* path, char* cdir, int argc, char** argv, double, int&
|
|
|
|
);
|
|
|
|
extern void kill_program(int);
|
|
|
|
extern int get_exit_status(int);
|
|
|
|
#endif
|
|
|
|
|
2007-01-24 22:55:00 +00:00
|
|
|
extern int wait_client_mutex(const char* dir, double timeout);
|
2006-12-14 00:42:43 +00:00
|
|
|
|
2003-06-10 18:50:43 +00:00
|
|
|
#endif
|