13 void semctl_test (int trace
, const char *fname
)
21 int val
; /* Value for SETVAL */
22 struct semid_ds
*buf
; /* Buffer for IPC_STAT, IPC_SET */
23 unsigned short *array
; /* Array for GETALL, SETALL */
24 struct seminfo
*__buf
; /* Buffer for IPC_INFO
30 key
= ftok (fname
, 1);
35 semid
= semget (key
, 2 * nr_of_readers
, IPC_CREAT
+ 0660);
40 printf("semid %d\n", semid
);
43 ret
= semctl (semid
, 0, IPC_STAT
, u
);
45 perror("semctl IPC_STAT");
47 printf("semid %d sem_nsems %d\n", semid
, (int) ds
.sem_nsems
);
50 unsigned short semarray
[2 * nr_of_readers
];
51 for (int count
= 0; count
< nr_of_readers
; count
++) {
52 semarray
[2 * count
] = 0;
53 semarray
[2 * count
+ 1] = 1000;
55 ret
= semctl (semid
, 0, SETALL
, semarray
);
57 perror ("semctl SETALL");
60 ret
= semctl (semid
, 0, IPC_RMID
);
62 perror ("semctl IPC_RMID");
65 int main(int argc
, char **argv
)
69 #ifdef HAVE_SEMTIMEDOP
73 if ((semid
= semget(IPC_PRIVATE
, 1, 0600)) < 0)
83 if (semop(semid
, &sop
, 1) < 0)
86 semctl(semid
, 0, IPC_RMID
);
90 if (semctl(semid
, 0, GETVAL
) != 1)
92 perror("semctl GETVAL");
93 semctl(semid
, 0, IPC_RMID
);
97 if (semctl(semid
, 0, GETPID
) != getpid())
99 perror("semctl GETPID");
100 semctl(semid
, 0, IPC_RMID
);
104 /* The next call to semtimedop causes the program to hang on
105 ppc32-linux (Yellow Dog 4.0). I don't know why. Hence the
107 #if defined(HAVE_SEMTIMEDOP) && !defined(__powerpc__)
113 ts
.tv_nsec
= 1000000;
115 if (semtimedop(semid
, &sop
, 1, &ts
) < 0 && errno
!= EAGAIN
)
117 perror("semtimedop");
118 semctl(semid
, 0, IPC_RMID
);
127 if (semop(semid
, &sop
, 1) < 0)
130 semctl(semid
, 0, IPC_RMID
);
134 #ifdef HAVE_SEMTIMEDOP
142 if (semtimedop(semid
, &sop
, 1, &ts
) < 0)
144 perror("semtimedop");
145 semctl(semid
, 0, IPC_RMID
);
150 if (semctl(semid
, 0, IPC_RMID
) < 0)
152 perror("semctl(IPC_RMID)");
156 semctl_test(argc
> 1, argv
[0]);