From 9b6439a5bb8cd00819bdfc0eb78bacaec7aa3075 Mon Sep 17 00:00:00 2001 From: Amber Lin Date: Thu, 2 Mar 2017 16:59:35 -0500 Subject: [PATCH] Make the lock file writable by others Though S_IWOTH flag is set in the open() call, the lock file is not created as accessable by others if others try to open the file with O_RDWR permission. It's because the default umask masks off S_IWOTH. This patch changes the umask to S_IXOTH since others don't need that permission but it'll open up S_IWOTH. Restore the umask to original after the file is opened. Change-Id: I8a239e1566ce0b0b18821913385f239db7c3588e [ROCm/ROCR-Runtime commit: 1a8a9cb57b6cc1d8acd11b734c08e032c205189e] --- projects/rocr-runtime/src/openclose.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/projects/rocr-runtime/src/openclose.c b/projects/rocr-runtime/src/openclose.c index 9983ab098b..3e0f5a8267 100644 --- a/projects/rocr-runtime/src/openclose.c +++ b/projects/rocr-runtime/src/openclose.c @@ -76,6 +76,7 @@ hsaKmtOpenKFD(void) HSAKMT_STATUS result; int fd; HsaSystemProperties sys_props; + mode_t mask; pthread_mutex_lock(&hsakmt_mutex); @@ -113,10 +114,13 @@ hsaKmtOpenKFD(void) if (init_device_debugging_memory(sys_props.NumNodes) != HSAKMT_STATUS_SUCCESS) printf("Insufficient Memory. Debugging unavailable\n"); + mask = umask(0); /* save the current umask */ + /* We don't want the existing umask to mask out S_IWOTH */ + umask(S_IXOTH); amd_hsa_thunk_lock_fd = open(tmp_file, - O_CREAT | //create the file if it's not present. - O_RDWR, - S_IROTH | S_IWOTH); //allow others to read/write + O_CREAT | O_RDWR, + 0666); + umask(mask); /* restore the original umask */ if (amd_hsa_thunk_lock_fd < 0) fprintf(stderr, "Profiling of privileged counters is not available\n");