4 * Lists all semaphores in all Teams.
8 * added command line args
10 * Legal stuff follows:
12 Copyright (c) 2002 Oliver Siebenmarck <olli@ithome.de>, OpenBeOS project
14 Permission is hereby granted, free of charge, to any person obtaining a copy of
15 this software and associated documentation files (the "Software"), to deal in
16 the Software without restriction, including without limitation the rights to
17 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
18 of the Software, and to permit persons to whom the Software is furnished to do
19 so, subject to the following conditions:
21 The above copyright notice and this permission notice shall be included in all
22 copies or substantial portions of the Software.
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
40 static void print_sem_info(sem_info
*info
)
42 printf("%7" B_PRId32
"%31s%7" B_PRId32
"\n", info
->sem
, info
->name
,
47 static void print_header(team_info
*tinfo
)
50 printf("TEAM %" B_PRId32
" (%s):\n", tinfo
->team
, tinfo
->args
);
52 printf(" ID name count\n");
53 printf("---------------------------------------------\n");
57 static void list_sems(team_info
*tinfo
)
64 while (get_next_sem_info(tinfo
->team
, &cookie
, &info
) == B_OK
)
65 print_sem_info(&info
);
70 int main(int argc
, char **argv
)
77 // show up some stats first...
78 get_system_info(&sysinfo
);
79 printf("sem: total: %5" B_PRIu32
", used: %5" B_PRIu32
", left: %5" B_PRIu32
80 "\n\n", sysinfo
.max_sems
, sysinfo
.used_sems
,
81 sysinfo
.max_sems
- sysinfo
.used_sems
);
84 while (get_next_team_info( &cookie
, &tinfo
) == B_OK
)
90 for (i
= 1; i
< argc
; i
++) {
91 if (strcmp(argv
[i
], "--help") == 0 || strcmp(argv
[i
], "-h") == 0) {
92 fprintf(stderr
, "Usage: %s [-s semid] [teamid]\n", argv
[0]);
93 fputs(" List the semaphores allocated by the specified\n",
95 fputs(" team, or all teams if none is specified.\n",
98 fputs(" The -s option displays the sem_info data for a\n",
100 fputs(" specified semaphore.\n", stderr
);
102 } else if (strcmp(argv
[i
], "-s") == 0) {
104 printf("-s used without associated sem id\n");
106 sem_id id
= atoi(argv
[i
+ 1]);
108 if (get_sem_info(id
, &info
) == B_OK
) {
110 print_sem_info(&info
);
112 printf("semaphore %" B_PRId32
" unknown\n\n", id
);
118 team
= atoi(argv
[i
]);
119 if (get_team_info(team
, &tinfo
) == B_OK
)
122 printf("team %" B_PRId32
" unknown\n\n", team
);