comparison ui/installwrapper.cpp @ 646:a9a57dc1eb2f

Start installer process as sudo if possible.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 25 Jun 2014 10:55:03 +0200
parents cef732072774
children 51830f4912c2
comparison
equal deleted inserted replaced
644:c7a35fa302ec 646:a9a57dc1eb2f
148 emit error (tr("The process failed with return code. %1").arg(retval)); 148 emit error (tr("The process failed with return code. %1").arg(retval));
149 return; 149 return;
150 } 150 }
151 #else /* WIN32 */ 151 #else /* WIN32 */
152 QProcess installerProcess; 152 QProcess installerProcess;
153 installerProcess.setProgram(cinstProcInfo.absoluteFilePath());
154 QStringList parameters; 153 QStringList parameters;
155 154
156 choicesFile.setAutoRemove(false); 155 choicesFile.setAutoRemove(false);
157 parameters << "list=" + mCertListFile << "choices=" + choicesFile.fileName(); 156 parameters << "list=" + mCertListFile << "choices=" + choicesFile.fileName();
158 installerProcess.setArguments(parameters); 157
159 158 bool sudo_started = false;
160 159 bool use_sudo = is_admin();
161 qDebug() << "Starting process " << cinstFileName <<" params: " << parameters; 160 if (use_sudo) {
162 installerProcess.start(); 161 QStringList sudoPrograms;
163 if (!installerProcess.waitForStarted() || 162 sudoPrograms << "gksudo" << "kdesudo" << "sudo";
164 installerProcess.state() == QProcess::NotRunning) { 163 QStringList sudoParams;
165 emit error (tr("Failed to start installer process.")); 164 sudoParams <<cinstProcInfo.absoluteFilePath() << parameters;
166 return; 165 installerProcess.setArguments(sudoParams);
166
167 foreach (const QString &sProg, sudoPrograms) {
168 installerProcess.setProgram(sProg);
169 qDebug() << "Starting process " << sProg <<" params: " << sudoParams;
170 installerProcess.start();
171 if (!installerProcess.waitForStarted() ||
172 installerProcess.state() == QProcess::NotRunning) {
173 continue;
174 } else {
175 sudo_started = true;
176 break;
177 }
178 }
179 }
180
181 /* Fallback to start without sudo */
182 if (!use_sudo || !sudo_started) {
183 installerProcess.setProgram(cinstProcInfo.absoluteFilePath());
184 installerProcess.setArguments(parameters);
185
186 qDebug() << "Starting process " << cinstFileName <<" params: " << parameters;
187 installerProcess.start();
188 if (!installerProcess.waitForStarted() ||
189 installerProcess.state() == QProcess::NotRunning) {
190 emit error (tr("Failed to start installer process."));
191 return;
192 }
167 } 193 }
168 194
169 installerProcess.waitForFinished(); 195 installerProcess.waitForFinished();
170 196
171 if (installerProcess.exitStatus() == QProcess::CrashExit) { 197 if (installerProcess.exitStatus() == QProcess::CrashExit) {

http://wald.intevation.org/projects/trustbridge/