process-util: dont allocate max length to read /proc/PID/cmdline
authorAnita Zhang <the.anitazha@gmail.com>
Tue, 23 Mar 2021 07:49:28 +0000 (00:49 -0700)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 24 Mar 2021 07:46:45 +0000 (16:46 +0900)
commit7b7a060e83d6c7de8705904d71978ba4664f0a65
treee03cae776c6710f46e22d86773f1448e35d8181a
parent7325a2b2d15af09a9389723d6153050130c0bd36
process-util: dont 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.
src/basic/process-util.c
src/test/test-process-util.c