Skip to content

Commit

Permalink
Remove last remnants of kdesu/kdesudo in the code
Browse files Browse the repository at this point in the history
We now always use pkexec, so we shouldn't even mention kdesu/kdesudo
anywhere.
  • Loading branch information
milianw committed Jul 21, 2023
1 parent 11b4bdb commit 867fff9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 43 deletions.
51 changes: 11 additions & 40 deletions src/perfrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ void createOutputFile(const QString& outputPath)
QFile::rename(outputPath, bakPath);
QFile(outputPath).open(QIODevice::WriteOnly);
}

QString findPkexec()
{
return QStandardPaths::findExecutable(QStringLiteral("pkexec"));
}
}

PerfRecord::PerfRecord(QObject* parent)
Expand All @@ -68,26 +73,6 @@ PerfRecord::~PerfRecord()
}
}

static QStringList sudoOptions(const QString& sudoBinary)
{
QStringList options;
if (sudoBinary.endsWith(QLatin1String("/kdesudo")) || sudoBinary.endsWith(QLatin1String("/kdesu"))) {
#if KWINDOWSYSTEM_VERSION >= QT_VERSION_CHECK(5, 101, 0)
auto activeWindowId = KX11Extras::activeWindow();
#else
auto activeWindowId = KWindowSystem::activeWindow();
#endif
// make the dialog transient for the current window
options.append(QStringLiteral("--attach"));
options.append(QString::number(activeWindowId));
}
if (sudoBinary.endsWith(QLatin1String("/kdesu"))) {
// show text output
options.append(QStringLiteral("-t"));
}
return options;
}

static bool privsAlreadyElevated()
{
auto readSysctl = [](const char* path) {
Expand Down Expand Up @@ -192,13 +177,13 @@ bool PerfRecord::runPerf(bool elevatePrivileges, const QStringList& perfOptions,
perfCommand += perfOptions;

if (elevatePrivileges) {
const auto sudoBinary = sudoUtil();
if (sudoBinary.isEmpty()) {
emit recordingFailed(tr("No sudo utility found. Please install pkexec, kdesudo or kdesu."));
const auto pkexec = findPkexec();
if (pkexec.isEmpty()) {
emit recordingFailed(tr("The pkexec utility was not found, cannot elevate privileges."));
return false;
}

auto options = sudoOptions(sudoBinary);
auto options = QStringList();
options.append(perfBinaryPath());
options += perfCommand;

Expand All @@ -212,7 +197,7 @@ bool PerfRecord::runPerf(bool elevatePrivileges, const QStringList& perfOptions,

createOutputFile(outputPath);

m_perfRecordProcess->start(sudoBinary, options);
m_perfRecordProcess->start(pkexec, options);
} else {
m_perfRecordProcess->start(perfBinaryPath(), perfCommand);
}
Expand Down Expand Up @@ -312,20 +297,6 @@ void PerfRecord::sendInput(const QByteArray& input)
m_perfRecordProcess->write(input);
}

QString PerfRecord::sudoUtil()
{
const auto commands = {
QStringLiteral("pkexec"),
};
for (const auto& cmd : commands) {
QString util = QStandardPaths::findExecutable(cmd);
if (!util.isEmpty()) {
return util;
}
}
return {};
}

QString PerfRecord::currentUsername()
{
return KUser().loginName();
Expand Down Expand Up @@ -412,7 +383,7 @@ bool PerfRecord::canCompress()

bool PerfRecord::canElevatePrivileges()
{
return !sudoUtil().isEmpty();
return !findPkexec().isEmpty();
}

QString PerfRecord::perfBinaryPath()
Expand Down
1 change: 0 additions & 1 deletion src/perfrecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class PerfRecord : public QObject
void stopRecording();
void sendInput(const QByteArray& input);

static QString sudoUtil();
static QString currentUsername();

static bool canTrace(const QString& path);
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 pkexec, 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. 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 pkexec, 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. 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 867fff9

Please sign in to comment.