Example #1
0
wxBitmap* CSimpleProjectPanel::GetProjectSpecificBitmap(char* project_url) {
    char defaultIcnPath[256];
    CSkinSimple* pSkinSimple = wxGetApp().GetSkinManager()->GetSimple();

    wxASSERT(pSkinSimple);

    // Only update it if project specific is found
    if(boinc_resolve_filename(GetProjectIconLoc(project_url).c_str(), defaultIcnPath, sizeof(defaultIcnPath)) == 0) {
        wxBitmap* projectBM;
        wxString strIconPath = wxString(defaultIcnPath,wxConvUTF8);
        if (wxFile::Exists(strIconPath)) {
#ifdef __WXMSW__
            if ((GetXDPIScaling() > 1.05) || (GetYDPIScaling() > 1.05)) {
                wxImage img = wxImage(strIconPath, wxBITMAP_TYPE_ANY);
                if (img.IsOk()) {
                    img.Rescale((int) (img.GetWidth()*GetXDPIScaling()), 
                                (int) (img.GetHeight()*GetYDPIScaling()), 
                                wxIMAGE_QUALITY_BILINEAR
                            );
                    projectBM = new wxBitmap(img);
                    if (projectBM->IsOk()) {
                        return projectBM;
                    }
                }
            } else 
#endif
            {
                projectBM = new wxBitmap();
                if ( projectBM->LoadFile(strIconPath, wxBITMAP_TYPE_ANY) ) {
                    return projectBM;
                }
            }
        }
    }
    return pSkinSimple->GetProjectImage()->GetBitmap();
}
Example #2
0
int main(int argc, char **argv) {    
    int retval;
    double fd;
    char output_path[512]; //, chkpt_path[512];
    //FILE* state;	
    retval = boinc_init();
    if (retval) {
        fprintf(stderr, "boinc_init returned %d\n", retval);
        exit(retval);
    }

	// extract a --device option
	std::vector<char*> argVec;
	int cudaDevice = -1;
	for(int ii = 0; ii < argc; ii++) {
		if(cudaDevice < 0 && strcmp(argv[ii], "--device") == 0 && ii + 1 < argc)
			cudaDevice = atoi(argv[++ii]);
		else
			argVec.push_back(argv[ii]);
	}
	argc = (int)argVec.size();
	argv = &argVec[0];
	if(cudaDevice < 0)
		cudaDevice = 0;

	boinc_begin_critical_section();

	// set the cuda device
	if ( rcuda::SetCudaDevice(cudaDevice) != 0 ) {
		fprintf(stderr, "Error setting device %u. Temporary exiting for 60 secs\n", cudaDevice);
		boinc_temporary_exitHack();
	}
	cudaDeviceProp deviceProp;
	if(cudaGetDeviceProperties(&deviceProp, cudaDevice) == cudaErrorInvalidDevice) {
		fprintf(stderr, "Error querying device %u. Temporary exiting for 60 secs\n", cudaDevice);
		boinc_temporary_exitHack();
	}
#ifdef WIN32
	SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
#endif
	int buffCount = 0x2000;
	int chainSize = 100;
	if(deviceProp.major == 1) {	
/*		
		buffCount = deviceProp.multiProcessorCount * 8;// 8 blocks per multiprocessor
		buffCount *= deviceProp.maxThreadsPerBlock / 64; // (BLOCK_X_SIZE)
//		buffCount *= 24;
		if(deviceProp.minor <= 1) buffCount *= 24; // 24 warps per multiprocessor for compute 1.0 and 1.1
		else buffCount *= 32; // 32 warps per multiprocessor for compute 1.2 and 1.3		
		*/
		buffCount = 0x2000;
	}
	else if(deviceProp.major == 2) {		
		chainSize = 200;
/*		buffCount = deviceProp.multiProcessorCount * 8;// 8 blocks per multiprocessor
		buffCount *= deviceProp.maxThreadsPerBlock / 64; //(BLOCK_X_SIZE)		
		buffCount *= 32; // 48 warps per multiprocessor for compute 2.x
/*		if(deviceProp.minor == 1) {
			buffCount *= 2;
		}
*/		
		buffCount = 0x4000;
	}
	if(cudaDevice > 0) {
		chainSize = 1000;
	}
	if(argc < 10)
	{
		fprintf(stderr, "Not enough parameters");
		return -1;
	}
	std::string sHashRoutineName, sCharsetName, sSalt, sCheckPoints;
	uint32 nRainbowChainCount, nPlainLenMin, nPlainLenMax, nRainbowTableIndex, nRainbowChainLen;
	uint64 nChainStart;
	sHashRoutineName = argv[1];
	sCharsetName = argv[2];
	nPlainLenMin = atoi(argv[3]);
	nPlainLenMax = atoi(argv[4]);
	nRainbowTableIndex = atoi(argv[5]);
	nRainbowChainLen = atoi(argv[6]);
	nRainbowChainCount = atoi(argv[7]);
#ifdef _WIN32
	nChainStart = _atoi64(argv[8]);
#else
	nChainStart = atoll(argv[8]);
#endif
	sCheckPoints = argv[9];
	std::vector<int> vCPPositions;
	char *cp = strtok((char *)sCheckPoints.c_str(), ",");
	while(cp != NULL)
	{
		vCPPositions.push_back(atoi(cp));
		cp = strtok(NULL, ",");
	}
	if(argc == 11)
	{
		sSalt = argv[10];
	}
	//std::cout << "Starting ChainGenerator" << std::endl;
	// Setup CChainWalkContext
	//std::cout << "ChainGenerator started." << std::endl;

	if (!CChainWalkContext::SetHashRoutine(sHashRoutineName))
	{
		fprintf(stderr, "hash routine %s not supported\n", sHashRoutineName.c_str());
		return 1;
	}
	//std::cout << "Hash routine validated" << std::endl;

	if (!CChainWalkContext::SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax))
	{	
		std::cerr << "charset " << sCharsetName << " not supported" << std::endl;
		return 2;
	}
	//std::cout << "Plain charset validated" << std::endl;

	if (!CChainWalkContext::SetRainbowTableIndex(nRainbowTableIndex))
	{
		std::cerr << "invalid rainbow table index " << nRainbowTableIndex << std::endl;
		return 3;
	}
	//std::cout << "Rainbowtable index validated" << std::endl;

	if(sHashRoutineName == "mscache")// || sHashRoutineName == "lmchall" || sHashRoutineName == "halflmchall")
	{
		// Convert username to unicode
		const char *szSalt = sSalt.c_str();
		int salt_length = strlen(szSalt);
		unsigned char cur_salt[256];
		for (int i=0; i<salt_length; i++)
		{
			cur_salt[i*2] = szSalt[i];
			cur_salt[i*2+1] = 0x00;
		}
		CChainWalkContext::SetSalt(cur_salt, salt_length*2);
	}
	else if(sHashRoutineName == "halflmchall")
	{ // The salt is hardcoded into the hash routine
	//	CChainWalkContext::SetSalt((unsigned char*)&salt, 8);
	}
	else if(sHashRoutineName == "oracle")
	{
		CChainWalkContext::SetSalt((unsigned char *)sSalt.c_str(), sSalt.length());
	}
	//std::cout << "Opening chain file" << std::endl;
	
	// Open file
	boinc_resolve_filename("result", output_path, sizeof(output_path));
	fclose(boinc_fopen(output_path, "a"));
	FILE *outfile = boinc_fopen(output_path, "r+b");
	
	if (outfile == NULL)
	{
		std::cerr << "failed to create " << output_path << std::endl;
		return 4;
	}
	
	// Check existing chains
	unsigned int nDataLen = (unsigned int)GetFileLen(outfile);
	
	// Round to boundary
	nDataLen = nDataLen / 10 * 10;
	if (nDataLen == nRainbowChainCount * 10)
	{		
		std::cerr << "precomputation of this rainbow table already finished" << std::endl;
		fclose(outfile);
		return 0;
	}

	fseek(outfile, nDataLen, SEEK_SET);
	//XXX size_t isn't 32/64 clean
	size_t nReturn;
	CChainWalkContext cwc;
	uint64 nIndex[2];
	//time_t tStart = time(NULL);

//	std::cout << "Starting to generate chains" << std::endl;
	int maxCalcBuffSize = rcuda::GetChainsBufferSize( buffCount );
	std::cerr << "maxCalcBuffSize - estimated: " << buffCount << ". Chosen: " << maxCalcBuffSize << std::endl;
	uint64 *calcBuff = new uint64[2*maxCalcBuffSize];
	int ii;

	CudaCWCExtender ex(&cwc);
	rcuda::RCudaTask cuTask;
	ex.Init();

	for(int nCurrentCalculatedChains = nDataLen / 10, calcSize; nCurrentCalculatedChains < nRainbowChainCount; )
	{		
		fd = (double)nCurrentCalculatedChains / (double)nRainbowChainCount;
		boinc_fraction_done(fd);
		
		cuTask.hash = ex.GetHash();
		cuTask.startIdx = nChainStart + nCurrentCalculatedChains;
		cuTask.idxCount = std::min<int>(nRainbowChainCount - nCurrentCalculatedChains, maxCalcBuffSize);
		cuTask.dimVec = ex.GetPlainDimVec();
		cuTask.dimVecSize = ex.GetPlainDimVecSize()/2;
		cuTask.charSet = ex.GetCharSet();
		cuTask.charSetSize = ex.GetCharSetSize();
		cuTask.cpPositions = &vCPPositions[0];
		cuTask.cpPosSize = vCPPositions.size();
		cuTask.reduceOffset = ex.GetReduceOffset();
		cuTask.plainSpaceTotal = ex.GetPlainSpaceTotal();
		cuTask.rainbowChainLen = nRainbowChainLen;
		cuTask.kernChainSize = chainSize;
		for(ii = 0; ii < cuTask.idxCount; ii++) {
			calcBuff[2*ii] = cuTask.startIdx + ii;
			calcBuff[2*ii+1] = 0;
		}
		calcSize = rcuda::CalcChainsOnCUDA(&cuTask, calcBuff);

		BOINC_STATUS boinc_status;
		boinc_get_status(&boinc_status);

		if (boinc_status.quit_request || boinc_status.abort_request)
		{
			boinc_end_critical_section();
			while (1) boinc_sleep(1);
		}

		if(calcSize > 0) {
			nCurrentCalculatedChains += calcSize;
			for(ii = 0; ii < cuTask.idxCount; ii++) {
				nIndex[0] = cuTask.startIdx + ii;
//				nReturn = fwrite(nIndex, 1, 8, outfile);
				nReturn = fwrite(calcBuff+(2*ii), 1, 8, outfile);
				nReturn += fwrite(calcBuff+(2*ii+1), 1, 2, outfile);
				if(nReturn != 10) {
					std::cerr << "disk write fail" << std::endl;
					fclose(outfile);
					return 9;
				}
			}
		} else {
			std::cerr << "Calculations on CUDA failed!" << std::endl;
			fclose(outfile);
			return -1;	
		}
	}
	delete [] calcBuff;
#ifdef _DEBUG
	std::cout << "Generation completed" << std::endl;
#endif
	fclose(outfile);
    
	boinc_fraction_done(1);
	boinc_finish(0);
}
Example #3
0
int main(int argc, char** argv) {
    passwd      *pw;
    group       *grp;
    char        user_name[256], group_name[256];
    char	gfx_app_path[MAXPATHLEN], resolved_path[MAXPATHLEN];
    char        *BOINCDatSlotsPath = "/Library/Application Support/BOINC Data/slots/";
    int         retval;
    int         pid;

    if (argc < 2) return EINVAL;

    strlcpy(user_name, "boinc_project", sizeof(user_name));
    strlcpy(group_name, user_name, sizeof(group_name));

#if 0       // For debugging only
    // Allow debugging without running as user or group boinc_project
    pw = getpwuid(getuid());
    if (pw) strlcpy(user_name, pw->pw_name, sizeof(user_name));
    grp = getgrgid(getgid());
    if (grp) strlcpy(group_name, grp->gr_gid, sizeof(group_name));

#endif

    // We are running setuid root, so setgid() sets real group ID, 
    // effective group ID and saved set_group-ID for this process
    grp = getgrnam(group_name);
    if (grp) setgid(grp->gr_gid);

    // We are running setuid root, so setuid() sets real user ID, 
    // effective user ID and saved set_user-ID for this process
    pw = getpwnam(user_name);
    if (pw) setuid(pw->pw_uid);

    // NOTE: call print_to_log_file only after switching user and group
#if 0           // For debugging only
    char	current_dir[MAXPATHLEN];

    getcwd( current_dir, sizeof(current_dir));
    print_to_log_file( "current directory = %s", current_dir);
    
    for (int i=0; i<argc; i++) {
         print_to_log_file("switcher arg %d: %s", i, argv[i]);
    }
#endif

    if (strcmp(argv[1], "-default_gfx") == 0) {
        strlcpy(resolved_path, "/Library/Application Support/BOINC Data/boincscr", sizeof(resolved_path));
        argv[2] = resolved_path;
        
#if 0           // For debugging only
    for (int i=2; i<argc; i++) {
         print_to_log_file("calling execv with arg %d: %s", i-2, argv[i]);
    }
#endif

        // For unknown reasons, the graphics application exits with 
        // "RegisterProcess failed (error = -50)" unless we pass its 
        // full path twice in the argument list to execv.
        execv(resolved_path, argv+2);
        // If we got here execv failed
        fprintf(stderr, "Process creation (%s) failed: errno=%d\n", resolved_path, errno);
        return errno;
    }
    
    if (strcmp(argv[1], "-launch_gfx") == 0) {
        strlcpy(gfx_app_path, BOINCDatSlotsPath, sizeof(gfx_app_path));
        strlcat(gfx_app_path, argv[2], sizeof(gfx_app_path));
        strlcat(gfx_app_path, "/", sizeof(gfx_app_path));
        strlcat(gfx_app_path, GRAPHICS_APP_FILENAME, sizeof(gfx_app_path));
        retval = boinc_resolve_filename(gfx_app_path, resolved_path, sizeof(resolved_path));
        if (retval) return retval;
        
        argv[2] = resolved_path;
        
#if 0           // For debugging only
    for (int i=2; i<argc; i++) {
         print_to_log_file("calling execv with arg %d: %s", i-2, argv[i]);
    }
#endif

        // For unknown reasons, the graphics application exits with 
        // "RegisterProcess failed (error = -50)" unless we pass its 
        // full path twice in the argument list to execv.
        execv(resolved_path, argv+2);
        // If we got here execv failed
        fprintf(stderr, "Process creation (%s) failed: errno=%d\n", resolved_path, errno);
        return errno;
    }

    if (strcmp(argv[1], "-kill_gfx") == 0) {
        pid = atoi(argv[2]);
        if (! pid) return EINVAL;
        if ( kill(pid, SIGKILL)) {
#if 0           // For debugging only
     print_to_log_file("kill(%d, SIGKILL) returned error %d", pid, errno);
#endif
            return errno;
        }
        return 0;
    }
    
    return EINVAL;  // Unknown command
}
Example #4
0
void worker() {
	int nchars = 0;
	int retval;
    char input_path[512];
	char output_path[512];
	FILE* outfile;
	FILE *infile;

    boinc_resolve_filename(INPUT_FILE, input_path, sizeof(input_path));
#ifdef _WIN32
    infile = boinc_fopen(input_path, "rb");
#else
    infile = boinc_fopen(input_path, "r");
#endif
    if (!infile) {
        fprintf(stderr,
            "Couldn't find input file, resolved name %s.\n", input_path
        );
        exit(-1);
    }

	// Dance Dance Revolution
	dfio_load_file(infile);
	SBMatrix* matrix = new SBMatrix();
	retval = dfio_read_matrix(matrix);
	if (retval) {
        fprintf(stderr, "APP: bdance parse input file failed:\n");
        fprintf(stderr, "error code %d\n", retval);
		dfio_cleanup();
        exit(1);
    }
	dfio_cleanup();
	fclose(infile);


	// Solve
	dlx_solve(matrix);
	uxlong solutions = dlx_count_solutions();
	delete matrix;


	// Write results.
    boinc_resolve_filename(OUTPUT_FILE, output_path, sizeof(output_path));
	outfile = boinc_fopen(output_path, "w");
    if (!outfile) {
        fprintf(stderr,
            "Couldn't find output file, resolved name %s.\n", output_path
        );
        exit(-1);
    }

	dfio_new_file(outfile, DFIO_TYPE_RESULT);
//	if (dfio_get_prop(DFIO_PROP_NO_SOLUTION_DATA)) {
		dfio_set_prop(DFIO_PROP_RESULTS_NUM, solutions);
		dfio_write_headers();
//	}

	dfio_cleanup();
	fclose(outfile);
    boinc_finish(0);
}
Example #5
0
int main(int argc, char **argv) {    
    int retval;
    double fd;
    char output_path[512]; //, chkpt_path[512];
    //FILE* state;	
    retval = boinc_init();
    if (retval) {
        fprintf(stderr, "boinc_init returned %d\n", retval);
        exit(retval);
    }
	

    // get size of input file (used to compute fraction done)
    //
    //file_size(input_path, fsize);

    // See if there's a valid checkpoint file.
    // If so seek input file and truncate output file
    //


	if(argc < 10)
	{
		fprintf(stderr, "Not enough parameters");
		return -1;
	}
	std::string sHashRoutineName, sCharsetName, sSalt, sCheckPoints;
	uint32 nRainbowChainCount, nPlainLenMin, nPlainLenMax, nRainbowTableIndex, nRainbowChainLen;
	uint64 nChainStart;
	sHashRoutineName = argv[1];
	sCharsetName = argv[2];
	nPlainLenMin = atoi(argv[3]);
	nPlainLenMax = atoi(argv[4]);
	nRainbowTableIndex = atoi(argv[5]);
	nRainbowChainLen = atoi(argv[6]);
	nRainbowChainCount = atoi(argv[7]);
#ifdef _WIN32

	nChainStart = _atoi64(argv[8]);

#else
	nChainStart = atoll(argv[8]);
#endif
	sCheckPoints = argv[9];
	std::vector<uint32> vCPPositions;
	char *cp = strtok((char *)sCheckPoints.c_str(), ",");
	while(cp != NULL)
	{
		vCPPositions.push_back(atoi(cp));
		cp = strtok(NULL, ",");
	}
	if(argc == 11)
	{
		sSalt = argv[10];
	}
	//std::cout << "Starting ChainGenerator" << std::endl;
	// Setup CChainWalkContext
	//std::cout << "ChainGenerator started." << std::endl;

	if (!CChainWalkContext::SetHashRoutine(sHashRoutineName))
	{
		fprintf(stderr, "hash routine %s not supported\n", sHashRoutineName.c_str());
		return 1;
	}
	//std::cout << "Hash routine validated" << std::endl;

	if (!CChainWalkContext::SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax))
	{	
		std::cerr << "charset " << sCharsetName << " not supported" << std::endl;
		return 2;
	}
	//std::cout << "Plain charset validated" << std::endl;

	if (!CChainWalkContext::SetRainbowTableIndex(nRainbowTableIndex))
	{
		std::cerr << "invalid rainbow table index " << nRainbowTableIndex << std::endl;
		return 3;
	}
	//std::cout << "Rainbowtable index validated" << std::endl;

	if(sHashRoutineName == "mscache")// || sHashRoutineName == "lmchall" || sHashRoutineName == "halflmchall")
	{
		// Convert username to unicode
		const char *szSalt = sSalt.c_str();
		int salt_length = strlen(szSalt);
		unsigned char cur_salt[256];
		for (int i=0; i<salt_length; i++)
		{
			cur_salt[i*2] = szSalt[i];
			cur_salt[i*2+1] = 0x00;
		}
		CChainWalkContext::SetSalt(cur_salt, salt_length*2);
	}
	else if(sHashRoutineName == "halflmchall")
	{ // The salt is hardcoded into the hash routine
	//	CChainWalkContext::SetSalt((unsigned char*)&salt, 8);
	}
	else if(sHashRoutineName == "oracle")
	{
		CChainWalkContext::SetSalt((unsigned char *)sSalt.c_str(), sSalt.length());
	}
	//std::cout << "Opening chain file" << std::endl;

	
	// Open file
    boinc_resolve_filename("result", output_path, sizeof(output_path));
	fclose(boinc_fopen(output_path, "a"));
	FILE *outfile = boinc_fopen(output_path, "r+b");
	
	if (outfile == NULL)
	{
		std::cerr << "failed to create " << output_path << std::endl;
		return 4;
	}
	
	// Check existing chains
	unsigned int nDataLen = (unsigned int)GetFileLen(outfile);
	
	// Round to boundary
	nDataLen = nDataLen / 10 * 10;
	if (nDataLen == nRainbowChainCount * 10)
	{		
		std::cerr << "precomputation of this rainbow table already finished" << std::endl;
		fclose(outfile);
		return 0;
	}
	nChainStart += (nDataLen / 10);
	fseek(outfile, nDataLen, SEEK_SET);
	//XXX size_t isn't 32/64 clean
	size_t nReturn;
	CChainWalkContext cwc;
	uint64 nIndex[2];
	//time_t tStart = time(NULL);

//	std::cout << "Starting to generate chains" << std::endl;
	for(uint32 nCurrentCalculatedChains = nDataLen / 10; nCurrentCalculatedChains < nRainbowChainCount; nCurrentCalculatedChains++)
	{		
		uint32 cpcheck = 0;
		unsigned short checkpoint = 0;
		fd = (double)nCurrentCalculatedChains / (double)nRainbowChainCount;
		boinc_fraction_done(fd);
		cwc.SetIndex(nChainStart++); // use a given index now!
		nIndex[0] = cwc.GetIndex();
		
		for (uint32 nPos = 0; nPos < nRainbowChainLen - 1; nPos++)
		{
		//	std::cout << "IndexToPlain()" << std::endl;
			cwc.IndexToPlain();
		//	std::cout << "PlainToHash()" << std::endl;
			cwc.PlainToHash();
		//	std::cout << "HashToIndex()" << std::endl;
			cwc.HashToIndex(nPos);
			if(cpcheck < vCPPositions.size() && nPos == vCPPositions[cpcheck])
			{
				
				checkpoint |= (1 << cpcheck) & (unsigned short)cwc.GetIndex() << cpcheck;
				cpcheck++;
			}
		}
		//std::cout << "GetIndex()" << std::endl;

		nIndex[1] = cwc.GetIndex();
		// Write chain to disk
		if ((nReturn = fwrite(&nIndex[1], 1, 8, outfile)) != 8)
		{
			std::cerr << "disk write fail" << std::endl;
			fclose(outfile);
			return 9;
		}
		if((nReturn = fwrite(&checkpoint, 1, 2, outfile)) != 2)
		{
			std::cerr << "disk write fail" << std::endl;
			fclose(outfile);
			return 9;
		}
	}
	//std::cout << "Generation completed" << std::endl;
	fclose(outfile);
    
	boinc_fraction_done(1);
	boinc_finish(0);
}
Example #6
0
int DC_sendResult(const char *logicalFileName, const char *path,
	DC_FileMode mode)
{
	char label[32], new_path[PATH_MAX], msg[PATH_MAX], *p;
	int ret;

	if (!logicalFileName)
	{
		DC_log(LOG_ERR, "%s: Missing logical file name", __func__);
		return DC_ERR_BADPARAM;
	}
	if (!path)
	{
		DC_log(LOG_ERR, "%s: Missing path", __func__);
		return DC_ERR_BADPARAM;
	}

	if (!DC_getMaxSubresults())
	{
		DC_log(LOG_ERR, "No more subresults are allowed to be sent");
		return DC_ERR_NOTIMPL;
	}

	/* We have to use the subresult labels that were defined by the
	 * master for doing the upload */
	snprintf(label, sizeof(label), "%s%d", SUBRESULT_PFX, ++subresult_cnt);
	if (boinc_resolve_filename(label, new_path, sizeof(new_path)))
		return DC_ERR_INTERNAL;

	/* We need the file name that will appear on the server */
	p = strrchr(new_path, PATHSEP);
	if (!p)
	{
		DC_log(LOG_ERR, "Failed to determine the on-server file name "
			"of the subresult");
		return DC_ERR_INTERNAL;
	}
	p++;

	switch (mode)
	{
		case DC_FILE_REGULAR:
			ret = _DC_copyFile(path, new_path);
			if (ret)
				return DC_ERR_SYSTEM;
			break;
		case DC_FILE_PERSISTENT:
#ifndef _WIN32
			ret = link(path, new_path);
			if (!ret)
				break;
#endif
			/* The client system may not support hard links so
			 * fall back to copying silently */
			ret = _DC_copyFile(path, new_path);
			if (ret)
				return DC_ERR_SYSTEM;
			break;
		case DC_FILE_VOLATILE:
			ret = rename(path, new_path);
			if (!ret)
				break;
			/* If renaming fails, fall back to copying, but in this
			 * case we are also responsible for deleting the
			 * original */
			ret = _DC_copyFile(path, new_path);
			if (ret)
				return DC_ERR_SYSTEM;
			break;
		case DC_FILE_REMOTE:
			/* Ignore this case, entirely handled by BOINC */
			break;
	}

	/* Stupid C++ */
	std::string str = label;
	ret = boinc_upload_file(str);
	if (ret)
	{
		unlink(new_path);
		return DC_ERR_INTERNAL;
	}

	DC_log(LOG_INFO, "File %s (%s) has been scheduled for upload",
		logicalFileName, label);

	snprintf(msg, sizeof(msg), "%s:%s:%s:%s", DCAPI_MSG_PFX, DC_MSG_UPLOAD,
		p, logicalFileName);
	DC_sendMessage(msg);

	/* If we had to copy volatile files, delete the original only when
	 * we are sure the upload will happen */
	if (mode == DC_FILE_VOLATILE)
		unlink(path);
	return 0;
}
Example #7
0
int DC_initClient(void)
{
	char path[PATH_MAX], *buf, label[32];
	int i, ret;
	FILE *f;

	/* We leave the redirection to BOINC and only copy stdout.txt/stderr.txt
	 * to the final output location in DC_finishClient(). This means BOINC
	 * can rotate the files so they won't grow too big. */
	if (boinc_init_diagnostics(BOINC_DIAG_REDIRECTSTDERR |
			BOINC_DIAG_REDIRECTSTDOUT))
		return DC_ERR_INTERNAL;

	if (boinc_init())
		return DC_ERR_INTERNAL;

	/* Parse the config file if the master sent one */
	buf = DC_resolveFileName(DC_FILE_IN, DC_CONFIG_FILE);
	if (buf)
	{
		ret = _DC_parseCfg(buf);
		if (ret && ret != DC_ERR_SYSTEM)
			return ret;
	}
	free(buf);

	/* Check if we are starting from a checkpoint file */
	if ((f = boinc_fopen(LAST_CKPT_FILE, "r")))
	{
		fgets(path, sizeof(path), f);
		fclose(f);
		if (strlen(path))
			last_complete_ckpt = strdup(path);
	}
	/* If the application did not generate a checkpoint file before, check
	 * if the master sent one */
	else
		last_complete_ckpt = DC_resolveFileName(DC_FILE_IN, CKPT_LABEL_IN);

	if (last_complete_ckpt)
		DC_log(LOG_INFO, "Found initial checkpoint file %s",
			last_complete_ckpt);

	/* Extract the WU name from init_data.xml */
	if (boinc_is_standalone())
	{
		DC_log(LOG_NOTICE, "Running in stand-alone mode, some "
			"functions are not available");
		wu_name[0] = '\0';
	}
	else
	{
		APP_INIT_DATA init_data;

		boinc_get_init_data(init_data);
		strncpy(wu_name, init_data.wu_name, sizeof(wu_name));
	}

	/* Initialize all optional output files as empty to prevent
	 * <file_xfer_error>s */
	for (i = 0; i < DC_getMaxSubresults(); i++)
	{
		snprintf(label, sizeof(label), "%s%d", SUBRESULT_PFX, i);
		if (boinc_resolve_filename(label, path, sizeof(path)))
			continue;
		f = boinc_fopen(path, "w");
		if (f)
			fclose(f);
	}
	ret = boinc_resolve_filename(CKPT_LABEL_OUT, path, sizeof(path));
	if (!ret)
	{
		f = boinc_fopen(path, "w");
		if (f)
			fclose(f);
	}

	DC_log(LOG_INFO, "DC-API initialized for work unit %s", wu_name);

	return 0;
}
Example #8
0
void boincrf_(const char* s, char* t, int s_len, int t_len) {
    STRING_FROM_FORTRAN sff(s, s_len);
    sff.strip_whitespace();
    boinc_resolve_filename(sff.c_str(), t, t_len);
    string_to_fortran(t, t_len);
}
Example #9
0
void read_sequence_file(char *filename) {
    FILE *sequence_file;
    char current_line[200];
    int current_length, line_length, name_length;
    int i;
    Sequence *current_sequence;
    char c;

#ifdef _BOINC_    
    int retval;
    char input_path[512];

    retval = boinc_resolve_filename(filename, input_path, sizeof(input_path));
    if (retval) {

        fprintf(stderr, "ERROR, Could not resolve filename for reading sequences: [%s]\n", filename);
        fprintf(stderr, "ERROR on line [%d], file [%s]\n", __LINE__, __FILE__);
        exit(0);
    }

    sequence_file = boinc_fopen(input_path, "r");
#else
    sequence_file = fopen(filename, "r");
#endif
    if (sequence_file == NULL) {
        fprintf(stderr, "ERROR, could not open filename to read sequence file: [%s]\n", filename);
        fprintf(stderr, "ERROR on line [%d], file [%s]\n", __LINE__, __FILE__);
        exit(0);
    }

    number_sequences = 0;

//    fprintf(stderr, "mallocing sequences\n");
    sequences = (Sequence**)malloc(sizeof(Sequence*));
//    fprintf(stderr, "malloced sequences\n");


    current_sequence = NULL;
    current_length = 0;

    while (NULL != fgets(current_line, 200, sequence_file)) {

        if (strcmp(current_line, "") == 0 || strcmp(current_line, "\n") == 0) {
//            fprintf(stdout, "skipping line: [%s]\n", current_line);
            continue;

        } else if (current_line[0] == '>') {
            //start a new sequence

//            fprintf(stdout, "starting new sequence with line: [%s]\n", current_line);

            number_sequences++;
//            fprintf(stderr, "reallocing sequences\n");
            sequences = (Sequence**)realloc(sequences, number_sequences * sizeof(Sequence*));
//            fprintf(stderr, "realloced sequences\n");

            sequences[number_sequences - 1] = (Sequence*)malloc(sizeof(Sequence));
            current_sequence = sequences[number_sequences - 1];

            name_length = strlen(current_line) - 1;
            current_sequence->name = (char*)malloc(sizeof(char) * (name_length));

            for (i = 1; i < name_length; i++) current_sequence->name[i-1] = current_line[i];
            current_sequence->name[name_length-1] = '\0';

            current_sequence->nucleotides = NULL;
            current_length = 0;

//            fprintf(stdout, "reading new sequence, named: [%s]\n", current_sequence->name);

        } else {
            //append the current line to the sequence

//            fprintf(stdout, "appending line to sequence: [%s]\n", current_line);

            line_length = strlen(current_line);
//            printf("current line is     [%s], length [%d]\n", current_line, line_length);

            for (i = 0; i < line_length; i++) {
                c = toupper(current_line[i]);
                if (c != 'A' && c != 'C' && c != 'G' && c != 'T' && c != 'X') {
                    current_line[i] = '\0';
                    line_length = i;
                    break;
                }
            }
//            printf("current line is     [%s], length [%d]\n", current_line, line_length);

//            current_line[line_length] = '\0';
            if (current_length == 0) {
//                fprintf(stderr, "mallocing nucleotides\n");
                current_sequence->nucleotides = (char*)malloc(line_length + 1);
//                fprintf(stderr, "malloced nucleotides\n");
            } else {
//                fprintf(stderr, "reallocing nucleotides\n");
                current_sequence->nucleotides = (char*)realloc(current_sequence->nucleotides, current_length + line_length + 1);
//                fprintf(stderr, "realloced nucleotides\n");
            }

            for (i = 0; i < line_length; i++) current_sequence->nucleotides[current_length + i] = current_line[i];
            current_sequence->nucleotides[current_length + line_length] = '\0';

            current_length += line_length;
            current_sequence->length = current_length;

            for (i = 0; i < current_sequence->length; i++) {
                c = toupper(current_sequence->nucleotides[i]);
                if (c != 'A' && c != 'C' && c != 'G' && c != 'T' && c != 'X') {
                    printf("error in sequence, character at [%d] is not ACGTX: [%c][%d]\n", i, c, (int)c);
                    exit(0);
                }
            }
//            printf("nucleotides  is now [%s], length [%d]\n\n", current_sequence->nucleotides, current_sequence->length);
        }

    }

    fclose(sequence_file);

//    printf("read %d sequences\n", number_sequences);
//    for (i = 0; i < number_sequences; i++) {
//        printf("[%s]\n", sequences[i]->name);
//        printf("[%d] %s\n", sequences[i]->length, sequences[i]->nucleotides);
//    }

    /**
     *  Convert the sequences to uppercase to make things easier (so we don't have to check for lowercase as well).
     */
    sequences_to_uppercase();

    /**
     *  Calculate the background probabilities since we only need to do this once.
     */
    calculate_background_nucleotide_probabilities();

    /**
     *  Testing: print out the sequences
     */
    /*
    for (i = 0; i < number_sequences; i++) {
        current_sequence = sequences[i];
        printf("name: [%s]\n", current_sequence->name);
        printf("nucleotides: [%s]\n", current_sequence->nucleotides);
        printf("length: [%d]\n", current_sequence->length);
        printf("strlen(nucleotides): [%d]\n", (int)strlen(current_sequence->nucleotides));

        printf("background_probability[A]: %.15lf\n", current_sequence->background_probability[A_POSITION]);
        printf("background_probability[C]: %.15lf\n", current_sequence->background_probability[C_POSITION]);
        printf("background_probability[G]: %.15lf\n", current_sequence->background_probability[G_POSITION]);
        printf("background_probability[T]: %.15lf\n", current_sequence->background_probability[T_POSITION]);

        if (strlen(current_sequence->nucleotides) != current_sequence->length) {
            //sanity check
            fprintf(stderr, "ERROR! strlen(nucleotides) != length!\n");
            exit(0);
        }

        printf("\n");
    }
    */
}
Example #10
0
int VBOX_JOB::parse() {
    MIOFILE mf;
    std::string str;
    char buf[1024];

    boinc_resolve_filename(JOB_FILENAME, buf, sizeof(buf));
    FILE* f = boinc_fopen(buf, "r");
    if (!f) {
        vboxlog_msg("VBOX_JOB::parse(): can't open job file %s", buf);
        return ERR_FOPEN;
    }
    mf.init_file(f);
    XML_PARSER xp(&mf);

    if (!xp.parse_start("vbox_job")) return ERR_XML_PARSE;
    while (!xp.get_tag()) {
        if (!xp.is_tag) {
            vboxlog_msg("VBOX_JOB::parse(): unexpected text %s", xp.parsed_tag);
            continue;
        }
        if (xp.match_tag("/vbox_job")) {
            fclose(f);
            return 0;
        }
        else if (xp.parse_string("vm_disk_controller_type", vm_disk_controller_type)) continue;
        else if (xp.parse_string("vm_disk_controller_model", vm_disk_controller_model)) continue;
        else if (xp.parse_string("os_name", os_name)) continue;
        else if (xp.parse_double("memory_size_mb", memory_size_mb)) continue;
        else if (xp.parse_double("job_duration", job_duration)) continue;
        else if (xp.parse_double("minimum_checkpoint_interval", minimum_checkpoint_interval)) continue;
        else if (xp.parse_double("minimum_heartbeat_interval", minimum_heartbeat_interval)) continue;
        else if (xp.parse_string("fraction_done_filename", fraction_done_filename)) continue;
        else if (xp.parse_string("heartbeat_filename", heartbeat_filename)) continue;
        else if (xp.parse_string("completion_trigger_file", completion_trigger_file)) continue;
        else if (xp.parse_string("temporary_exit_trigger_file", temporary_exit_trigger_file)) continue;
        else if (xp.parse_bool("enable_cern_dataformat", enable_cern_dataformat)) continue;
        else if (xp.parse_bool("enable_network", enable_network)) continue;
        else if (xp.parse_bool("network_bridged_mode", network_bridged_mode)) continue;
        else if (xp.parse_bool("enable_shared_directory", enable_shared_directory)) continue;
        else if (xp.parse_bool("enable_scratch_directory", enable_scratch_directory)) continue;
        else if (xp.parse_bool("enable_floppyio", enable_floppyio)) continue;
        else if (xp.parse_bool("enable_cache_disk", enable_cache_disk)) continue;
        else if (xp.parse_bool("enable_isocontextualization", enable_isocontextualization)) continue;
        else if (xp.parse_bool("enable_remotedesktop", enable_remotedesktop)) continue;
        else if (xp.parse_bool("enable_gbac", enable_gbac)) continue;
        else if (xp.parse_bool("enable_screenshots_on_error", enable_screenshots_on_error)) continue;
        else if (xp.parse_bool("enable_graphics_support", enable_graphics_support)) continue;
        else if (xp.parse_bool("enable_vm_savestate_usage", enable_vm_savestate_usage)) continue;
        else if (xp.parse_bool("disable_automatic_checkpoints", disable_automatic_checkpoints)) continue;
        else if (xp.parse_bool("boot_iso", boot_iso)) continue;
        else if (xp.parse_int("pf_guest_port", pf_guest_port)) continue;
        else if (xp.parse_int("pf_host_port", pf_host_port)) continue;
        else if (xp.parse_string("copy_to_shared", str)) {
            copy_to_shared.push_back(str);
            continue;
        }
        else if (xp.parse_string("trickle_trigger_file", str)) {
            trickle_trigger_files.push_back(str);
            continue;
        }
        else if (xp.parse_string("intermediate_upload_file", str)) {
            VBOX_INTERMEDIATE_UPLOAD iu;
            iu.clear();
            iu.file = str;
            intermediate_upload_files.push_back(iu);
            continue;
        }
        else if (xp.match_tag("port_forward")) {
            VBOX_PORT_FORWARD pf;
            pf.clear();
            pf.parse(xp);
            if (pf.nports) {
                VBOX_PORT_FORWARD pf_range;
                pf_range = pf;
                pf_range.nports = 0;
                for (int i = 0; i < pf.nports; ++i) {
                    port_forwards.push_back(pf_range);
                    pf_range.host_port++;
                    pf_range.guest_port++;
                }
            } else {
                port_forwards.push_back(pf);
            }
        }
        vboxlog_msg("VBOX_JOB::parse(): unexpected text %s", xp.parsed_tag);
    }
    fclose(f);
    return ERR_XML_PARSE;
}