12 void semctl_test (int trace
, const char *fname
)
20 int val
; /* Value for SETVAL */
21 struct semid_ds
*buf
; /* Buffer for IPC_STAT, IPC_SET */
22 unsigned short *array
; /* Array for GETALL, SETALL */
23 struct seminfo
*__buf
; /* Buffer for IPC_INFO
29 key
= ftok (fname
, 1);
34 semid
= semget (key
, 2 * nr_of_readers
, IPC_CREAT
+ 0660);
39 printf("semid %d\n", semid
);
42 ret
= semctl (semid
, 0, IPC_STAT
, u
);
44 perror("semctl IPC_STAT");
46 printf("semid %d sem_nsems %d\n", semid
, (int) ds
.sem_nsems
);
49 unsigned short semarray
[2 * nr_of_readers
];
50 for (int count
= 0; count
< nr_of_readers
; count
++) {
51 semarray
[2 * count
] = 0;
52 semarray
[2 * count
+ 1] = 1000;
54 ret
= semctl (semid
, 0, SETALL
, semarray
);
56 perror ("semctl SETALL");
59 ret
= semctl (semid
, 0, IPC_RMID
);
61 perror ("semctl IPC_RMID");
64 int main(int argc
, char **argv
)
68 #ifdef HAVE_SEMTIMEDOP
72 if ((semid
= semget(IPC_PRIVATE
, 1, 0600)) < 0)
82 if (semop(semid
, &sop
, 1) < 0)
85 semctl(semid
, 0, IPC_RMID
);
89 if (semctl(semid
, 0, GETVAL
) != 1)
91 perror("semctl GETVAL");
92 semctl(semid
, 0, IPC_RMID
);
96 if (semctl(semid
, 0, GETPID
) != getpid())
98 perror("semctl GETPID");
99 semctl(semid
, 0, IPC_RMID
);
103 /* The next call to semtimedop causes the program to hang on
104 ppc32-linux (Yellow Dog 4.0). I don't know why. Hence the
106 #if defined(HAVE_SEMTIMEDOP) && !defined(__powerpc__)
112 ts
.tv_nsec
= 1000000;
114 if (semtimedop(semid
, &sop
, 1, &ts
) < 0 && errno
!= EAGAIN
)
116 perror("semtimedop");
117 semctl(semid
, 0, IPC_RMID
);
126 if (semop(semid
, &sop
, 1) < 0)
129 semctl(semid
, 0, IPC_RMID
);
133 #ifdef HAVE_SEMTIMEDOP
141 if (semtimedop(semid
, &sop
, 1, &ts
) < 0)
143 perror("semtimedop");
144 semctl(semid
, 0, IPC_RMID
);
149 if (semctl(semid
, 0, IPC_RMID
) < 0)
151 perror("semctl(IPC_RMID)");
155 semctl_test(argc
> 1, argv
[0]);