From: Bart Van Assche Date: Sat, 5 Mar 2011 14:49:12 +0000 (+0000) Subject: DRD tests, Darwin: check return value of sem_open(). X-Git-Tag: svn/VALGRIND_3_7_0~639 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=63b96ade4ad5612c25c43e98970abc6480a0bfc6;p=thirdparty%2Fvalgrind.git DRD tests, Darwin: check return value of sem_open(). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11590 --- diff --git a/drd/tests/circular_buffer.c b/drd/tests/circular_buffer.c index dcfc6115a8..b7ab564164 100644 --- a/drd/tests/circular_buffer.c +++ b/drd/tests/circular_buffer.c @@ -60,7 +60,13 @@ int fetch_and_add(int* p, int i) static sem_t* create_semaphore(const char* const name, const int value) { #ifdef VGO_darwin - sem_t* p = sem_open(name, O_CREAT, 0600, value); + char name_and_pid[32]; + snprintf(name_and_pid, sizeof(name_and_pid), "%s-%d", name, getpid()); + sem_t* p = sem_open(name_and_pid, O_CREAT | O_EXCL, 0600, value); + if (p == SEM_FAILED) { + perror("sem_open"); + return NULL; + } return p; #else sem_t* p = malloc(sizeof(*p)); diff --git a/drd/tests/pth_inconsistent_cond_wait.c b/drd/tests/pth_inconsistent_cond_wait.c index ccfbc3a20b..fb95fd8a91 100644 --- a/drd/tests/pth_inconsistent_cond_wait.c +++ b/drd/tests/pth_inconsistent_cond_wait.c @@ -45,7 +45,13 @@ static int s_quiet; static sem_t* create_semaphore(const char* const name) { #ifdef VGO_darwin - sem_t* p = sem_open(name, O_CREAT, 0600, 0); + char name_and_pid[32]; + snprintf(name_and_pid, sizeof(name_and_pid), "%s-%d", name, getpid()); + sem_t* p = sem_open(name_and_pid, O_CREAT | O_EXCL, 0600, 0); + if (p == SEM_FAILED) { + perror("sem_open"); + return NULL; + } return p; #else sem_t* p = malloc(sizeof(*p)); diff --git a/drd/tests/sem_open.c b/drd/tests/sem_open.c index d45200950f..65ee28b3d6 100644 --- a/drd/tests/sem_open.c +++ b/drd/tests/sem_open.c @@ -58,8 +58,9 @@ int main(int argc, char** argv) * Use the ipcs and ipcrm commands to clean up named semaphores left by * aborted instances of this process. */ - snprintf(semaphore_name, sizeof(semaphore_name), "drd-sem-open-test"); - s_sem = sem_open(semaphore_name, O_CREAT, 0600, 1); + snprintf(semaphore_name, sizeof(semaphore_name), "drd-sem-open-test-%d", + getpid()); + s_sem = sem_open(semaphore_name, O_CREAT | O_EXCL, 0600, 1); if (s_sem == SEM_FAILED) { fprintf(stderr, "Failed to create a semaphore with name %s\n",