aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeander Schulten <Leander.Schulten@rwth-aachen.de>2020-03-27 07:52:48 +0100
committerLeander Schulten <Leander.Schulten@rwth-aachen.de>2020-03-27 07:52:48 +0100
commit49c282a64c2e357185cce851f7ce02f426a58afb (patch)
tree24455aff3ea8fe029b8090f35edcc18eb74d7e1a
parentMerge pull request #96 from itay-grudev/primary_user (diff)
downloadsingleapplication-49c282a64c2e357185cce851f7ce02f426a58afb.tar.xz
The codec for string from qgetenv and pw->pw_name is not necessarily utf8. So use QString::fromLocal8Bit and QStrings.
-rw-r--r--singleapplication_p.cpp17
-rw-r--r--singleapplication_p.h4
2 files changed, 11 insertions, 10 deletions
diff --git a/singleapplication_p.cpp b/singleapplication_p.cpp
index 8eb49ab..705a980 100644
--- a/singleapplication_p.cpp
+++ b/singleapplication_p.cpp
@@ -84,23 +84,24 @@ SingleApplicationPrivate::~SingleApplicationPrivate()
delete memory;
}
-QByteArray SingleApplicationPrivate::getUsername(){
+QString SingleApplicationPrivate::getUsername()
+{
#ifdef Q_OS_WIN
wchar_t username[UNLEN + 1];
// Specifies size of the buffer on input
DWORD usernameLength = UNLEN + 1;
if( GetUserNameW( username, &usernameLength ) )
- return QString::fromWCharArray( username ).toUtf8();
- return qgetenv( "USERNAME" );
+ return QString::fromWCharArray( username );
+ return qEnvironmentVariable( "USERNAME" );
#endif
#ifdef Q_OS_UNIX
- QByteArray username;
+ QString username;
uid_t uid = geteuid();
struct passwd *pw = getpwuid( uid );
if( pw )
- username = pw->pw_name;
+ username = QString::fromLocal8Bit( pw->pw_name );
if( username.isEmpty() )
- username = qgetenv( "USER" );
+ username = qEnvironmentVariable( "USER" );
return username;
#endif
}
@@ -127,7 +128,7 @@ void SingleApplicationPrivate::genBlockServerName()
// User level block requires a user specific data in the hash
if( options & SingleApplication::Mode::User ) {
- appData.addData( getUsername() );
+ appData.addData( getUsername().toUtf8() );
}
// Replace the backslash in RFC 2045 Base64 [a-zA-Z0-9+/=] to comply with
@@ -175,7 +176,7 @@ void SingleApplicationPrivate::startPrimary()
inst->primary = true;
inst->primaryPid = q->applicationPid();
- strncpy( inst->primaryUser, getUsername().data(), 127 );
+ strncpy( inst->primaryUser, getUsername().toUtf8().data(), 127 );
inst->primaryUser[127] = '\0';
inst->checksum = blockChecksum();
diff --git a/singleapplication_p.h b/singleapplication_p.h
index 5161411..2682b87 100644
--- a/singleapplication_p.h
+++ b/singleapplication_p.h
@@ -70,9 +70,9 @@ public:
Q_DECLARE_PUBLIC(SingleApplication)
SingleApplicationPrivate( SingleApplication *q_ptr );
- ~SingleApplicationPrivate();
+ ~SingleApplicationPrivate();
- QByteArray getUsername();
+ QString getUsername();
void genBlockServerName();
void initializeMemoryBlock();
void startPrimary();