util-lib: rework get_process_cmdline() (#3529)
authorLennart Poettering <lennart@poettering.net>
Tue, 14 Jun 2016 21:52:29 +0000 (23:52 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 14 Jun 2016 21:52:29 +0000 (17:52 -0400)
commit69281c49eb824b2cc854fdb5b97f134b1371be8d
tree27049e3af27d4d8ab79440aabdaea4fc61df4ddb
parent8dd57192bcee3c23625247ac8f11ef2043fcb36b
util-lib: rework get_process_cmdline() (#3529)

This reworks get_process_cmdline() quite substantially, fixing the following:

- Fixes:
  https://github.com/systemd/systemd/pull/3512/commits/a4e3bf4d7ac2de51191ce136ee9361ba319e106c#r66837630

- The passed max_length is also applied to the "comm" name, if comm_fallback is
  set.

- The right thing happens if max_length == 1 is specified

- when the cmdline "foobar" is abbreviated to 6 characters the result is not
  "foobar" instead of "foo...".

- trailing whitespace are removed before the ... suffix is appended. The 7
  character abbreviation of "foo barz" is hence "foo..." instead of "foo ...".

- leading whitespace are suppressed from the cmdline

- a comprehensive test case is added
src/basic/process-util.c
src/test/test-process-util.c