listsem didn't actually support the -s option its help listed.
Minor cleanups.
This commit is contained in:
parent
f5a14b17df
commit
662b04ff7d
|
@ -1,14 +1,14 @@
|
||||||
/*
|
/*
|
||||||
* listsem.c
|
* listsem.c
|
||||||
*
|
*
|
||||||
* Lists all semaphores in all Teams.
|
* Lists all semaphores in all Teams.
|
||||||
* by O.Siebenmarck.
|
* by O.Siebenmarck.
|
||||||
*
|
*
|
||||||
* 04-27-2002 - mmu_man
|
* 04-27-2002 - mmu_man
|
||||||
* added command line args
|
* added command line args
|
||||||
*
|
*
|
||||||
* Legal stuff follows:
|
* Legal stuff follows:
|
||||||
|
|
||||||
Copyright (c) 2002 Oliver Siebenmarck <olli@ithome.de>, OpenBeOS project
|
Copyright (c) 2002 Oliver Siebenmarck <olli@ithome.de>, OpenBeOS project
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
@ -33,29 +33,44 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
|
|
||||||
|
static void print_sem_info(sem_info *info)
|
||||||
|
{
|
||||||
|
printf("%7ld%31s%7ld\n", info->sem ,info->name , info->count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void print_header(team_info *tinfo)
|
||||||
|
{
|
||||||
|
if (tinfo != NULL)
|
||||||
|
printf("TEAM %ld (%s):\n", tinfo->team, tinfo->args );
|
||||||
|
|
||||||
|
printf(" ID name count\n");
|
||||||
|
printf("---------------------------------------------\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void list_sems(team_info *tinfo)
|
static void list_sems(team_info *tinfo)
|
||||||
{
|
{
|
||||||
sem_info info;
|
sem_info info;
|
||||||
int32 cookie = 0;
|
int32 cookie = 0;
|
||||||
|
|
||||||
printf("TEAM %ld (%s):\n", tinfo->team, tinfo->args );
|
print_header(tinfo);
|
||||||
printf(" ID name count\n");
|
|
||||||
printf("---------------------------------------------\n");
|
|
||||||
|
|
||||||
while (get_next_sem_info(tinfo->team, &cookie, &info) == B_OK)
|
while (get_next_sem_info(tinfo->team, &cookie, &info) == B_OK)
|
||||||
{
|
print_sem_info(&info);
|
||||||
printf("%7ld%31s%7ld\n", info.sem ,info.name , info.count );
|
|
||||||
}
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
team_info tinfo;
|
team_info tinfo;
|
||||||
int32 cook = 0;
|
int32 cookie = 0;
|
||||||
int i;
|
int32 i;
|
||||||
system_info sysinfo;
|
system_info sysinfo;
|
||||||
|
|
||||||
// show up some stats first...
|
// show up some stats first...
|
||||||
|
@ -63,12 +78,12 @@ int main(int argc, char **argv)
|
||||||
printf("sem: total: %5li, used: %5li, left: %5li\n\n", sysinfo.max_sems, sysinfo.used_sems, sysinfo.max_sems - sysinfo.used_sems);
|
printf("sem: total: %5li, used: %5li, left: %5li\n\n", sysinfo.max_sems, sysinfo.used_sems, sysinfo.max_sems - sysinfo.used_sems);
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
while (get_next_team_info( &cook, &tinfo) == B_OK)
|
while (get_next_team_info( &cookie, &tinfo) == B_OK)
|
||||||
{
|
|
||||||
list_sems(&tinfo);
|
list_sems(&tinfo);
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
|
if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
|
||||||
fprintf(stderr, "Usage: %s [-s semid] [teamid]\n", argv[0]);
|
fprintf(stderr, "Usage: %s [-s semid] [teamid]\n", argv[0]);
|
||||||
|
@ -78,15 +93,31 @@ int main(int argc, char **argv)
|
||||||
fputs(" The -s option displays the sem_info data for a\n", stderr);
|
fputs(" The -s option displays the sem_info data for a\n", stderr);
|
||||||
fputs(" specified semaphore.\n", stderr);
|
fputs(" specified semaphore.\n", stderr);
|
||||||
return 0;
|
return 0;
|
||||||
|
} else if (!strcmp(argv[i], "-s")) {
|
||||||
|
if (argc < i + 2)
|
||||||
|
printf("-s used without associated sem id\n");
|
||||||
|
else {
|
||||||
|
sem_id sem = atoi(argv[i+1]);
|
||||||
|
|
||||||
|
}
|
||||||
|
int semID = atoi(argv[i+1]);
|
||||||
|
sem_info info;
|
||||||
|
if (get_sem_info(semID, &info) == B_OK) {
|
||||||
|
print_header(NULL);
|
||||||
|
print_sem_info(&info);
|
||||||
|
} else
|
||||||
|
printf("semaphore %ld unknown\n\n", semID);
|
||||||
|
i++;
|
||||||
} else {
|
} else {
|
||||||
int t;
|
team_id team;
|
||||||
t = atoi(argv[i]);
|
team = atoi(argv[i]);
|
||||||
if (get_team_info(t, &tinfo) == B_OK)
|
if (get_team_info(team, &tinfo) == B_OK)
|
||||||
list_sems(&tinfo);
|
list_sems(&tinfo);
|
||||||
else
|
else
|
||||||
printf("team %i unknown\n\n", t);
|
printf("team %ld unknown\n\n", team);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue