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)