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 goup ID of the shared memory object is set to the effective 11 * group ID of the process when the shared memory object does not exists and 12 * the O_CREAT flags is set. 13 * 14 * The test use fstat to check the flag. 15 */ 16 17 #include <sys/mman.h> 18 #include <sys/stat.h> 19 #include <fcntl.h> 20 #include <stdio.h> 21 #include <errno.h> 22 #include <unistd.h> 23 #include "posixtest.h" 24 25 #define SHM_NAME "posixtest_17-1" 26 27 int main(void) 28 { 29 int fd, result; 30 struct stat stat_buf; 31 32 result = shm_unlink(SHM_NAME); 33 if (result != 0 && errno != ENOENT) { 34 /* The shared memory object exist and shm_unlink can not 35 remove it. */ 36 perror("An error occurs when calling shm_unlink()"); 37 return PTS_UNRESOLVED; 38 } 39 40 fd = shm_open(SHM_NAME, O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR); 41 if (fd == -1) { 42 perror("An error occurs when calling shm_open()"); 43 return PTS_UNRESOLVED; 44 } 45 46 result = fstat(fd, &stat_buf); 47 if (result != 0) { 48 perror("An error occurs when calling fstat()"); 49 shm_unlink(SHM_NAME); 50 return PTS_UNRESOLVED; 51 } 52 53 shm_unlink(SHM_NAME); 54 55 if (stat_buf.st_gid == getegid()) { 56 printf("Test PASSED\n"); 57 return PTS_PASS; 58 } 59 printf 60 ("shm_open() does not set the user ID to the effective user ID of the process.\n"); 61 return PTS_FAIL; 62 } 63