RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / bin / release.c
blob8199b6ab5982509a336d9cd0f5a02baaf4e7830f
1 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
2 //
3 // Copyright (c) 2004, OpenBeOS
4 //
5 // This software is part of the OpenBeOS distribution and is covered
6 // by the MIT License.
7 //
8 //
9 // File: release.c
10 // Author: Jérôme Duval (korli@chez.com)
11 // Description: release a semaphore.
13 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <OS.h>
20 static int usage(char *prog)
22 printf("usage: release [-f] [-c count] semaphore_number\n");
23 printf("warning: this can be hazardous...\n");
24 exit(1);
28 int main(int argc, char **argv)
30 int count = 1;
31 bool force = false;
32 sem_id semid = -1;
33 status_t err;
34 team_id teamid = -1;
36 int i;
37 if (argc < 2 || argc > 5)
38 usage("release");
39 for (i = 1; i < argc; i++) {
40 if (strncmp(argv[i], "-f", 2) == 0) {
41 force = true;
42 } else if (strncmp(argv[i], "-c", 2) == 0) {
43 i++;
44 if (i < argc) {
45 count = strtol(argv[i], NULL, 10);
46 } else
47 usage("release");
48 } else {
49 semid = strtol(argv[i], NULL, 10);
53 if (semid <=0)
54 usage("release");
56 if (force) {
57 sem_info sinfo;
58 thread_info tinfo;
59 get_sem_info(semid, &sinfo);
60 teamid = sinfo.team;
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);
68 if (err < B_OK) {
69 fprintf(stderr, "release_sem failed: %s\n", strerror(err));
70 return 1;
71 } else if (force) {
72 set_sem_owner(semid, teamid);
75 return 0;