Fix when the name of a process called with sudo is not shown.
ClosedPublic

Authored by cjlcarvalho on May 8 2018, 8:00 AM.

Details

Summary

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.

Diff Detail

Repository
R319 Konsole
Lint
Lint Skipped
Unit
Unit Tests Skipped
cjlcarvalho created this revision.May 8 2018, 8:00 AM
Restricted Application added a project: Konsole. · View Herald TranscriptMay 8 2018, 8:00 AM
cjlcarvalho requested review of this revision.May 8 2018, 8:00 AM

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() ?

Restricted Application added a subscriber: konsole-devel. · View Herald TranscriptMay 9 2018, 1:37 PM

Removing duplicated code in readProcessInfo(). Getting process name from _arguments after calling readArguments().

cjlcarvalho added a comment.EditedMay 10 2018, 6:52 AM

@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

cjlcarvalho added a comment.EditedMay 10 2018, 1:08 PM

readArguments and readCurrentDir should be called before readProcInfo?

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

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'

cjlcarvalho marked an inline comment as done.May 12 2018, 3:59 PM

@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?

hindenburg accepted this revision.May 12 2018, 5:16 PM

Well I think to get it "correct" would take a lot more code and likely not worth. I"m fine with this as-is

This revision is now accepted and ready to land.May 12 2018, 5:16 PM
This revision was automatically updated to reflect the committed changes.