1 /* 2 * This program is free software; you can redistribute it and/or modify 3 * it under the terms of the GNU General Public License version 2. 4 * 5 * This program is distributed in the hope that it will be useful, 6 * but WITHOUT ANY WARRANTY; without even the implied warranty of 7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 8 * GNU General Public License for more details. 9 * 10 * Test that the name is removed before shm_unlink() returns even if one or 11 * more references to the shared memory object exist when the object is 12 * unlinked. 13 */ 14 15 #include <stdio.h> 16 #include <sys/mman.h> 17 #include <sys/stat.h> 18 #include <fcntl.h> 19 #include <errno.h> 20 #include "posixtest.h" 21 22 #define SHM_NAME "posixtest_2-1" 23 24 int main(void) 25 { 26 int fd; 27 28 fd = shm_open(SHM_NAME, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 29 if (fd == -1) { 30 perror("An error occurs when calling shm_open()"); 31 return PTS_UNRESOLVED; 32 } 33 34 if (shm_unlink(SHM_NAME) != 0) { 35 perror("An error occurs when calling shm_unlink()"); 36 return PTS_UNRESOLVED; 37 } 38 39 fd = shm_open(SHM_NAME, O_RDONLY, 0); 40 41 if (fd == -1 && errno == ENOENT) { 42 printf("Test PASSED\n"); 43 return PTS_PASS; 44 } else if (fd == -1) { 45 perror("shm_open"); 46 return PTS_UNRESOLVED; 47 } 48 49 printf("The name of shared memory object was not removed.\n"); 50 shm_unlink(SHM_NAME); 51 return PTS_FAIL; 52 53 } 54