2020-03-03 22:17:08 +01:00
|
|
|
|
#ifdef _NZG_HPUX
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
#else
|
|
|
|
|
#include <wait.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "libnazgul.h"
|
|
|
|
|
|
2020-03-04 00:06:43 +01:00
|
|
|
|
void usage(char *myname)
|
|
|
|
|
{
|
|
|
|
|
printf("Usage: %s [--all | msgSpaceId1 msgSpaceId2 ... ]\n", myname);
|
2020-03-03 22:17:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-04 00:06:43 +01:00
|
|
|
|
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;
|
2020-03-03 22:17:08 +01:00
|
|
|
|
} else {
|
2020-03-04 00:06:43 +01:00
|
|
|
|
int err;
|
|
|
|
|
msgSpaceListLock();
|
|
|
|
|
err = msgSpaceListFindId(spaceId);
|
|
|
|
|
msgSpaceListUnlock();
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
msgPoolDataTabLock(space);
|
|
|
|
|
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);
|
|
|
|
|
msgPoolDataTabUnlock(space);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// on quitte : l'element n'existe
|
|
|
|
|
fprintf(stderr, "Ident %s does not exist.\n", spaceId);
|
|
|
|
|
}
|
2020-03-03 22:17:08 +01:00
|
|
|
|
}
|
2020-03-04 00:06:43 +01:00
|
|
|
|
return 0;
|
|
|
|
|
ERROR:
|
|
|
|
|
return -1;
|
2020-03-03 22:17:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-04 00:06:43 +01:00
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
printf("Args %d\n", argc);
|
|
|
|
|
if (argc < 2) {
|
|
|
|
|
usage(argv[0]);
|
2020-03-03 22:17:08 +01:00
|
|
|
|
} else {
|
2020-03-04 00:06:43 +01:00
|
|
|
|
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]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-03 22:17:08 +01:00
|
|
|
|
}
|
2020-03-04 00:06:43 +01:00
|
|
|
|
return 0;
|
2020-03-03 22:17:08 +01:00
|
|
|
|
}
|