Example #1
0
/* atexit procedure */
void
WinExit(void)
{
    LPGW lpgw;

    /* Last chance, call before anything else to avoid a crash. */
    WinCloseHelp();

    /* clean-up call for printing system */
    PrintingCleanup();

    term_reset();

    _fcloseall();

    /* Close all graph windows */
    for (lpgw = listgraphs; lpgw != NULL; lpgw = lpgw->next) {
	if (GraphHasWindow(lpgw))
	    GraphClose(lpgw);
    }

#ifndef WGP_CONSOLE
    TextMessage();  /* process messages */
# ifndef __WATCOMC__
    /* revert C++ stream redirection */
    RedirectOutputStreams(FALSE);
# endif
#endif
#ifdef HAVE_GDIPLUS
    gdiplusCleanup();
#endif
    return;
}
Example #2
0
///////////////////////////////////////////////////////////////////////////////////
//Close All Files
///////////////////////////////////////////////////////////////////////////////////
Int FileHandler::CloseAllFiles()
{
	Int NumberClosed;
	NumberClosed = _fcloseall();

	return NumberClosed;
}
Example #3
0
void CTabToolsDlg::OnBnClickedBtnStopSe()
{
	TerminateThread(this->_opThds, 0);
	_fcloseall();
	this->_SetItemStatusInList(this->_curErasingItem, _T("Canceled"));
	this->_EnableCtrls(1);
}
int main()
{
	//"Texto del que se eliminan cosas a escribir como quotoes y demas"
	//char p1[]="Texto del que se elimi"""na"n co"sas a es"cribir como" quotoes y de"mas",p2[1024];
	//elimina(p1,p2,""");
	//char p1[]="Text<kaka>o del que se el<kaka><kaka>iminan cosas a escri<a>bir como quotoes y<kakakaka><><a> demas",p2[1024];
	//elimina(p1,p2,'<','>');



	FILE *strin,*strout;   errno_t err,err1;
//	err= fopen_s(&strin,"data/prueba.htm","r");
	err= fopen_s(&strin,"data/Yahoo.htm","r");
	err1=fopen_s(&strout,"data/out.htm","w");
	if ((err)||(err1)) 	{  printf("ERROR en ficheros");getchar();getchar(); return -1;  }
	char ch;
	long size_buffer1=0,size_buffer2,sizeant=0;
	while(!feof(strin))
	{
		ch=fgetc(strin);
		size_buffer1++;
	}
	printf("Tamano buffer1=%li",size_buffer1);sizeant=size_buffer1;
	rewind(strin);
	char *buffer1=new char[size_buffer1];
	char *buffer2=new char[size_buffer1];
	char *buffer3;
	long i;
	for (i=0;i<(size_buffer1-1);i++)
	{
		buffer1[i]=fgetc(strin);
	}
	buffer1[i]='\0';
	extrae_2(buffer1,buffer2);buffer3=buffer1;buffer1=buffer2;buffer2=buffer3;
	sizeant=size_buffer1;size_buffer1=strlen(buffer1);printf("\nTamano buffer2 1=%li %li",size_buffer1,size_buffer1-sizeant);

	elimina(buffer1,buffer2,"&quot;");buffer3=buffer1;buffer1=buffer2;buffer2=buffer3;
	sizeant=size_buffer1;size_buffer1=strlen(buffer1);printf("\nTamano buffer2 2=%li %li",size_buffer1,size_buffer1-sizeant);

	elimina(buffer1,buffer2,"(EFE)");buffer3=buffer1;buffer1=buffer2;buffer2=buffer3;
	sizeant=size_buffer1;size_buffer1=strlen(buffer1);printf("\nTamano buffer2 3=%li %li",size_buffer1,size_buffer1-sizeant);

	eliminaduplicados(buffer1,buffer2);buffer3=buffer1;buffer1=buffer2;buffer2=buffer3;
	sizeant=size_buffer1;size_buffer1=strlen(buffer1);printf("\nTamano buffer2 4=%li %li",size_buffer1,size_buffer1-sizeant);

	//Imprimo el ultimo buffer. ¡¡OJO!! pudiera ser buffer1 ó 2, el último válido
	printf("\nTamano buffer1 FIN=%li",strlen(buffer1));
	char *ptr;
	ptr=buffer1;
	while(*ptr)
	{
		fputc(*ptr++,strout);
	}
	fputc(*ptr++,strout);//El null del final
	_fcloseall( );
	getchar();getchar();
	return 0;

}
Example #5
0
/*
 * @implemented
 */
void abort()
{
	fflush(NULL);
	_fcloseall();
	raise(SIGABRT);
	_write(stderr->_file, msg, sizeof(msg)-1);
	exit(3);
}
Example #6
0
void __cdecl __endstdio(void)
{
        /* flush all streams */
        _flushall();

        /* if in callable exit, close all streams */
        if (_exitflag)
                _fcloseall();
}
Example #7
0
void __cdecl __endstdio(void) {
    /* flush all streams */
    _flushall();

    /* if in callable exit, close all streams */
    if (_exitflag) {
        _fcloseall();
    }

    _free_crt(__piob);
}
Example #8
0
//Catch system signal
BOOL WINAPI SignalHandler(
	const DWORD SignalType)
{
//Print to screen.
	switch (SignalType)
	{
	//Handle the CTRL-C signal.
		case CTRL_C_EVENT:
		{
			fwprintf_s(stderr, L"[Notice] Get Control-C.\n");
			PrintProcess(true, true);
		}break;
	//Handle the CTRL-Break signal.
		case CTRL_BREAK_EVENT:
		{
			fwprintf_s(stderr, L"[Notice] Get Control-Break.\n");
			PrintProcess(true, true);

		//Exit process.
			return TRUE;
		}break;
	//Handle other signals.
		default:
		{
			fwprintf_s(stderr, L"[Notice] Get closing signal.\n");
			PrintProcess(true, true);
		}
	}

//Close file handle.
	if (ConfigurationParameter.OutputFile != nullptr)
	{
		fclose(ConfigurationParameter.OutputFile);
		ConfigurationParameter.OutputFile = nullptr;
	}

//Close all file handles and WinSock cleanup.
#if defined(PLATFORM_WIN)
	if (ConfigurationParameter.IsInitialized_WinSock)
	{
		WSACleanup();
		ConfigurationParameter.IsInitialized_WinSock = false;
	}

	_fcloseall();
#elif (defined(PLATFORM_FREEBSD) || (defined(PLATFORM_LINUX) && !defined(PLATFORM_OPENWRT)))
	fcloseall();
#endif

//Exit process.
//	exit(EXIT_SUCCESS);
	return FALSE;
}
void main()
{
	FILE *fp = NULL;
	int nClosed = 0;
	fopen("Test1.txt", "w");
	fopen("Test2.txt", "w");
	fopen("Test3.txt", "w");

	//지금까지 개방한 파일들을 '모두' 닫는다. FILE*는 필요없다!
	nClosed = _fcloseall();
	printf("%d\n", nClosed);
}
Example #10
0
//Тело основной функции программы
int _tmain(int argc, _TCHAR* argv[])
{
	int numclosed;
	SetLoc(1251);


	while (true)
	{
		switch (PaintMainMenu())
		{
		case '1':FreqOne();			break;
		case '2':WriteCodeFile();	break;
		case '3':entropyBinOne();	break;
		case '4':numclosed = _fcloseall(); return 0;
		default:	break;
		}
	}


	numclosed = _fcloseall();
	return 0;
}
Example #11
0
int main(void)
{
	FILE* file;
	int error = fopen_s(&file, FILENAME, "w+");
	uint32_t random;
	size_t i;
	for (i = 0; i < SIZE; i++)
	{
		while (rand_s(&random))
		{ }
		fwrite(&random, sizeof(random), 1, file);
	}
	_fcloseall();
	return 0;
}
Example #12
0
bool DHudpEncoder::initClib(QString rawFn)
{
    qDebug() << "DHudpEncoder::initClib()";
     if ( preNC() == cTRUE ){
         qDebug() << "\t load: \"muldiv.tab\" succeeded.";
     }else{
         qDebug() << "\t load: \"muldiv.tab\" failed.";
         _fcloseall( );
     }

     //NC params
     i_cb = (NCCB *)malloc(sizeof(NCCB));
     if( i_cb == NULL){
         qDebug() << "\t malloc NCCB failed";
         exit(-1);
     }else {
         this->setRawFile(rawFn);
         this->setEncodedFile("Out.wmv");

         //init NC
         i_blockNum = this->getRawFileBlockNum();
         qDebug() << "\t raw file block num" << i_blockNum;

         if( cFALSE == initNC(i_cb,
                            i_rawFile.fileName().toAscii().data(),
                            i_blockSize,
                            i_blockNum,
                            i_d)){
             qDebug() << "\t initNC() failed";
             _fcloseall( );
         }
     }
     i_isInitOk = true;
     qDebug() << "\t initNC() ok";
     return true;
}
void main()
{
	FILE *fpc, *fps;
	fpc = fopen("client.txt", "w");
	int ch= 0; char data, input[50];
	fprintf(fpc, "%d", ch);
	fseek(fpc, 512, SEEK_SET);
	fprintf(fpc, "%d", ch); 
	fseek(fpc, 0, SEEK_END);
	ch = ftell(fpc);
	printf("%d",ch);
	_getch();
	_fcloseall();
	while(1)
		{
			fpc = fopen("client.txt", "r+");
			printf("\nEnter any message");
			gets(input);
			ch = 1;
			fprintf(fpc, "%d%s\n", ch, input);
			fclose(fpc);
			fpc = fopen("client.txt", "r+");
			fseek(fpc, 0, SEEK_SET);
			fscanf(fpc, "%d", &ch);
			ch = 0;
			if (ch != 1)
			{
				ch = 0;
				fprintf(fpc, "%d", ch);
				fclose(fpc);
			}
			fpc = fopen("client.txt", "r+");
				while (ch != 1)
				{
				fseek(fpc, 512, SEEK_SET);
				fscanf(fpc, "%d", &ch);
				}
			printf("\nServer replied : ");
			data = fgetc(fpc);
			while (data != '\n'&&!feof(fpc))
			{
				printf("%c", data);
				data = fgetc(fpc);
			}
			fclose(fpc);
		}
		_getch();
}
Example #14
0
/* atexit procedure */
void
WinExit(void)
{
	LPGW lpgw;

    /* Last chance, call before anything else to avoid a crash. */
    WinCloseHelp();

    term_reset();

    _fcloseall();

	/* Close all graph windows */
	for (lpgw = listgraphs; lpgw != NULL; lpgw = lpgw->next) {
		if (GraphHasWindow(lpgw))
			GraphClose(lpgw);
	}

#ifndef WGP_CONSOLE
    TextMessage();  /* process messages */
# ifndef __WATCOMC__
    /* revert C++ stream redirection */
    RedirectOutputStreams(FALSE);
# endif
#else
#ifdef CONSOLE_SWITCH_CP
    /* restore console codepages */
    if (cp_changed) {
		SetConsoleCP(cp_input);
		SetConsoleOutputCP(cp_output);
		/* file APIs are per process */
    }
#endif
#endif
#ifdef HAVE_GDIPLUS
    gdiplusCleanup();
#endif
    return;
}
Example #15
0
void SearchFromFiles()
{
	errno_t err;

	FILE *names; err = fopen_s(&names, "window-names.txt", "r+");
	FILE *images; err = fopen_s(&images, "window-images.txt", "r+");
	FILE *classes; err = fopen_s(&classes, "window-classes.txt", "r+");

	UINT32 id = 0;
	CHAR buffer[1024] = { 0 };

	while ((err = fscanf_s(names, "%u %1000[^\n]", &id, buffer, _countof(buffer))) != EOF)
	{
		g_windows2[(HWND) id] = buffer; 
		OutputDebugStringA("+window: ");
		OutputDebugStringA(buffer);
		OutputDebugStringA("\n");
	}
	while ((err = fscanf_s(images, "%u %1000[^\n]", &id, buffer, _countof(buffer))) != EOF)
	{
		g_images2[(HWND) id] = buffer;
		OutputDebugStringA("+image: ");
		OutputDebugStringA(buffer);
		OutputDebugStringA("\n");
	}
	while ((err = fscanf_s(classes, "%u %1000[^\n]", &id, buffer, _countof(buffer))) != EOF)
	{
		g_classes2[(HWND) id] = buffer;
		OutputDebugStringA("+class: ");
		OutputDebugStringA(buffer);
		OutputDebugStringA("\n");
	}

	_fcloseall();

	EnumWindows(&::enumWindowsProc, 0);


}
Example #16
0
void CInitDevInfo::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	char cur_temp[500]={0x00};
	GetCurrentDirectory(500,cur_temp);
	CString CurrentPath;
	CurrentPath.Format("%s",cur_temp);

	this->OnOK();

	int state = 0;
	

	CDevKeyFirResume devKeyFirResumeDlg1(1,phSHandle);
	if(IDOK!=devKeyFirResumeDlg1.DoModal())
		return;
	devKeyFirResumeDlg1.GetRecoverState(&state);
	if(2 != state)
		return;

	//恢复管理员
	CDevKeyFirResume devKeyFirResumeDlg2(2,phSHandle);
	if(IDOK!=devKeyFirResumeDlg2.DoModal())
		return;
	devKeyFirResumeDlg2.GetRecoverState(&state);
	if(2 != state)
		return;


	SetCurrentDirectory(CurrentPath);

	int numclosed = _fcloseall( );
   
	Cph_PWMngrDlg phDlg(NULL,1,NULL,NULL,NULL/*phContainer*/,PWMMNGR_CAPTION);
	phDlg.DoModal();
}
Example #17
0
int _tmain(int argc, _TCHAR* argv[])
{
	FILE *tFile = fopen("myfile.txt", "w+");
	fprintf(tFile, "%s", "Привет мир из файла");
	system("pause");
	fclose(tFile);
	if (fopen_s(&tFile, "myFile.txt", "r")) return 0;
	setlocale(LC_ALL, ".1251");
	char *ch = new char[100];
	fseek(tFile, 0, SEEK_SET);
	while (!feof(tFile)) {
		fscanf_s(tFile, "%20s", ch, 100);
		printf("%s\n", ch);
	}
	system("pause");
	delete[] ch;
	_fcloseall();
	if (fopen_s(&tFile, "myFile.txt", "w+")) return 0;
	fprintf(tFile, "%s", "Привет опять из файла");
	if (freopen_s(&tFile, "myFile.txt", "r", tFile)) return 0;
	ch = new char[100];
	fseek(tFile, 0, SEEK_SET);
	while (!feof(tFile)) {
		fscanf_s(tFile, "%20s", ch, 100);
		printf("%s\n", ch);
	}
	system("pause");
	delete[] ch;
	_fcloseall();
	if (fopen_s(&tFile, "myFile.dat", "a+b")) return 0;
	fseek(tFile, 0, SEEK_SET);
	ch = new char[100];
	strcpy_s(ch, 100, "Привет снова из файла");
	MyStruct *str = new MyStruct;
	str->chislo = 10.5;
	str->mode = 10;
	str->str = new char[100];
	strcpy_s(str->str, 100, ch);
	str->mode = strlen(str->str);
	fwrite(&str->chislo, sizeof(str->chislo), 1, tFile);
	fwrite(&str->mode, sizeof(str->mode), 1, tFile);
	fwrite(str->str, 1, strlen(str->str) + 1, tFile);
	delete[] str->str;
	delete str;
	if (freopen_s(&tFile, "myFile.dat", "r+b", tFile)) return 0;
	fseek(tFile, 0, SEEK_SET);
	str = new MyStruct;
	while (!feof(tFile)) {
		fread_s(&str->chislo, sizeof(str->chislo), sizeof(str->chislo), 1, tFile);
		fread_s(&str->mode, sizeof(str->mode), sizeof(str->mode), 1, tFile);
		fpos_t pos;
		fgetpos(tFile, &pos);
		printf("%d, %f, %d\n", str->mode, str->chislo, pos);
		str->str = new char[100];
		fread_s(str->str, 100, 1, str->mode + 1, tFile);
		printf("%s\n", str->str);
		delete[] str->str;
	}
	delete str;
	system("pause");
	delete[] ch;
	fclose(tFile);
	return 0;
}
DWORD WINAPI zipCompress(LPVOID lpParam){
	_filename = COMPRESS_PREPARING;
	sTime = time(NULL);

	CZipArchive zip;
	vector<__int64>filesize;
	_size_all = 1;

	/*char b[123];
	sprintf(b, "%d", spanSize);
	MessageBox(0, b, "", 0);*/
	
	if(spanSize == 0)
		zip.Open(archive_name, CZipArchive::OpenMode::zipCreate);
	else
		zip.Open(archive_name, CZipArchive::OpenMode::zipCreateSpan, spanSize);
	zip.SetPassword(passwd);
	//zip.SetAutoFlush();
	
	_filename = COMPRESS_GETTING_FILE_SIZES;
	for (int i=0; i<int(filename.size()); ++i) {
      FILE* f=fopen(filename[i].c_str(), "rb");
      if(f){
		_fseeki64(f, 0LL, SEEK_END);
		filesize.push_back(_ftelli64(f));
        _size_all += _ftelli64(f);
        fclose(f);
      }
    }

	for(int i=0;i<filename.size();i++){
		_filename = filename[i];
		//zip.AddNewFile(filename[i].c_str(), MEM);
		zip.AddNewFile(filename[i].c_str(), filename[i].c_str(), MEM);
		_done_all += filesize[i];
		
		CZipFileHeader fhInfo;
		zip.GetFileInfo(fhInfo, i);
		_compressed += fhInfo.GetEffComprSize() + fhInfo.GetSize() + fhInfo.GetExtraFieldSize();
		
	}
	zip.Close();

	/*FILE *f = fopen(archive_name, "rb");
	if(f){
		_fseeki64(f, 0LL, SEEK_END);
		_compressed = _ftelli64(f);
		fclose(f);
	}*/

	if(sfx_arch){ //do³¹czamy modu³ sfx
		_filename = COMPRESS_ADDING_SFX_MOD;
		
		/*archive_name[strlen(archive_name)-3] = '\0';
		sprintf(archive_name, "%sexe", archive_name);*/

		//odczytujemy œcie¿kê do modu³u
		HANDLE hProc = GetCurrentProcess();
		HMODULE hMod;
        DWORD cbNeeded;
		char processName[MAX_PATH];

        EnumProcessModules(hProc, &hMod, sizeof(hMod), &cbNeeded);
        GetModuleFileNameEx(hProc, hMod, processName, MAX_PATH);
        
		for(int i=strlen(processName)-1;i>=0;i--){
			if(processName[i] == '\\' || processName[i] == '/'){
				processName[i+1] = '\0';
				sprintf(processName, "%skgb_arch_sfx_zip.mod", processName);
				break;
			}
		}

		FILE *sfx = fopen(processName, "rb");

		//MessageBox(0, "", "", 0);
		if(sfx == NULL){
			MessageBox(0, "An internal error has occured, please reinstall KGB Archiver!", "KGB Archiver", 0);
			_fcloseall();
			DeleteFile(archive_name);
			return false;
		}

		//MessageBox(0, archive_name, "", 0);

		FILE *archive = fopen(archive_name, "rb");
		if(archive == NULL){
			_fcloseall();
			return false;
		}
		//MessageBox(0, "", "", 0);

		archive_name[strlen(archive_name)-3] = '\0';
		sprintf(archive_name, "%sexe", archive_name);

		//MessageBox(0, archive_name, "", 0);

		FILE *archive_sfx = fopen(archive_name, "wb");
		if(archive_sfx == NULL){
			_fcloseall();
			return false;
		}

		//MessageBox(0, "2", "", 0);

		int count=0;
		char buffer[65536];
		while(!feof(sfx)){
			count = fread(buffer, sizeof(char), sizeof(buffer), sfx);
			fwrite(buffer, sizeof(char), count, archive_sfx);
		}
		while(!feof(archive)){
			count = fread(buffer, sizeof(char), sizeof(buffer), archive);
			fwrite(buffer, sizeof(char), count, archive_sfx);
		}
		fclose(archive);
		fclose(sfx);
		fclose(archive_sfx);

		archive_name[strlen(archive_name)-3] = '\0';
		sprintf(archive_name, "%szip", archive_name);
		DeleteFile(archive_name);
	}

	_done_all++;

	return true;
}
BOOL Ckgb_arch_decompressDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	/*ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);*/

	/*CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}*/

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	//SetIcon(m_hIcon, TRUE);		// Set small icon

	// TODO: Add extra initialization here
	
	lFiles.InsertColumn(0, loadString(IDS_FILE), LVCFMT_LEFT, 300);
	lFiles.InsertColumn(1, loadString(IDS_SIZE), LVCFMT_RIGHT, 100);

	
	char curDir[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, curDir);
	eDestination.SetWindowText(curDir);

	vector<string>files;
	vector<unsigned long>fsize;
	char arch[MAX_PATH];

	HANDLE hProc = GetCurrentProcess();
	HMODULE hMod;
    DWORD cbNeeded;

    EnumProcessModules(hProc, &hMod, sizeof(hMod), &cbNeeded);
    GetModuleFileNameEx(hProc, hMod, arch, MAX_PATH); //pierwszy modu³ jest aplikacj¹
    
//MessageBox("");
	if(isSFXencrypted(arch)){
		//wo³amy o has³o
		dlgPasswd dlgPass;
		if(dlgPass.DoModal() != IDOK){
			theApp.ExitInstance();
			return false;
		}

		strcpy(passwd, dlgPass._passwd);
		for(int i=strlen(passwd);i<32;i++)
			passwd[i] = '\0';
		
		char arch2[MAX_PATH];
		//strcpy(arch2, arch.c_str());
		GetTempPath(MAX_PATH, arch2);
		GetLongPathName(arch2, arch2, sizeof(arch2));
		strcat(arch2, "temp.kgb");
		//arch2[strlen(arch2)-1] = 'b';

		aes_ctx ctx[1];
		ctx->n_rnd = 0; // ensure all flags are initially set to zero
		ctx->n_blk = 0;
		aes_dec_key((const unsigned char*)passwd, 32, ctx);
		
		/*CDialog dProgress;
		dProgress.Create(IDD_DECODING);
		dProgress.ShowWindow(SW_SHOW);
		dProgress.UpdateWindow();*/
		
		FILE *fin = fopen(arch, "rb");
		if(fin == 0)
			return false;
		fseek(fin, isSFXencrypted(arch), SEEK_SET);
		FILE *fout = fopen(arch2, "wb");
		if(fout == 0)
			return false;
		decfile(fin, fout, ctx, arch, arch2);

		fclose(fin);
		fclose(fout);
		/*dProgress.ShowWindow(SW_HIDE);
		dProgress.~CDialog();*/
		if(!checkArchiveFormat(arch2)){
			_fcloseall();
			DeleteFile(arch2);
			//eArchName.SetWindowText("");
			MessageBox(loadString(IDS_WRONG_PASSWD), "KGB Archiver");
			theApp.ExitInstance();
			return false;
		}

		strcpy(arch, arch2);
		getFilesFromArchive(arch, files, fsize);
	}else{
		getFilesFromArchive(arch, files, fsize);
	}
	strcpy(globalARCH, arch);
//MessageBox("");
	for(unsigned long i=0;i<files.size();i++){
		char buffer[32];
		/*if(filesizes[i] < 1024)
			sprintf(buffer, "%dB", filesizes[i]);
		else if(filesizes[i] < 1024*1024)
			sprintf(buffer, "%dKB", filesizes[i]/1024);
		else
			sprintf(buffer, "%dMB", filesizes[i]/1024/1024);
		*/
		sprintf(buffer, "%.1fKB", (double)fsize[i]/1024.0);
		lFiles.InsertItem(0, i, 0, 0, 0, 0, 0);
		
		lFiles.SetItemText(i, 0, files[i].c_str());
		lFiles.SetItemText(i, 1, buffer);
	}

	//MessageBox("");

	//delete curDir;

	/*char *cmd = theApp.m_lpCmdLine;
	char temp[MAX_PATH];
	bool isArchName = true;
	
	/*sscanf(cmd, "-%c", &mode);
	switch(mode){
		case 'c':
			cmd += 2; //przesówamy wskaŸnik* /

	for(unsigned long i=0;i<strlen(cmd);i++){
		if(cmd[i] == '"'){
			for(unsigned long j=0;i+j+1<strlen(cmd);j++){
				if(cmd[i+j+1] != '"')
					temp[j] = cmd[i+j+1];
				else if(cmd[i+j+1] == '"'){
					temp[j] = 0;
					i += j+1;
					if(!isArchName)
						//lFiles.AddString(temp);
						eDestination.SetWindowText(temp);
					else{
						eArchName.SetWindowText(temp);
						isArchName = false;
					}
					break;
				}
			}
		}
	}*/

	//MessageBox(cmd);

	/*if(strlen(temp) == 0 || strlen(cmd) <= 2)
		return TRUE;

	vector<string> files;
	vector<unsigned long> filesizes;
	if(!getFilesFromArchive(temp, files, filesizes)){
		MessageBox("Wybrany plik nie jest prawid³owym archiwum KGB!");
		eArchName.SetWindowText("");
		eDestination.SetWindowText("");
		return TRUE;
	}

	//lFiles.DeleteAllItems();

	for(unsigned long i=0;i<files.size();i++){
		char buffer[32];
		/*if(filesizes[i] < 1024)
			sprintf(buffer, "%dB", filesizes[i]);
		else if(filesizes[i] < 1024*1024)
			sprintf(buffer, "%dKB", filesizes[i]/1024);
		else
			sprintf(buffer, "%dMB", filesizes[i]/1024/1024);
		* /
		sprintf(buffer, "%.1fKB", (double)filesizes[i]/1024.0);
		lFiles.InsertItem(0, i, 0, 0, 0, 0, 0);
		
		lFiles.SetItemText(i, 0, files[i].c_str());
		lFiles.SetItemText(i, 1, buffer);
	}*/

	return TRUE;  // return TRUE  unless you set the focus to a control
}
Example #20
0
void LoadTeacherDataFromFile(char *source,char *destination)
{
	FILE *norfile, *binfile;
	errno_t e = fopen_s(&norfile,source, "r+");
	errno_t e1 = fopen_s(&binfile, destination, "r+b");
	char stringdata[64];
	char name[24];
	char dept[12];
	char college[24];
	int staffid;
	struct TeacherLeafPage l;
	memset(&l, 0, sizeof(struct TeacherLeafPage));
	int data_offset = 0;
	struct Teacher s;
	struct NonLeafPage n;
	memset(&n, 0, sizeof(struct NonLeafPage));
	struct TableSector t;
	int BlocksCount = 128;
	int tableOffset = 1;
	int of_offsets = 0, key_offset = 0;
	if (e1 != 0 || e != 0)
	{
		printf("e1=%d\te2=%d\n", e, e1);
		printf("Error while loading pages");
		return;
	}

	fread(&t, sizeof(struct TableSector), 1, binfile);

	fseek(binfile, 0, SEEK_END);
	while (!feof(norfile))
	{
		fgets(stringdata, 64, norfile);
		separateValuesTeacher(stringdata, name, college,dept, &staffid);
		strcpy_s(s.clgname, college);
		strcpy_s(s.name, name);
		strcpy_s(s.dept, dept);
		s.staffid = staffid;
		//printf("%d\t%s\t%s\t%s\n", s.staffid, s.name, s.dept, s.clgname);
		l.data[data_offset++] = s;
		//printf("data offset=%d\n", data_offset);
		if (data_offset == 7)
		{
			fseek(binfile, (BlocksCount*blocksize), SEEK_SET);
			l.pagetype = 1;
			l.tableid = 2;
			fwrite(&l, sizeof(struct TeacherLeafPage), 1, binfile);
			n.offsets[of_offsets++] = BlocksCount*blocksize;
			//printf("\n\noffset=%d\tBlock Count=%d\n\n",of_offsets, n.offsets[of_offsets-1]/512);
			BlocksCount++;
			n.keys[key_offset++] = l.data[6].staffid + 1;
			if (of_offsets > 1)
			{
				n.offsets[0] = 128 * 512;
				n.pagetype = 2;
				fwrite(&n, sizeof(struct NonLeafPage), 1, binfile);
				//printf(" Non Leaf Block Count=%d\n", BlocksCount);
				BlocksCount++;
			}
			t.tableIds[tableOffset] = 1;
			t.rootNodeIds[tableOffset] = (BlocksCount - 1)*blocksize;
			data_offset = 0;
		}
	}
	fseek(binfile, t.rootNodeIds[1], SEEK_SET);
	//printf("\npostion=%d\n", ftell(binfile));
	fwrite(&n, sizeof(struct NonLeafPage), 1, binfile);
	//printf("Blocks Count=%d\n", BlocksCount);
	//printf("table id=%d \t table root=%d\n", t.tableIds[1], t.rootNodeIds[1]);
	fseek(binfile, 0, SEEK_SET);
	fwrite(&t, sizeof(struct TableSector), 1, binfile);
	_fcloseall();
}
Example #21
0
void LoadFromTheFileAndSave(char *source, char *destination)
{
	FILE *norfile, *binfile;
	errno_t e = fopen_s(&norfile, source, "r+");
	errno_t e1 = fopen_s(&binfile, "s.bin", "wb+");
	char stringdata[64];
	char name[24];
	char college[24];
	int rollno;
	struct LeafPage l;
	int data_offset = 0;
	struct Student s;
	struct NonLeafPage n;
	memset(&n, 0, sizeof(struct NonLeafPage));
	struct TableSector t;
	int BlocksCount = 1;
	int tableOffset = 0;
	int of_offsets = 0, key_offset = 0;
	if (e1 != 0 || e != 0)
	{
		printf("e1=%d\te2=%d\n", e, e1);
		printf("Error while loading pages");
		return;
	}
	while (!feof(norfile))
	{
		fgets(stringdata, 64, norfile);
		separateValues1(stringdata, name, college, &rollno);
		strcpy_s(s.clgname, college);
		strcpy_s(s.name, name);
		s.rollno = rollno;
		l.data[data_offset++] = s;
		if (data_offset == 10)
		{
			l.pagetype = 1;
			fseek(binfile, (BlocksCount*blocksize), SEEK_SET);
			l.pagetype = 1;
			l.tableid = 1;
			fwrite(&l, sizeof(struct LeafPage), 1, binfile);
			n.offsets[of_offsets++] = BlocksCount*blocksize;
			BlocksCount++;
			n.keys[key_offset++] = l.data[9].rollno + 1;
			if (of_offsets > 1)
			{
				n.offsets[0] = 512;
				n.pagetype = 2;
				fwrite(&n, sizeof(struct NonLeafPage), 1, binfile);
				//printf(" Non Leaf Block Count=%d\n", BlocksCount);
				BlocksCount++;
			}
			t.tableIds[tableOffset] = 1;
			t.rootNodeIds[tableOffset] = (BlocksCount-1)*blocksize;
			data_offset = 0;
		}
	}
	printf("Blocks Count=%d\n", BlocksCount);
	printf("table id=%d \t table root=%d\n", t.tableIds[0], t.rootNodeIds[0]);
	fseek(binfile, 0, SEEK_SET);
	fwrite(&t, sizeof(struct TableSector), 1, binfile);
	_fcloseall();
}
Example #22
0
void main()
{
 char oppcde[10],oprnd[10],lable[10],cde[10][10],chh;
 char mnm[20][20]={"PROG","LDCH","STCH","END"};//MENMONICS USED
 int loctre,strt,lengt,i=0,j=0;
 FILE *fp4,*fp5,*fp6;//FILE POINTERS
 fp4=fopen("INPUT.DAT","r");//OPENING INPUT FILE IN READ MODE
 fp5=fopen("SYM.DAT","w");
 fp6=fopen("OUT.DAT","w");
 fscanf(fp4,"%s%s%s",lable,oppcde,oprnd);
 if(strcmp(oppcde,"PROG")==0)//CHECKING STARTING SYMBOL
  {
   strt=atoi(oprnd);
   loctre=strt;
   fprintf(fp6,"%s\t%s\t%s\n",lable,oppcde,oprnd);
   fscanf(fp4,"%s%s%s",lable,oppcde,oprnd);
  }
 else
  loctre=0;
 while(strcmp(oppcde,"END")!=0)
  {
   fprintf(fp6,"%d",loctre);
   if(strcmp(lable,"**")!=0)
     fprintf(fp5,"%s\t%d\n",lable,loctre);
   strcpy(cde[i],mnm[j]);
   while(strcmp(mnm[j],"END")!=0)
    {
     if(strcmp(oppcde,mnm[j])==0)
     {
      loctre+=3;
      break;
     }
     strcpy(cde[i],mnm[j]);
     j++;
    }
   if(strcmp(oppcde,"WORD")==0)
    loctre+=3;
   else if(strcmp(oppcde,"RESW")==0)
    loctre+=(3*(atoi(oprnd)));
   else if(strcmp(oppcde,"RESB")==0)
    loctre+=(atoi(oprnd));
   else if(strcmp(oppcde,"BYTE")==0)
    ++loctre;
   fprintf(fp6,"\t%s\t%s\t%s\n",lable,oppcde,oprnd);
   fscanf(fp4,"%s%s%s",lable,oppcde,oprnd);
  }
  fprintf(fp6,"%d\t%s\t%s\t%s\n",loctre,lable,oppcde,oprnd);
  _fcloseall();
  printf("\nThe contents of Input Table :\n");//PRINTING INPUT FILE
  fp4=fopen("INPUT.DAT","r");
  chh=fgetc(fp4);
  while(chh!=EOF)
   {
    printf("%c",chh);
    chh=fgetc(fp4);
   }
  printf("\nThe contents of Output Table :\n\t");//PRINTING OF INTERMEDIATE FILE
  fp6=fopen("OUT.DAT","r");
  chh=fgetc(fp6);
  while(chh!=EOF)
   {
    printf("%c",chh);
    chh=fgetc(fp6);
   }
  printf("\nThe contents of Sym Table :\n");//PRINTING OF SYMTABLE
  fp5=fopen("SYM.DAT","r");
  chh=fgetc(fp5);
  while(chh!=EOF)
   {
    printf("%c",chh);
    chh=fgetc(fp5);
   }
  _fcloseall();
}
void WriteApplicationFile(char *mappname,char* MessageString)
{
	try
	{
		char mmCurentDir[512];
		SYSTEMTIME systime;

		
		char mdate[255]={0};
		char mmdate[255]={0};
		char mtime[255]={0};
		char mmFileName[512]={0};
		bool isFileExist;
		char mlogtype[1024]={0};
		bool isPerDeleted=false;
		
		//lstrcpy(mmCurentDir , mAPPLOG);
		//strcpy(mmCurentDir,SAAZODSetUpPath);
		lstrcat(mmCurentDir ,"ApplicationLog\\");
		//strcat(mmCurentDir , "\\Log");

		GetLocalTime(&systime);

		sprintf(mdate  , "%04d-%02d-%02d" ,systime.wYear, systime.wDay , systime.wMonth );
		sprintf(mmdate , "%04d%02d%02d" ,systime.wYear, systime.wDay , systime.wMonth);
		//GetTimeFormat(LOCALE_SYSTEM_DEFAULT , NULL , &systime , "hh':'mm':'ss" , mtime , 255);
		sprintf(mtime , "%02d:%02d:%02d" , systime.wHour, systime.wMinute , systime.wSecond);
		sprintf(mmFileName , "%s\\%s.Log" , mmCurentDir , mappname);
		FILE *fp=NULL;

		if(IsDirExist(mmFileName) == false)
		{
			isFileExist = false;
			fp=fopen( mmFileName ,"w+"); //for wiping out the contents
			_fcloseall( );
		}
		else
		{
			isFileExist = true;
		}

		DWORD dwFileSize = IsFile2MB(mmFileName);// Check for 2 MB (2097152 Bytes)

		if(dwFileSize >= 2097152)
		{
			isPerDeleted = true;
			isFileExist = false;
			fp=fopen( mmFileName ,"w+"); //For wiping out the contents
			_fcloseall( );
		}
		
		fp = fopen( mmFileName , "a");
		if(!(fp == NULL))
		{
			if (isFileExist == false)
			{
				fprintf(fp , "#Software: %s\n#Version: 1.0 \n#Date: %s %s\n# \n" , "zSmart.exe", mdate , mtime);
				fprintf(fp , "----------------------------------------------------------------------\n" );
				//fprintf(fp , "#Fields:\tdtime\tSession Id\tSession User Name\tmodule\n");
				if(isPerDeleted == true)
				{
					fprintf(fp , "Previous content is deleted. Due to the size limit of 2 MB\n" );
					fprintf(fp , "----------------------------------------------------------------------\n" );
				}
			}

				
			fprintf(fp , "%s %s\t%s \n" , mdate , mtime , MessageString);
		
		}
		else
		{ 

		}
		_fcloseall( );
	}
	catch(...)
	{
	}
}
Example #24
0
void WriteCodeFile()
{
	int numclosed;
	errno_t err;
	UINT8 ch = 0;
	readFilename();

	err = fopen_s(&fcode, "code.txt", "wb");
	if (err == 0)
	{
		printf_s("The file CODE.txt was opened\n");
	}
	else
	{
		printf_s("The file CODE.txt was not opened\n");
		numclosed = _fcloseall();
	}
	while (!feof(fi))
	{

		fscanf_s(fi, "%c", &ch);
		if (feof(fi))
		{
			break;
		}
		if (strchr(rusUp, ch))
		{
			ch = ch - 0xC0 + 0xE0;
			fwrite(ArrAlfa[ch].code, ArrAlfa[ch].length, 1, fcode);

		}
		else
		if (strchr(rusDown, ch))
		{
			fwrite(ArrAlfa[ch].code, ArrAlfa[ch].length, 1, fcode);
		}
		else
		if (strchr(engUp, ch))
		{
			ch = ch - 'A' + 'a';
			fwrite(ArrAlfa[ch].code, ArrAlfa[ch].length, 1, fcode);
		}
		else
		if (strchr(engDown, ch))
		{
			fwrite(ArrAlfa[ch].code, ArrAlfa[ch].length, 1, fcode);
		}
		else
		if (strchr("-.,:!?;", ch))
		{
			ch = '.';
			fwrite(ArrAlfa[ch].code, ArrAlfa[ch].length, 1, fcode);
		}
		else
		if (ch == ' ')
		{
			fwrite(ArrAlfa[ch].code, ArrAlfa[ch].length, 1, fcode);
		}
		else
		if (ch == 0xA8 || ch == 0xB8)
		{
			ch = 0xE5;
			fwrite(ArrAlfa[ch].code, ArrAlfa[ch].length, 1, fcode);
		}

	}
	numclosed = _fcloseall();

	system("pause");
}
Example #25
0
int
main(int argc, char **argv)
#endif	/* WIN32 */
{
#ifdef	WIN32
	struct arg_param *p = (struct arg_param *)pv;
	int      		argc;
	char			**argv;
	SERVICE_STATUS          ss;
#endif	/* WIN32 */
	char *name = NULL;
	struct tpp_config conf;
	int rpp_fd;
	char *pc;
	int numthreads;
	char lockfile[MAXPATHLEN + 1];
	char path_log[MAXPATHLEN + 1];
	char svr_home[MAXPATHLEN + 1];
	char *log_file = 0;
	char *host;
	int port;
	char *routers = NULL;
	int c, i, rc;
	extern char *optarg;
	int	are_primary;
	int	num_var_env;
#ifndef WIN32
	struct sigaction act;
	struct sigaction oact;
#endif

#ifndef WIN32
	/*the real deal or just pbs_version and exit*/

	execution_mode(argc, argv);
#endif

	/* As a security measure and to make sure all file descriptors	*/
	/* are available to us,  close all above stderr			*/
#ifdef WIN32
	_fcloseall();
#else
	i = sysconf(_SC_OPEN_MAX);
	while (--i > 2)
		(void)close(i); /* close any file desc left open by parent */
#endif

	/* If we are not run with real and effective uid of 0, forget it */
#ifdef WIN32
	argc = p->argc;
	argv = p->argv;

	ZeroMemory(&ss, sizeof(ss));
	ss.dwCheckPoint = 0;
	ss.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
	ss.dwCurrentState = g_dwCurrentState;
	ss.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
	ss.dwWaitHint = 6000;

	if (g_ssHandle != 0)
		SetServiceStatus(g_ssHandle, &ss);

	if (!isAdminPrivilege(getlogin())) {
		fprintf(stderr, "%s: Must be run by root\n", argv[0]);
		return (2);
	}

#else
	if ((getuid() != 0) || (geteuid() != 0)) {
		fprintf(stderr, "%s: Must be run by root\n", argv[0]);
		return (2);
	}
#endif	/* WIN32 */

	/* set standard umask */
#ifndef WIN32
	umask(022);
#endif

	/* load the pbs conf file */
	if (pbs_loadconf(0) == 0) {
		fprintf(stderr, "%s: Configuration error\n", argv[0]);
		return (1);
	}

	umask(022);

#ifdef	WIN32
	save_env();
#endif
	/* The following is code to reduce security risks                */
	/* start out with standard umask, system resource limit infinite */
	if ((num_var_env = setup_env(pbs_conf.pbs_environment)) == -1) {
#ifdef	WIN32
		g_dwCurrentState = SERVICE_STOPPED;
		ss.dwCurrentState = g_dwCurrentState;
		ss.dwWin32ExitCode = ERROR_INVALID_ENVIRONMENT;
		if (g_ssHandle != 0) SetServiceStatus(g_ssHandle, &ss);
		return (1);
#else
		exit(1);
#endif	/* WIN32 */
	}

#ifndef WIN32
	i = getgid();
	(void)setgroups(1, (gid_t *)&i);	/* secure suppl. groups */
#endif

	log_event_mask = &pbs_conf.pbs_comm_log_events;
	tpp_set_logmask(*log_event_mask);

#ifdef WIN32
	winsock_init();
#endif

	routers = pbs_conf.pbs_comm_routers;
	numthreads = pbs_conf.pbs_comm_threads;

	server_host[0] = '\0';
	if (pbs_conf.pbs_comm_name) {
		name = pbs_conf.pbs_comm_name;
		host = tpp_parse_hostname(name, &port);
		if (host)
			snprintf(server_host, sizeof(server_host), "%s", host);
		free(host);
		host = NULL;
	} else if (pbs_conf.pbs_leaf_name) {
		char *endp;

		snprintf(server_host, sizeof(server_host), "%s", pbs_conf.pbs_leaf_name);
		endp = strchr(server_host, ','); /* find the first name */
		if (endp)
			*endp = '\0';
		endp = strchr(server_host, ':'); /* cut out the port */
		if (endp)
			*endp = '\0';
		name = server_host;
	} else {
		if (gethostname(server_host, (sizeof(server_host) - 1)) == -1) {
#ifndef WIN32
			sprintf(log_buffer, "Could not determine my hostname, errno=%d", errno);
#else
			sprintf(log_buffer, "Could not determine my hostname, errno=%d", WSAGetLastError());
#endif
			fprintf(stderr, "%s\n", log_buffer);
			return (1);
		}
		if ((get_fullhostname(server_host, server_host, (sizeof(server_host) - 1)) == -1)) {
			sprintf(log_buffer, "Could not determine my hostname");
			fprintf(stderr, "%s\n", log_buffer);
			return (1);
		}
		name = server_host;
	}
	if (server_host[0] == '\0') {
		sprintf(log_buffer, "Could not determine server host");
		fprintf(stderr, "%s\n", log_buffer);
		return (1);
	}

	while ((c = getopt(argc, argv, "r:t:e:N")) != -1) {
		switch (c) {
			case 'e': *log_event_mask = strtol(optarg, NULL, 0);
				break;
			case 'r':
				routers = optarg;
				break;
			case 't':
				numthreads = atol(optarg);
				if (numthreads == -1) {
					usage(argv[0]);
					return (1);
				}
				break;
			case 'N':
				stalone = 1;
				break;
			default:
				usage(argv[0]);
				return (1);
		}
	}

	(void)strcpy(daemonname, "Comm@");
	(void)strcat(daemonname, name);
	if ((pc = strchr(daemonname, (int)'.')) != NULL)
		*pc = '\0';

	if(set_msgdaemonname(daemonname)) {
		fprintf(stderr, "Out of memory\n");
		return 1;
	}

	(void) snprintf(path_log, sizeof(path_log), "%s/%s", pbs_conf.pbs_home_path, PBS_COMM_LOGDIR);
#ifdef WIN32
	/*
	 * let SCM wait 10 seconds for log_open() to complete
	 * as it does network interface query which can take time
	 */

	ss.dwCheckPoint++;
	ss.dwWaitHint = 60000;
	if (g_ssHandle != 0) SetServiceStatus(g_ssHandle, &ss);
#endif
	(void) log_open(log_file, path_log);

	/* set pbs_comm's process limits */
	set_limits(); /* set_limits can call log_record, so call only after opening log file */

	/* set tcp function pointers */
	set_tpp_funcs(log_tppmsg);

	(void) snprintf(svr_home, sizeof(svr_home), "%s/%s", pbs_conf.pbs_home_path, PBS_SVR_PRIVATE);
	if (chdir(svr_home) != 0) {
		(void) sprintf(log_buffer, msg_init_chdir, svr_home);
		log_err(-1, __func__, log_buffer);
		return (1);
	}

	(void) sprintf(lockfile, "%s/%s/comm.lock", pbs_conf.pbs_home_path, PBS_SVR_PRIVATE);
	if ((are_primary = are_we_primary()) == FAILOVER_SECONDARY) {
		strcat(lockfile, ".secondary");
	} else if (are_primary == FAILOVER_CONFIG_ERROR) {
		sprintf(log_buffer, "Failover configuration error");
		log_err(-1, __func__, log_buffer);
#ifdef WIN32
		g_dwCurrentState = SERVICE_STOPPED;
		ss.dwCurrentState = g_dwCurrentState;
		ss.dwWin32ExitCode = ERROR_SERVICE_NOT_ACTIVE;
		if (g_ssHandle != 0) SetServiceStatus(g_ssHandle, &ss);
#endif
		return (3);
	}

	if ((lockfds = open(lockfile, O_CREAT | O_WRONLY, 0600)) < 0) {
		(void) sprintf(log_buffer, "pbs_comm: unable to open lock file");
		log_err(errno, __func__, log_buffer);
		return (1);
	}

	if ((host = tpp_parse_hostname(name, &port)) == NULL) {
		sprintf(log_buffer, "Out of memory parsing leaf name");
		log_err(errno, __func__, log_buffer);
		return (1);
	}

	rc = 0;
	if (pbs_conf.auth_method == AUTH_RESV_PORT) {
		rc = set_tpp_config(&pbs_conf, &conf, host, port, routers, pbs_conf.pbs_use_compression,
				TPP_AUTH_RESV_PORT, NULL, NULL);
	} else {
		/* for all non-resv-port based authentication use a callback from TPP */
		rc = set_tpp_config(&pbs_conf, &conf, host, port, routers, pbs_conf.pbs_use_compression,
				TPP_AUTH_EXTERNAL, get_ext_auth_data, validate_ext_auth_data);
	}
	if (rc == -1) {
		(void) sprintf(log_buffer, "Error setting TPP config");
		log_err(-1, __func__, log_buffer);
		return (1);
	}
	free(host);

	i = 0;
	if (conf.routers) {
		while (conf.routers[i]) {
			sprintf(log_buffer, "Router[%d]:%s", i, conf.routers[i]);
			fprintf(stdout, "%s\n", log_buffer);
			log_event(PBSEVENT_SYSTEM | PBSEVENT_FORCE, PBS_EVENTCLASS_SERVER, LOG_INFO, msg_daemonname, log_buffer);
			i++;
		}
	}

#ifndef DEBUG
#ifndef WIN32
	if (stalone != 1)
		go_to_background();
#endif
#endif


#ifdef WIN32
	ss.dwCheckPoint = 0;
	g_dwCurrentState = SERVICE_RUNNING;
	ss.dwCurrentState = g_dwCurrentState;
	if (g_ssHandle != 0) SetServiceStatus(g_ssHandle, &ss);
#endif

	if (already_forked == 0)
		lock_out(lockfds, F_WRLCK);

	/* go_to_backgroud call creates a forked process,
	 * thus print/log pid only after go_to_background()
	 * has been called
	 */
	sprintf(log_buffer, "%s ready (pid=%d), Proxy Name:%s, Threads:%d", argv[0], getpid(), conf.node_name, numthreads);
	fprintf(stdout, "%s\n", log_buffer);
	log_event(PBSEVENT_SYSTEM | PBSEVENT_FORCE, PBS_EVENTCLASS_SERVER, LOG_INFO, msg_daemonname, log_buffer);

#ifndef DEBUG
	pbs_close_stdfiles();
#endif

#ifdef WIN32
	signal(SIGINT, stop_me);
	signal(SIGTERM, stop_me);
#else
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	act.sa_handler = hup_me;
	if (sigaction(SIGHUP, &act, &oact) != 0) {
		log_err(errno, __func__, "sigaction for HUP");
		return (2);
	}
	act.sa_handler = stop_me;
	if (sigaction(SIGINT, &act, &oact) != 0) {
		log_err(errno, __func__, "sigaction for INT");
		return (2);
	}
	if (sigaction(SIGTERM, &act, &oact) != 0) {
		log_err(errno, __func__, "sigactin for TERM");
		return (2);
	}
	if (sigaction(SIGQUIT, &act, &oact) != 0) {
		log_err(errno, __func__, "sigactin for QUIT");
		return (2);
	}
#ifdef SIGSHUTDN
	if (sigaction(SIGSHUTDN, &act, &oact) != 0) {
		log_err(errno, __func__, "sigactin for SHUTDN");
		return (2);
	}
#endif	/* SIGSHUTDN */

	act.sa_handler = SIG_IGN;
	if (sigaction(SIGPIPE, &act, &oact) != 0) {
		log_err(errno, __func__, "sigaction for PIPE");
		return (2);
	}
	if (sigaction(SIGUSR1, &act, &oact) != 0) {
		log_err(errno, __func__, "sigaction for USR1");
		return (2);
	}
	if (sigaction(SIGUSR2, &act, &oact) != 0) {
		log_err(errno, __func__, "sigaction for USR2");
		return (2);
	}
#endif 	/* WIN32 */

	conf.node_type = TPP_ROUTER_NODE;
	conf.numthreads = numthreads;

	if ((rpp_fd = tpp_init_router(&conf)) == -1) {
		log_err(-1, __func__, "tpp init failed\n");
		return 1;
	}

	/* Protect from being killed by kernel */
	daemon_protect(0, PBS_DAEMON_PROTECT_ON);

	/* go in a while loop */
	while (get_out == 0) {

		if (hupped == 1) {
			struct pbs_config pbs_conf_bak;
			int new_logevent;

			hupped = 0; /* reset back */
			memcpy(&pbs_conf_bak, &pbs_conf, sizeof(struct pbs_config));

			if (pbs_loadconf(1) == 0) {
				log_tppmsg(LOG_CRIT, NULL, "Configuration error, ignoring");
				memcpy(&pbs_conf, &pbs_conf_bak, sizeof(struct pbs_config));
			} else {
				/* restore old pbs.conf */
				new_logevent = pbs_conf.pbs_comm_log_events;
				memcpy(&pbs_conf, &pbs_conf_bak, sizeof(struct pbs_config));
				pbs_conf.pbs_comm_log_events = new_logevent;
				log_tppmsg(LOG_INFO, NULL, "Processed SIGHUP");

				log_event_mask = &pbs_conf.pbs_comm_log_events;
				tpp_set_logmask(*log_event_mask);
			}
		}

		sleep(3);
	}

	tpp_router_shutdown();

	log_event(PBSEVENT_SYSTEM | PBSEVENT_FORCE, PBS_EVENTCLASS_SERVER, LOG_NOTICE, msg_daemonname, "Exiting");
	log_close(1);

	lock_out(lockfds, F_UNLCK);	/* unlock  */
	(void)close(lockfds);
	(void)unlink(lockfile);

	return 0;
}
Example #26
0
EXPORT BOOL WINAPI mhsp_fcloseall(int p1, int p2, int p3, int p4)
{
	return -_fcloseall();
}