diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2009-02-25 21:05:57 +0000 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2009-02-25 21:05:57 +0000 |
commit | c96452ac9236bc4288c11ebdcd7f4583a9ac189a (patch) | |
tree | 8301ef22efda460703f3f78ae25263cc6d0bb4cb /rbutil/rbutilqt/rbsettings.cpp | |
parent | 884dc711b8e91d34f9a354db73222ce674c393d9 (diff) | |
download | rockbox-c96452ac9236bc4288c11ebdcd7f4583a9ac189a.tar.gz rockbox-c96452ac9236bc4288c11ebdcd7f4583a9ac189a.zip |
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
Diffstat (limited to 'rbutil/rbutilqt/rbsettings.cpp')
-rw-r--r-- | rbutil/rbutilqt/rbsettings.cpp | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/rbutil/rbutilqt/rbsettings.cpp b/rbutil/rbutilqt/rbsettings.cpp index 45e61bee51..b26f86b921 100644 --- a/rbutil/rbutilqt/rbsettings.cpp +++ b/rbutil/rbutilqt/rbsettings.cpp | |||
@@ -16,11 +16,15 @@ | |||
16 | * KIND, either express or implied. | 16 | * KIND, either express or implied. |
17 | * | 17 | * |
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | 19 | ||
20 | #include "rbsettings.h" | 20 | #include "rbsettings.h" |
21 | 21 | ||
22 | #include <QSettings> | 22 | #include <QSettings> |
23 | 23 | ||
24 | #if defined(Q_OS_LINUX) | ||
25 | #include <unistd.h> | ||
26 | #endif | ||
27 | |||
24 | void RbSettings::open() | 28 | void RbSettings::open() |
25 | { | 29 | { |
26 | // only use built-in rbutil.ini | 30 | // only use built-in rbutil.ini |
@@ -28,11 +32,12 @@ void RbSettings::open() | |||
28 | // portable installation: | 32 | // portable installation: |
29 | // check for a configuration file in the program folder. | 33 | // check for a configuration file in the program folder. |
30 | QFileInfo config; | 34 | QFileInfo config; |
31 | config.setFile(QCoreApplication::instance()->applicationDirPath() + "/RockboxUtility.ini"); | 35 | config.setFile(QCoreApplication::instance()->applicationDirPath() |
32 | if(config.isFile()) | 36 | + "/RockboxUtility.ini"); |
37 | if(config.isFile()) | ||
33 | { | 38 | { |
34 | userSettings = new QSettings(QCoreApplication::instance()->applicationDirPath() + "/RockboxUtility.ini", | 39 | userSettings = new QSettings(QCoreApplication::instance()->applicationDirPath() |
35 | QSettings::IniFormat, this); | 40 | + "/RockboxUtility.ini", QSettings::IniFormat, this); |
36 | qDebug() << "config: portable"; | 41 | qDebug() << "config: portable"; |
37 | } | 42 | } |
38 | else | 43 | else |
@@ -46,7 +51,25 @@ void RbSettings::open() | |||
46 | void RbSettings::sync() | 51 | void RbSettings::sync() |
47 | { | 52 | { |
48 | userSettings->sync(); | 53 | userSettings->sync(); |
49 | } | 54 | #if defined(Q_OS_LINUX) |
55 | // when using sudo it runs rbutil with uid 0 but unfortunately without a | ||
56 | // proper login shell, thus the configuration file gets placed in the | ||
57 | // calling users $HOME. This in turn will cause issues if trying to | ||
58 | // run rbutil later as user. Try to detect this case via the environment | ||
59 | // variable SUDO_UID and SUDO_GID and if set chown the user config file. | ||
60 | if(getuid() == 0) | ||
61 | { | ||
62 | char* realuser = getenv("SUDO_UID"); | ||
63 | char* realgroup = getenv("SUDO_GID"); | ||
64 | if(realuser != NULL && realgroup != NULL) | ||
65 | { | ||
66 | int realuid = atoi(realuser); | ||
67 | int realgid = atoi(realgroup); | ||
68 | chown(qPrintable(userSettings->fileName()), realuid, realgid); | ||
69 | } | ||
70 | } | ||
71 | #endif | ||
72 | } | ||
50 | 73 | ||
51 | QVariant RbSettings::deviceSettingCurGet(QString entry,QString def) | 74 | QVariant RbSettings::deviceSettingCurGet(QString entry,QString def) |
52 | { | 75 | { |
@@ -260,12 +283,12 @@ QString RbSettings::lastTalkedFolder() | |||
260 | { | 283 | { |
261 | return userSettings->value("last_talked_folder").toString(); | 284 | return userSettings->value("last_talked_folder").toString(); |
262 | } | 285 | } |
263 | 286 | ||
264 | QString RbSettings::voiceLanguage() | 287 | QString RbSettings::voiceLanguage() |
265 | { | 288 | { |
266 | return userSettings->value("voicelanguage").toString(); | 289 | return userSettings->value("voicelanguage").toString(); |
267 | } | 290 | } |
268 | 291 | ||
269 | int RbSettings::wavtrimTh() | 292 | int RbSettings::wavtrimTh() |
270 | { | 293 | { |
271 | return userSettings->value("wavtrimthreshold",500).toInt(); | 294 | return userSettings->value("wavtrimthreshold",500).toInt(); |
@@ -328,7 +351,7 @@ QStringList RbSettings::allPlatforms() | |||
328 | QStringList result; | 351 | QStringList result; |
329 | devices->beginGroup("platforms"); | 352 | devices->beginGroup("platforms"); |
330 | QStringList a = devices->childKeys(); | 353 | QStringList a = devices->childKeys(); |
331 | for(int i = 0; i < a.size(); i++) | 354 | for(int i = 0; i < a.size(); i++) |
332 | { | 355 | { |
333 | result.append(devices->value(a.at(i), "null").toString()); | 356 | result.append(devices->value(a.at(i), "null").toString()); |
334 | } | 357 | } |
@@ -341,7 +364,7 @@ QStringList RbSettings::allLanguages() | |||
341 | QStringList result; | 364 | QStringList result; |
342 | devices->beginGroup("languages"); | 365 | devices->beginGroup("languages"); |
343 | QStringList a = devices->childKeys(); | 366 | QStringList a = devices->childKeys(); |
344 | for(int i = 0; i < a.size(); i++) | 367 | for(int i = 0; i < a.size(); i++) |
345 | { | 368 | { |
346 | result.append(devices->value(a.at(i), "null").toString()); | 369 | result.append(devices->value(a.at(i), "null").toString()); |
347 | } | 370 | } |
@@ -385,7 +408,7 @@ QString RbSettings::nameOfTargetId(int id) | |||
385 | } | 408 | } |
386 | devices->endGroup(); | 409 | devices->endGroup(); |
387 | } | 410 | } |
388 | 411 | ||
389 | return result; | 412 | return result; |
390 | } | 413 | } |
391 | 414 | ||
@@ -397,7 +420,7 @@ QMap<int, QString> RbSettings::usbIdMap() | |||
397 | devices->beginGroup("platforms"); | 420 | devices->beginGroup("platforms"); |
398 | platforms = devices->childKeys(); | 421 | platforms = devices->childKeys(); |
399 | devices->endGroup(); | 422 | devices->endGroup(); |
400 | 423 | ||
401 | for(int i = 0; i < platforms.size(); i++) | 424 | for(int i = 0; i < platforms.size(); i++) |
402 | { | 425 | { |
403 | devices->beginGroup("platforms"); | 426 | devices->beginGroup("platforms"); |
@@ -423,7 +446,7 @@ QMap<int, QString> RbSettings::usbIdErrorMap() | |||
423 | devices->beginGroup("platforms"); | 446 | devices->beginGroup("platforms"); |
424 | platforms = devices->childKeys(); | 447 | platforms = devices->childKeys(); |
425 | devices->endGroup(); | 448 | devices->endGroup(); |
426 | 449 | ||
427 | for(int i = 0; i < platforms.size(); i++) | 450 | for(int i = 0; i < platforms.size(); i++) |
428 | { | 451 | { |
429 | devices->beginGroup("platforms"); | 452 | devices->beginGroup("platforms"); |
@@ -449,7 +472,7 @@ QMap<int, QString> RbSettings::usbIdIncompatMap() | |||
449 | devices->beginGroup("platforms"); | 472 | devices->beginGroup("platforms"); |
450 | platforms = devices->childKeys(); | 473 | platforms = devices->childKeys(); |
451 | devices->endGroup(); | 474 | devices->endGroup(); |
452 | 475 | ||
453 | for(int i = 0; i < platforms.size(); i++) | 476 | for(int i = 0; i < platforms.size(); i++) |
454 | { | 477 | { |
455 | devices->beginGroup("platforms"); | 478 | devices->beginGroup("platforms"); |
@@ -580,7 +603,7 @@ void RbSettings::setTTSLang(QString tts, QString lang) | |||
580 | void RbSettings::setTTSUseSapi4(bool value) | 603 | void RbSettings::setTTSUseSapi4(bool value) |
581 | { | 604 | { |
582 | userSettingsGroupSet("sapi","useSapi4",value); | 605 | userSettingsGroupSet("sapi","useSapi4",value); |
583 | } | 606 | } |
584 | 607 | ||
585 | void RbSettings::setEncoderPath(QString enc, QString path) | 608 | void RbSettings::setEncoderPath(QString enc, QString path) |
586 | { | 609 | { |