process-util: don't allocate max length to read /proc/PID/cmdline v247.6
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:25:18 +0000 (11:25 +0100)
commitfca334fb072545e2db8a81a51f8d1ab343fb610f
treede6c4b4271db38c4d27e07877c65353675617f93
parent0d4ba1519552761baeb4b464fad8854b24497193
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)
src/basic/process-util.c
src/test/test-process-util.c