Process pass performance

This patch fixes the algorithm used by cfagent to enumerate processes owned by root and not owned by root. On Solaris 6, 7 and 8 it yields performance improvements of close to two orders of magnitude.

This patch was merged into cfengine 2.2.2.


Process pass for cfengine 2.2.1


cfagent calls LoadProcessTable() to read the output of /bin/ps (or equivalent). The lines of output are stored in a linked list (struct Item *). The list is duplicated twice. One copy is called rootprocs and the other otherprocs. cfagent then eliminates non-root process information from the rootprocs list and root process information from otherprocs by walking the lists and freeing the non-matching entries.

The method used to check whether a process is owned by root is to perform a regular expression match for /.*root.*/ on each entry in the list. On SPARC Solaris machines I found this to be very inefficient.

This patch changes the behaviour to perform a substring match for root instead.

A production server that took 5 minutes to run cfagent cut its execution time to 9 seconds with this patch.