[PATCH 1 of 3] Start installer process as sudo if possible
Wald Commits
scm-commit at wald.intevation.org
Wed Jun 25 12:46:03 CEST 2014
# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1403686503 -7200
# Node ID a9a57dc1eb2f83faf1d0c60ca36e72b1d329868c
# Parent c7a35fa302ec64f2e52eac3e97694b4758769f9b
Start installer process as sudo if possible.
diff -r c7a35fa302ec -r a9a57dc1eb2f ui/installwrapper.cpp
--- a/ui/installwrapper.cpp Tue Jun 24 18:10:10 2014 +0200
+++ b/ui/installwrapper.cpp Wed Jun 25 10:55:03 2014 +0200
@@ -150,20 +150,46 @@
}
#else /* WIN32 */
QProcess installerProcess;
- installerProcess.setProgram(cinstProcInfo.absoluteFilePath());
QStringList parameters;
choicesFile.setAutoRemove(false);
parameters << "list=" + mCertListFile << "choices=" + choicesFile.fileName();
- installerProcess.setArguments(parameters);
+ bool sudo_started = false;
+ bool use_sudo = is_admin();
+ if (use_sudo) {
+ QStringList sudoPrograms;
+ sudoPrograms << "gksudo" << "kdesudo" << "sudo";
+ QStringList sudoParams;
+ sudoParams <<cinstProcInfo.absoluteFilePath() << parameters;
+ installerProcess.setArguments(sudoParams);
- qDebug() << "Starting process " << cinstFileName <<" params: " << parameters;
- installerProcess.start();
- if (!installerProcess.waitForStarted() ||
- installerProcess.state() == QProcess::NotRunning) {
- emit error (tr("Failed to start installer process."));
- return;
+ foreach (const QString &sProg, sudoPrograms) {
+ installerProcess.setProgram(sProg);
+ qDebug() << "Starting process " << sProg <<" params: " << sudoParams;
+ installerProcess.start();
+ if (!installerProcess.waitForStarted() ||
+ installerProcess.state() == QProcess::NotRunning) {
+ continue;
+ } else {
+ sudo_started = true;
+ break;
+ }
+ }
+ }
+
+ /* Fallback to start without sudo */
+ if (!use_sudo || !sudo_started) {
+ installerProcess.setProgram(cinstProcInfo.absoluteFilePath());
+ installerProcess.setArguments(parameters);
+
+ qDebug() << "Starting process " << cinstFileName <<" params: " << parameters;
+ installerProcess.start();
+ if (!installerProcess.waitForStarted() ||
+ installerProcess.state() == QProcess::NotRunning) {
+ emit error (tr("Failed to start installer process."));
+ return;
+ }
}
installerProcess.waitForFinished();
More information about the Trustbridge-commits
mailing list