autotest: Create consent file, and chown it, atomically
Create consent file as a temp file first, chown it to chronos, and then
rename it to "Consent To Send Stats". I'm not sure if this is necessary,
but it will fix the problem if there's somehow a race condition with
session_manager_setup.sh removing the consent file because it's owned by
root.
BUG=chromium-os:18413
TEST=logging_{UserCrash,CrashSender}
Change-Id: I805c2bac8526cbef94082e5ede1b1a87231773b2
Reviewed-on: http://gerrit.chromium.org/gerrit/6353
Reviewed-by: Ken Mixter <kmixter@chromium.org>
Tested-by: Michael Krebs <mkrebs@chromium.org>
diff --git a/client/cros/crash_test.py b/client/cros/crash_test.py
index f307711..0b314c4 100644
--- a/client/cros/crash_test.py
+++ b/client/cros/crash_test.py
@@ -188,9 +188,13 @@
# Create deprecated consent file. This is created *after* the
# policy file in order to avoid a race condition where chrome
# might remove the consent file if the policy's not set yet.
+ # We create it as a temp file first in order to make the creation
+ # of the consent file, owned by chronos, atomic.
# See crosbug.com/18413.
- utils.open_write_close(self._CONSENT_FILE, 'test-consent')
- utils.system('chown chronos:chronos "%s"' % (self._CONSENT_FILE))
+ temp_file = self._CONSENT_FILE + '.tmp';
+ utils.open_write_close(temp_file, 'test-consent')
+ utils.system('chown chronos:chronos "%s"' % (temp_file))
+ shutil.move(temp_file, self._CONSENT_FILE)
logging.info('Created ' + self._CONSENT_FILE)
else:
# Create policy file that disables metrics/consent.