process-util: don't allocate max length to read /proc/PID/cmdline v246.13
authorAnita Zhang <the.anitazha@gmail.com>
Tue, 23 Mar 2021 07:49:28 +0000 (00:49 -0700)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 24 Mar 2021 10:26:20 +0000 (11:26 +0100)
commitd890e8b3e309acd8fca3be00b931399da15f9b66
tree34aac61301fb0bdd7955fb4b3f4ca62f860dc4d5
parent7deae040617834bf4d5b881fc49bb3e567d527f0
process-util: don't allocate max length to read /proc/PID/cmdline

Alternative title: Replace get_process_cmdline()'s fopen()/fread() with
read_full_virtual_file().

When RLIMIT_STACK is set to infinity:infinity, _SC_ARG_MAX will
return 4611686018427387903 (depending on the system, but definitely
something larger than most systems have). It's impractical to allocate this
in one go when most cmdlines are much shorter than that.

Instead use read_full_virtual_file() which seems to increase the buffer
depending on the size of the contents.

(cherry picked from commit 7b7a060e83d6c7de8705904d71978ba4664f0a65)
(cherry picked from commit fca334fb072545e2db8a81a51f8d1ab343fb610f)
src/basic/process-util.c
src/test/test-process-util.c