diff --git a/singleapplication_p.cpp b/singleapplication_p.cpp index de4945e..a129aa0 100644 --- a/singleapplication_p.cpp +++ b/singleapplication_p.cpp @@ -33,11 +33,8 @@ #include #include -#include #include -#include #include -#include #include #include #include @@ -45,6 +42,12 @@ #include "singleapplication.h" #include "singleapplication_p.h" +#ifdef Q_OS_UNIX + #include + #include + #include +#endif + #ifdef Q_OS_WIN #include #include @@ -109,22 +112,22 @@ void SingleApplicationPrivate::genBlockServerName() if( GetUserNameW( username, &usernameLength ) ) { appData.addData( QString::fromWCharArray(username).toUtf8() ); } else { - appData.addData( QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).join("").toUtf8() ); + appData.addData( qgetenv("USERNAME") ); } #endif #ifdef Q_OS_UNIX - QProcess process; - process.start( "whoami" ); - if( process.waitForFinished( 100 ) && - process.exitCode() == QProcess::NormalExit) { - appData.addData( process.readLine() ); - } else { - appData.addData( - QDir( - QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).first() - ).absolutePath().toUtf8() - ); + QByteArray username; + uid_t uid = geteuid(); + if( uid != -1 ) { + struct passwd *pw = getpwuid(uid); + if( pw ) { + username = pw->pw_name; + } } + if( username.isEmpty() ) { + username = qgetenv("USER"); + } + appData.addData(username); #endif }