2004-03-07 12:26:42 +00:00
|
|
|
|
#ifdef _NZG_HPUX
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
#else
|
2004-02-26 10:37:42 +00:00
|
|
|
|
#include <wait.h>
|
2004-03-07 12:26:42 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2004-02-26 10:37:42 +00:00
|
|
|
|
#include "libnazgul.h"
|
|
|
|
|
|
|
|
|
|
void usage(char * myname){
|
|
|
|
|
printf("Usage: %s [--all | msgSpaceId1 msgSpaceId2 ... ]\n",myname);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int about(char * spaceId){
|
|
|
|
|
msgPoolDataTabSemId ressourceSemId;
|
|
|
|
|
sem_t * ressourceSemFd;
|
|
|
|
|
int i;
|
|
|
|
|
msgPoolData * poolDataTab;
|
|
|
|
|
msgSpace * space;
|
|
|
|
|
int ressourceSemVal;
|
|
|
|
|
if (strlen(spaceId)> MSGSPACE_ID_LEN){
|
|
|
|
|
//verif de la longueur
|
|
|
|
|
fprintf(stderr,"Too long ident : %s\n",spaceId);
|
|
|
|
|
goto ERROR;
|
|
|
|
|
} else {
|
|
|
|
|
int err;
|
|
|
|
|
msgSpaceListLock();
|
2004-02-26 10:52:40 +00:00
|
|
|
|
err=msgSpaceListFindId(spaceId);
|
|
|
|
|
msgSpaceListUnlock();
|
2004-02-26 10:37:42 +00:00
|
|
|
|
if (err < 1){
|
|
|
|
|
if (err==0){
|
|
|
|
|
// le msgSpace existe
|
|
|
|
|
space=msgSpaceOpen(spaceId);
|
|
|
|
|
// on lit les informations sur le msgSpace
|
|
|
|
|
// les pool
|
|
|
|
|
for (i=0;i<space->poolNb;i++){
|
|
|
|
|
msgPoolSemIdIntern(ressourceSemId,space->externId,i);
|
|
|
|
|
ressourceSemFd = sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
|
|
|
|
|
if (ressourceSemFd == SEM_FAILED){
|
|
|
|
|
NZG_ERROR("sem_open",ressourceSemId);
|
|
|
|
|
goto ERROR;
|
|
|
|
|
}
|
|
|
|
|
if (sem_getvalue(ressourceSemFd, &ressourceSemVal) < 0){
|
|
|
|
|
NZG_ERROR("sem_getvalue",ressourceSemId);
|
|
|
|
|
goto ERROR;
|
|
|
|
|
}
|
2004-02-26 10:47:46 +00:00
|
|
|
|
msgPoolDataTabLock(space);
|
2004-02-26 10:37:42 +00:00
|
|
|
|
poolDataTab= msgPoolDataTabOpen(space);
|
|
|
|
|
// donner le nombre de buffer disponibles
|
|
|
|
|
printf("- %d/%d free buffers in pool #%d\n",
|
|
|
|
|
ressourceSemVal,
|
|
|
|
|
poolDataTab[i].bufferNb,
|
|
|
|
|
i);
|
|
|
|
|
msgPoolDataTabClose(space,poolDataTab);
|
2004-02-26 10:47:46 +00:00
|
|
|
|
msgPoolDataTabUnlock(space);
|
2004-02-26 10:37:42 +00:00
|
|
|
|
if(sem_close(ressourceSemFd) <0){
|
|
|
|
|
NZG_ERROR("sem_getvalue",ressourceSemId);
|
|
|
|
|
goto ERROR;
|
|
|
|
|
}
|
|
|
|
|
// pour chaque buffer, dire s'il est libre ou pas
|
|
|
|
|
// et le processus/addresse associ<63>
|
|
|
|
|
}
|
|
|
|
|
msgSpaceClose(space);
|
|
|
|
|
} else {
|
|
|
|
|
// zut, il y a soit une erreur
|
|
|
|
|
NZG_ERROR("spaceListFindId : error ",spaceId);
|
|
|
|
|
}
|
2004-02-26 10:52:40 +00:00
|
|
|
|
} else {
|
2004-02-26 10:37:42 +00:00
|
|
|
|
// on quitte : l'element n'existe
|
|
|
|
|
fprintf(stderr,"Ident %s does not exist.\n",spaceId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
ERROR:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc,char **argv){
|
|
|
|
|
printf("Args %d\n",argc);
|
|
|
|
|
if (argc<2){
|
|
|
|
|
usage(argv[0]);
|
|
|
|
|
}else {
|
|
|
|
|
if (argc==2){
|
|
|
|
|
if (strcmp("--all",argv[1])==0){
|
|
|
|
|
// listing
|
|
|
|
|
printf("[ Listing of msgSpaces ]\n");
|
|
|
|
|
} else {
|
|
|
|
|
// only one msgSpaceId
|
|
|
|
|
printf("[ About %s ]\n",argv[1]);
|
|
|
|
|
about(argv[1]);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
int i;
|
|
|
|
|
for (i=1;i<argc;i++){
|
|
|
|
|
printf("[ About %s ]\n",argv[i]);
|
|
|
|
|
about(argv[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|