mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
Work around sudo not changing $HOME thus the configuration file ending up in the invoking user $HOME with root permissions, leading to an unwriteable configuration file if running as user.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20103 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
884dc711b8
commit
c96452ac92
1 changed files with 38 additions and 15 deletions
|
@ -21,6 +21,10 @@
|
||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void RbSettings::open()
|
void RbSettings::open()
|
||||||
{
|
{
|
||||||
// only use built-in rbutil.ini
|
// only use built-in rbutil.ini
|
||||||
|
@ -28,11 +32,12 @@ void RbSettings::open()
|
||||||
// portable installation:
|
// portable installation:
|
||||||
// check for a configuration file in the program folder.
|
// check for a configuration file in the program folder.
|
||||||
QFileInfo config;
|
QFileInfo config;
|
||||||
config.setFile(QCoreApplication::instance()->applicationDirPath() + "/RockboxUtility.ini");
|
config.setFile(QCoreApplication::instance()->applicationDirPath()
|
||||||
|
+ "/RockboxUtility.ini");
|
||||||
if(config.isFile())
|
if(config.isFile())
|
||||||
{
|
{
|
||||||
userSettings = new QSettings(QCoreApplication::instance()->applicationDirPath() + "/RockboxUtility.ini",
|
userSettings = new QSettings(QCoreApplication::instance()->applicationDirPath()
|
||||||
QSettings::IniFormat, this);
|
+ "/RockboxUtility.ini", QSettings::IniFormat, this);
|
||||||
qDebug() << "config: portable";
|
qDebug() << "config: portable";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -46,6 +51,24 @@ void RbSettings::open()
|
||||||
void RbSettings::sync()
|
void RbSettings::sync()
|
||||||
{
|
{
|
||||||
userSettings->sync();
|
userSettings->sync();
|
||||||
|
#if defined(Q_OS_LINUX)
|
||||||
|
// when using sudo it runs rbutil with uid 0 but unfortunately without a
|
||||||
|
// proper login shell, thus the configuration file gets placed in the
|
||||||
|
// calling users $HOME. This in turn will cause issues if trying to
|
||||||
|
// run rbutil later as user. Try to detect this case via the environment
|
||||||
|
// variable SUDO_UID and SUDO_GID and if set chown the user config file.
|
||||||
|
if(getuid() == 0)
|
||||||
|
{
|
||||||
|
char* realuser = getenv("SUDO_UID");
|
||||||
|
char* realgroup = getenv("SUDO_GID");
|
||||||
|
if(realuser != NULL && realgroup != NULL)
|
||||||
|
{
|
||||||
|
int realuid = atoi(realuser);
|
||||||
|
int realgid = atoi(realgroup);
|
||||||
|
chown(qPrintable(userSettings->fileName()), realuid, realgid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant RbSettings::deviceSettingCurGet(QString entry,QString def)
|
QVariant RbSettings::deviceSettingCurGet(QString entry,QString def)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue