remove extra mkfs.1
[minix.git] / test / ipc / shmt / shmt01.c
blob4264b58780080c79a400cda39e7cb6980615548f
1 /*
2 * NAME
3 * shmt01
5 * CALLS
6 * shmat(2) shmget(2) shmdt(2)
8 * ALGORITHM
9 * Create and attach a shared memory segment, write to it
10 * and then detach the shared memroy twice, the second one will FAIL.
14 #include <stdio.h>
15 #include <sys/types.h>
16 #include <sys/ipc.h>
17 #include <sys/shm.h>
18 #include <sys/utsname.h>
19 #include <errno.h>
21 /** LTP Port **/
22 #include "test.h"
23 #include "usctest.h"
25 char *TCID="shmt01"; /* Test program identifier. */
26 int TST_TOTAL=4; /* Total number of test cases. */
27 extern int Tst_count; /* Test Case counter for tst_* routines */
30 /**************/
32 #define K_1 1024
34 int rm_shm(int);
36 int main(void)
38 register int shmid;
39 char *cp;
40 key_t key;
41 int r;
43 errno = 0;
44 key = (key_t)getpid() ;
46 /*----------------------------------------------------------------*/
49 if ((shmid = shmget(key, 16*K_1, IPC_CREAT|0666)) < 0 ) {
50 perror("shmget");
51 tst_resm(TFAIL, "shmget Failed: shmid = %d, errno = %d\n",
52 shmid, errno) ;
53 tst_exit() ;
56 tst_resm(TPASS, "shmget") ;
58 /*----------------------------------------------------------------*/
61 /* are we doing with ia64 or arm_arch_4t arch */
62 #if defined (__ia64__) || defined (__ARM_ARCH_4T__)
63 cp = (char *) shmat(shmid, (void *)NULL, 0);
64 #else
65 cp = (char *) shmat(shmid, (void *)0x80000, 0);
66 #endif
67 if (cp == (char *)-1) {
68 perror("shmat");
69 tst_resm(TFAIL, "shmat Failed: shmid = %d, errno = %d\n",
70 shmid, errno) ;
71 rm_shm(shmid) ;
72 tst_exit() ;
75 *cp = '1';
76 *(cp+1) = '2';
78 tst_resm(TPASS, "shmat") ;
80 /*----------------------------------------------------------------*/
82 r = shmdt(cp);
83 if (r < 0) {
84 perror("shmdt");
85 tst_resm(TFAIL, "shmdt Failed: shmid = %d, errno = %d\n",
86 shmid, errno);
87 rm_shm(shmid);
88 tst_exit();
91 tst_resm(TPASS, "shmdt first time.");
93 r = shmdt(cp);
94 if (r == 0) {
95 perror("shmdt");
96 tst_resm(TFAIL, "shmdt Failed: shmid = %d, errno = %d\n",
97 shmid, errno);
98 rm_shm(shmid);
99 tst_exit();
102 rm_shm(shmid) ;
104 tst_resm(TPASS, "shmdt second time.");
106 /*------------------------------------------------------------------*/
108 tst_exit() ;
110 /*-------------------- THIS LINE IS NOT REACHED -------------------*/
111 return(0);
114 int rm_shm(shmid)
115 int shmid ;
117 if (shmctl(shmid, IPC_RMID, NULL) == -1) {
118 perror("shmctl");
119 tst_resm(TFAIL,
120 "shmctl Failed to remove: shmid = %d, errno = %d\n",
121 shmid, errno) ;
122 tst_exit();
124 return(0);