libpromises/generic_agent.c: chmod and chown internal directories only when needed.

Avoids gratuitous chmod and chown calls on internal directories by examining
the populated stat struct after stat(). Important for devices backed by flash
in order to avoid wanton wearing of the storage medium.
new $(sys.statedir) special variable
move embedded databases exclusive to state/ directory
LogTotalCompliance(): prevent cf-agent from bailing with custom logdir
tests/load: use CFENGINE_TEST_OVERRIDE_WORKDIR in combination with GetStateDir()
tests/unit: use CFENGINE_TEST_OVERRIDE_WORKDIR in combination with GetStateDir()
known_dirs.c: Collapse GetInputDir(), GetMasterDir(), GetStateDir() with preprocessor
obliterate CFWORKDIR (GLOBAL_C) and its usage in the main codebase.

- CFWORKDIR globals remain in tests/{unit,load}/ but are unrelated
  to the main global that is being obliterated here.
examples/measure_log.cf: comment to account for potential compile-time statedir
RemoveDates(): move datetime string literal computation to compile-time

- comment on uncertainty of two-digit hh:mm:ss and time-zones shorter
  than three letters.

Pointed out by Edward Welbourne
libpromises/known_dirs.c: remove initializer from static array

No need to initialize the static arrary in GET_DEFAULT_DIRECTORY_DEFINE()
because statics are zero-filled at compile-time.
Changelog: update

Change: all embedded databases now rooted in state/ directory.
Feature: --with-statedir compile-time option to override state/ path.
tests/unit: convert unit tests from setenv to putenv usage

- tests/unit/db_concurrent_test.c
- tests/unit/db_test.c
- tests/unit/dbm_migration_bundles_test.c
- tests/unit/lastseen_migration_test.c
- tests/unit/lastseen_test.c
tests/load: convert load tests from setenv to putenv usage

- tests/load/db_load.c
- tests/load/lastseen_load.c
fixup! use GetStateDir() and replace hardcoded state/ paths