Première version

This commit is contained in:
smas
2000-07-31 13:15:35 +00:00
commit 43e6f0ee89
16 changed files with 10505 additions and 0 deletions

426
util/logadmin.c Normal file
View File

@@ -0,0 +1,426 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/time.h>
#include <log.h>
#include <tool.h>
VER_INFO_EXPORT (logadmin, "$Revision: 1.1 $", "$Name: $", __FILE__, "$Author: smas $")
#define USAGE "Usage : %s [ --help | --version [-v] | --create | --destroy | --load [1|2|3] ] | --unload [1|2|3] ]\n"
typedef struct {
double sec;
struct timeval start;
struct timeval stop;
} cpt;
#define t_start(x){gettimeofday(&(x.start), NULL);}
#define t_stop(x){gettimeofday(&(x.stop), NULL); x.sec = (double)(x.stop.tv_sec) - (double)(x.start.tv_sec) + ((double)(x.stop.tv_usec) - (double)(x.start.tv_usec)) / 1000000;}
cpt t_exec;
#define QUIT 0
#define BASE_INIT 1
#define BASE_OPEN 2
#define BASE_INFO 3
#define BASE_CLOSE 4
#define BASE_END 5
#define BASE_LOAD 6
#define BASE_UNLOAD 7
#define SHOW_CHANNEL_LIST 8
#define SHOW_RTAB_LIST 9
#define CHANNEL_DUMP 10
#define RTAB_DUMP 11
#define TEST_EVENT 12
char menu [1000];
char tmp [100];
void init_menu (void);
int print_menu (void);
char * Get_Rooting (LOGT_Rooting);
char * Get_RC (LOGT_RC);
int main (int argc, char ** argv)
{
int choice, i;
char Name [100];
LOGT_Channel * My_Channel;
char Answer[10];
NDT_Node * Node;
NDT_Root * Root;
LOGT_RTab RTab;
int Mode;
LOGT_Info * Info;
TL_Library_Stderr_Set (stderr);
/* Lancement de commande d'administration ? */
if (argc >= 2)
{
if (!strcmp (argv [1], "--help"))
{
fprintf (stderr, USAGE, argv [0]);
return -1;
}
else if (!strcmp (argv [1], "--version"))
{
if (argc >= 3 && !strcmp (argv [2], "-v"))
return VER_Object_Print (stdout, VERD_VERBOSE);
else
return VER_Object_Print (stdout, VERD_MINIMAL);
}
else if (!strcmp (argv [1], "--create"))
{
if (SM_Library_Open (0, NULL, SMD_OPEN | SMD_DEBUG_ALL) != SMS_OK)
{
fprintf (stderr, "=> Impossible d'ouvrir l'instance de la LIBSHMEM\n");
return -1;
}
if (LOG_Library_Open (0, NULL, LOGD_CREATE | SMD_DEBUG_ALL) != LOGS_OK)
{
fprintf (stderr, "=> Création de la LIBLOG impossible\n");
return -1;
}
return 0;
}
else if (!strcmp (argv [1], "--load"))
{
Mode = 0;
if (argc > 2)
{
if (strchr (argv [2], '1')) Mode += TLD_KMOD;
if (strchr (argv [2], '2')) Mode += TLD_KFORMAT;
if (strchr (argv [2], '3')) Mode += TLD_GDRT;
}
if (LOG_Library_Open (0, NULL, LOGD_OPEN | SMD_DEBUG_ALL) != LOGS_OK)
{
fprintf (stderr, "=> Ouverture de la LIBLOG impossible\n");
return -1;
}
if (TL_LIBLOG_Load (Mode) != LOGS_OK)
{
fprintf (stderr, "=> Chargement de la LIBLOG impossible\n");
return -1;
}
return 0;
}
else if (!strcmp (argv [1], "--unload"))
{
Mode = 0;
if (argc > 2)
{
if (strchr (argv [2], '1')) Mode += TLD_KMOD;
if (strchr (argv [2], '2')) Mode += TLD_KFORMAT;
if (strchr (argv [2], '3')) Mode += TLD_GDRT;
}
if (LOG_Library_Open (0, NULL, LOGD_OPEN | SMD_DEBUG_ALL) != LOGS_OK)
{
fprintf (stderr, "=> Ouverture de la LIBLOG impossible\n");
return -1;
}
if (TL_LIBLOG_Unload (Mode) != LOGS_OK)
{
fprintf (stderr, "=> Déchargement de la LIBLOG impossible\n");
return -1;
}
return 0;
}
else if (!strcmp (argv [1], "--destroy"))
{
if (LOG_Library_Open (0, NULL, LOGD_OPEN | SMD_DEBUG_ALL) != LOGS_OK)
{
fprintf (stderr, "=> Ouverture de la LIBLOG à détruire impossible\n");
return -1;
}
if (LOG_Library_Close (LOGD_DESTROY) != LOGS_OK)
{
fprintf (stderr, "=> Destruction de la LIBLOG impossible\n");
return -1;
}
return 0;
}
else
{
fprintf (stderr, USAGE, argv [0]);
return -1;
}
}
/* Lancement du menu intercatif */
init_menu ();
choice = print_menu ();
while (choice != QUIT)
{
strcpy (Answer, "yes");
switch (choice)
{
case BASE_INIT:
fprintf (stdout, "\nReturn code = %s\n", \
LOG_Library_Open (0, NULL, LOGD_CREATE | SMD_DEBUG_ALL) == LOGS_OK ? "OK" : "NOK" );
break;
case BASE_OPEN:
fprintf (stdout, "\nReturn code = %s\n", \
LOG_Library_Open (0, NULL, LOGD_OPEN | SMD_DEBUG_ALL) == LOGS_OK ? "OK" : "NOK" );
break;
case BASE_END:
fprintf (stdout, "\nReturn code = %s\n", \
LOG_Library_Close (LOGD_DESTROY) == LOGS_OK ? "OK" : "NOK" );
break;
case BASE_CLOSE:
fprintf (stdout, "\nReturn code = %s\n", \
LOG_Library_Close (LOGD_CLOSE) == LOGS_OK ? "OK" : "NOK" );
break;
case BASE_INFO:
DS_DataStruct_Info_Print (LOG_Base->KMOD, stdout);
DS_DataStruct_Info_Print (LOG_Base->KFORMAT, stdout);
DS_DataStruct_Info_Print (LOG_Base->GDRT->Root, stdout);
DS_DataStruct_Info_Print (LOG_Base->LMRT_List, stdout);
DS_DataStruct_Info_Print (LOG_Base->LDRT_List, stdout);
DS_DataStruct_Info_Print (LOG_Base->URT_List, stdout);
DS_DataStruct_Info_Print (LOG_Base->Channel_List, stdout);
break;
case BASE_LOAD:
fprintf (stdout, "\nCache to load ? (KMOD=1, KFORMAT=2, GDRT=3) ");
gets (Name);
Mode = 0;
if (strchr (Name, '1')) Mode |= TLD_KMOD;
if (strchr (Name, '2')) Mode += TLD_KFORMAT;
if (strchr (Name, '3')) Mode += TLD_GDRT;
fprintf (stdout, "\nReturn code = %s\n", TL_LIBLOG_Load (Mode) == LOGS_OK ? "OK" : "NOK" );
break;
case BASE_UNLOAD:
fprintf (stdout, "\nCache to unload ? (KMOD=1, KFORMAT=2, GDRT=3) ");
gets (Name);
Mode = 0;
if (strchr (Name, '1')) Mode += TLD_KMOD;
if (strchr (Name, '2')) Mode += TLD_KFORMAT;
if (strchr (Name, '3')) Mode += TLD_GDRT;
fprintf (stdout, "\nReturn code = %s\n", TL_LIBLOG_Unload (Mode) == LOGS_OK ? "OK" : "NOK" );
break;
case SHOW_RTAB_LIST:
DS_DataStruct_Print (LOG_Base->LMRT_List, stdout);
DS_DataStruct_Print (LOG_Base->LDRT_List, stdout);
DS_DataStruct_Print (LOG_Base->URT_List, stdout);
break;
case SHOW_CHANNEL_LIST:
DS_DataStruct_Print (LOG_Base->Channel_List, stdout);
break;
case CHANNEL_DUMP:
fprintf (stdout, "\nChannel address ? ");
gets (Name);
i = atoi (Name);
if (DS_Node_Find (LOG_Base->Channel_List, &Node, (void *)i, NULL) != DSS_OK)
fprintf (stdout, "Unable to find channel at address %d\n", i);
else
{
My_Channel = (LOGT_Channel *)(Node->Value);
ND_Manager_Exec (LOG_Base->Channel_List->Manager, NDD_CMD_PRINT_VALUE, &My_Channel, stdout);
if (fprintf (stdout, "\n\nShow rooting tables ? (y/n) ") && gets (tmp) && *tmp == 'y')
DS_DataStruct_Print (My_Channel->RTab_List, stdout);
if (fprintf (stdout, "\nShow submodules ? (y/n) ") && gets (tmp) && *tmp == 'y')
DS_DataStruct_Print (My_Channel->SubModule_List, stdout);
if (fprintf (stdout, "\nShow triggers ? (y/n) ") && gets (tmp) && *tmp == 'y')
DS_DataStruct_Print (My_Channel->Trigger_List, stdout);
if (fprintf (stdout, "\nShow event counters ? (y/n) ") && gets (tmp) && *tmp == 'y')
DS_DataStruct_Print (My_Channel->Event_Cpt_List, stdout);
}
break;
case RTAB_DUMP:
fprintf (stdout, "\nTable Name ? ");
gets (Name);
RTab.Name = Name;
if ((DS_Node_Find (LOG_Base->LMRT_List, &Node, &RTab, NULL) == DSS_OK && (Root = LOG_Base->LMRT_List)) ||
(DS_Node_Find (LOG_Base->LDRT_List, &Node, &RTab, NULL) == DSS_OK && (Root = LOG_Base->LDRT_List)) ||
(DS_Node_Find (LOG_Base->URT_List, &Node, &RTab, NULL) == DSS_OK && (Root = LOG_Base->URT_List)))
{
ND_Manager_Exec (Root->Manager, NDD_CMD_PRINT_VALUE, (void **)&(Node->Value), stdout);
if (fprintf (stdout, "\n\nShow events ? (y/n) ") && gets (tmp) && *tmp == 'y')
DS_DataStruct_Print (((LOGT_RTab *)(Node->Value))->Root, stdout);
}
else
fprintf (stdout, "\nUnable to find rooting table \"%s\"\n", Name);
break;
case TEST_EVENT:
fprintf (stdout, "\nEvent name ? ");
gets (Name);
Info = (LOGT_Info *)malloc(sizeof(LOGT_Info));
t_start (t_exec);
if (LOG_Event_Info_Get(NULL, &Info, Name) != LOGS_OK)
{
fprintf (stdout, "\nEvénement \"%s\" non résolu\n", Name);
t_stop (t_exec);
}
else
{
t_stop (t_exec);
fprintf (stdout, "\nEvénement \"%s\" résolu en %.4f sec :\n", Name, t_exec.sec);
fprintf (stdout, "\t- Type : %s (%d)\n", Info->Event_Name, Info->Event_Type);
fprintf (stdout, "\t- Routage : %s\n", Get_Rooting(Info->Rooting));
fprintf (stdout, "\t- Gravité : %c\n", (char)Info->Gravite);
fprintf (stdout, "\t- Code retour : %s\n", Get_RC(Info->RC));
fprintf (stdout, "\t- Format :");
if (Info->Data_List)
{
ND_Node_First_Get(Info->Data_List, &Node);
i = 0;
while (Node)
{
if (i > 0) fprintf (stdout, ",");
fprintf (stdout, " %s", (char *)(Node->Value));
ND_Node_Next_Get (Node, &Node);
i++;
}
}
fprintf (stdout, "\n\n");
}
free(Info);
break;
case QUIT:
fprintf (stdout, "\nExiting program ...\n");
break;
default:
fprintf (stdout, "\nUndefined choice %d\n", choice);
}
choice = print_menu ();
}
return 0;
}
void init_menu (void)
{
sprintf (menu, "Menu :\n");
sprintf (tmp, " - %2d) %-25s", QUIT, "Quit"); strcat (menu, tmp);
sprintf (tmp, " - %2d) %-25s\n", BASE_INIT, "Init library"); strcat (menu, tmp);
sprintf (tmp, " - %2d) %-25s", BASE_OPEN, "Open library"); strcat (menu, tmp);
sprintf (tmp, " - %2d) %-25s\n", BASE_INFO, "Info library"); strcat (menu, tmp);
sprintf (tmp, " - %2d) %-25s", BASE_CLOSE, "Close library"); strcat (menu, tmp);
sprintf (tmp, " - %2d) %-25s\n", BASE_END, "End library"); strcat (menu, tmp);
sprintf (tmp, " - %2d) %-25s", BASE_LOAD, "Load library cache"); strcat (menu, tmp);
sprintf (tmp, " - %2d) %-25s\n", BASE_UNLOAD, "Unload library cache"); strcat (menu, tmp);
sprintf (tmp, " - %2d) %-25s", SHOW_CHANNEL_LIST, "Show channels"); strcat (menu, tmp);
sprintf (tmp, " - %2d) %-25s\n", SHOW_RTAB_LIST, "Show rooting tables"); strcat (menu, tmp);
sprintf (tmp, " - %2d) %-25s", CHANNEL_DUMP, "Dump a channel"); strcat (menu, tmp);
sprintf (tmp, " - %2d) %-25s\n", RTAB_DUMP, "Dump a rooting table"); strcat (menu, tmp);
sprintf (tmp, " - %2d) %-25s\n", TEST_EVENT, "Test an event"); strcat (menu, tmp);
}
int print_menu (void)
{
fprintf (stdout, "---------------------------------------------------------------------------\n%s", menu);
tmp[0] = '\0';
while (tmp[0] == '\0')
{
printf ("\nChoice ? ");
gets (tmp);
}
return atoi (tmp);
}
char *Get_Rooting(LOGT_Rooting Rooting)
{
static char lib[20];
switch ((int)Rooting)
{
case LOGD_ROOTING_NULL:
strcpy(lib, "NULL");
break;
case LOGD_ROOTING_STDERR:
strcpy(lib, "STDERR");
break;
case LOGD_ROOTING_DATABASE:
strcpy(lib, "BASE");
break;
case LOGD_ROOTING_DEFAULT:
strcpy(lib, "DEFAULT");
break;
case LOGD_ROOTING_PREVIOUS:
strcpy(lib, "PREVIOUS");
break;
default:
strcpy(lib, "unknown");
break;
}
return lib;
}
char *Get_RC(LOGT_RC RC)
{
static char lib[20];
switch ((int)RC)
{
case LOGD_RC_OK:
strcpy(lib, "OK");
break;
case LOGD_RC_ANOERR:
strcpy(lib, "ANOERR");
break;
case LOGD_RC_REJDON:
strcpy(lib, "REJDON");
break;
case LOGD_RC_REJENR:
strcpy(lib, "REJENR");
break;
case LOGD_RC_WARNING:
strcpy(lib, "WARNING");
break;
case LOGD_RC_RECYCLE:
strcpy(lib, "RECYCLE");
break;
case LOGD_RC_EXIT:
strcpy(lib, "EXIT");
break;
case LOGD_RC_ABEND:
strcpy(lib, "ABEND");
break;
default:
strcpy(lib, "unknown");
break;
}
return lib;
}

504
util/logagent.c Normal file
View File

@@ -0,0 +1,504 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <ver.h>
#define MSG_MODE 1
#include <msg.h>
#include <log.h>
#include <logagent.h>
VER_INFO_EXPORT (logagent, "$Revision: 1.1 $", "$Name: $", __FILE__, "$Author: smas $")
void Parse_Arg (int , char **);
void Event_Msg_Process ( MSGT_Message * );
void System_Msg_Process ( MSGT_Message * );
void Info_Trace ( void );
unsigned int End_Agent, Nb_Event, Nb_System_Msg;
MSGT_Port * Private_Port, * Event_Port;
MSGT_PortList * Private_PortList;
unsigned int Num_Agent, Status, Debug;
char Debug_Trace [512];
/*--------------------------------------------------------------------------------------------------*/
/* Fonction principale */
/*--------------------------------------------------------------------------------------------------*/
int main ( int argc, char ** argv )
{
MSGT_Message * Msg;
char Private_Port_Name [256];
/* Récupération des arguments de la ligne de commande */
Parse_Arg (argc, argv);
/* Démarrage de l'agent */
Status = ACTIVE;
/* Ouverture de la librairie LIBMSG */
if (MSG_Library_Open (NULL, NULL, MSGD_OPEN) != MSGS_OK)
{
strcpy (Debug_Trace, "impossible d'ouvrir la librairie LIBMSG");
Info_Trace ();
return KO;
}
/* Ouverture du port de message dans lequel sont envoyés les événements */
if (MSG_Port_Open (LOGD_EVENT_PORT_NAME, &Event_Port, MSGD_OPEN | MSGD_CREATE) != MSGS_OK)
{
strcpy (Debug_Trace, "impossible d'ouvrir le port de messages des événements");
Info_Trace ();
MSG_Library_Close (MSGD_CLOSE);
return KO;
}
/* Ouverture (cas du restart) ou création du port privé de l'agent */
sprintf (Private_Port_Name, "Agent_%d_port", Num_Agent);
if (MSG_Port_Open (Private_Port_Name, &Private_Port, MSGD_OPEN | MSGD_CREATE) != MSGS_OK)
{
strcpy (Debug_Trace, "impossible de d'ouvrir ou de créer mon port de messages privé");
Info_Trace ();
MSG_Port_Close (Event_Port, MSGD_CLOSE);
MSG_Library_Close (MSGD_CLOSE);
return KO;
}
/* Création d'une liste de ports (port public + port privé) que l'agent va écouter */
if (MSG_PortList_Open (&Private_PortList) != MSGS_OK)
{
strcpy (Debug_Trace, "impossible de créer ma liste de ports");
Info_Trace ();
MSG_Port_Close (Event_Port, MSGD_CLOSE);
MSG_Port_Close (Private_Port, MSGD_DESTROY);
MSG_Library_Close (MSGD_CLOSE);
return KO;
}
if (MSG_PortList_Port_Add (Private_PortList, Private_Port) != MSGS_OK || MSG_PortList_Port_Add (Private_PortList, Event_Port) != MSGS_OK)
{
strcpy (Debug_Trace, "impossible d'ajouter les ports privé et public à ma liste de ports");
Info_Trace ();
MSG_PortList_Close (Private_PortList);
MSG_Port_Close (Event_Port, MSGD_CLOSE);
MSG_Port_Close (Private_Port, MSGD_DESTROY);
MSG_Library_Close (MSGD_CLOSE);
return KO;
}
sprintf (Debug_Trace, "démarrage en mode trace %s", Debug == TRUE ? "activé" : "désactivé");
Info_Trace ();
/* Boucle principale */
Nb_System_Msg = 0;
Nb_Event = 0;
End_Agent = FALSE;
while (End_Agent == FALSE)
{
unsigned int Expected_Type;
if (Status == ACTIVE)
{
/* Quand l'agent est actif, il traite tous les types de messages */
Expected_Type = MSGD_NO_TYPE;
}
else
{
/* Quand l'agent est stoppé, il ne traite que les messages système */
Expected_Type = MSGD_SYSTEM_GENERIC;
}
/* Ecoute des ports de messages de la liste */
if (MSG_PortList_Listen (Private_PortList, Expected_Type, &Msg, MSGD_WAIT) != MSGS_OK)
{
strcpy (Debug_Trace, "impossible de réceptionner un message depuis l'un des ports écoutés");
Info_Trace ();
MSG_PortList_Close (Private_PortList);
MSG_Port_Close (Private_Port, MSGD_DESTROY);
MSG_Library_Close (MSGD_CLOSE);
return KO;
}
/* Traitement du message */
switch (Msg->Type)
{
case LOGD_EVENT_MSG_TYPE:
/* Il s'agit d'un événement */
Event_Msg_Process (Msg);
Nb_Event ++;
break;
default:
/* Il s'agit d'un message système */
System_Msg_Process (Msg);
Nb_System_Msg ++;
break;
}
}
/* Suppression de la liste de ports de l'agent */
if (MSG_PortList_Close (Private_PortList) != MSGS_OK)
{
strcpy (Debug_Trace, "impossible de supprimer ma liste de ports");
Info_Trace ();
MSG_Port_Close (Private_Port, MSGD_DESTROY);
MSG_Library_Close (MSGD_CLOSE);
return KO;
}
/* Suppression du port privé de l'agent */
if (MSG_Port_Close (Private_Port, MSGD_DESTROY) != MSGS_OK)
{
strcpy (Debug_Trace, "impossible de supprimer mon port de messages privé");
Info_Trace ();
MSG_Library_Close (MSGD_CLOSE);
return KO;
}
/* Fermeture de la librairie */
if (MSG_Library_Close (MSGD_CLOSE) != MSGS_OK)
{
strcpy (Debug_Trace, "impossible de fermer la librairie LIBMSG");
Info_Trace ();
return KO;
}
strcpy (Debug_Trace, "terminé");
Info_Trace ();
return OK;
}
/*--------------------------------------------------------------------------------------------------*/
/* Récupération de la ligne de commande */
/*--------------------------------------------------------------------------------------------------*/
void Parse_Arg (int argc, char ** argv)
{
int i;
Debug = FALSE;
for (i = 1; i < argc; i++)
{
if (!strcmp (argv[i], "--help") || !strcmp (argv[i], "-h"))
{
fprintf (stderr, "Usage : %s [ [--help|-h] | --version [-v] | -id <id_agent> [--debug] ]\n", argv [0]);
exit (1);
}
if (!strcmp (argv[i], "-id"))
{
i++;
if (i == argc)
{
fprintf (stderr, "Argument manquant après \"%s\"\n", argv[i - 1]);
exit (0);
}
Num_Agent = atoi (argv[i]);
continue;
}
if (!strcmp (argv[i], "--version"))
{
if (i+1 < argc && !strcmp (argv[i+1], "-v"))
{
VER_Object_Print (stdout, VERD_VERBOSE);
exit (0);
}
else
{
VER_Object_Print (stdout, VERD_MINIMAL);
exit (0);
}
}
if (!strcmp (argv[i], "--debug"))
{
Debug = TRUE;
continue;
}
fprintf (stderr, "Option invalide \"%s\"\n", argv[i]);
exit (0);
}
if (Num_Agent == 0)
{
fprintf (stderr, "Option \"-id\" manquante ou bien valeur incorrecte (doit être > 0)\n");
exit (0);
}
}
/*--------------------------------------------------------------------------------------------------*/
/* Traitement d'un message contenant un événement */
/*--------------------------------------------------------------------------------------------------*/
void Event_Msg_Process (MSGT_Message * Msg)
{
LOGT_Event_Msg_Data * Msg_Data;
unsigned int Length, Event_Type;
char Event_Name [256];
char Cd_Support [256];
char Data_Name [256];
char Data_Value [256];
unsigned int i;
char * Event_Data_Ptr;
/* Récupération des données de l'entête de l'événement */
Msg_Data = (LOGT_Event_Msg_Data *)(Msg->Data);
/* Vérification de la version du format */
if (strcmp (Msg_Data->Header.Version, EVENT_FORMAT_VERSION))
{
sprintf (Debug_Trace, "version du format de message \"%s\" incorrect (\"%s\" attendu)", Msg_Data->Header.Version, EVENT_FORMAT_VERSION);
Info_Trace ();
/* Suppression du message */
MSG_Message_Free (Msg);
return;
}
sprintf (Debug_Trace, "réception d'un événement de la part du processus %d (module %d/%d)",
Msg_Data->Header.Sending_Pid,
Msg_Data->Header.ModuleId,
Msg_Data->Header.Master_ModuleId);
/* Récupération de l'identifiant du type d'événement */
Event_Type = Msg_Data->Event_Type;
/* Récupération du nom de l'événement */
Event_Data_Ptr = &(Msg_Data->Event_Data);
i = 0;
Length = (unsigned int)(Event_Data_Ptr [i]);
strncpy (Event_Name, Event_Data_Ptr + i + 1, Length);
Event_Name [Length] = (char)0;
i += 1 + Length;
if (Debug == TRUE) fprintf (stderr, "%s\nEvénement \"%s\" (type=%d):", Debug_Trace, Event_Name, Event_Type);
Length = (unsigned int)(Event_Data_Ptr [i]);
strncpy (Cd_Support, Event_Data_Ptr + i + 1, Length);
Cd_Support [Length] = (char)0;
if (Debug == TRUE) fprintf (stderr, "%s\n\t- support=\"%s\"\n", Debug_Trace, Cd_Support);
i += 1 + Length;
/* Récupération des macro-données */
while (i < Msg_Data->Data_Size)
{
/* Récupération du nom de la macro-donnée */
Length = (unsigned int)(Event_Data_Ptr [i]);
strncpy (Data_Name, Event_Data_Ptr + i + 1, Length);
Data_Name [Length] = (char)0;
i += 1 + Length;
if (i < Msg->Size)
{
/* Récupération de la valeur de la macro-donnée */
Length = (unsigned int)(Event_Data_Ptr [i]);
strncpy (Data_Value, Event_Data_Ptr + i + 1, Length);
Data_Value [Length] = (char)0;
i += 1 + Length;
}
else
{
strcpy (Debug_Trace, "mauvais format d'événement");
Info_Trace ();
}
if (Debug == TRUE) fprintf (stderr, "\t- %s=%s\n", Data_Name, Data_Value);
}
/* Traitement de l'événement
...
...
...
*/
/* Renvoi du message à l'envoyeur */
if (MSG_Message_Reply (Msg) != MSGS_OK)
{
strcpy (Debug_Trace, "impossible de renvoyer le message de l'événement à son envoyeur");
Info_Trace ();
}
}
/*--------------------------------------------------------------------------------------------------*/
/* Traitement d'un message système par un agent */
/*--------------------------------------------------------------------------------------------------*/
void System_Msg_Process (MSGT_Message * Msg)
{
/* Pour accuser réception du message système, on commence par remplir les données liées à l'agent */
((Agent_Stat *)(Msg->Data))->Num_Agent = Num_Agent;
((Agent_Stat *)(Msg->Data))->Pid = getpid ();
switch (Msg->Type)
{
case MSGD_SYSTEM_STOP_REQUEST:
if (Status == ACTIVE)
{
/* On indique que la requête a bien été prise en compte */
((Agent_Stat *)(Msg->Data))->Answer = TRUE;
/* Pause de l'agent jusqu'à réception d'un message MSGD_SYSTEM_CONTINUE_REQUEST */
Status = STOPPED;
strcpy (Debug_Trace, "pause");
Info_Trace ();
}
else
{
/* On indique que la requête n'a pas été prise en compte */
((Agent_Stat *)(Msg->Data))->Answer = FALSE;
}
break;
case MSGD_SYSTEM_CONTINUE_REQUEST:
if (Status == STOPPED)
{
/* On indique que la requête a bien été prise en compte */
((Agent_Stat *)(Msg->Data))->Answer = TRUE;
/* Reprise de l'agent */
Status = ACTIVE;
strcpy (Debug_Trace, "reprise");
Info_Trace ();
}
else
{
/* On indique que la requête n'a pas été prise en compte */
((Agent_Stat *)(Msg->Data))->Answer = FALSE;
}
break;
case MSGD_SYSTEM_SHUTDOWN_REQUEST:
/* Fin de la boucle principale de l'agent */
End_Agent = TRUE;
strcpy (Debug_Trace, "terminaison en cours...");
Info_Trace ();
break;
case MSGD_SYSTEM_STATUS_REQUEST:
/* On informe le superviseur sur l'état dans lequel on se trouve */
((Agent_Stat *)(Msg->Data))->Status = Status;
((Agent_Stat *)(Msg->Data))->Debug = Debug;
break;
case MSGD_SYSTEM_INFO_REQUEST:
/* On informe le superviseur sur le nombre de messages (système et événement) traités */
((Agent_Stat *)(Msg->Data))->Cpt_Event = Nb_Event;
((Agent_Stat *)(Msg->Data))->Cpt_System = Nb_System_Msg;
break;
case MSGD_SYSTEM_TRACEON_REQUEST:
Debug = TRUE;
strcpy (Debug_Trace, "activation du mode trace");
Info_Trace ();
break;
case MSGD_SYSTEM_TRACEOFF_REQUEST:
strcpy (Debug_Trace, "désactivation du mode trace");
Info_Trace ();
Debug = FALSE;
break;
default :
/* On indique que la requête n'a pas été prise en compte */
((Agent_Stat *)(Msg->Data))->Answer = FALSE;
break;
}
/* On accuse réception du message */
MSG_Message_Reply (Msg);
}
/*--------------------------------------------------------------------------------------------------*/
/* Affichage sur la sortie standard d'erreur d'un message généré par un agent */
/*--------------------------------------------------------------------------------------------------*/
void Info_Trace ( void )
{
time_t dts;
struct tm * dt;
char Current_Date [25];
if (Debug == TRUE)
{
/* Récupère la date courante */
time (&dts);
dt = localtime (&dts);
sprintf (Current_Date, "%02d/%02d/%04d %02d:%02d:%02d", dt->tm_mday, dt->tm_mon + 1, dt->tm_year + 1900, dt->tm_hour, dt->tm_min, dt->tm_sec);
fprintf (stderr, "[%s] Agent n°%d : %s\n", Current_Date, Num_Agent, Debug_Trace);
}
}

24
util/logagent.h Normal file
View File

@@ -0,0 +1,24 @@
#define ANSWER_SIZE 1000 /* Taille minimale des messages système adressés au superviseur */
#define DEFAULT_TIMEOUT 5 /* Nombre de secondes avant lesquelles les agents devront répondre aux requêtes du superviseur */
#define NB_MAX_AGENT 50 /* Nombre maximal d'agents pouvant être suivis par le superviseur */
/* Etats possibles d'un agent */
#define STOPPED 0
#define ACTIVE 1
#define OK 1
#define KO -1
/* Structure contenant les informations qu'un agent renvoie au superviseur */
typedef struct {
unsigned int Num_Agent; /* Numéro de l 'agent */
pid_t Pid; /* Identifiant du processus de l'agent */
unsigned int Status; /* Etat dans lequel se trouve l'agent */
unsigned int Debug; /* Mode debug dans lequel se trouve l'agent */
unsigned int Cpt_Event; /* Nombre d'événements traités */
unsigned int Cpt_System; /* Nombre de messages système traités */
unsigned int Answer; /* Réponse de l'agent à la requête */
} Agent_Stat;

150
util/logbench.c Normal file
View File

@@ -0,0 +1,150 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <sys/time.h>
#define LOG_MODE 1
#include <log.h>
#include <tool.h>
typedef struct {
double sec;
long count;
struct timeval start;
struct timeval stop;
} cpt;
#define t_init(x) {x.sec = 0; x.count = 0;}
#define t_start(x) {gettimeofday(&(x.start), NULL);}
#define t_stop(x) {gettimeofday(&(x.stop), NULL); x.sec += (double)(x.stop.tv_sec) - (double)(x.start.tv_sec) + ((double)(x.stop.tv_usec) - (double)(x.start.tv_usec)) / 1000000; x.count++;}
int main (int argc, char ** argv)
{
LOGT_Channel * My_Channel;
char Line [1000], * Event_Data;
FILE * fid;
unsigned int Nb_Send, Line_Number, i;
cpt Compteur;
if (argc != 2)
{
fprintf (stderr, "Usage : %s <event_list>\n", argv [0]);
return -1;
}
/* Ouverture du fichier de test */
fid = fopen (argv [1], "r");
if (!fid)
{
fprintf (stderr, "Unable to open file \"%s\" for reading\n", argv [1]);
return -1;
}
/* Ouverture de la librairie */
if (LOG_Library_Open (0, NULL, LOGD_OPEN | LOGD_DEBUG_ALL) != LOGS_OK)
{
fprintf (stderr, "\n=> Impossible d'ouvrir la librairie LIBLOG\n");
return -1;
}
/* Ouverture d'un channel */
if (LOG_Channel_Open (&My_Channel, 0, 1, "IPR_CAVpopulate2.pc", "IPR_CAV") != LOGS_OK)
{
fprintf (stderr, "\n=> Impossible d'ouvrir un channel\n");
return -1;
}
/* Ajout des tables de routage utilisateur */
if (TL_Channel_RTab_Add (My_Channel, "UTILS:ROOTING:ROOTING_TABLE") != TLS_OK)
{
fprintf (stderr, "\n=> Impossible d'ajouter les tables de routage au channel\n");
LOG_Channel_Close (My_Channel);
return -1;
}
/* Ajout des triggers */
if (TL_Channel_Trigger_Add (My_Channel, "UTILS:ROOTING:TRIGGER") != TLS_OK)
{
fprintf (stderr, "\n=> Impossible d'ajouter les triggers au channel\n");
LOG_Channel_Close (My_Channel);
return -1;
}
/* Initialisation du compteur */
t_init (Compteur);
/* Envoi des événements paramétrés dans le fichier */
Line_Number = 1;
while (!feof (fid) && fgets (Line, 1000, fid))
{
/* Récupération des informations dans la ligne du fichier */
Event_Data = strchr (Line, '#');
if (Event_Data == NULL)
{
fprintf (stderr, "Warning ligne n°%d : format incorrect (caractère '#' manquant)\n", Line_Number);
}
else
{
*Event_Data = (char)0;
Nb_Send = atoi (Line);
if (Nb_Send <= 0)
{
fprintf (stderr, "Warning ligne n°%d : valeur (%d) incorrecte avant le caracatère '#'\n", Line_Number, Nb_Send);
Nb_Send = 1;
}
Event_Data++;
for (i = 0; i < Nb_Send; i++)
{
t_start (Compteur);
/* Envoi de l'événement proprement dit */
if (LOG_Event_External_Send (My_Channel, argv [1], Event_Data) == LOGD_RC_WARNING)
fprintf (stderr, "Warning ligne n°%d : code retour WARNING sur envoi de l'événement\n", Line_Number);
t_stop (Compteur);
}
}
Line_Number++;
}
fclose (fid);
/* Affichage du résultat du benchmark */
fprintf (stdout, "%ld événements envoyés en %.2f sec (%.2f évt/sec)\n", Compteur.count, Compteur.sec, Compteur.count / Compteur.sec);
/* Fermeture du channel */
if (LOG_Channel_Close (My_Channel) != LOGS_OK)
{
fprintf (stderr, "\n=> Impossible de fermer le channel\n");
return -1;
}
/* Fermeture de la librairie */
if (LOG_Library_Close (LOGD_CLOSE) != LOGS_OK)
{
fprintf (stderr, "\n=> Impossible de fermer la librairie LIBLOG\n");
return -1;
}
return 1;
}

187
util/logresolve.c Normal file
View File

@@ -0,0 +1,187 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <stdarg.h>
#include <ver.h>
#define ND_MODE 1
#include <node.h>
#define LOG_MODE 1
#include <log.h>
VER_INFO_EXPORT (logresolve, "$Revision: 1.1 $", "$Name: $", __FILE__, "$Author: smas $")
typedef struct {
double sec;
struct timeval start;
struct timeval stop;
} cpt;
#define t_start(x){gettimeofday (&(x.start), NULL);}
#define t_stop(x){gettimeofday (&(x.stop), NULL); x.sec = (double)(x.stop.tv_sec) - (double)(x.start.tv_sec) + \
((double)(x.stop.tv_usec) - (double)(x.start.tv_usec)) / 1000000;}
cpt t_exec;
char * Get_Rooting (LOGT_Rooting);
char * Get_RC (LOGT_RC);
#define USAGE "Usage : %s [ --help | --version [-v] | --event <event name> ]\n"
int main (int argc, char **argv)
{
LOGT_Info * Info;
char * Event;
int i;
if (argc >= 2)
{
if (!strcmp (argv [1], "--help"))
{
fprintf (stderr, USAGE, argv [0]);
return 1;
}
else if (!strcmp (argv [1], "--version"))
{
if (argc >= 3 && !strcmp (argv [2], "-v"))
return VER_Object_Print (stdout, VERD_VERBOSE);
else
return VER_Object_Print (stdout, VERD_MINIMAL);
}
else if (!strcmp (argv [1], "--event"))
{
if (argc != 3)
{
fprintf (stderr, USAGE, argv [0]);
return 0;
}
Event = argv [2];
}
else
{
fprintf (stderr, USAGE, argv [0]);
return 0;
}
}
else
{
fprintf (stderr, USAGE, argv [0]);
return 0;
}
/* Récupération des informations sur un événement */
Info = (LOGT_Info *) malloc (sizeof (LOGT_Info));
if (LOG_Library_Open (0, NULL, LOGD_OPEN | LOGD_DEBUG_ALL) != LOGS_OK)
{
fprintf (stderr, "=> Ouverture de la librairie LIBLOG impossible\n");
return 0;
}
t_start (t_exec);
if (LOG_Event_Info_Get (NULL, &Info, Event) != LOGS_OK)
{
t_stop (t_exec);
fprintf (stderr, "=> Impossible de résoudre l'événement \"%s\"\n", Event);
}
else
{
NDT_Node * Node;
t_stop (t_exec);
fprintf (stdout, "\nEvénement \"%s\" résolu en %.4f sec :\n", Event, t_exec.sec);
fprintf (stdout, "\t- Type : %s (Id=%d)\n", Info->Event_Name, Info->Event_Type);
fprintf (stdout, "\t- Routage : %s\n", Get_Rooting (Info->Rooting));
fprintf (stdout, "\t- Gravité : %c\n", (char)Info->Gravite);
fprintf (stdout, "\t- Code retour : %s\n", Get_RC (Info->RC));
fprintf (stdout, "\t- Format :");
if (Info->Data_List)
{
ND_Node_First_Get (Info->Data_List, &Node);
i = 0;
while (Node)
{
if (i > 0) fprintf (stdout, ",");
fprintf (stdout, " %s", (char *)(Node->Value));
ND_Node_Next_Get (Node, &Node);
i++;
}
}
fprintf (stdout, "\n\n");
}
LOG_Library_Close (LOGD_CLOSE);
free (Info);
return 0;
}
char * Get_Rooting (LOGT_Rooting Rooting)
{
static char lib [20];
switch ((int)Rooting)
{
case LOGD_ROOTING_NULL:
strcpy (lib, "NULL");
break;
case LOGD_ROOTING_STDERR:
strcpy (lib, "STDERR");
break;
case LOGD_ROOTING_DATABASE:
strcpy (lib, "BASE");
break;
case LOGD_ROOTING_DEFAULT:
strcpy (lib, "DEFAULT");
break;
case LOGD_ROOTING_PREVIOUS:
strcpy (lib, "PREVIOUS");
break;
default:
strcpy (lib, "unknown");
break;
}
return lib;
}
char * Get_RC (LOGT_RC RC)
{
static char lib [20];
switch ((int)RC)
{
case LOGD_RC_OK:
strcpy (lib, "OK");
break;
case LOGD_RC_ANOERR:
strcpy (lib, "ANOERR");
break;
case LOGD_RC_REJDON:
strcpy (lib, "REJDON");
break;
case LOGD_RC_REJENR:
strcpy (lib, "REJENR");
break;
case LOGD_RC_WARNING:
strcpy (lib, "WARNING");
break;
case LOGD_RC_RECYCLE:
strcpy (lib, "RECYCLE");
break;
case LOGD_RC_EXIT:
strcpy (lib, "EXIT");
break;
case LOGD_RC_ABEND:
strcpy (lib, "ABEND");
break;
default:
strcpy (lib, "unknown");
break;
}
return lib;
}

1246
util/logsupervisor.c Normal file

File diff suppressed because it is too large Load Diff