00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <stdio.h>
00039 #include <sys/types.h>
00040 #include <sys/ipc.h>
00041 #include <sys/shm.h>
00042 #include <errno.h>
00043
00044 #define K_1 1024
00045
00047 #include "test.h"
00048 #include "usctest.h"
00049
00050 char *TCID="shmt08";
00051 int TST_TOTAL=2;
00052 extern int Tst_count;
00053
00054
00055 key_t key;
00056
00057 int rm_shm(int);
00058
00059 int main(void)
00060 {
00061 char *cp=NULL, *cp1=NULL;
00062 int shmid;
00063
00064 key = (key_t) getpid() ;
00065 errno = 0 ;
00066
00067
00068
00069 if ((shmid = shmget(key, 24*K_1, IPC_CREAT|0666)) < 0) {
00070 perror("shmget");
00071 tst_resm(TFAIL,"Error: shmget: shmid = %d, errno = %d\n",
00072 shmid, errno) ;
00073 tst_exit() ;
00074 }
00075
00076 cp = (char *) shmat(shmid, (void *)0, 0);
00077 if (cp == (char *)-1) {
00078 tst_resm(TFAIL,"shmat1 Failed");
00079 rm_shm(shmid) ;
00080 tst_exit() ;
00081 }
00082
00083 cp1 = (char *) shmat(shmid, (void *)0, 0);
00084 if (cp1 == (char *)-1) {
00085 perror("shmat2");
00086 rm_shm(shmid) ;
00087 tst_exit() ;
00088 }
00089
00090 tst_resm(TPASS,"shmget,shmat");
00091
00092
00093
00094
00095 if (shmdt(cp) < 0) {
00096 perror("shmdt2");
00097 tst_resm(TFAIL,"shmdt:cp") ;
00098 }
00099
00100 if (shmdt(cp1) < 0 ) {
00101 perror("shmdt1");
00102 tst_resm(TFAIL,"shmdt:cp1") ;
00103 }
00104
00105 tst_resm(TPASS,"shmdt");
00106
00107
00108 rm_shm(shmid) ;
00109 tst_exit() ;
00110
00111
00112 return(0);
00113 }
00114
00115 int rm_shm(shmid)
00116 int shmid ;
00117 {
00118 if (shmctl(shmid, IPC_RMID, NULL) == -1) {
00119 perror("shmctl");
00120 tst_resm(TFAIL,
00121 "shmctl Failed to remove: shmid = %d, errno = %d\n",
00122 shmid, errno) ;
00123 tst_exit();
00124 }
00125 return(0);
00126 }
00127