1 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
3 // Copyright (c) 2004, OpenBeOS
5 // This software is part of the OpenBeOS distribution and is covered
10 // Author: Jérôme Duval (korli@chez.com)
11 // Description: release a semaphore.
13 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
20 static int usage(char *prog
)
22 printf("usage: release [-f] [-c count] semaphore_number\n");
23 printf("warning: this can be hazardous...\n");
28 int main(int argc
, char **argv
)
37 if (argc
< 2 || argc
> 5)
39 for (i
= 1; i
< argc
; i
++) {
40 if (strncmp(argv
[i
], "-f", 2) == 0) {
42 } else if (strncmp(argv
[i
], "-c", 2) == 0) {
45 count
= strtol(argv
[i
], NULL
, 10);
49 semid
= strtol(argv
[i
], NULL
, 10);
59 get_sem_info(semid
, &sinfo
);
61 get_thread_info(find_thread(NULL
), &tinfo
);
62 set_sem_owner(semid
, tinfo
.team
);
65 printf("releasing semaphore %d\n", (int)semid
);
66 err
= release_sem_etc(semid
, count
, 0);
69 fprintf(stderr
, "release_sem failed: %s\n", strerror(err
));
72 set_sem_owner(semid
, teamid
);