Why does the service not get restarted?
void page_maintenance_general::on_rtunnel_restart_Button_clicked()
{
QProcess process;
// Seems to work, but in journalctl it's clear it did not execute.
process.start("echo 'pwdshereshouldbeavoidedIknow' | sudo -S -n systemctl restart rtunnel.service");
//process.start("nmcli networking connectivity"); // works fine
process.waitForFinished(-1);
QString feedback = process.readAllStandardOutput();
//QString feedback = process.readAllStandardError();
qDebug() << "rtunnel restart status: " << feedback;
ui->backend_status_label->setText("rtunnel restart " + feedback);
}
- For an innocent command, things work well.
nmcli networking connectivity
givesfull
echo 'pwdthatshouldbeavoidedIknow' | sudo -S -n systemctl restart rtunnel.service
works when executed as the same user that executes the program in a terminal.- Other
sudo
commands work too in the same program e.g.
QString command = "echo 'mypassword' | sudo -S shutdown -r 0"; // works fine
system(qPrintable(command));