diff --git a/Makefile.am b/Makefile.am index 0c2ea149c63..f74a3637e91 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,9 +22,9 @@ endif if ENABLE_MANAGER CLIENTGUI_SUBDIRS = clientgui locale -#if BUILD_X11_SCREENSAVER -# CLIENTGUI_SUBDIRS += clientscr -#endif +if BUILD_X11_SCREENSAVER + CLIENTGUI_SUBDIRS += clientscr +endif endif # ORDER MATTERS below. One must build dependencies FIRST, then things diff --git a/api/graphics2_util.cpp b/api/graphics2_util.cpp index fd58bf7e6fb..36fb3bfc58c 100644 --- a/api/graphics2_util.cpp +++ b/api/graphics2_util.cpp @@ -35,7 +35,7 @@ #ifdef __EMX__ static key_t get_shmem_name(const char* prog_name) { - char cwd[256], path[256]; + char cwd[MAXPATHLEN], path[MAXPATHLEN]; boinc_getcwd(cwd); sprintf(path, "%s/init_data.xml", cwd); return ftok(path, 2); @@ -54,7 +54,7 @@ static void get_shmem_name(const char* prog_name, char* shmem_name) { void* boinc_graphics_make_shmem(const char* prog_name, int size) { #ifdef _WIN32 HANDLE shmem_handle; - char shmem_name[256]; + char shmem_name[MAXPATHLEN]; void* p; get_shmem_name(prog_name, shmem_name); shmem_handle = create_shmem(shmem_name, size, &p); @@ -67,7 +67,7 @@ void* boinc_graphics_make_shmem(const char* prog_name, int size) { int retval = create_shmem(key, size, 0, &p); #else // V6 Unix/Linux/Mac applications always use mmap() shared memory for graphics communication - char shmem_name[256]; + char shmem_name[MAXPATHLEN]; get_shmem_name(prog_name, shmem_name); int retval = create_shmem_mmap(shmem_name, size, &p); // Graphics app may be run by a different user & group than worker app @@ -82,7 +82,7 @@ void* boinc_graphics_make_shmem(const char* prog_name, int size) { #ifdef _WIN32 void* boinc_graphics_get_shmem(const char* prog_name) { HANDLE shmem_handle; - char shmem_name[256]; + char shmem_name[MAXPATHLEN]; void* p; get_shmem_name(prog_name, shmem_name); shmem_handle = attach_shmem(shmem_name, &p); @@ -100,7 +100,7 @@ void* boinc_graphics_get_shmem(const char* prog_name) { retval = attach_shmem(key, &p); #else // V6 Unix/Linux/Mac applications always use mmap() shared memory for graphics communication - char shmem_name[256]; + char shmem_name[MAXPATHLEN]; get_shmem_name(prog_name, shmem_name); retval = attach_shmem_mmap(shmem_name, &p); #endif diff --git a/api/gutil.cpp b/api/gutil.cpp index a83d219f6d6..affd372a598 100644 --- a/api/gutil.cpp +++ b/api/gutil.cpp @@ -687,7 +687,10 @@ tImageJPG *LoadJPG(const char *filename) { int TEXTURE_DESC::CreateTextureJPG(const char* strFileName) { if(!strFileName) return -1; - tImageJPG *pImage = LoadJPG(strFileName); // Load the image and store the data + + // Load the image and store the data + // + tImageJPG *pImage = LoadJPG(strFileName); if(pImage == NULL) return -1; glPixelStorei(GL_UNPACK_ALIGNMENT,1); glGenTextures(1, (GLuint*)&id); @@ -698,12 +701,10 @@ int TEXTURE_DESC::CreateTextureJPG(const char* strFileName) { xsize = pImage->sizeX; ysize = pImage->sizeY; - if (pImage) { - if (pImage->data) { - free(pImage->data); - } - free(pImage); - } + if (pImage->data) { + free(pImage->data); + } + free(pImage); return 0; } diff --git a/checkin_notes b/checkin_notes index 82665733e08..9d0b6f3853e 100644 --- a/checkin_notes +++ b/checkin_notes @@ -6015,3 +6015,8 @@ David 20 Sept 2012 tools/ backend_lib.cpp,h cancel_jobs.cpp + +David 20 Sept 2012 + - A bunch of tweaks from Steffen Moller, e.g. using MAXPATHLEN + + various files diff --git a/client/app.cpp b/client/app.cpp index d927ae8f154..da06713287a 100644 --- a/client/app.cpp +++ b/client/app.cpp @@ -890,7 +890,7 @@ void ACTIVE_TASK_SET::report_overdue() { // int ACTIVE_TASK::handle_upload_files() { std::string filename; - char buf[256], path[MAXPATHLEN]; + char buf[MAXPATHLEN], path[MAXPATHLEN]; int retval; DirScanner dirscan(slot_dir); diff --git a/client/app.h b/client/app.h index 557d91e2430..981f6db0073 100644 --- a/client/app.h +++ b/client/app.h @@ -112,7 +112,7 @@ struct ACTIVE_TASK { double bytes_received; char slot_dir[256]; // directory where process runs (relative) - char slot_path[512]; + char slot_path[MAXPATHLEN]; // same, absolute // This is used only to run graphics apps // (that way don't have to worry about top-level dirs diff --git a/client/check_security.cpp b/client/check_security.cpp index e9daee3ec13..5790e204edf 100644 --- a/client/check_security.cpp +++ b/client/check_security.cpp @@ -39,10 +39,11 @@ bool IsUserInGroupBM(); #endif -static int CheckNestedDirectories(char * basepath, int depth, - int use_sandbox, int isManager, - char * path_to_error - ); +static int CheckNestedDirectories( + char * basepath, int depth, + int use_sandbox, int isManager, + cont char * path_to_error +); #if (! defined(__WXMAC__) && ! defined(_MAC_INSTALLER)) static char * PersistentFGets(char *buf, size_t buflen, FILE *f); diff --git a/client/cs_statefile.cpp b/client/cs_statefile.cpp index 64cfc13abfc..ed5c585f7b0 100644 --- a/client/cs_statefile.cpp +++ b/client/cs_statefile.cpp @@ -865,7 +865,7 @@ int CLIENT_STATE::parse_app_info(PROJECT* p, FILE* in) { _("File referenced in app_info.xml does not exist: ") ); strcat(buf, fip->name); - msg_printf(p, MSG_USER_ALERT, buf); + msg_printf(p, MSG_USER_ALERT, "%s", buf); delete fip; continue; } diff --git a/client/sandbox.cpp b/client/sandbox.cpp index 760e620bb4f..68e917fe950 100644 --- a/client/sandbox.cpp +++ b/client/sandbox.cpp @@ -185,7 +185,7 @@ int delete_project_owned_file(const char* path, bool retry) { // If an error occurs, delete as much as possible. // int client_clean_out_dir(const char* dirpath, const char* reason) { - char filename[256], path[MAXPATHLEN]; + char filename[MAXPATHLEN], path[MAXPATHLEN]; int retval, final_retval = 0; DIRREF dirp; diff --git a/client/stream.cpp b/client/stream.cpp deleted file mode 100644 index e17628efdbe..00000000000 --- a/client/stream.cpp +++ /dev/null @@ -1,331 +0,0 @@ -// This file is part of BOINC. -// http://boinc.berkeley.edu -// Copyright (C) 2008 University of California -// -// 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. -// -// BOINC 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. -// -// You should have received a copy of the GNU Lesser General Public License -// along with BOINC. If not, see . - -// Memory bandwidth benchmark derived from STREAM. Original copyright -// notice follows. Notice that we cannot call our results "STREAM -// benchmark results" -// Original Copyright Notice: -/*-----------------------------------------------------------------------*/ -/* Program: Stream */ -/* Revision: Id: stream.c,v 5.6 2005/10/04 00:19:59 mccalpin */ -/* Original code developed by John D. McCalpin */ -/* Programmers: John D. McCalpin */ -/* Joe R. Zagar */ -/* */ -/* This program measures memory transfer rates in MB/s for simple */ -/* computational kernels coded in C. */ -/*-----------------------------------------------------------------------*/ -/* Copyright 1991-2005: John D. McCalpin */ -/*-----------------------------------------------------------------------*/ -/* License: */ -/* 1. You are free to use this program and/or to redistribute */ -/* this program. */ -/* 2. You are free to modify this program for your own use, */ -/* including commercial use, subject to the publication */ -/* restrictions in item 3. */ -/* 3. You are free to publish results obtained from running this */ -/* program, or from works that you derive from this program, */ -/* with the following limitations: */ -/* 3a. In order to be referred to as "STREAM benchmark results", */ -/* published results must be in conformance to the STREAM */ -/* Run Rules, (briefly reviewed below) published at */ -/* http://www.cs.virginia.edu/stream/ref.html */ -/* and incorporated herein by reference. */ -/* As the copyright holder, John McCalpin retains the */ -/* right to determine conformity with the Run Rules. */ -/* 3b. Results based on modified source code or on runs not in */ -/* accordance with the STREAM Run Rules must be clearly */ -/* labelled whenever they are published. Examples of */ -/* proper labelling include: */ -/* "tuned STREAM benchmark results" */ -/* "based on a variant of the STREAM benchmark code" */ -/* Other comparable, clear and reasonable labelling is */ -/* acceptable. */ -/* 3c. Submission of results to the STREAM benchmark web site */ -/* is encouraged, but not required. */ -/* 4. Use of this program or creation of derived works based on this */ -/* program constitutes acceptance of these licensing restrictions. */ -/* 5. Absolutely no warranty is expressed or implied. */ -/*-----------------------------------------------------------------------*/ -# include -# include -# include -# include -# include -# include -# include - -static int N=64; -static const int NTIMES(10); -static const int OFFSET(0); - -static double avgtime[4] = {0}, maxtime[4] = {0}, - mintime[4] = {FLT_MAX,FLT_MAX,FLT_MAX,FLT_MAX}; - -static char *label[4] = {"Copy: ", "Scale: ", - "Add: ", "Triad: "}; - -static double bytes[4] = { - 2 * sizeof(double) * N, - 2 * sizeof(double) * N, - 3 * sizeof(double) * N, - 3 * sizeof(double) * N - }; - -extern double mysecond(); -extern double checktick(); -extern void checkSTREAMresults(double *a,double *b, double *c); - -void mem_bw(double &avg_bw, double &cache_size) { - avg_bw=0; - double *a=(double *)malloc((N+OFFSET)*sizeof(double)); - double *b=(double *)malloc((N+OFFSET)*sizeof(double)); - double *c=(double *)malloc((N+OFFSET)*sizeof(double)); - double quantum=checktick(); - int BytesPerWord; - register int j, k; - double scalar, t, times[4][NTIMES]; - double rv=0; - - - double tt[30],t_max; - int cache_ratio=1,cache_level=1; - int i=0; - - int check_cache=(cache_size==0); - do { - N*=2; - a=(double *)realloc(a,(N+OFFSET)*sizeof(double)); - b=(double *)realloc(b,(N+OFFSET)*sizeof(double)); - c=(double *)realloc(c,(N+OFFSET)*sizeof(double)); - if ( !a || !b || !c ) return; - - for (j=0; j - - double mysecond() { - struct timeval tp; - struct timezone tzp; - int i; - - i = gettimeofday(&tp,&tzp); - return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 ); - } - - void checkSTREAMresults (double *a, double *b, double *c) { - double aj,bj,cj,scalar; - double asum,bsum,csum; - double epsilon; - int j,k; - - /* reproduce initialization */ - aj = 1.0; - bj = 2.0; - cj = 0.0; - /* a[] is modified during timing check */ - aj = 2.0E0 * aj; - /* now execute timing loop */ - scalar = 3.0; - for (k=0; k= 0 ? (a) : -(a)) -#endif - epsilon = 1.e-8; - - if (abs(aj-asum)/asum > epsilon) { - printf ("Failed Validation on array a[]\n"); - printf (" Expected : %f \n",aj); - printf (" Observed : %f \n",asum); - } else if (abs(bj-bsum)/bsum > epsilon) { - printf ("Failed Validation on array b[]\n"); - printf (" Expected : %f \n",bj); - printf (" Observed : %f \n",bsum); - } else if (abs(cj-csum)/csum > epsilon) { - printf ("Failed Validation on array c[]\n"); - printf (" Expected : %f \n",cj); - printf (" Observed : %f \n",csum); - } else { - printf ("Solution Validates\n"); - } - } - -#ifdef STREAM_TEST - -int main() { - double cache_size=0; - double avg_bw=0; - mem_bw(avg_bw,cache_size); - printf("Average bandwidth=%f MB/s\n",avg_bw/1024/1024); - printf("Cache Size=%f kB\n",cache_size/1024); -} - -#endif diff --git a/clientgui/BOINCListCtrl.cpp b/clientgui/BOINCListCtrl.cpp index 7a6410d8caf..c6c174be028 100644 --- a/clientgui/BOINCListCtrl.cpp +++ b/clientgui/BOINCListCtrl.cpp @@ -267,7 +267,7 @@ wxListItemAttr* CBOINCListCtrl::OnGetItemAttr(long item) const { void CBOINCListCtrl::DrawProgressBars() { - long topItem, numItems, numVisibleItems, i, row; + long topItem, numItems, numVisibleItems, row; wxRect r, rr; int w = 0, x = 0, xx, yy, ww; int progressColumn = m_pParentView->GetProgressColumn(); @@ -300,7 +300,7 @@ void CBOINCListCtrl::DrawProgressBars() if (numItems <= (topItem + numVisibleItems)) numVisibleItems = numItems - topItem; x = 0; - for (i=0; i< progressColumn; i++) { + for (int i=0; i< progressColumn; i++) { x += GetColumnWidth(i); } w = GetColumnWidth(progressColumn); diff --git a/clientgui/MainDocument.cpp b/clientgui/MainDocument.cpp index 5a176a3a717..50fd9624dfb 100644 --- a/clientgui/MainDocument.cpp +++ b/clientgui/MainDocument.cpp @@ -906,8 +906,8 @@ void CMainDocument::RunPeriodicRPCs(int frameRefreshRate) { pFrame->AddPendingEvent(event); CTaskBarIcon* pTaskbar = wxGetApp().GetTaskBarIcon(); if (pTaskbar) { - CTaskbarEvent event(wxEVT_TASKBAR_REFRESH, pTaskbar); - pTaskbar->AddPendingEvent(event); + CTaskbarEvent tbevent(wxEVT_TASKBAR_REFRESH, pTaskbar); + pTaskbar->AddPendingEvent(tbevent); } CDlgEventLog* eventLog = wxGetApp().GetEventLog(); if (eventLog) { @@ -1303,10 +1303,10 @@ PROJECT* CMainDocument::project(unsigned int i) { PROJECT* CMainDocument::project(char* url) { - for (unsigned int i=0; i< state.projects.size(); i++) { - PROJECT* tp = state.projects[i]; - if (!strcmp(url, tp->master_url)) return tp; - } + for (unsigned int i=0; i< state.projects.size(); i++) { + PROJECT* tp = state.projects[i]; + if (!strcmp(url, tp->master_url)) return tp; + } return NULL; } @@ -1528,7 +1528,9 @@ int CMainDocument::WorkResume(char* url, char* name) { // If the graphics application for the current task is already // running, return a pointer to its RUNNING_GFX_APP struct. // -RUNNING_GFX_APP* CMainDocument::GetRunningGraphicsApp(RESULT* result, int slot) { +RUNNING_GFX_APP* CMainDocument::GetRunningGraphicsApp( + RESULT* rp, int slot +) { bool exited = false; std::vector::iterator gfx_app_iter; @@ -1536,7 +1538,7 @@ RUNNING_GFX_APP* CMainDocument::GetRunningGraphicsApp(RESULT* result, int slot) gfx_app_iter != m_running_gfx_apps.end(); gfx_app_iter++ ) { - if ( (slot >= 0) && ((*gfx_app_iter).slot != slot) ) continue; + if ((slot >= 0) && ((*gfx_app_iter).slot != slot)) continue; #ifdef _WIN32 unsigned long exit_code; @@ -1551,8 +1553,9 @@ RUNNING_GFX_APP* CMainDocument::GetRunningGraphicsApp(RESULT* result, int slot) } #endif if (! exited) { - if ( (result->name == (*gfx_app_iter).name) && - (result->project_url == (*gfx_app_iter).project_url) ) { + if ((rp->name == (*gfx_app_iter).name) && + (rp->project_url == (*gfx_app_iter).project_url) + ) { return &(*gfx_app_iter); } @@ -1660,15 +1663,15 @@ void CMainDocument::KillGraphicsApp(int pid) { } #endif -int CMainDocument::WorkShowGraphics(RESULT* result) { +int CMainDocument::WorkShowGraphics(RESULT* rp) { int iRetVal = 0; - if (strlen(result->web_graphics_url)) { - wxString url(result->web_graphics_url, wxConvUTF8); + if (strlen(rp->web_graphics_url)) { + wxString url(rp->web_graphics_url, wxConvUTF8); wxLaunchDefaultBrowser(url); return 0; } - if (strlen(result->graphics_exec_path)) { + if (strlen(rp->graphics_exec_path)) { // V6 Graphics RUNNING_GFX_APP gfx_app; RUNNING_GFX_APP* previous_gfx_app; @@ -1680,12 +1683,12 @@ int CMainDocument::WorkShowGraphics(RESULT* result) { int id; #endif - p = strrchr((char*)result->slot_path, '/'); + p = strrchr((char*)rp->slot_path, '/'); if (!p) return ERR_INVALID_PARAM; slot = atoi(p+1); // See if we are already running the graphics application for this task - previous_gfx_app = GetRunningGraphicsApp(result, slot); + previous_gfx_app = GetRunningGraphicsApp(rp, slot); #ifndef __WXMSW__ char* argv[4]; @@ -1709,13 +1712,13 @@ int CMainDocument::WorkShowGraphics(RESULT* result) { // exits with "RegisterProcess failed (error = -50)" unless // we pass its full path twice in the argument list to execv. // - argv[1] = (char *)result->graphics_exec_path; - argv[2] = (char *)result->graphics_exec_path; + argv[1] = (char *)rp->graphics_exec_path; + argv[2] = (char *)rp->graphics_exec_path; argv[3] = 0; if (g_use_sandbox) { iRetVal = run_program( - result->slot_path, + rp->slot_path, "../../switcher/switcher", 3, argv, @@ -1724,8 +1727,8 @@ int CMainDocument::WorkShowGraphics(RESULT* result) { ); } else { iRetVal = run_program( - result->slot_path, - result->graphics_exec_path, + rp->slot_path, + rp->graphics_exec_path, 1, &argv[2], 0, @@ -1741,8 +1744,8 @@ int CMainDocument::WorkShowGraphics(RESULT* result) { argv[0] = 0; iRetVal = run_program( - result->slot_path, - result->graphics_exec_path, + rp->slot_path, + rp->graphics_exec_path, 0, argv, 0, @@ -1751,8 +1754,8 @@ int CMainDocument::WorkShowGraphics(RESULT* result) { #endif if (!iRetVal) { gfx_app.slot = slot; - gfx_app.project_url = result->project_url; - gfx_app.name = result->name; + gfx_app.project_url = rp->project_url; + gfx_app.name = rp->name; gfx_app.pid = id; m_running_gfx_apps.push_back(gfx_app); } @@ -1775,32 +1778,32 @@ int CMainDocument::WorkShowVMConsole(RESULT* result) { strCommand = wxT("rdesktop-vrdp ") + strConnection; wxExecute(strCommand); #elif defined(__WXMAC__) - FSRef theFSRef; - OSStatus status = noErr; + FSRef theFSRef; + OSStatus status = noErr; - // I have found no reliable way to pass the IP address and port to Microsoft's - // Remote Desktop Connection application for the Mac, so I'm using CoRD. - // Unfortunately, CoRD does not seem as reliable as I would like either. - // - // First try to find the CoRD application by Bundle ID and Creator Code - status = LSFindApplicationForInfo('RDC#', CFSTR("net.sf.cord"), + // I have found no reliable way to pass the IP address and port to Microsoft's + // Remote Desktop Connection application for the Mac, so I'm using CoRD. + // Unfortunately, CoRD does not seem as reliable as I would like either. + // + // First try to find the CoRD application by Bundle ID and Creator Code + status = LSFindApplicationForInfo('RDC#', CFSTR("net.sf.cord"), NULL, &theFSRef, NULL); - if (status != noErr) { - CBOINCBaseFrame* pFrame = wxGetApp().GetFrame(); - if (pFrame) { - pFrame->ShowAlert( - _("Missing application"), - _("Please download and install the CoRD application from http://cord.sourceforge.net"), - wxOK | wxICON_INFORMATION, + if (status != noErr) { + CBOINCBaseFrame* pFrame = wxGetApp().GetFrame(); + if (pFrame) { + pFrame->ShowAlert( + _("Missing application"), + _("Please download and install the CoRD application from http://cord.sourceforge.net"), + wxOK | wxICON_INFORMATION, false ); - } - return ERR_FILE_MISSING; - } + } + return ERR_FILE_MISSING; + } - strCommand = wxT("osascript -e 'tell application \"CoRD\"' -e 'activate' -e 'open location \"rdp://") + strConnection + wxT("\"' -e 'end tell'"); - strCommand.Replace(wxT("localhost"), wxT("127.0.0.1")); - system(strCommand.char_str()); + strCommand = wxT("osascript -e 'tell application \"CoRD\"' -e 'activate' -e 'open location \"rdp://") + strConnection + wxT("\"' -e 'end tell'"); + strCommand.Replace(wxT("localhost"), wxT("127.0.0.1")); + system(strCommand.char_str()); #endif } @@ -2377,11 +2380,11 @@ int CMainDocument::GetSimpleGUIWorkCount() { CachedSimpleGUIUpdate(); CachedStateUpdate(); - for(i=0; iactive_task) { - iCount++; - } - } + for(i=0; iactive_task) { + iCount++; + } + } return iCount; } @@ -2414,7 +2417,7 @@ wxString result_description(RESULT* result, bool show_resources) { PROJECT* project; CC_STATUS status; int retval; - wxString strBuffer= wxEmptyString; + wxString strBuffer= wxEmptyString; strBuffer.Clear(); retval = doc->GetCoreClientStatus(status); @@ -2427,7 +2430,7 @@ wxString result_description(RESULT* result, bool show_resources) { } project = doc->state.lookup_project(result->project_url); - int throttled = status.task_suspend_reason & SUSPEND_REASON_CPU_THROTTLE; + int throttled = status.task_suspend_reason & SUSPEND_REASON_CPU_THROTTLE; switch(result->state) { case RESULT_NEW: strBuffer += _("New"); diff --git a/clientscr/Makefile.am b/clientscr/Makefile.am index 7115ea79e6e..51ed3cda1cb 100644 --- a/clientscr/Makefile.am +++ b/clientscr/Makefile.am @@ -3,6 +3,7 @@ include $(top_srcdir)/Makefile.incl +AM_LDFLAGS += -lpthread if ENABLE_CLIENT_RELEASE AM_LDFLAGS += -static-libtool-libs ## for an entirely statically linked library, you may want to try diff --git a/clientscr/screensaver_x11.cpp b/clientscr/screensaver_x11.cpp index a2e26493f19..6c8af6efe3d 100644 --- a/clientscr/screensaver_x11.cpp +++ b/clientscr/screensaver_x11.cpp @@ -23,7 +23,7 @@ // // GL: boincscr -root \n\ // -// If your BOINC directory differs from /var/lib/boinc, you can use +// If your BOINC directory differs from /var/lib/boinc-client, you can use // the -boinc_dir command line argument. // // When run, this screensaver connects to the BOINC client via RPC, asks for @@ -63,8 +63,7 @@ extern "C" { It shows the text "screensaver loading" when redrwan. A client window may be xembedded into it, which will also be resized. */ -class scr_window -{ +class scr_window { private: /// X server connection xcb_connection_t *con; @@ -94,17 +93,15 @@ class scr_window /// Small helper function to convert std::string to xcb_char2b_t* /** Remember to delete[] the returned string. */ - xcb_char2b_t *char2b(std::string str) - { + xcb_char2b_t *char2b(std::string str) { xcb_char2b_t *s = new xcb_char2b_t[str.size()]; if(!s) return NULL; - for(int c = 0; c < str.size(); c++) - { + for(int c = 0; c < str.size(); c++) { s[c].byte1 = '\0'; s[c].byte2 = str[c]; - } + } return s; - } +} public: /// Constructs the screensaver window. @@ -124,28 +121,24 @@ class scr_window if(!parent) parent = scr->root; // use parent window size when not in windowed mode - if(!windowed) - { - xcb_get_geometry_cookie_t geo_cookie = xcb_get_geometry(con, parent); - xcb_get_geometry_reply_t *reply = - xcb_get_geometry_reply(con, geo_cookie, &error); - if(error) - { - std::cerr << "Could not get parent window geometry." << std::endl; - exit(1); - } - width = reply->width; - height = reply->height; - free(reply); - } - else // use some defaults in windowed mode - { - width = 640; - height = 480; - } + if(!windowed) { + xcb_get_geometry_cookie_t geo_cookie = xcb_get_geometry(con, parent); + xcb_get_geometry_reply_t *reply = + xcb_get_geometry_reply(con, geo_cookie, &error); + if(error) { + std::cerr << "Could not get parent window geometry." << std::endl; + exit(1); + } + width = reply->width; + height = reply->height; + free(reply); + } else { + // use some defaults in windowed mode + width = 640; + height = 480; + } - if(windowed) - { + if(windowed) { // create a black maybe override-redirected window // and register for expose and resize events. mask = XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK; @@ -153,23 +146,22 @@ class scr_window values[1] = !windowed; // only if in fullscreen mode, otherwise normal window values[2] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY; win = xcb_generate_id(con); - cookie = xcb_create_window_checked(con, XCB_COPY_FROM_PARENT, win, - parent, 0, 0, width, height, 0, - XCB_WINDOW_CLASS_INPUT_OUTPUT, - scr->root_visual, mask, values); + cookie = xcb_create_window_checked( + con, XCB_COPY_FROM_PARENT, win, + parent, 0, 0, width, height, 0, + XCB_WINDOW_CLASS_INPUT_OUTPUT, + scr->root_visual, mask, values + ); error = xcb_request_check(con, cookie); - if(error) - { + if(error) { std::cerr << "Could not create window." << std::endl; exit(1); - } + } // map the window on the screen xcb_map_window(con, win); xcb_flush(con); - } - else - { + } else { // directly use the parent window win = parent; @@ -181,12 +173,11 @@ class scr_window xcb_change_window_attributes(con, win, mask, values); xcb_generic_error_t *error = xcb_request_check(con, cookie); - if(error) - { + if(error) { std::cerr << "Could not configure window." << std::endl; exit(1); - } - } + } + } // open a font. "fixed" should hopefully be available everywhere font = xcb_generate_id(con); @@ -194,11 +185,10 @@ class scr_window cookie = xcb_open_font_checked(con, font, font_name.size(), font_name.c_str()); error = xcb_request_check(con, cookie); - if(error) - { + if(error) { std::cerr << "Could not open font " << font_name << "." << std::endl; exit(1); - } + } // allocate white text graphics context with above font txt_gc = xcb_generate_id(con); @@ -207,30 +197,26 @@ class scr_window values[1] = font; cookie = xcb_create_gc_checked(con, txt_gc, win, mask, values); error = xcb_request_check(con, cookie); - if(error) - { + if(error) { std::cerr << "Could not create graphics context." << std::endl; exit(1); - } + } } /// Destructor - ~scr_window() - { + ~scr_window() { // clean up xcb_unmap_window(con, win); xcb_destroy_window(con, win); } /// Returns the window id. - xcb_window_t get_window_id() - { + xcb_window_t get_window_id() { return win; } /// Sets the text to be drawn - void set_text(std::string txt) - { + void set_text(std::string txt) { text = txt; redraw(); } @@ -239,8 +225,7 @@ class scr_window /** Draws a black background with white text. Should be calld when an expose event is received. */ - void redraw() - { + void redraw() { // convert the text to be displayed. xcb_char2b_t *str = char2b(text); @@ -269,14 +254,12 @@ class scr_window /// Notifies the window on resizes and resizes the client, if any. /** Should be called when a configure notify event is received. */ - void resize(uint16_t w, uint16_t h) - { + void resize(uint16_t w, uint16_t h) { width = w; height = h; // resize client window, if any. - if(client_win) - { + if(client_win) { // moving the client back to (0, 0) is required when maximizing uint32_t values[4] = { 0, 0, width, height }; uint32_t mask = XCB_CONFIG_WINDOW_X |XCB_CONFIG_WINDOW_Y | @@ -289,13 +272,12 @@ class scr_window { std::cerr << "Could not resize client." << std::endl; exit(1); - } - } - } + } + } +} /// Xembeds a X window - void xembed(xcb_window_t client) - { + void xembed(xcb_window_t client) { client_win = client; uint32_t values[4]; uint32_t mask; @@ -310,21 +292,19 @@ class scr_window cookie = xcb_configure_window_checked(con, client_win, mask, values); error = xcb_request_check(con, cookie); - if(error) - { + if(error) { std::cerr << "Could not change client attributes." << std::endl; exit(1); - } + } // reparent client cookie = xcb_reparent_window_checked(con, client_win, win, 0, 0); error = xcb_request_check(con, cookie); - if(error) - { + if(error) { std::cerr << "Could not reparent client." << std::endl; exit(1); - } + } // move and resize client window values[0] = 0; @@ -336,11 +316,10 @@ class scr_window cookie = xcb_configure_window_checked(con, client_win, mask, values); error = xcb_request_check(con, cookie); - if(error) - { + if(error) { std::cerr << "Could not resize client." << std::endl; exit(1); - } + } // make client overwrite-redirected values[0] = true; @@ -348,11 +327,10 @@ class scr_window cookie = xcb_change_window_attributes(con, client_win, mask, values); error = xcb_request_check(con, cookie); - if(error) - { + if(error) { std::cerr << "Could not change client attributes." << std::endl; exit(1); - } + } } }; @@ -360,15 +338,12 @@ xcb_connection_t *con; scr_window *window; /// X event loop -void *event_loop(void*) -{ +void *event_loop(void*) { xcb_generic_event_t *event; // wait for X events and process them - while((event = xcb_wait_for_event(con))) - { - switch(event->response_type & ~0x80) - { + while((event = xcb_wait_for_event(con))) { + switch(event->response_type & ~0x80) { case XCB_EXPOSE: { xcb_expose_event_t *expose_event @@ -376,7 +351,7 @@ void *event_loop(void*) // ignore the expose event, if there are more waiting. if(!expose_event->count && window && window->get_window_id() == - expose_event->window) window->redraw(); + expose_event->window) window->redraw(); break; } case XCB_CONFIGURE_NOTIFY: @@ -395,27 +370,25 @@ void *event_loop(void*) break; } free(event); - } - pthread_exit(0); + } + pthread_exit(0); } /// Program entry point. -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { unsigned long int window_id = 0; bool windowed = true; - std::string boinc_wd = "/var/lib/boinc"; + std::string boinc_wd = "/var/lib/boinc-client"; // parse command line - for(int c = 0; c < argc; c++) - { + for(int c = 0; c < argc; c++) { std::string option = argv[c]; if(option == "-window-id" && argv[c+1]) - sscanf(argv[++c], "%lx", &window_id); + sscanf(argv[++c], "%lx", &window_id); else if(option == "-root") - windowed = false; + windowed = false; else if (option == "-window") - windowed = true; + windowed = true; else if (option == "-boinc_dir") if(argv[++c]) boinc_wd = argv[c]; @@ -423,30 +396,27 @@ int main(int argc, char *argv[]) // if no -window-id command line argument is given, // look for the XSCREENSAVER_WINDOW environment variable - if(!window_id) - { + if(!window_id) { char *xssw = getenv("XSCREENSAVER_WINDOW"); - if(xssw && *xssw) - { + if(xssw && *xssw) { unsigned long int id = 0; char c; if (sscanf(xssw, "0x%lx %c", &id, &c) == 1 || sscanf(xssw, "%lu %c", &id, &c) == 1) window_id = id; - } - } + } + } // connect to the X server using $DISPLAY int screen_num = 0; con = xcb_connect(NULL, &screen_num); - if(!con) - { + if(!con) { std::cerr << "Cannot connect to your X server." << std::endl << "Please check if it's running and whether your DISPLAY " << "environment variable is set correctly." << std::endl; return 1; - } + } // get default screen xcb_screen_t *screen; @@ -460,37 +430,33 @@ int main(int argc, char *argv[]) // start the X event loop pthread_t thread; - if(pthread_create(&thread, NULL, event_loop, NULL)) - { + if(pthread_create(&thread, NULL, event_loop, NULL)) { std::cerr << "Could not create a thread." << std::endl; exit(1); - } + } // try to connect RPC_CLIENT *rpc = new RPC_CLIENT; - if(rpc->init(NULL)) - { + if(rpc->init(NULL)) { window->set_text("boinc not running"); pthread_join(thread, NULL); return 0; - } + } // get results that support graphics RESULTS results; - while(true) - { + while(true) { int suspend_reason = 0; rpc->get_screensaver_tasks(suspend_reason, results); if(results.results.empty()) sleep(10); else break; - } + } srandom(time(NULL)); std::string graphics_cmd = "graphics_app"; // the loop skips projects that do not yet // support the graphics_app soft link. - while(graphics_cmd == "graphics_app") - { + while(graphics_cmd == "graphics_app") { // select a random result int n = random() % results.results.size(); RESULT *result = results.results[n]; @@ -499,83 +465,79 @@ int main(int argc, char *argv[]) std::stringstream stream; stream << boinc_wd << "/slots/" << result->slot << "/"; std::string slot_dir = stream.str(); - if(chdir(slot_dir.c_str())) - { + if(chdir(slot_dir.c_str())) { perror("chdir"); exit(1); - } + } // resolve graphics_app soft link boinc_resolve_filename_s(graphics_cmd.c_str(), graphics_cmd); - } + } // fork and... pid_t pid = fork(); - if(pid == -1) - { + if(pid == -1) { perror("fork"); exit(1); - } + } // ...spawn graphics app if(!pid) // child - if(execl(graphics_cmd.c_str(), graphics_cmd.c_str(), NULL)) - { + if(execl(graphics_cmd.c_str(), graphics_cmd.c_str(), NULL)) { perror("exec"); exit(1); - } + } // look for our graphics app // do this 10 times, every 1/2 seconds, then give up. + // xcb_window_t client = 0; - for(int n = 0; n < 10; n++) - { + for(int n = 0; n < 10; n++) { // get list of x clients - xcb_atom_t NET_CLIENT_LIST = xcb_atom_get(con, "_NET_CLIENT_LIST"); + xcb_intern_atom_cookie_t cookie0=xcb_intern_atom( + con, 0, strlen("_NET_CLIENT_LIST"), "_NET_CLIENT_LIST" + ); + xcb_intern_atom_reply_t *reply0=xcb_intern_atom_reply(con, cookie0, NULL); + xcb_get_property_cookie_t cookie = - xcb_get_property(con, 0, screen->root, NET_CLIENT_LIST, WINDOW, 0, - std::numeric_limits::max()); + xcb_get_property(con, 0, screen->root, reply0->atom, XCB_ATOM_WINDOW, 0, + std::numeric_limits::max()); xcb_generic_error_t *error; xcb_get_property_reply_t *reply = xcb_get_property_reply(con, cookie, &error); - if(error) - { + if(error) { std::cerr << "Could not get client list." << std::endl; exit(1); - } + } xcb_window_t *clients = static_cast(xcb_get_property_value(reply)); // check if one of them is our graphics app - for(int c = 0; c < reply->length; c++) - { + for(int c = 0; c < reply->length; c++) { xcb_get_property_reply_t *reply2; // check WM_COMMAND - cookie = xcb_get_property(con, 0, clients[c], WM_COMMAND, STRING, + cookie = xcb_get_property(con, 0, clients[c], XCB_ATOM_WM_COMMAND, XCB_ATOM_STRING, 0, std::numeric_limits::max()); reply2 = xcb_get_property_reply(con, cookie, &error); - if(!error) // ignore errors - { + if(!error) // ignore errors { char *command = static_cast(xcb_get_property_value(reply2)); - if(command && graphics_cmd == command) - { + if(command && graphics_cmd == command) { client = clients[c]; break; - } + } free(reply2); - } + } // check WM_CLASS - cookie = xcb_get_property(con, 0, clients[c], WM_CLASS, STRING, + cookie = xcb_get_property(con, 0, clients[c], XCB_ATOM_WM_CLASS, XCB_ATOM_STRING, 0, std::numeric_limits::max()); reply2 = xcb_get_property_reply(con, cookie, &error); - if(!error) // ignore errors - { + if(!error) // ignore errors { char *clas = static_cast(xcb_get_property_value(reply2)); size_t pos = graphics_cmd.find_last_of('/'); @@ -583,25 +545,24 @@ int main(int argc, char *argv[]) if(pos == std::string::npos) executable = graphics_cmd; else executable = graphics_cmd.substr(pos + 1); - if(clas && executable == clas) - { + if(clas && executable == clas) { client = clients[c]; break; } free(reply2); - } + } // More checks are possible, but a single method for all graphics // applications would be preferred, such as WM_CLASS = "BOINC". - } + } free(reply); if(client) break; usleep(500000); - } + } // if the client window was found, xembed it if(client) diff --git a/lib/crypt.cpp b/lib/crypt.cpp index 624841d1c0b..b34f4d7d3d6 100644 --- a/lib/crypt.cpp +++ b/lib/crypt.cpp @@ -345,7 +345,9 @@ int check_file_signature( clear_signature.len = MD5_LEN; retval = decrypt_public(key, signature, clear_signature); if (retval) { - fprintf(stderr, "check_file_signature: decrypt_public error %d\n", retval); + fprintf(stderr, + "check_file_signature: decrypt_public error %d\n", retval + ); return retval; } answer = !strncmp(md5_buf, clear_buf, n); diff --git a/lib/diagnostics_win.cpp b/lib/diagnostics_win.cpp index c0861ed1c52..21e4c43f2b0 100644 --- a/lib/diagnostics_win.cpp +++ b/lib/diagnostics_win.cpp @@ -331,7 +331,7 @@ int diagnostics_get_process_information(PVOID* ppBuffer, PULONG pcbBuffer) { do { *ppBuffer = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, *pcbBuffer); if (*ppBuffer == NULL) { - retval = ERROR_NOT_ENOUGH_MEMORY; + return ERROR_NOT_ENOUGH_MEMORY; } Status = pNTQSI( @@ -1631,17 +1631,27 @@ int diagnostics_dump_exception_record(PEXCEPTION_POINTERS pExPtrs) { break; case EXCEPTION_ACCESS_VIOLATION: strcpy(status, "Access Violation"); + strcpy(substatus, ""); if (pExPtrs->ExceptionRecord->NumberParameters == 2) { switch(pExPtrs->ExceptionRecord->ExceptionInformation[0]) { case 0: // read attempt - sprintf(substatus, "read attempt to address 0x%8.8X", pExPtrs->ExceptionRecord->ExceptionInformation[1]); + sprintf(substatus, + "read attempt to address 0x%8.8X", + pExPtrs->ExceptionRecord->ExceptionInformation[1] + ); break; case 1: // write attempt - sprintf(substatus, "write attempt to address 0x%8.8X", pExPtrs->ExceptionRecord->ExceptionInformation[1]); + sprintf(substatus, + "write attempt to address 0x%8.8X", + pExPtrs->ExceptionRecord->ExceptionInformation[1] + ); break; } } - fprintf(stderr, "Reason: %s (0x%x) at address 0x%p %s\n\n", status, exception_code, exception_address, substatus); + fprintf(stderr, + "Reason: %s (0x%x) at address 0x%p %s\n\n", + status, exception_code, exception_address, substatus + ); break; case EXCEPTION_DATATYPE_MISALIGNMENT: diagnostics_dump_generic_exception("Data Type Misalignment", exception_code, exception_address); diff --git a/lib/filesys.cpp b/lib/filesys.cpp index 32179e464d6..7138aa96f70 100644 --- a/lib/filesys.cpp +++ b/lib/filesys.cpp @@ -412,7 +412,7 @@ int dir_size(const char* dirpath, double& size, bool recurse) { } while (FindNextFileA(hFind, &findData)); ::FindClose(hFind); #else - char filename[1024], subdir[1024]; + char filename[MAXPATHLEN], subdir[MAXPATHLEN]; int retval=0; DIRREF dirp; double x; @@ -541,7 +541,7 @@ int boinc_copy(const char* orig, const char* newf) { } return 0; #elif defined(__EMX__) - char cmd[1024]; + char cmd[2*MAXPATHLEN]; sprintf(cmd, "copy \"%s\" \"%s\"", orig, newf); return system(cmd); #else @@ -652,11 +652,11 @@ int boinc_chown(const char* path, gid_t gid) { // create directories dirpath/a, dirpath/a/b etc. // int boinc_make_dirs(const char* dirpath, const char* filepath) { - char buf[1024], oldpath[1024], newpath[1024]; + char buf[MAXPATHLEN], oldpath[MAXPATHLEN], newpath[MAXPATHLEN]; int retval; char *p, *q; - if (strlen(filepath) + strlen(dirpath) > 1023) return ERR_BUFFER_OVERFLOW; + if (strlen(filepath) + strlen(dirpath) > MAXPATHLEN-1) return ERR_BUFFER_OVERFLOW; strcpy(buf, filepath); strcpy(oldpath, dirpath); diff --git a/lib/util.cpp b/lib/util.cpp index df38d0d33f3..a62d34dad23 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -310,7 +310,7 @@ void boinc_crash() { #ifdef _WIN32 DebugBreak(); #else - *(int*)0 = 0; + abort(); #endif } diff --git a/sched/sched_driver.cpp b/sched/sched_driver.cpp index dedfe9a1924..0eeb403f7bb 100644 --- a/sched/sched_driver.cpp +++ b/sched/sched_driver.cpp @@ -51,9 +51,9 @@ using std::vector; struct HOST_DESC{ - char os_name[128]; - char p_vendor[128]; - char p_model[128]; + char os_name[256]; + char p_vendor[256]; + char p_model[256]; }; vector host_descs; diff --git a/test/test.inc b/test/test.inc index 46ee6657369..ad8a36d5fad 100644 --- a/test/test.inc +++ b/test/test.inc @@ -348,9 +348,9 @@ class Project { function mkdir($dir, $chmod=0) { $d = "$this->project_dir/$dir"; - mkdir($d,0777); + mkdir($d,0775); if ($chmod) { - chmod($d, 0777); + chmod($d, 0775); } } diff --git a/tools/db_query b/tools/db_query index f5649dacbc2..4852cfa1eb1 100755 --- a/tools/db_query +++ b/tools/db_query @@ -1,4 +1,4 @@ -#! /bin/csh +#! /bin/tcsh set CIVDATE = `date "+%Y:%m:%d:%H:%M"` set UNIXDATE = `perl -e 'print time()'` diff --git a/tools/dir_hier_move.cpp b/tools/dir_hier_move.cpp index c2d7bac3040..9d80f854715 100644 --- a/tools/dir_hier_move.cpp +++ b/tools/dir_hier_move.cpp @@ -43,15 +43,15 @@ int main(int argc, char** argv) { int retval; if ( (argc == 1) || !strcmp(argv[1], "-h") || !strcmp(argv[1],"--help") || (argc != 4) ) { - printf (usage); - exit(1); + fprintf(stderr, usage); + exit(1); } src_dir = argv[1]; dst_dir = argv[2]; fanout = atoi(argv[3]); if (!fanout) { - printf ( usage ); - exit(1); + fprintf(stderr, usage); + exit(1); } DirScanner scanner(src_dir); diff --git a/tools/dir_hier_path.cpp b/tools/dir_hier_path.cpp index 97401a42010..3900ed458b6 100644 --- a/tools/dir_hier_path.cpp +++ b/tools/dir_hier_path.cpp @@ -42,8 +42,8 @@ int main(int argc, char** argv) { int retval; if ( (argc == 1) || !strcmp(argv[1], "-h") || !strcmp(argv[1],"--help") || (argc != 2) ) { - printf (usage); - exit(1); + fprintf(stderr, usage); + exit(1); } retval = config.parse_file();