Fix incorrect initialization of pthread_once variable.

This fixes a startup crash on Mac OS X, and should be safer on other
platforms too.
(cherry picked from commit 1c7bd2982034176f90c82958a8151aa722867b03)
Fix race condition and file permissions in file editing.

Previously the original was removed and then the edited file was
renamed, leaving a small timeframe where the file did not exist, which
can lead to bad situations. Fixed by leaving the file in place until
rename is called, which is atomic on all POSIX platforms.

Also make sure all permissions, including ACLs and SELinux security
contexts, are preserved when making a copy of the original file.

Fixes issue 2545.
(cherry picked from commit a3f1a964ad5e079f8abc419bb9e0489aa8c62f7a)
Check extended attributes supported status also when setting them.

This should not be necessary, since we already checked when getting
them. However, fakeroot seems to return this occasionally when running
tests, so better to check both times.

Addition to issue 2545.
(cherry picked from commit 908fb187191b41df44bdfb7d092a429cded06436)
Remove redundant SELinux code.

This is covered in the CopyFilePermissionsDisk() function, and should
have been part of commit a3f1a964ad5e079f8a.

Addition to issue 2545.
(cherry picked from commit 76d895609ea7dee55502139acf52b1b141ca9b10)
Redmine #2693: some 10_files tests check for unpromised gid numbers

Some platforms, such as HP-UX, do not have root in group 0 by default.
Certain tests expect a string showing mode, nlinks, uid, gid, and size
to show a uid and gid of zero for the test file, but without promising
the GID the file defaults to root's primary group. On HP-UX this is 3,
causing the test to fail.

The tests have been updated to promise the same mode, uid, and gid that
are expected in the "expect" string for the test file that is created.
(cherry picked from commit 90f96d014e35fcf6d28cf6e65006017907617db4)
Redmine #2702: add missing uid/gid name mapping for hpux & aix

Tests 01_vars/02_functions/001.cf and 002.cf fail on HP-UX and AIX
because the hard classes don't cover the uid and gid mappings for
those platforms. This commit adds the necessary information to
allow the tests to pass on those two platforms.

HP-UX information was gathered from and tested on my own HP-UX
system, and for AIX see the following links for sample passwd
and group files:

http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.security%2Fdoc%2Fsecurity%2Fpasswords_etc_passwd_file.htm

http://www.rootunix.org/AIX/migrate.txt
(cherry picked from commit 496d5a8b551b3bb9b959b6a23848cc78cd4dc7f5)
Redmine #2704: fix canonify issue with negative signed chars

On HP-UX 11.11, the "isalnum()" call expects a range of values from
-1 to 255. However the range of a signed char is -127 to 127, and
when an out-of-range negative number is passed to isalnum() on this
platform, the results in the case of the Yen symbol in acceptance
test 01_vars/02_functions/007.cf, with a signed char value of -91,
isalnum() returns "2" which is taken to mean that the Yen symbol
is alphanumeric.

By casting to "unsigned char" before the cast to "int" for the call,
the "-91" value is converted to a valid character set value of 165,
which is properly handled by isalnum() and thus allows the test to
pass.
(cherry picked from commit a0111e61d5dddca715c307cd7385c7ead0ac3125)
Fix filestat test pass condition.

Pass when all conditions are met, not when any condition is met.
(cherry picked from commit a1b118c34c625a290e48d4a7ec7ed512e39a81f5)
rename uniq() to unique() everywhere
(cherry picked from commit a58feec75fddf5e7a674bf9ce628ad98fa57f0a4)
Change 'This promise has already been verified' message from verbose to debug
(cherry picked from commit 708d24453222ed64e8e1a51bee3dce2465979e4f)
NULL-proof ScopeGet

This arised when function regarray was calling ScopeGet with a NULL pointer,
resulting in a segfault. We have as a rule agreed that this is an error on
the caller side, but since we are getting close to the release, I don't want
to risk additional segfaults due to careless callers. Either way, ScopeGet is
marked for deprecation.
(cherry picked from commit e62516455b5ea6a6a8a12ed7c09dc50de91184d4)
Added FreeBSD portmaster package_method
(cherry picked from commit 50cfc98ede0791ce08f7b01197c7780374b23dbf)
Ensure policy validated marker files are generated.

Close #2659, #2694
(cherry picked from commit 9f77d688f156d48d0f644974820623e955942019)
Ensure scope 'this' is properly restored, add unit test.

Close #2632
(cherry picked from commit 4defc519a1d22d7c4f3461b35bbaf1b9d9e3f59c)
Ensure common bundle convergence, acceptance test, Close #5222

This ensures that common bundles are converged (variable resolution) before
other types of bundles, and that promise types within common bundles
are converged in normal order.
(cherry picked from commit 074c5fb541ba06e3c256f6dbb4a2a3ae878b2fce)
Switch to a compromise behavior in shell execution.

After powershell support was introduced in 0117c067e4fc67c6e2, we
stopped caring if the first word in a shell command was a valid
executable with an absolute path. This was in order to be able to use
shell builtins. However, it causes a behavior change in existing
policies that is potentially dangerous: Specifying a nonexisting
command would leave the variable unassigned with the old behavior,
whereas in the new behavior, the variable will contain the error
message from the shell.

Switching back to the old behavior will break shell builtins again, so
instead we do the compromise: Only look for an executable if the
command starts with an absolute filename. Since absolute filenames
were previously enforced, virtually all existing policies should have
them and therefore use the old behavior.

Solves issue 2738.
(cherry picked from commit bf2196898c1c60a89af45135781e5204c758f105)
More ChangeLog entries.
(cherry picked from commit 5184c4e54aac0ff57f9d4affb469cd3e1b9c60df)
Fix syntax errors in standard library

1. In valid slist (missing ",")
2. expireafter not allowed in package_method
(cherry picked from commit a279c0d5cc5e771145b3edcdd2121e755769daa6)
Show extra promise info in verbose mode

On promise status update (cfPS), print additional info about the promise
 handle, comment, version, promisee, if available, at verbose level.

Close #2636
(cherry picked from commit ff8563cb81e2ff08396e075fbb199d405d3e0ba1)
More output standardization

There should only be output string changes in this commit and therefore
should be riskless.
(cherry picked from commit 0aa8e0418a46c1964dbde668a0e5264db1685238)