Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 580458
Collapse All | Expand All

(-)slim-1.3.6/log.cpp (-6 / +20 lines)
Lines 1-23 Link Here
1
#include "log.h"
1
#include "log.h"
2
#include <iostream>
2
#include <iostream>
3
3
4
#include <sys/types.h>
5
#include <sys/stat.h>
6
#include <fcntl.h>
7
4
bool
8
bool
5
LogUnit::openLog(const char * filename)
9
LogUnit::openLog(const char * filename)
6
{
10
{
7
	if (logFile.is_open()) {
11
	if ( closeLog() )
12
	{
8
		cerr << APPNAME
13
		cerr << APPNAME
9
			<< ": opening a new Log file, while another is already open"
14
			<< ": opening a new Log file, while another is already open"
10
			<< endl;
15
			<< endl;
11
		logFile.close();
12
	}
16
	}
13
	logFile.open(filename, ios_base::app);
17
18
	// go through quite some trouble to get a close-on-exec file
19
	// descriptor and wrapping it into an ostream object for easing
20
	// logging
21
22
	fileBuffer.open( filename, ios_base::app );
23
	fcntl(fileBuffer.fd(), F_SETFD, FD_CLOEXEC);
24
	logFile.rdbuf( &fileBuffer );
14
25
15
	return !(logFile.fail());
26
	return !(logFile.fail());
16
}
27
}
17
28
18
void
29
bool
19
LogUnit::closeLog()
30
LogUnit::closeLog()
20
{
31
{
21
	if (logFile.is_open())
32
	if( ! fileBuffer.is_open() )
22
		logFile.close();
33
		return false;
34
35
	fileBuffer.close();
36
	return true;
23
}
37
}
(-)slim-1.3.6/log.h (-2 / +6 lines)
Lines 8-23 Link Here
8
#include "PAM.h"
8
#include "PAM.h"
9
#endif
9
#endif
10
#include "const.h"
10
#include "const.h"
11
#include <ext/stdio_filebuf.h>
11
#include <fstream>
12
#include <fstream>
12
13
13
using namespace std;
14
using namespace std;
14
15
15
static class LogUnit {
16
static class LogUnit {
16
	ofstream logFile;
17
	typedef __gnu_cxx::stdio_filebuf<char> FileDescBuffer;
18
	FileDescBuffer fileBuffer;
19
	ostream logFile;
17
public:
20
public:
18
	bool openLog(const char * filename);
21
	bool openLog(const char * filename);
19
	void closeLog();
22
	bool closeLog();
20
23
24
	LogUnit() : logFile(&fileBuffer) { }
21
	~LogUnit() { closeLog(); }
25
	~LogUnit() { closeLog(); }
22
26
23
	template<typename Type>
27
	template<typename Type>

Return to bug 580458