Implemented these changes: - Make this code C++. - Avoid hangs by adding a timeout. - Add the necessary TEMP_FAILURE_RETRY calls. - Restructure the code a bit. Bug: 18800936 Change-Id: Iba9f86a4c7beee4f0f36e51234855f4c0834db47