1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

* Don't steal the logfile when starting a secondary instance of Tomahawk.

This commit is contained in:
Christian Muehlhaeuser
2011-06-21 05:40:07 +02:00
parent eb70419203
commit 4006452d15
2 changed files with 31 additions and 22 deletions

View File

@@ -86,7 +86,8 @@
using namespace std; using namespace std;
ofstream logfile; ofstream logfile;
void TomahawkLogHandler( QtMsgType type, const char *msg ) void
TomahawkLogHandler( QtMsgType type, const char *msg )
{ {
static QMutex s_mutex; static QMutex s_mutex;
@@ -120,7 +121,8 @@ void TomahawkLogHandler( QtMsgType type, const char *msg )
logfile.flush(); logfile.flush();
} }
void setupLogfile() void
setupLogfile()
{ {
if ( QFileInfo( LOGFILE ).size() > LOGFILE_SIZE ) if ( QFileInfo( LOGFILE ).size() > LOGFILE_SIZE )
{ {
@@ -146,6 +148,28 @@ void setupLogfile()
qInstallMsgHandler( TomahawkLogHandler ); qInstallMsgHandler( TomahawkLogHandler );
} }
void
increaseMaxFileDescriptors()
{
#ifdef Q_WS_MAC
/// Following code taken from Clementine project, main.cpp. Thanks!
// Bump the soft limit for the number of file descriptors from the default of 256 to
// the maximum (usually 1024).
struct rlimit limit;
getrlimit( RLIMIT_NOFILE, &limit );
// getrlimit() lies about the hard limit so we have to check sysctl.
int max_fd = 0;
size_t len = sizeof( max_fd );
sysctlbyname( "kern.maxfilesperproc", &max_fd, &len, NULL, 0 );
limit.rlim_cur = max_fd;
int ret = setrlimit( RLIMIT_NOFILE, &limit );
if ( ret == 0 )
qDebug() << "Max fd:" << max_fd;
#endif
}
using namespace Tomahawk; using namespace Tomahawk;
@@ -158,12 +182,13 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] )
setApplicationName( QLatin1String( TOMAHAWK_APPLICATION_NAME ) ); setApplicationName( QLatin1String( TOMAHAWK_APPLICATION_NAME ) );
setApplicationVersion( QLatin1String( TOMAHAWK_VERSION ) ); setApplicationVersion( QLatin1String( TOMAHAWK_VERSION ) );
registerMetaTypes(); registerMetaTypes();
setupLogfile();
} }
void void
TomahawkApp::init() TomahawkApp::init()
{ {
setupLogfile();
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) ); qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
#ifdef TOMAHAWK_HEADLESS #ifdef TOMAHAWK_HEADLESS
@@ -222,24 +247,7 @@ TomahawkApp::init()
Tomahawk::setShortcutHandler( static_cast<MacShortcutHandler*>( m_shortcutHandler.data() ) ); Tomahawk::setShortcutHandler( static_cast<MacShortcutHandler*>( m_shortcutHandler.data() ) );
Tomahawk::setApplicationHandler( this ); Tomahawk::setApplicationHandler( this );
increaseMaxFileDescriptors();
/// Following code taken from Clementine project, main.cpp. Thanks!
// Bump the soft limit for the number of file descriptors from the default of 256 to
// the maximum (usually 1024).
struct rlimit limit;
getrlimit(RLIMIT_NOFILE, &limit);
// getrlimit() lies about the hard limit so we have to check sysctl.
int max_fd = 0;
size_t len = sizeof(max_fd);
sysctlbyname("kern.maxfilesperproc", &max_fd, &len, NULL, 0);
limit.rlim_cur = max_fd;
int ret = setrlimit(RLIMIT_NOFILE, &limit);
if (ret == 0) {
qDebug() << "Max fd:" << max_fd;
}
#endif #endif
// Connect up shortcuts // Connect up shortcuts

View File

@@ -105,9 +105,10 @@ private slots:
void setupSIP(); void setupSIP();
private: private:
void registerMetaTypes();
void initLocalCollection(); void initLocalCollection();
void loadPlugins(); void loadPlugins();
void registerMetaTypes();
void startServent(); void startServent();
void setupDatabase(); void setupDatabase();
void setupPipeline(); void setupPipeline();