Skip to content

Commit

Permalink
Add support for pkexec to elevate privileges
Browse files Browse the repository at this point in the history
This seems to be a nice drop-in replacement for kdesu{,do} for
our purposes. And it's much more available compared to the other
helpers. Sadly, it doesn't support the `--attach` mode, but that's
not too bad either.

Fixes: #173
  • Loading branch information
milianw committed Jun 5, 2020
1 parent 6603142 commit 5ee201d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ when using hotspot's record feature:

To workaround this limitation, hotspot can temporarily elevate the perf privileges.
This is achieved by applying [these steps](https://superuser.com/questions/980632/run-perf-without-root-right),
bundled into [a script](scripts/elevate_perf_privileges.sh) that is run via `kdesudo` or `kdesu`.
bundled into [a script](scripts/elevate_perf_privileges.sh) that is run via `pkexec`, `kdesudo` or `kdesu`.
The resulting elevated privileges are also required for kernel tracing in general and Off-CPU profiling in particular.

## Qt Creator
Expand Down
8 changes: 6 additions & 2 deletions src/perfrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void PerfRecord::startRecording(bool elevatePrivileges, const QStringList& perfO
// once perf has started
const auto sudoBinary = sudoUtil();
if (sudoBinary.isEmpty()) {
emit recordingFailed(tr("No graphical sudo utility found. Please install kdesudo or kdesu."));
emit recordingFailed(tr("No sudo utility found. Please install pkexec, kdesudo or kdesu."));
return;
}

Expand Down Expand Up @@ -154,6 +154,10 @@ void PerfRecord::startRecording(bool elevatePrivileges, const QStringList& perfO
readSlot();
// then delete the process
m_elevatePrivilegesProcess->deleteLater();

if (!m_perfRecordProcess) {
emit recordingFailed(tr("Failed to elevate privileges."));
}
});

m_elevatePrivilegesProcess->start(sudoBinary, options);
Expand Down Expand Up @@ -308,7 +312,7 @@ void PerfRecord::sendInput(const QByteArray& input)
QString PerfRecord::sudoUtil()
{
const auto commands = {
QStringLiteral("kdesudo"), QStringLiteral("kdesu"),
QStringLiteral("pkexec"), QStringLiteral("kdesudo"), QStringLiteral("kdesu"),
// gksudo / gksu seem to close stdin and thus the elevate script doesn't wait on read
};
for (const auto& cmd : commands) {
Expand Down
2 changes: 1 addition & 1 deletion src/recordpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ RecordPage::RecordPage(QWidget* parent)
ui->elevatePrivilegesCheckBox->setChecked(false);
ui->elevatePrivilegesCheckBox->setEnabled(false);
ui->elevatePrivilegesCheckBox->setText(
tr("(Note: Install kdesudo or kdesu to temporarily elevate perf privileges.)"));
tr("(Note: Install pkexec, kdesudo or kdesu to temporarily elevate perf privileges.)"));
}

connect(ui->elevatePrivilegesCheckBox, &QCheckBox::toggled, this, &RecordPage::updateOffCpuCheckboxState);
Expand Down
4 changes: 2 additions & 2 deletions src/recordpage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
<item row="1" column="0">
<widget class="QLabel" name="elevatePrivilegesLabel">
<property name="toolTip">
<string>When enabled, hotspot will temporarily elevate the perf privileges via kdesudo or kdesu. This allows you to access advanced perf features such as kernel tracepoints required for Off-CPU profiling.</string>
<string>When enabled, hotspot will temporarily elevate the perf privileges via pkexec, kdesudo or kdesu. This allows you to access advanced perf features such as kernel tracepoints required for Off-CPU profiling.</string>
</property>
<property name="text">
<string>Elevate Privileges:</string>
Expand All @@ -236,7 +236,7 @@
<item row="1" column="1">
<widget class="QCheckBox" name="elevatePrivilegesCheckBox">
<property name="toolTip">
<string>When enabled, hotspot will temporarily elevate the perf privileges via kdesudo or kdesu. This allows you to access advanced perf features such as kernel tracepoints required for Off-CPU profiling.</string>
<string>When enabled, hotspot will temporarily elevate the perf privileges via pkexec, kdesudo or kdesu. This allows you to access advanced perf features such as kernel tracepoints required for Off-CPU profiling.</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 5ee201d

Please sign in to comment.