Any process that is called in foreground with sudo (ex: sudo qtcreator) is identified by ProcessInfo::name only with the word "sudo", being unable to identify which process it is. This fix makes it shows sudo along with the name of the process called.
Details
- Reviewers
hindenburg - Group Reviewers
Konsole - Commits
- R319:90b96b695f35: Fix when the name of a process called with sudo is not shown
Diff Detail
- Repository
- R319 Konsole
- Lint
Lint Skipped - Unit
Unit Tests Skipped
That info should be in _arguments once readArguments() is called. I'd rather not duplicate the code. Can you add this check after the calls in readProcessInfo() ?
Removing duplicated code in readProcessInfo(). Getting process name from _arguments after calling readArguments().
@hindenburg I needed to change clearArguments call in UnixProcessInfo::readProcessInfo to happen after readProcInfo call.
I was thinking of putting the "if" after line 368 at end of readProcessInfo() to avoid calling readArguments twice
Something like this - I threw this together quickly - it needs looked at more closely
diff --git a/src/ProcessInfo.cpp b/src/ProcessInfo.cpp
index 410682b..e588d1d 100644
- a/src/ProcessInfo.cpp
+++ b/src/ProcessInfo.cpp
@@ -365,6 +365,16 @@ void UnixProcessInfo::readProcessInfo(int pid)
if (readProcInfo(pid)) { readArguments(pid); readCurrentDir(pid);
+
+ bool ok = false;
+ const QString &processNameString = name(&ok);
+ if (!ok || processNameString == QLatin1String("sudo")) {
+ const QVector<QString> &args = arguments(&ok);
+
+ if (ok && args.size() > 1) {
+ setName(processNameString + QStringLiteral(" ") + args[1]);
+ }
+ }
}
}
I copied/paste the wrong line
src/ProcessInfo.cpp | ||
---|---|---|
372 ↗ | (On Diff #33926) | This should be "if (ok && " |
Also note that any options given to sudo will cause only the first option to be displayed. Example "sudo -H top" -> 'sudo -H'
@hindenburg Well, I can search for the next argument that does not start with "-", but this makes another problem...
Because some sudo options (like -u, -g or -h) need arguments that does not start with "-".
Do you know some Qt native way to check if a name is a program? Or can I check the return code of "command -v PROCESS" or "which PROCESS" commands to check it?
Well I think to get it "correct" would take a lot more code and likely not worth. I"m fine with this as-is