stats: factor out common code from stats_register_counter() and stats_register_dynamic_counter()

This patch extracts common code from two stats function, eliminating some
duplication on the way.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
logmsg: forget the stored MSGHDR value in case PID is set

When a message comes in, syslog-ng automatically stores the MSGHDR as it
looked like initially in order to be able to reproduce the message
in its original form.

The syslog-ng parser sometimes skips spaces, so otherwise the reproduced
message might somewhat be different.

However, if the nvpairs that make up $MSGHDR are changed, this behaviour
is quite unintuitive, resulting the changes to be ignored in the MSGHDR.

This patch adds a similar treatment to the PID nvpair as was already
present for PROGRAM.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>