util: create a copy of program_name
authorAnsis Atteka <aatteka@nicira.com>
Thu, 3 Jul 2014 20:41:02 +0000 (13:41 -0700)
committerAnsis Atteka <aatteka@nicira.com>
Thu, 3 Jul 2014 21:20:24 +0000 (14:20 -0700)
commit64b732912c203bf2e95684c26241118f07c2c786
tree6b33e645590a0d3a410b52aa2b909d2e022729f1
parentaa0b1810b2e9a05c9af15545fe13319acbbf463d
util: create a copy of program_name

Commit 8a9562 ("dpif-netdev: Add DPDK netdev.") reversed sequence
in which set_program_name() and proctitle_init() functions are
called.  This introduced a regression where program_name and argv_start
would point to exactly the same memory (previously both of these
pointers were pointing to different memory locations because
proctitle_init() would have beforehand created a copy of argv[0]
for the succeeding set_program_name() call).

This regression on my system caused ovs-vswitchd monitoring process to
show up without process name:

...  00:00:00 : monitoring pid 26308 (healthy)

Ps output was lacking process name because following code was
using overlapping memory for source and target buffer:.

proctitle_set(const char *format, ...)
{
    ...
    n = snprintf(argv_start, argv_size, "%s: ", program_name);

Overall C99 and POSIX standards state that behavior is undefined
if source and target buffers overlap.

Signed-Off-By: Ansis Atteka <aatteka@nicira.com>
Acked-By: Ben Pfaff <blp@nicira.com>
lib/util.c