[KProcessList] Split command line and process name
ClosedPublic

Authored by davidedmundson on Jul 15 2019, 10:38 AM.

Details

Summary

Currently KProcessList had a method called "name" which confusingly
returns the entire command line.

In many cases where we want to use this class we need both. (See D22327)

This class exposes both "name" and "command" with the respective
properties.

In order to do this correctly we need to split the process name before
the null characters are replaced with spaces.

Test Plan

Unit test
Manually invoked ps list output

Diff Detail

Repository
R244 KCoreAddons
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
Restricted Application added a project: Frameworks. · View Herald TranscriptJul 15 2019, 10:38 AM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
davidedmundson requested review of this revision.Jul 15 2019, 10:38 AM

+1

src/lib/util/kprocesslist_p.h
46

Order name before since that's how the methods are ordered

Swap member order

apol added a subscriber: apol.Jul 15 2019, 1:19 PM

So now name() will often return an empty string?

src/lib/util/kprocesslist_unix.cpp
142

if it's -1, when you do ++ it will become 0 anyway.

So now name() will often return an empty string?

That's certainly not the intention.

The system is:

Firstly we do the fallback. Reading from /proc/N/state . Though this is rubbish and truncates things.
Both name and command are set to this.

Then we read /proc/N/cmdline

Then we extract the command.
We set the name to the first segment of the command (between the final / and the first null byte
We set the command to the full thing, but with all null bytes becoming spaces

On windows, name and command will return the same thing.

src/lib/util/kprocesslist_unix.cpp
142

It would, but it would then requires a huge comment explaining it.

Should we ship this now? After frameworks tagging I guess.
Also, can you add a CHANGELOG: KProcessInfo::name() now returns only the name of the executable. For the full command line use KProcessInfo::command() so it shows up nicely in the release announcement changelog

This revision was not accepted when it landed; it landed in state Needs Review.Aug 15 2019, 3:26 PM
This revision was automatically updated to reflect the committed changes.