diff --git a/include/shmem.h b/include/shmem.h index 4e853a2..35af4a7 100644 --- a/include/shmem.h +++ b/include/shmem.h @@ -310,6 +310,7 @@ typedef struct { /* (I) Context : nom du nouveau contexte */ /* (I) Flags : indicateur création/ouverture + mode d'affichage des erreurs */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Library_Open_I ( int Instance, const char * Context, SMT_Flags Flags ); SMD_API SMT_Status SM_Library_Open_C ( int Instance, const char * Context, SMT_Flags Flags ); @@ -320,6 +321,7 @@ SMD_API SMT_Status SM_Library_Open_C ( int Instance, const char * Context, SMT_ /*------------------------------------------------------------------------------*/ /* (O) Instance : adresse du numéro de l'instance utilisée */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Library_Instance_Get_I ( int * Instance); SMD_API SMT_Status SM_Library_Instance_Get_C ( int * Instance); @@ -330,6 +332,7 @@ SMD_API SMT_Status SM_Library_Instance_Get_C ( int * Instance); /*------------------------------------------------------------------------------*/ /* (I) Context : nom du nouveau contexte */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Library_Context_Set_I ( const char * Context ); SMD_API SMT_Status SM_Library_Context_Set_C ( const char * Context ); @@ -340,6 +343,7 @@ SMD_API SMT_Status SM_Library_Context_Set_C ( const char * Context ); /*------------------------------------------------------------------------------*/ /* (O) Context : adresse du nom du contexte utilisé */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Library_Context_Get_I ( char ** Context ); SMD_API SMT_Status SM_Library_Context_Get_C ( char ** Context ); @@ -350,6 +354,7 @@ SMD_API SMT_Status SM_Library_Context_Get_C ( char ** Context ); /*------------------------------------------------------------------------------*/ /* (I) Flags : mode de fermeture (destruction ou fermeture simple) */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Library_Close_I ( SMT_Flags Flags ); SMD_API SMT_Status SM_Library_Close_C ( SMT_Flags Flags ); @@ -360,6 +365,7 @@ SMD_API SMT_Status SM_Library_Close_C ( SMT_Flags Flags ); /*------------------------------------------------------------------------------*/ /* (I) Out : pointeur sur le flux de sortie */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Library_Dump_I ( FILE * Out ); SMD_API SMT_Status SM_Library_Dump_C ( FILE * Out ); @@ -368,6 +374,7 @@ SMD_API SMT_Status SM_Library_Dump_C ( FILE * Out ); /*------------------------------------------------------------------------------*/ /* Libération de tous les verrous (base, heap) */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Library_Unlock_I ( void ); SMD_API SMT_Status SM_Library_Unlock_C ( void ); @@ -376,6 +383,7 @@ SMD_API SMT_Status SM_Library_Unlock_C ( void ); /*------------------------------------------------------------------------------*/ /* Définition de la sortie standard des messages d'erreur de la librairie */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Library_Stderr_Set_I ( FILE * Out ); SMD_API SMT_Status SM_Library_Stderr_Set_C ( FILE * Out ); @@ -386,6 +394,7 @@ SMD_API SMT_Status SM_Library_Stderr_Set_C ( FILE * Out ); /*------------------------------------------------------------------------------*/ /* (I) Heap_Name : nom du heap */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Heap_Exist_I ( const char * Heap_Name ); SMD_API SMT_Status SM_Heap_Exist_C ( const char * Heap_Name ); @@ -400,6 +409,7 @@ SMD_API SMT_Status SM_Heap_Exist_C ( const char * Heap_Name ); /* (I) Flags : mode d'ouverture du heap */ /* (O) Locked : verrou effectif (TRUE ou FALSE) */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Heap_Open_I ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg_Size, SMT_Flags Flags, int * Locked ); SMD_API SMT_Status SM_Heap_Open_C ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg_Size, SMT_Flags Flags, int * Locked ); @@ -411,6 +421,7 @@ SMD_API SMT_Status SM_Heap_Open_C ( const char * Heap_Name, SMT_Heap ** Heap, s /* (I) Heap_Name : nom du heap */ /* (O) Heap : adresse du pointeur sur le heap ouvert */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Heap_IsOpen_I ( const char * Heap_Name, SMT_Heap ** Heap ); SMD_API SMT_Status SM_Heap_IsOpen_C ( const char * Heap_Name, SMT_Heap ** Heap ); @@ -421,6 +432,7 @@ SMD_API SMT_Status SM_Heap_IsOpen_C ( const char * Heap_Name, SMT_Heap ** Heap /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur un heap ouvert */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap ); SMD_API SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap ); @@ -431,6 +443,7 @@ SMD_API SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap ); /*------------------------------------------------------------------------------*/ /* (I) Heap_Name : nom du heap */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Heap_End_I ( const char * Heap_Name ); SMD_API SMT_Status SM_Heap_End_C ( const char * Heap_Name ); @@ -442,6 +455,7 @@ SMD_API SMT_Status SM_Heap_End_C ( const char * Heap_Name ); /* (I) Heap : pointeur sur un heap ouvert */ /* (O) Compress : pointeur sur la taille mémoire gagnée */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Heap_Compress_I ( SMT_Heap * Heap, size_t * Compress ); SMD_API SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress ); @@ -453,6 +467,7 @@ SMD_API SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress ); /* (I) Heap : pointeur sur un heap ouvert */ /* (I) Tag : type de configuration */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Heap_Config_I ( SMT_Heap * Heap, SMT_Config Tag, ... ); SMD_API SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ); @@ -466,6 +481,7 @@ SMD_API SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ); /* (O) Nb_Corrected : pointeur sur le nombre d'erreurs corrigées */ /* (I) Out : pointeur sur le flux de sortie du rapport */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Corrected, FILE * Out); SMD_API SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Corrected, FILE * Out); @@ -478,6 +494,7 @@ SMD_API SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap, int * Nb_Detected, int * /* (I) Flags : mode de verrouillage (SMD_READ ou SMD_WRITE) */ /* (O) Locked : verrouillage effectué (TRUE ou FALSE) */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Flags, int * Locked ); SMD_API SMT_Status SM_Heap_Lock_C ( SMT_Heap * Heap, SMT_Flags Flags, int * Locked ); @@ -488,6 +505,7 @@ SMD_API SMT_Status SM_Heap_Lock_C ( SMT_Heap * Heap, SMT_Flags Flags, int * Loc /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur un heap ouvert */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Heap_Unlock_I ( SMT_Heap * Heap ); SMD_API SMT_Status SM_Heap_Unlock_C ( SMT_Heap * Heap ); @@ -500,6 +518,7 @@ SMD_API SMT_Status SM_Heap_Unlock_C ( SMT_Heap * Heap ); /* (I) Size : taille du chunk */ /* (O) Ptr : pointeur sur la zone de données allouée */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ); SMD_API SMT_Status SM_Chunk_Alloc_C ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ); @@ -511,6 +530,7 @@ SMD_API SMT_Status SM_Chunk_Alloc_C ( SMT_Heap * Heap, size_t Alloc_Size, void /* (I) Heap : pointeur sur un heap ouvert */ /* (I) Ptr : adresse de la zone de données du chunk à désallouer */ /*------------------------------------------------------------------------------*/ + SMD_API SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr ); SMD_API SMT_Status SM_Chunk_Free_C ( SMT_Heap * Heap, void * Ptr ); diff --git a/lib/libshmem.c b/lib/libshmem.c index 2e28cfc..a5b9d0d 100644 --- a/lib/libshmem.c +++ b/lib/libshmem.c @@ -77,7 +77,7 @@ SMT_Status SM_Library_Open_I( int Instance, const char *Context, SMT_Flags O if( SMD_DEBUG_MSK( Open_Mode)) SM_stderr = stderr; if( Open_Mode & SMD_DEBUG_ALL) ND_Debug = TRUE; - if( ( lg_status = LG_Library_Open( LGD_LOG_WRITER_DEFAULT, true)) != LGS_OK) + if( ( lg_status = LG_Library_Open( LGD_LOG_WRITER_DEFAULT, false)) != LGS_OK) { fprintf( stderr, "Can't open LibLog library: (%d)\n", lg_status); return( -1); @@ -90,7 +90,7 @@ SMT_Status SM_Library_Open_I( int Instance, const char *Context, SMT_Flags O if( Instance) To_Open_Instance = Instance; else { - if( !getenv( INSTANCE_ENV_VAR) || ( To_Open_Instance = atoi ( getenv( INSTANCE_ENV_VAR))) <= 0) + if( !getenv( INSTANCE_ENV_VAR) || ( To_Open_Instance = atoi( getenv( INSTANCE_ENV_VAR))) <= 0) { To_Open_Instance = DEFAULT_INSTANCE; } @@ -102,8 +102,8 @@ SMT_Status SM_Library_Open_I( int Instance, const char *Context, SMT_Flags O if( SM_Open_Counter > 0) { - sprintf( SM_Error_Msg, "SM_Library_Open : the current process has already opened an instance (%d) of the LIBSHMEM base", SM_Instance); - SM_Error_Print(); + LG_LOG_ERROR_1( "SM_Library_Open : the current process has already opened an instance: (%d) of the LIBSHMEM base", SM_Instance); + return( SMS_ERRAPI); } @@ -112,8 +112,8 @@ SMT_Status SM_Library_Open_I( int Instance, const char *Context, SMT_Flags O rc = ND_Library_Open( ND_Debug); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Library_Open : unable to open the LIBNODE library"); - SM_Error_Print(); + LG_LOG_ERROR_0( "SM_Library_Open : unable to open the LIBNODE library"); + return( rc); } @@ -122,8 +122,8 @@ SMT_Status SM_Library_Open_I( int Instance, const char *Context, SMT_Flags O rc = ND_DataStruct_Open( &Opened_Heap_List, 1, &index_type, "SM_Opened_Heap_List_Manager", NULL, NULL, NULL, NULL, NULL, TRUE, NULL); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Library_Open : unable to create the local opened heap cache"); - SM_Error_Print(); + LG_LOG_ERROR_0( "SM_Library_Open : unable to create the local opened heap cache"); + goto Error1; } @@ -134,8 +134,8 @@ SMT_Status SM_Library_Open_I( int Instance, const char *Context, SMT_Flags O rc = SM_Base_Init(); if( rc != SMS_OK ) { - sprintf( SM_Error_Msg, "SM_Library_Open : unable to initialize the shared memory base"); - SM_Error_Print(); + LG_LOG_ERROR_0( "SM_Library_Open : unable to initialize the shared memory base"); + goto Error2; } } @@ -145,8 +145,8 @@ SMT_Status SM_Library_Open_I( int Instance, const char *Context, SMT_Flags O if( SM_Open_Counter > 0 && To_Open_Instance != SM_Instance) { - sprintf( SM_Error_Msg, "SM_Library_Open : the current process cannot open instance %d because it is already accessing instance %d", To_Open_Instance, SM_Instance); - SM_Error_Print(); + LG_LOG_ERROR_2( "SM_Library_Open : the current process cannot open instance: (%d) because it is already accessing instance: (%d)", To_Open_Instance, SM_Instance); + return( SMS_ERRAPI); } @@ -161,8 +161,8 @@ SMT_Status SM_Library_Open_I( int Instance, const char *Context, SMT_Flags O rc = ND_Library_Open( ND_Debug); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Library_Open : unable to open the LIBNODE library"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to open the LIBNODE library"); + return( rc); } @@ -171,8 +171,8 @@ SMT_Status SM_Library_Open_I( int Instance, const char *Context, SMT_Flags O rc = ND_DataStruct_Open( &Opened_Heap_List, 1, &index_type, "SM_Opened_Heap_List_Manager", NULL, NULL, NULL, NULL, NULL, TRUE, NULL); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Library_Open : unable to create the local opened heap cache"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to create the local opened heap cache"); + goto Error1; } @@ -181,8 +181,8 @@ SMT_Status SM_Library_Open_I( int Instance, const char *Context, SMT_Flags O rc = SM_Base_Open(); if( rc != SMS_OK ) { - sprintf( SM_Error_Msg, "SM_Library_Open : unable to open the shared memory base"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to open the shared memory base"); + goto Error2; } } @@ -261,9 +261,9 @@ SMT_Status SM_Library_Context_Set_I( const char *Context ) } else { - if( getenv( CONTEXT_ENV_VAR) && strlen ( getenv( CONTEXT_ENV_VAR))) + if( getenv( CONTEXT_ENV_VAR) && strlen( getenv( CONTEXT_ENV_VAR))) { - SM_Context = strdup( getenv (CONTEXT_ENV_VAR)); + SM_Context = strdup( getenv( CONTEXT_ENV_VAR)); } else { @@ -297,8 +297,8 @@ SMT_Status SM_Library_Close_I( SMT_Flags Close_Mode) rc = SM_Base_End(); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Library_Close: unable to destroy the shared memory base"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to destroy the shared memory base"); + return( rc); } @@ -334,8 +334,8 @@ SMT_Status SM_Library_Close_I( SMT_Flags Close_Mode) rc = SM_Base_Close(); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Library_Close : unable to close the shared memory base"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to close the shared memory base"); + return( rc); } @@ -359,7 +359,7 @@ SMT_Status SM_Library_Close_I( SMT_Flags Close_Mode) SM_Open_Counter--; } - if( ( lg_status = LG_Library_Close( true)) != LGS_OK) + if( ( lg_status = LG_Library_Close( false)) != LGS_OK) { fprintf( stderr, "Can't close LibLog library: (%d)\n", lg_status); return( SMS_KO); @@ -421,8 +421,7 @@ SMT_Status SM_Library_Unlock_I( void) if( semctl( SM_Base->SemId, 0, SETVAL, Sem_Ctl)) { - sprintf( SM_Error_Msg, "SM_Library_Free : unable to unlock the shared memory base"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to unlock the shared memory base"); return( SMS_ERRSEM); } @@ -439,8 +438,8 @@ SMT_Status SM_Library_Unlock_I( void) if( semctl( MHH->SemId, 0, SETVAL, Sem_Ctl)) { - sprintf( SM_Error_Msg, "SM_Library_Free : unable to unlock heap \"%s\"", MHH->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to unlock heap: [%s]", MHH->Name); + return( SMS_ERRSEM); } @@ -466,7 +465,7 @@ SMT_Status SM_Library_Unlock_I( void) /* Définition de la sortie standard des messages d'erreur de la librairie */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Stderr_Set_I ( FILE *Out) +SMT_Status SM_Library_Stderr_Set_I( FILE *Out) { SM_stderr = Out; @@ -483,7 +482,7 @@ SMT_Status SM_Library_Stderr_Set_I ( FILE *Out) /* (I) Heap_Name : Nom du heap */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Exist_I ( const char *Heap_Name) +SMT_Status SM_Heap_Exist_I( const char *Heap_Name) { NDT_Node *Node; SMT_MHH *MHH; @@ -533,17 +532,17 @@ SMT_Status SM_Heap_Exist_I ( const char *Heap_Name) /*------------------------------------------------------------------------------*/ /* Ouverture/création d'un heap */ /*------------------------------------------------------------------------------*/ -/* (I) Heap_Name : nom du heap */ -/* (O) Heap : pointeur sur le heap ouvert / créé */ -/* (I) Seg_Size : taille des segments du heap */ -/* (I) Open_Mode : mode d'ouverture du heap */ -/* (O) Locked : verrou effectif (TRUE ou FALSE) */ +/* (I) Heap_Name: nom du heap */ +/* (O) Heap_Ptr_Ptr: pointeur sur le heap ouvert / créé */ +/* (I) Seg_Size: taille des segments du heap */ +/* (I) Open_Mode: mode d'ouverture du heap */ +/* (O) Locked: verrou effectif (TRUE ou FALSE) */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Seg_Size, SMT_Flags Open_Mode, int *Locked) +SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap_Ptr_Ptr, size_t Seg_Size, SMT_Flags Open_Mode, int *Locked) { SMT_MHH *MHH; - NDT_Node *Node; + NDT_Node *Node_Ptr; SMT_DSH *New_DSH; char prefixed_name[ SMD_NAME_SIZE]; union semun Sem_Ctl; @@ -556,18 +555,17 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se /* On regarde si le heap est déjà ouvert par le processus courant */ - if( SM_Heap_IsOpen_I( Heap_Name, Heap) == SMS_YES) + if( SM_Heap_IsOpen_I( Heap_Name, Heap_Ptr_Ptr) == SMS_YES) { if( Open_Mode & SMD_OPEN) { /* Verrouillage du heap dans le mode demandé */ - rc = SM_Heap_Lock_I( *Heap, SMD_LOCK_MSK( Open_Mode), Locked); + rc = SM_Heap_Lock_I( *Heap_Ptr_Ptr, SMD_LOCK_MSK( Open_Mode), Locked); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to lock heap \"%s\" for %s", Heap_Name, Open_Mode & SMD_READ ? "reading" : "writing"); - SM_Error_Print(); - + LG_LOG_ERROR_2( "Unable to lock heap: [%s] for: [%s]", Heap_Name, Open_Mode & SMD_READ ? "reading" : "writing"); + return( rc); } @@ -575,8 +573,7 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se } else { - sprintf( SM_Error_Msg, "SM_Heap_Open : the heap already exists but (Flags & SMD_OPEN) is false"); - SM_Error_Print(); + LG_LOG_ERROR_0( "The heap already exists but (Flags & SMD_OPEN) is false"); return( SMS_ERRAPI); } @@ -598,64 +595,60 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se /* Ouverture d'un heap existant */ strcpy( To_Find.Name, prefixed_name); - ND_Index_Node_Find( &Node, SM_Base->MHR, NDD_INDEX_PRIMARY, &To_Find, NULL); + ND_Index_Node_Find( &Node_Ptr, SM_Base->MHR, NDD_INDEX_PRIMARY, &To_Find, NULL); - MHH = (SMT_MHH *)( Node->Value); + MHH = (SMT_MHH *)( Node_Ptr->Value); - *Heap = (SMT_Heap *) malloc( sizeof( SMT_Heap)); - if( !*Heap) + *Heap_Ptr_Ptr = (SMT_Heap *) malloc( sizeof( SMT_Heap)); + if( !*Heap_Ptr_Ptr) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to allocate memory for the opened heap \"%s\"", prefixed_name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to allocate memory for the opened heap: [%s]", prefixed_name); return( SMS_ERRMEM); } - ( *Heap)->Name = strdup( prefixed_name); - ( *Heap)->MHH = MHH; - ( *Heap)->Lock_Mode = SMD_NO_LOCK; + ( *Heap_Ptr_Ptr)->Name = strdup( prefixed_name); + ( *Heap_Ptr_Ptr)->MHH = MHH; + ( *Heap_Ptr_Ptr)->Lock_Mode = SMD_NO_LOCK; /* On ouvre tous les segments du heap */ - ND_Index_Node_First_Get( &Node, ( *Heap)->MHH->DSR, NDD_INDEX_PRIMARY); + ND_Index_Node_First_Get( &Node_Ptr, ( *Heap_Ptr_Ptr)->MHH->DSR, NDD_INDEX_PRIMARY); - while( Node) + while( Node_Ptr) { - rc = SM_DataSegment_Open( Node->Value); + rc = SM_DataSegment_Open( Node_Ptr->Value); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to open one of the data segments of heap \"%s\"", prefixed_name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to open one of the data segments of heap: [%s]", prefixed_name); goto Error1; } - ND_Index_Node_Next_Get( &Node, Node); + ND_Index_Node_Next_Get( &Node_Ptr, Node_Ptr); } - (*Heap)->Nb_Seg = (*Heap)->MHH->DSR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; + ( *Heap_Ptr_Ptr)->Nb_Seg = ( *Heap_Ptr_Ptr)->MHH->DSR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; /* Verrouillage du heap dans le mode demandé */ - rc = SM_Heap_Lock_I( *Heap, SMD_LOCK_MSK( Open_Mode), Locked); + rc = SM_Heap_Lock_I( *Heap_Ptr_Ptr, SMD_LOCK_MSK( Open_Mode), Locked); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to lock heap \"%s\" for %s", prefixed_name, Open_Mode & SMD_READ ? "reading" : "writing"); - SM_Error_Print(); + LG_LOG_ERROR_2( "Unable to lock heap: [%s] for: [%s]", prefixed_name, Open_Mode & SMD_READ ? "reading" : "writing"); goto Error1; } /* Ajout au cache des heaps ouverts */ - rc = ND_DataStruct_Value_Add (Opened_Heap_List, *Heap); + rc = ND_DataStruct_Value_Add (Opened_Heap_List, *Heap_Ptr_Ptr); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to add heap \"%s\" to the opened heap cache", prefixed_name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to add heap: [%s] to the opened heap cache", prefixed_name); goto Error2; } @@ -664,8 +657,7 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se } else { - sprintf( SM_Error_Msg, "SM_Heap_Open : the heap already exists but (Open_Mode & SMD_OPEN) is false"); - SM_Error_Print(); + LG_LOG_ERROR_0( "The heap already exists but (Open_Mode & SMD_OPEN) is false"); return( SMS_ERRAPI); } @@ -674,8 +666,7 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se if( !( Open_Mode & SMD_CREATE)) { - sprintf( SM_Error_Msg, "SM_Heap_Open : the heap \"%s\" does no exist and (Open_Mode & SMD_CREATE) is false", prefixed_name); - SM_Error_Print(); + LG_LOG_ERROR_1( "The heap: [%s] does no exist and (Open_Mode & SMD_CREATE) is false", prefixed_name); return( SMS_ERRAPI); } @@ -685,8 +676,8 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se rc = ND_Value_Alloc( (void **)&MHH, SM_Base->MHR, prefixed_name, Seg_Size); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to alloc a new MHH structure"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to alloc a new MHH structure"); + return(SMS_ERRAPI); } @@ -695,8 +686,8 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se rc = ND_DataStruct_Value_Add( SM_Base->MHR, MHH); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to add the new heap to the MHR structure"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to add the new heap to the MHR structure"); + goto Error9; } @@ -705,9 +696,8 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se rc = SM_Heap_Lock_Set( MHH, SMD_LOCK_MSK( Open_Mode)); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to lock heap \"%s\" for %s", - prefixed_name, Open_Mode & SMD_READ ? "reading" : "writing"); - SM_Error_Print(); + LG_LOG_ERROR_2( "Unable to lock heap: [%s] for: [%s]", prefixed_name, Open_Mode & SMD_READ ? "reading" : "writing"); + goto Error10; } @@ -715,26 +705,25 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se /* Ajout du nouveau heap au cache des heaps ouverts */ - *Heap = (SMT_Heap *)malloc( sizeof( SMT_Heap)); - if( !*Heap) + *Heap_Ptr_Ptr = (SMT_Heap *)malloc( sizeof( SMT_Heap)); + if( !*Heap_Ptr_Ptr) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to allocate memory for a new opened heap \"%s\"", prefixed_name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to allocate memory for a new opened heap: [%s]", prefixed_name); + rc = SMS_ERRMEM; goto Error10; } - ( *Heap)->Name = strdup( prefixed_name); - ( *Heap)->MHH = MHH; - ( *Heap)->Lock_Mode = SMD_LOCK_MSK( Open_Mode); - ( *Heap)->Nb_Seg = 1; + ( *Heap_Ptr_Ptr)->Name = strdup( prefixed_name); + ( *Heap_Ptr_Ptr)->MHH = MHH; + ( *Heap_Ptr_Ptr)->Lock_Mode = SMD_LOCK_MSK( Open_Mode); + ( *Heap_Ptr_Ptr)->Nb_Seg = 1; - rc = ND_DataStruct_Value_Add( Opened_Heap_List, *Heap); + rc = ND_DataStruct_Value_Add( Opened_Heap_List, *Heap_Ptr_Ptr); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to add heap \"%s\" to the opened heap cache", prefixed_name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to add heap: [%s] to the opened heap cache", prefixed_name); goto Error11; } @@ -746,10 +735,10 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se /* Gestion d'erreur sur création */ Error11: - free( ( *Heap)->Name); - free( *Heap); + free( ( *Heap_Ptr_Ptr)->Name); + free( *Heap_Ptr_Ptr); - *Heap = NULL; + *Heap_Ptr_Ptr = NULL; Error10: ND_DataStruct_Value_Remove( SM_Base->MHR, MHH); @@ -780,13 +769,13 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se /* Gestion d'erreur sur ouverture */ Error2: - SM_Heap_Unlock_I( *Heap); + SM_Heap_Unlock_I( *Heap_Ptr_Ptr); Error1: - free( (*Heap)->Name); - free( *Heap); + free( ( *Heap_Ptr_Ptr)->Name); + free( *Heap_Ptr_Ptr); - *Heap = NULL; + *Heap_Ptr_Ptr = NULL; return( rc); } @@ -798,11 +787,11 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se /*------------------------------------------------------------------------------*/ /* Teste si un heap a déjà été ouvert par le processus courant */ /*------------------------------------------------------------------------------*/ -/* (I) Heap_Name : Nom du heap */ -/* (O) Heap : pointeur sur le heap ouvert */ +/* (I) Heap_Name: Nom du heap */ +/* (O) Heap_Ptr_Ptr: pointeur sur le heap ouvert */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_IsOpen_I( const char *Heap_Name, SMT_Heap **Heap ) +SMT_Status SM_Heap_IsOpen_I( const char *Heap_Name, SMT_Heap **Heap_Ptr_Ptr) { SMT_Status rc; char prefixed_name[ SMD_NAME_SIZE]; @@ -810,7 +799,7 @@ SMT_Status SM_Heap_IsOpen_I( const char *Heap_Name, SMT_Heap **Heap ) NDT_Node *Node_Ptr; - *Heap = NULL; + *Heap_Ptr_Ptr = NULL; To_Find.Name = prefixed_name; SM_Name_Prefix( prefixed_name, Heap_Name); @@ -825,12 +814,14 @@ SMT_Status SM_Heap_IsOpen_I( const char *Heap_Name, SMT_Heap **Heap ) { if( Node_Ptr == NULL) { - *Heap = NULL; + *Heap_Ptr_Ptr = NULL; + return( SMS_NO); } else { - *Heap = (SMT_Heap *)( Node_Ptr->Value); + *Heap_Ptr_Ptr = (SMT_Heap *)( Node_Ptr->Value); + return( SMS_YES); } } @@ -846,42 +837,40 @@ SMT_Status SM_Heap_IsOpen_I( const char *Heap_Name, SMT_Heap **Heap ) /* (I) Heap : pointeur sur un heap ouvert */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_End_I ( const char * Heap_Name ) +SMT_Status SM_Heap_End_I( const char *Heap_Name ) { SMT_Status rc; SMT_Heap * Heap; int Locked; - rc = SM_Heap_Exist_I (Heap_Name); + rc = SM_Heap_Exist_I( Heap_Name); if( SM_ERROR(rc)) return rc; if( rc == SMS_NO) { - sprintf( SM_Error_Msg, "SM_Heap_End: heap \"%s\" does not exist", Heap_Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "SM_Heap_End: heap: [%s] does not exist", Heap_Name); return SMS_KO; } - rc = SM_Heap_IsOpen_I (Heap_Name, &Heap); + rc = SM_Heap_IsOpen_I( Heap_Name, &Heap); if( SM_ERROR(rc)) return rc; if( rc == SMS_YES) { /* Verrouillage en écriture */ - rc = SM_Heap_Lock_I (Heap, SMD_WRITE, &Locked); + rc = SM_Heap_Lock_I( Heap, SMD_WRITE, &Locked); } else { /* Ouverture du heap en écriture */ - rc = SM_Heap_Open_I (Heap_Name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked); + rc = SM_Heap_Open_I( Heap_Name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_End : unable to open the heap to remove for writing"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to open the heap to remove for writing"); - return rc; + return( rc); } } @@ -890,22 +879,21 @@ SMT_Status SM_Heap_End_I ( const char * Heap_Name ) rc = ND_DataStruct_Value_Remove( SM_Base->MHR, Heap->MHH); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_End: unable to remove heap \"%s\" from the MHR structure", Heap_Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to remove heap: [%s] from the MHR structure", Heap_Name); - return rc; + return( rc); } rc = ND_Value_Free( SM_Base->MHR, Heap->MHH); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_End: unable to free heap \"%s\"", Heap_Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "SM_Heap_End: unable to free heap: [%s]", Heap_Name); + - return rc; + return( rc); } - return SMS_OK; + return( SMS_OK); } @@ -918,7 +906,7 @@ SMT_Status SM_Heap_End_I ( const char * Heap_Name ) /* (I) Heap : pointeur sur un heap ouvert */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap) +SMT_Status SM_Heap_Close_I( SMT_Heap *Heap) { SMT_Status rc; NDT_Node * Node; @@ -929,9 +917,9 @@ SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap) */ ND_Index_Node_Last_Get( &Node, Heap->MHH->DSR, NDD_INDEX_PRIMARY); - while (Node) + while( Node) { - rc = SM_DataSegment_Close (Node->Value); + rc = SM_DataSegment_Close( Node->Value); if( SM_ERROR(rc)) return rc; ND_Index_Node_Previous_Get( &Node, Node); @@ -939,7 +927,7 @@ SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap) /* Déverrouillage du heap */ - SM_Heap_Unlock_I (Heap); + SM_Heap_Unlock_I( Heap); /* Suppression du heap de la liste des heaps ouverts */ @@ -962,7 +950,7 @@ SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap) /* (O) Locked : verrouillage effectué (TRUE ou FALSE) */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) +SMT_Status SM_Heap_Lock_I( SMT_Heap *Heap, SMT_Flags Lock_Mode, int *Locked ) { SMT_Status rc; int Nb_Detected, Nb_Corrected; @@ -975,8 +963,8 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) fprintf( stderr, "SM_Heap_Lock: heap [%s] already locked in mode: (%d)!\n", Heap->Name, Lock_Mode); fflush( stderr); */ - LG_LOG_WARNING_2( "heap [%s] already locked in mode: (%d)", Heap->Name, Lock_Mode); - LG_STACK_TRACE( LGD_LOG_LEVEL_DEFAULT); + LG_LOG_WARNING_2( "Heap: [%s] already locked in mode: (%d)", Heap->Name, Lock_Mode); +// LG_STACK_TRACE( LGD_LOG_LEVEL_DEFAULT); *Locked = FALSE; // *Locked = TRUE; @@ -993,10 +981,9 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) if( Heap->MHH->State == SMD_STATE_CORRUPTED) { - sprintf( SM_Error_Msg, "SM_Heap_Lock : heap \"%s\" is flagged as being corrupted", Heap->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Heap: [%s] is flagged as being corrupted", Heap->Name); - return SMS_KO; + return( SMS_KO); } /* Verrouillage du heap dans le mode demandé */ @@ -1004,8 +991,7 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) rc = SM_Heap_Lock_Set( Heap->MHH, Lock_Mode); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock : unable to lock heap \"%s\" for %s", Heap->Name, Lock_Mode & SMD_READ ? "reading" : "writing"); - SM_Error_Print(); + LG_LOG_ERROR_2( "Unable to lock heap [%s] for: [%s]", Heap->Name, Lock_Mode & SMD_READ ? "reading" : "writing"); return rc; } @@ -1021,10 +1007,9 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) rc = SM_Heap_Lock_Change( Heap->MHH, SMD_WRITE); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock : unable to lock heap \"%s\" for writing before checking", Heap->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to lock heap: [%s] for writing before checking", Heap->Name); - SM_Heap_Unlock_I (Heap); + SM_Heap_Unlock_I( Heap); return rc; } } @@ -1032,13 +1017,12 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) /* Vérification du heap */ Nb_Detected = Nb_Corrected = 0; - rc = SM_Heap_Check_I (Heap, &Nb_Detected, &Nb_Corrected, SM_stderr); + rc = SM_Heap_Check_I( Heap, &Nb_Detected, &Nb_Corrected, SM_stderr); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock : unable to check heap \"%s\"", Heap->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to check heap: [%s]", Heap->Name); - SM_Heap_Unlock_I (Heap); + SM_Heap_Unlock_I( Heap); return rc; } @@ -1046,13 +1030,12 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) if( Lock_Mode == SMD_READ) { - rc = SM_Heap_Lock_Change (Heap->MHH, SMD_READ); + rc = SM_Heap_Lock_Change( Heap->MHH, SMD_READ); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock : unable to lock heap \"%s\" for reading", Heap->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to lock heap: [%s] for reading", Heap->Name); - SM_Heap_Unlock_I (Heap); + SM_Heap_Unlock_I( Heap); return rc; } } @@ -1067,8 +1050,7 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) if( SM_Heap_IsOpen_I( "system", &heap_ptr) != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock : Internal Error 1 !"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Internal Error 1 !"); } else { @@ -1078,8 +1060,7 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) if( node_ptr == NULL) { - sprintf( SM_Error_Msg, "SM_Heap_Lock : Internal Error 2 !"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Internal Error 2 !"); } else { @@ -1087,14 +1068,13 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) { if( ( rc = SM_DataSegment_Open( node_ptr->Value)) != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock : unable to open one of the data segments of heap \"%s\"", - ( (SMT_MHH *)(node_ptr->Value))->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to open one of the data segments of heap: [%s]", + ( (SMT_MHH *)(node_ptr->Value))->Name); } else { -// sprintf( SM_Error_Msg, "SM_Heap_Lock : Opening Segment (%x)", node_ptr->Value); -// SM_Error_Print(); +// LG_LOG_ERROR_1( "SM_Heap_Lock : Opening Segment (%x)", node_ptr->Value); +// } ND_Index_Node_Next_Get( &node_ptr, node_ptr); @@ -1113,15 +1093,14 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) /* On ouvre tous les segments du heap */ ND_Index_Node_First_Get( &Node, Heap->MHH->DSR, NDD_INDEX_PRIMARY); - while (Node) + while( Node) { rc = SM_DataSegment_Open (Node->Value); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock : unable to open one of the data segments of heap \"%s\"", Heap->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to open one of the data segments of heap: [%s]", Heap->Name); - SM_Heap_Unlock_I (Heap); + SM_Heap_Unlock_I( Heap); return rc; } @@ -1138,11 +1117,10 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) { /* Verrouillage du heap qui est déjà verrouillé dans un autre mode */ - rc = SM_Heap_Lock_Change (Heap->MHH, Lock_Mode); + rc = SM_Heap_Lock_Change( Heap->MHH, Lock_Mode); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock : unable to change lock of heap \"%s\" for %s", Heap->Name, Lock_Mode & SMD_READ ? "reading" : "writing"); - SM_Error_Print(); + LG_LOG_ERROR_2( "Unable to change lock of heap: [%s] for [%s]", Heap->Name, Lock_Mode & SMD_READ ? "reading" : "writing"); return rc; } @@ -1151,7 +1129,7 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) *Locked = TRUE; } - LG_LOG_TRACE_2( LGD_LOG_LEVEL_DEFAULT, "Locked: heap [%s] lock_mode: (%d)", Heap->Name, Heap->Lock_Mode); + LG_LOG_TRACE_2( LGD_LOG_LEVEL_DEFAULT, "Locked: heap: [%s] lock_mode: (%d)", Heap->Name, Heap->Lock_Mode); return( SMS_OK); } @@ -1166,24 +1144,24 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) /* (I) Heap : pointeur sur unheap ouvert */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Unlock_I ( SMT_Heap * Heap) +SMT_Status SM_Heap_Unlock_I( SMT_Heap *Heap) { SMT_Status rc; - rc = SM_Heap_Lock_Release (Heap->MHH, Heap->Lock_Mode); + rc = SM_Heap_Lock_Release( Heap->MHH, Heap->Lock_Mode); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Unlock : unable to unlock heap \"%s\" for %s", + LG_LOG_ERROR_2( "Unable to unlock heap: [%s] for: [%s]", Heap->Name, Heap->Lock_Mode & SMD_READ ? "reading" : "writing"); - SM_Error_Print(); + return( rc); } Heap->Lock_Mode = SMD_NO_LOCK; - LG_LOG_TRACE_2( LGD_LOG_LEVEL_DEFAULT, "Unlocked: heap [%s] lock_mode: (%d)", Heap->Name, Heap->Lock_Mode); + LG_LOG_TRACE_2( LGD_LOG_LEVEL_DEFAULT, "Unlocked: heap: [%s] lock_mode: (%d)", Heap->Name, Heap->Lock_Mode); return( SMS_OK); } @@ -1199,7 +1177,7 @@ SMT_Status SM_Heap_Unlock_I ( SMT_Heap * Heap) /* (I) Tag : type de configuration */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Config_I ( SMT_Heap * Heap, SMT_Config Tag, ... ) +SMT_Status SM_Heap_Config_I( SMT_Heap *Heap, SMT_Config Tag, ... ) { va_list Arguments; size_t Size, Current_Size; @@ -1207,24 +1185,26 @@ SMT_Status SM_Heap_Config_I ( SMT_Heap * Heap, SMT_Config Tag, ... ) va_start (Arguments, Tag); - switch (Tag) + switch( Tag) { case SMD_AUTO_COMPRESS: - + { Size = va_arg (Arguments, size_t); Heap->MHH->Auto_Compress = Size; break; + } case SMD_SEGMENT_SIZE: - + { Size = va_arg (Arguments, size_t); Heap->MHH->Segment_Size = Size; break; + } case SMD_HEAP_LIMIT: - + { Size = va_arg (Arguments, size_t); Current_Size = 0; @@ -1232,15 +1212,14 @@ SMT_Status SM_Heap_Config_I ( SMT_Heap * Heap, SMT_Config Tag, ... ) { /* On contrôle que la limite fixée est inférieure à la taille actuelle du heap */ - rc = ND_DataStruct_Traverse (Heap->MHH->DSR, NDD_CMD_VALUE_SUM, (void *)&Current_Size); + rc = ND_DataStruct_Traverse( Heap->MHH->DSR, NDD_CMD_VALUE_SUM, (void *)&Current_Size); if( rc != NDS_OK) return rc; if( Current_Size > Size) { - sprintf( SM_Error_Msg, "SM_Heap_Config : the heap has already exceeded the limit size (%d bytes)", Current_Size); - SM_Error_Print(); + LG_LOG_ERROR_1( "The heap has already exceeded the limit size: (%d) bytes", Current_Size); - va_end (Arguments); + va_end( Arguments); return SMS_ERRAPI; } } @@ -1248,16 +1227,19 @@ SMT_Status SM_Heap_Config_I ( SMT_Heap * Heap, SMT_Config Tag, ... ) Heap->MHH->Limit_Size = Size; break; + } - default : - sprintf( SM_Error_Msg, "SM_Heap_Config : unknown config tag %d", Tag); - SM_Error_Print(); - - va_end (Arguments); + default: + { + LG_LOG_ERROR_1( "Unknown config tag: (%d)", Tag); + + va_end( Arguments); + return SMS_ERRAPI; + } } - va_end (Arguments); + va_end( Arguments); return SMS_OK; } @@ -1317,21 +1299,23 @@ SMT_Status SM_Heap_Compress_I( SMT_Heap *Heap, size_t *Compress) /* (I) Out : pointeur sur le flux de sortie du rapport */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Corrected, FILE * Out) +SMT_Status SM_Heap_Check_I( SMT_Heap *Heap, int *Nb_Detected, int *Nb_Corrected, FILE *Out) { SMT_Status rc; NDT_Node * Node; - if( Out) fprintf( Out, "Checking heap \"%s\" ...\n", Heap->Name); + + LG_LOG_INFO_1( "Checking heap: [%s]", Heap->Name); if( Heap->MHH->DSR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number == 0) { - sprintf( SM_Error_Msg, "SM_Heap_Check : unable to check heap \"%s\" which has no data segment", Heap->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to check heap: [%s] which has no data segment", Heap->Name); - (*Nb_Detected) ++; + ( *Nb_Detected) ++; - if( Out) fprintf( Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); + LG_LOG_INFO_2( "(%d) error(s) could not be corrected in heap: [%s] which will be declared as corrupted", *Nb_Detected - *Nb_Corrected, Heap->Name); + LG_LOG_INFO_0( "Please contact an administrator about it"); + Heap->MHH->State = SMD_STATE_CORRUPTED; return SMS_ERRAPI; @@ -1340,38 +1324,41 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc { /* Vérification de la structure DSR du heap */ - if( Out) fprintf( Out, "Checking the DSR node structure ...\n"); + LG_LOG_INFO_0( "Checking the DSR node structure"); rc = ND_DataStruct_Check (Heap->MHH->DSR, Nb_Detected, Nb_Corrected, Out); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Check : unable to check the DSR structure"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to check the DSR structure"); - if( Out) fprintf( Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); + LG_LOG_INFO_2( "(%d) error(s) could not be corrected in heap: [%s] which will be declared as corrupted", *Nb_Detected - *Nb_Corrected, Heap->Name); + LG_LOG_INFO_0( "Please contact an administrator about it"); + Heap->MHH->State = SMD_STATE_CORRUPTED; return rc; } } - fprintf( Out, "Trying to open every data segment of the heap ...\n"); + LG_LOG_INFO_0( "Trying to open every data segment of the heap"); /* Ouverture des segments du heap au cas ça n'aurait pas été fait */ ND_Index_Node_First_Get( &Node, Heap->MHH->DSR, NDD_INDEX_PRIMARY); - while (Node) + while( Node) { rc = SM_DataSegment_Open (Node->Value); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Check : unable to open one of the data segments of heap \"%s\"", Heap->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to open one of the data segments of heap: [%s]", Heap->Name); - (*Nb_Detected) ++; + ( *Nb_Detected) ++; - if( Out) fprintf( Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); + LG_LOG_INFO_2( "(%d) error(s) could not be corrected in heap: [%s] which will be declared as corrupted.", + *Nb_Detected - *Nb_Corrected, Heap->Name); + LG_LOG_INFO_0( "Please contact an administrator about it"); + Heap->MHH->State = SMD_STATE_CORRUPTED; return rc; @@ -1380,17 +1367,20 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc ND_Index_Node_Next_Get( &Node, Node); } + /* Vérification de la structure ACR du heap */ - if( Out) fprintf( Out, "Checking the ACR node structure ...\n"); + LG_LOG_INFO_0( "Checking the ACR node structure"); rc = ND_DataStruct_Check (Heap->MHH->ACR, Nb_Detected, Nb_Corrected, Out); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Check : unable to check the ACR node structure"); - SM_Error_Print(); + LG_LOG_ERROR_0( "SM_Heap_Check : unable to check the ACR node structure"); - if( Out) fprintf( Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); + LG_LOG_INFO_2( "(%d) error(s) could not be corrected in heap: [%s] which will be declared as corrupted.", + *Nb_Detected - *Nb_Corrected, Heap->Name); + LG_LOG_INFO_0( "Please contact an administrator about it"); + Heap->MHH->State = SMD_STATE_CORRUPTED; return rc; @@ -1398,15 +1388,17 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc /* Vérification de la structure FCR du heap */ - if( Out) fprintf( Out, "Checking the FCR node structure ...\n"); + LG_LOG_INFO_0( "Checking the FCR node structure"); rc = ND_DataStruct_Check (Heap->MHH->FCR, Nb_Detected, Nb_Corrected, Out); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Check : unable to check the ACR node structure"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to check the ACR node structure"); + + + LG_LOG_INFO_2( "(%d) error(s) could not be corrected in heap: [%s] which will be declared as corrupted", *Nb_Detected - *Nb_Corrected, Heap->Name); + LG_LOG_INFO_0( "Please contact an administrator about it"); - if( Out) fprintf( Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); Heap->MHH->State = SMD_STATE_CORRUPTED; return rc; @@ -1418,7 +1410,9 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc { /* On déclare le heap corrompu afin que plus personne n'y accède */ - if( Out) fprintf( Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); + LG_LOG_INFO_2( "(%d) error(s) could not be corrected in heap: [%s] which will be declared as corrupted", + *Nb_Detected - *Nb_Corrected, Heap->Name); + LG_LOG_INFO_0( "Please contact an administrator about it"); Heap->MHH->State = SMD_STATE_CORRUPTED; @@ -1429,11 +1423,11 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc if( *Nb_Detected == 0) { - if( Out) fprintf( Out, "No error detected on heap \"%s\" which will be declared as a valid heap\n", Heap->Name); + LG_LOG_INFO_1( "No error detected on heap: [%s] which will be declared as a valid heap", Heap->Name); } else { - if( Out) fprintf( Out, "Every %d error(s) have beeen corrected on heap \"%s\" which will be declared as a valid heap\n", *Nb_Corrected, Heap->Name); + LG_LOG_WARNING_2( "Every (%d) error(s) have beeen corrected on heap: [%s] which will be declared as a valid heap", *Nb_Corrected, Heap->Name); } Heap->MHH->State = SMD_STATE_VALID; @@ -1453,7 +1447,7 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc /* (O) Ptr : adresse d'un pointeur sur la zone de données allouée */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) +SMT_Status SM_Chunk_Alloc_I( SMT_Heap *Heap, size_t Alloc_Size, void **Ptr ) { NDT_Node * Node; SMT_Chunk * Chunk; @@ -1497,7 +1491,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) Found = FALSE; ND_Index_Node_First_Get( &Node, Heap->MHH->FCR, NDD_INDEX_PRIMARY); - while (Found == FALSE && Node) + while( Found == FALSE && Node) { Chunk = (SMT_Chunk *)(Node->Value); @@ -1523,8 +1517,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) rc = ND_Value_Alloc( (void**)&DSH, Heap->MHH->DSR, Heap->MHH, Seg_Size); if( rc != NDS_OK ) { - sprintf( SM_Error_Msg, "SM_Chunk_Alloc : unable to create a new data segment for heap \"%s\"", Heap->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to create a new data segment for heap: [%s]", Heap->Name); return SMS_ERRSHM; } @@ -1532,12 +1525,10 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) rc = ND_DataStruct_Value_Add (Heap->MHH->DSR, DSH); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Chunk_Alloc : unable to add a data segment to the DSR structure of heap \"%s\"", Heap->Name); - SM_Error_Print(); - - - ND_Value_Free(Heap->MHH->DSR, DSH); + LG_LOG_ERROR_1( "Unable to add a data segment to the DSR structure of heap: [%s]", Heap->Name); + ND_Value_Free(Heap->MHH->DSR, DSH); + return rc; } @@ -1552,11 +1543,10 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) /* Suppression du chunk de la liste des chunks libres */ - rc = ND_Index_Node_Remove (Node); + rc = ND_Index_Node_Remove( Node); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Chunk_Alloc : unable to remove a chunk from the FCR structure of heap \"%s\"", Heap->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to remove a chunk from the FCR structure of heap: [%s]", Heap->Name); return rc; } @@ -1566,8 +1556,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) rc = ND_Index_Node_Add( Heap->MHH->ACR, NDD_INDEX_PRIMARY, Node); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Chunk_Alloc : unable to add a chunk to the ACR structure of heap \"%s\"", Heap->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to add a chunk to the ACR structure of heap: [%s]", Heap->Name); /* On tente de revenir en arrière */ @@ -1599,15 +1588,15 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) /* Création d'un nouveau chunk libre (noeud puis valeur) juste derrière le chunk trouvé */ - New_Node = (NDT_Node *)((size_t)(Chunk->Data) + Alloc_Size); + New_Node = (NDT_Node *)( (size_t)(Chunk->Data) + Alloc_Size); - New_Chunk = (SMT_Chunk *)((size_t)New_Node + sizeof (NDT_Node) ); + New_Chunk = (SMT_Chunk *)( (size_t)New_Node + sizeof (NDT_Node) ); New_Chunk_Size = Remaining_Size - sizeof (SMT_Chunk) - sizeof (NDT_Node); New_Chunk->Size = New_Chunk_Size; - New_Chunk->Data = (void *)((size_t)(New_Chunk) + sizeof (SMT_Chunk) ); + New_Chunk->Data = (void *)( (size_t)(New_Chunk) + sizeof (SMT_Chunk) ); New_Node->Root = NULL; New_Node->Parent = NULL; @@ -1618,8 +1607,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) rc = ND_Index_Node_Add( Heap->MHH->FCR, NDD_INDEX_PRIMARY, New_Node); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Chunk_Alloc : unable to add a chunk to the FCR structure of heap \"%s\"", Heap->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to add a chunk to the FCR structure of heap: [%s]", Heap->Name); return rc; } @@ -1648,7 +1636,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) /* On compte le nombre de chunks libres "utilisables" dans la structure FCR */ ND_Index_Node_First_Get( &Node, Heap->MHH->FCR, NDD_INDEX_PRIMARY); - while (Node) + while( Node) { Free_Chunk = Node->Value; @@ -1704,8 +1692,8 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) rc = ND_Value_Alloc( (void**)&DSH, Heap->MHH->DSR, Heap->MHH, Heap->MHH->Segment_Size); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Chunk_Alloc : unable to create un new data segment for the system heap (anticipation)"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to create un new data segment for the system heap (anticipation)"); + return SMS_ERRSHM; } @@ -1717,9 +1705,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) rc = ND_Index_Node_Add( Heap->MHH->DSR, NDD_INDEX_PRIMARY, New_Node); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Chunk_Alloc : unable to add a data segment to the DSR structure of the system heap (anticipation)"); - SM_Error_Print(); - + LG_LOG_ERROR_0( "Unable to add a data segment to the DSR structure of the system heap (anticipation)"); ND_Value_Free( Heap->MHH->DSR, DSH); return rc; @@ -1752,7 +1738,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) /* (I) Ptr : pointeur sur la zone de données du chunk à désallouer */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr) +SMT_Status SM_Chunk_Free_I( SMT_Heap *Heap, void *Ptr) { NDT_Node * Node; SMT_Chunk * Chunk; @@ -1771,17 +1757,16 @@ SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr) de le rechercher dans la liste des chunks alloués. */ - Node = (NDT_Node *)((size_t)Ptr - sizeof (SMT_Chunk) - sizeof (NDT_Node)); + Node = (NDT_Node *)( (size_t)Ptr - sizeof (SMT_Chunk) - sizeof (NDT_Node)); Chunk = Node->Value; /* Suppression du chunk de la liste des chunks alloués */ - rc = ND_Index_Node_Remove (Node); + rc = ND_Index_Node_Remove( Node); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Chunk_Free : unable to remove the allocated chunk from the ACR structure of heap \"%s\"", Heap->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to remove the allocated chunk from the ACR structure of heap: [%s]", Heap->Name); return rc; } @@ -1791,8 +1776,7 @@ SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr) rc = ND_Index_Node_Add( Heap->MHH->FCR, NDD_INDEX_PRIMARY, Node); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Chunk_Free : unable to add the free chunk to the FCR structure of heap \"%s\"", Heap->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to add the free chunk to the FCR structure of heap: [%s]", Heap->Name); /* Retour arrière */ @@ -1818,8 +1802,8 @@ SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr) rc = SM_Heap_Compress (Heap, &Compress_Size); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Chunk_Free : unable to compress FCR structure of heap \"%s\" which contains %ld free chunks", Heap->Name, Heap->MHH->FCR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number); - SM_Error_Print(); + LG_LOG_ERROR_2( "Unable to compress FCR structure of heap: [%s] which contains: (%ld) free chunks", Heap->Name, Heap->MHH->FCR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number); + return rc; } } @@ -1843,9 +1827,9 @@ SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr) /* (I) Open_Mode : indicateur création/ouverture + mode d'affichage des erreurs */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Open_C ( int Instance, const char * Context, SMT_Flags Open_Mode ) +SMT_Status SM_Library_Open_C( int Instance, const char *Context, SMT_Flags Open_Mode) { - return SM_Library_Open_I (Instance, Context, Open_Mode); + return SM_Library_Open_I( Instance, Context, Open_Mode); } @@ -1858,9 +1842,9 @@ SMT_Status SM_Library_Open_C ( int Instance, const char * Context, SMT_Flags Ope /* (O) Instance : adresse du numéro de l'instance utilisée */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Instance_Get_C ( int * Instance ) +SMT_Status SM_Library_Instance_Get_C( int *Instance) { - return SM_Library_Instance_Get_I (Instance); + return SM_Library_Instance_Get_I( Instance); } @@ -1873,9 +1857,9 @@ SMT_Status SM_Library_Instance_Get_C ( int * Instance ) /* (O) Context : adresse du nom du contexte utilisé */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Context_Get_C ( char ** Context ) +SMT_Status SM_Library_Context_Get_C( char **Context) { - return SM_Library_Context_Get_I (Context); + return SM_Library_Context_Get_I( Context); } @@ -1888,9 +1872,9 @@ SMT_Status SM_Library_Context_Get_C ( char ** Context ) /* (I) Context : nom du nouveau contexte */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Context_Set_C ( const char * Context ) +SMT_Status SM_Library_Context_Set_C( const char *Context) { - return SM_Library_Context_Set_I (Context); + return SM_Library_Context_Set_I( Context); } @@ -1903,17 +1887,11 @@ SMT_Status SM_Library_Context_Set_C ( const char * Context ) /* (I) Close_Mode : mode de fermeture (destruction ou fermeture simple) */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Close_C ( SMT_Flags Close_Mode ) +SMT_Status SM_Library_Close_C( SMT_Flags Close_Mode) { - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Library_Close : the LIBSHMEM library is not open"); - SM_Error_Print(); + SM_LIBSHMEM_OPEN_CHECK(); - return SMS_ERRAPI; - } - - return SM_Library_Close_I (Close_Mode); + return SM_Library_Close_I( Close_Mode); } @@ -1924,16 +1902,11 @@ SMT_Status SM_Library_Close_C ( SMT_Flags Close_Mode ) /* Affichage des informations de la base de mémoires partagées */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Dump_C (FILE * Out) +SMT_Status SM_Library_Dump_C( FILE *Out) { - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Library_Dump : the LIBSHMEM library is not open"); - SM_Error_Print(); - return SMS_ERRAPI; - } + SM_LIBSHMEM_OPEN_CHECK(); - return SM_Library_Dump_I (Out); + return SM_Library_Dump_I( Out); } @@ -1944,16 +1917,11 @@ SMT_Status SM_Library_Dump_C (FILE * Out) /* Libération de tous les verrous (base, heap) */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Unlock_C ( void ) +SMT_Status SM_Library_Unlock_C( void) { - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Library_Unlock : the LIBSHMEM library is not open"); - SM_Error_Print(); - return SMS_ERRAPI; - } + SM_LIBSHMEM_OPEN_CHECK(); - return SM_Library_Unlock_I (); + return SM_Library_Unlock_I( ); } @@ -1964,9 +1932,9 @@ SMT_Status SM_Library_Unlock_C ( void ) /* Définition de la sortie standard des messages d'erreur de la librairie */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Stderr_Set_C ( FILE * Out ) +SMT_Status SM_Library_Stderr_Set_C( FILE *Out) { - return SM_Library_Stderr_Set_I (Out); + return SM_Library_Stderr_Set_I( Out); } @@ -1979,23 +1947,12 @@ SMT_Status SM_Library_Stderr_Set_C ( FILE * Out ) /* (I) Heap_Name : Nom du heap */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Exist_C ( const char * Heap_Name ) +SMT_Status SM_Heap_Exist_C( const char *Heap_Name) { - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Heap_Exist : the LIBSHMEM library is not open"); - SM_Error_Print(); - return SMS_ERRAPI; - } + SM_LIBSHMEM_OPEN_CHECK(); + SM_HEAP_NAME_CHECK( Heap_Name); - if( !Heap_Name) - { - sprintf( SM_Error_Msg, "SM_Heap_Exist : the heap name is undefined"); - SM_Error_Print(); - return SMS_ERRAPI; - } - - return SM_Heap_Exist_I (Heap_Name); + return SM_Heap_Exist_I( Heap_Name); } @@ -2012,24 +1969,12 @@ SMT_Status SM_Heap_Exist_C ( const char * Heap_Name ) /* (O) Locked : verrou effectif (TRUE ou FALSE) */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Open_C ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg_Size, SMT_Flags Open_Mode, int * Locked ) +SMT_Status SM_Heap_Open_C( const char * Heap_Name, SMT_Heap **Heap_Ptr_Ptr, size_t Seg_Size, SMT_Flags Open_Mode, int *Locked) { - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Heap_Open : the LIBSHMEM library is not open"); - SM_Error_Print(); + SM_LIBSHMEM_OPEN_CHECK(); + SM_HEAP_NAME_CHECK( Heap_Name); - return SMS_ERRAPI; - } - - if( !Heap_Name) - { - sprintf( SM_Error_Msg, "SM_Heap_Open : the heap name is undefined"); - SM_Error_Print(); - return SMS_ERRAPI; - } - - return SM_Heap_Open_I (Heap_Name, Heap, Seg_Size, Open_Mode, Locked); + return SM_Heap_Open_I( Heap_Name, Heap_Ptr_Ptr, Seg_Size, Open_Mode, Locked); } @@ -2043,24 +1988,12 @@ SMT_Status SM_Heap_Open_C ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg /* (O) Heap : pointeur sur le heap ouvert */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_IsOpen_C ( const char * Heap_Name, SMT_Heap ** Heap ) +SMT_Status SM_Heap_IsOpen_C( const char * Heap_Name, SMT_Heap ** Heap ) { - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Heap_IsOpen : the LIBSHMEM library is not open"); - SM_Error_Print(); + SM_LIBSHMEM_OPEN_CHECK(); + SM_HEAP_NAME_CHECK( Heap_Name); - return SMS_ERRAPI; - } - - if( !Heap_Name) - { - sprintf( SM_Error_Msg, "SM_Heap_IsOpen : the heap name is undefined"); - SM_Error_Print(); - return SMS_ERRAPI; - } - - return SM_Heap_IsOpen_I (Heap_Name, Heap); + return SM_Heap_IsOpen_I( Heap_Name, Heap); } @@ -2073,24 +2006,12 @@ SMT_Status SM_Heap_IsOpen_C ( const char * Heap_Name, SMT_Heap ** Heap ) /* (I) Heap : pointeur sur un heap ouvert */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_End_C ( const char * Heap_Name ) +SMT_Status SM_Heap_End_C( const char * Heap_Name ) { - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Heap_End : the LIBSHMEM library is not open"); - SM_Error_Print(); + SM_LIBSHMEM_OPEN_CHECK(); + SM_HEAP_NAME_CHECK( Heap_Name); - return SMS_ERRAPI; - } - - if( !Heap_Name) - { - sprintf( SM_Error_Msg, "SM_Heap_End : the heap name is undefined"); - SM_Error_Print(); - return SMS_ERRAPI; - } - - return SM_Heap_End_I (Heap_Name); + return SM_Heap_End_I( Heap_Name); } @@ -2103,24 +2024,12 @@ SMT_Status SM_Heap_End_C ( const char * Heap_Name ) /* (I) Heap : pointeur sur un heap ouvert */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap ) +SMT_Status SM_Heap_Close_C( SMT_Heap *Heap_Ptr) { - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Heap_Close : the LIBSHMEM library is not open"); - SM_Error_Print(); + SM_LIBSHMEM_OPEN_CHECK(); + SM_HEAP_CHECK( Heap_Ptr); - return SMS_ERRAPI; - } - - if( !Heap) - { - sprintf( SM_Error_Msg, "SM_Heap_Close : the heap is undefined"); - SM_Error_Print(); - return SMS_ERRAPI; - } - - return SM_Heap_Close_I (Heap); + return SM_Heap_Close_I( Heap_Ptr); } @@ -2135,24 +2044,12 @@ SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap ) /* (O) Locked : verrouillage effectué (TRUE ou FALSE) */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Lock_C ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) +SMT_Status SM_Heap_Lock_C( SMT_Heap *Heap_Ptr, SMT_Flags Lock_Mode, int * Locked ) { - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Heap_Lock : the LIBSHMEM library is not open"); - SM_Error_Print(); - - return SMS_ERRAPI; - } - - if( !Heap) - { - sprintf( SM_Error_Msg, "SM_Heap_Lock : the heap is undefined"); - SM_Error_Print(); - return SMS_ERRAPI; - } - - return SM_Heap_Lock_I (Heap, Lock_Mode, Locked); + SM_LIBSHMEM_OPEN_CHECK(); + SM_HEAP_CHECK( Heap_Ptr); + + return SM_Heap_Lock_I( Heap_Ptr, Lock_Mode, Locked); } @@ -2165,24 +2062,12 @@ SMT_Status SM_Heap_Lock_C ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) /* (I) Heap : pointeur sur unheap ouvert */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Unlock_C ( SMT_Heap * Heap ) +SMT_Status SM_Heap_Unlock_C( SMT_Heap *Heap_Ptr) { - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Heap_Unlock : the LIBSHMEM library is not open"); - SM_Error_Print(); + SM_LIBSHMEM_OPEN_CHECK(); + SM_HEAP_CHECK( Heap_Ptr); - return SMS_ERRAPI; - } - - if( !Heap) - { - sprintf( SM_Error_Msg, "SM_Heap_Unlock : the heap is undefined"); - SM_Error_Print(); - return SMS_ERRAPI; - } - - return SM_Heap_Unlock_I (Heap); + return SM_Heap_Unlock_I( Heap_Ptr); } @@ -2196,41 +2081,31 @@ SMT_Status SM_Heap_Unlock_C ( SMT_Heap * Heap ) /* (I) Tag : type de configuration */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ) +SMT_Status SM_Heap_Config_C( SMT_Heap *Heap_Ptr, SMT_Config Tag, ... ) { - va_list Arguments; - size_t Segment_Size, Limit_Size, Current_Size; - SMT_Status rc; + va_list Arguments; + size_t Segment_Size, Limit_Size, Current_Size; + SMT_Status rc; - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Heap_Config : the LIBSHMEM library is not open"); - SM_Error_Print(); - - return SMS_ERRAPI; - } - - if( !Heap) - { - sprintf( SM_Error_Msg, "SM_Heap_Config : the heap is undefined"); - SM_Error_Print(); - return SMS_ERRAPI; - } + SM_LIBSHMEM_OPEN_CHECK(); + SM_HEAP_CHECK( Heap_Ptr); va_start (Arguments, Tag); - switch (Tag) + switch( Tag) { case SMD_SEGMENT_SIZE: + { Segment_Size = va_arg (Arguments, size_t); - Heap->MHH->Segment_Size = Segment_Size; + Heap_Ptr->MHH->Segment_Size = Segment_Size; break; - + } + case SMD_HEAP_LIMIT: - + { Limit_Size = va_arg (Arguments, size_t); Current_Size = 0; @@ -2238,32 +2113,33 @@ SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ) { /* On contrôle que la limite fixée est inférieure à la taille actuelle du heap */ - rc = ND_DataStruct_Traverse (Heap->MHH->DSR, NDD_CMD_VALUE_SUM, (void *)&Current_Size); + rc = ND_DataStruct_Traverse( Heap_Ptr->MHH->DSR, NDD_CMD_VALUE_SUM, (void *)&Current_Size); if( rc != NDS_OK) return rc; if( Current_Size > Limit_Size) { - sprintf( SM_Error_Msg, "SM_Heap_Config : the heap has already exceeded the limit size (%d bytes)", Current_Size); - SM_Error_Print(); + LG_LOG_ERROR_1( "The heap has already exceeded the limit size: (%d) bytes", Current_Size); - va_end (Arguments); + va_end( Arguments); return SMS_ERRAPI; } } - Heap->MHH->Limit_Size = Limit_Size; + Heap_Ptr->MHH->Limit_Size = Limit_Size; break; + } - default : - sprintf( SM_Error_Msg, "SM_Heap_Config : unknown config tag %d", Tag); - SM_Error_Print(); + default: + { + LG_LOG_ERROR_1( "Unknown config tag: (%d)", Tag); - va_end (Arguments); + va_end( Arguments); return SMS_ERRAPI; + } } - va_end (Arguments); + va_end( Arguments); return SMS_OK; } @@ -2279,31 +2155,19 @@ SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ) /* (O) Compress : pointeur sur la taille mémoire gagnée */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress ) +SMT_Status SM_Heap_Compress_C( SMT_Heap *Heap_Ptr, size_t *Compress) { - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Heap_Compress : the LIBSHMEM library is not open"); - SM_Error_Print(); - - return SMS_ERRAPI; - } - - if( !Heap) - { - sprintf( SM_Error_Msg, "SM_Heap_Compress : the heap is undefined"); - SM_Error_Print(); - return SMS_ERRAPI; - } + SM_LIBSHMEM_OPEN_CHECK(); + SM_HEAP_CHECK( Heap_Ptr); if( !Compress) { - sprintf( SM_Error_Msg, "SM_Heap_Compress : the compress size pointer is null"); - SM_Error_Print(); + LG_LOG_ERROR_0( "The compress size pointer is null"); + return SMS_ERRAPI; } - return SM_Heap_Compress_I (Heap, Compress); + return SM_Heap_Compress_I( Heap_Ptr, Compress); } @@ -2319,38 +2183,26 @@ SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress ) /* (I) Out : pointeur sur le flux de sortie du rapport */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Corrected, FILE * Out ) +SMT_Status SM_Heap_Check_C( SMT_Heap *Heap_Ptr, int *Nb_Detected, int *Nb_Corrected, FILE *Out) { - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Heap_Check : the LIBSHMEM library is not open"); - SM_Error_Print(); - - return SMS_ERRAPI; - } - - if( !Heap) - { - sprintf( SM_Error_Msg, "SM_Heap_Check : the heap is undefined"); - SM_Error_Print(); - return SMS_ERRAPI; - } + SM_LIBSHMEM_OPEN_CHECK(); + SM_HEAP_CHECK( Heap_Ptr); if( !Nb_Detected || !Nb_Corrected) { - sprintf( SM_Error_Msg, "SM_Heap_Check : the error number pointer is null"); - SM_Error_Print(); + LG_LOG_ERROR_0( "The error number pointer is null"); + return SMS_ERRAPI; } if( !Out) { - sprintf( SM_Error_Msg, "SM_Heap_Check : the out stream is null"); - SM_Error_Print(); + LG_LOG_ERROR_0( "The out stream is null"); + return SMS_ERRAPI; } - return SM_Heap_Check_I (Heap, Nb_Detected, Nb_Corrected, Out); + return SM_Heap_Check_I( Heap_Ptr, Nb_Detected, Nb_Corrected, Out); } @@ -2365,31 +2217,19 @@ SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc /* (O) Ptr : adresse d'un pointeur sur la zone de données allouée */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Chunk_Alloc_C ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr) +SMT_Status SM_Chunk_Alloc_C( SMT_Heap *Heap_Ptr, size_t Alloc_Size, void **Ptr) { - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Chunk_Alloc : the LIBSHMEM library is not open"); - SM_Error_Print(); - - return SMS_ERRAPI; - } - - if( !Heap) - { - sprintf( SM_Error_Msg, "SM_Chunk_Alloc : the heap is undefined"); - SM_Error_Print(); - return SMS_ERRAPI; - } + SM_LIBSHMEM_OPEN_CHECK(); + SM_HEAP_CHECK( Heap_Ptr); if( !Ptr) { - sprintf( SM_Error_Msg, "SM_Chunk_Alloc : the chunk address is null"); - SM_Error_Print(); + LG_LOG_ERROR_0( "The chunk address is null"); + return SMS_ERRAPI; } - return SM_Chunk_Alloc_I (Heap, Alloc_Size, Ptr); + return SM_Chunk_Alloc_I( Heap_Ptr, Alloc_Size, Ptr); } @@ -2403,31 +2243,19 @@ SMT_Status SM_Chunk_Alloc_C ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr) /* (I) Ptr : pointeur sur la zone de données du chunk à désallouer */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Chunk_Free_C ( SMT_Heap * Heap, void * Ptr) +SMT_Status SM_Chunk_Free_C( SMT_Heap *Heap_Ptr, void *Ptr) { - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Chunk_Free : the LIBSHMEM library is not open"); - SM_Error_Print(); - - return SMS_ERRAPI; - } - - if( !Heap) - { - sprintf( SM_Error_Msg, "SM_Chunk_Free : the heap is undefined"); - SM_Error_Print(); - return SMS_ERRAPI; - } + SM_LIBSHMEM_OPEN_CHECK(); + SM_HEAP_CHECK( Heap_Ptr); if( !Ptr) { - sprintf( SM_Error_Msg, "SM_Chunk_Free : the chunk pointer is null"); - SM_Error_Print(); + LG_LOG_ERROR_0( "The chunk pointer is null"); + return SMS_ERRAPI; } - return SM_Chunk_Free_I (Heap, Ptr); + return SM_Chunk_Free_I( Heap_Ptr, Ptr); } @@ -2451,7 +2279,7 @@ SMT_Status SM_Chunk_Free_C ( SMT_Heap * Heap, void * Ptr) NDT_Status SM_Base_Alloc( void **Ptr, size_t Size, void *Data_Ptr) { *Ptr = SM_Base->Free; - SM_Base->Free = (void *)((size_t)(SM_Base->Free) + Size); + SM_Base->Free = (void *)( (size_t)(SM_Base->Free) + Size); return( NDS_OK); } @@ -2522,23 +2350,26 @@ SMT_Status SM_Base_Init ( void ) SemId = semget (IPC_PRIVATE, 1, 0777|IPC_CREAT|IPC_EXCL); if( SemId == -1) { - switch (errno) + switch( errno) { case ENOMEM: - sprintf( SM_Error_Msg, "SM_Base_Init : the amount of memory is not sufficient to create a new semaphore"); + { + LG_LOG_ERROR_0( "The amount of memory is not sufficient to create a new semaphore"); break; - + } + case ENOSPC: - sprintf( SM_Error_Msg, "SM_Base_Init : the number of semaphores exceeds the system-imposed limit"); + { break; + } - default : - sprintf( SM_Error_Msg, "SM_Base_Init : unknown error (%d) while creating a semaphore", errno); + default: + { + LG_LOG_ERROR_1( "Unknown error: (%d) while creating a semaphore", errno); break; + } } - SM_Error_Print(); - return SMS_ERRSEM; } @@ -2546,60 +2377,68 @@ SMT_Status SM_Base_Init ( void ) Sem_Ctl.val = 1; - if( semctl (SemId, 0, SETVAL, Sem_Ctl )) + if( semctl( SemId, 0, SETVAL, Sem_Ctl )) { - sprintf( SM_Error_Msg, "SM_Base_Init : unable to initialize the value of semaphore %d", SemId); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to initialize the value of semaphore: (%d)", SemId); rc = SMS_ERRSEM; goto Error1; } + /* Création d'un segment de mémoire partagée qui contiendra la structure SMT_Base. Ce segment peut être attaché à n'importe quelle adresse. */ - SysMemId = shmget (SM_Instance, (int) sizeof (SMT_Base), 0777|IPC_CREAT|IPC_EXCL); + SysMemId = shmget( SM_Instance, (int) sizeof( SMT_Base), ( 0777 | IPC_CREAT | IPC_EXCL)); if( SysMemId == -1) { - switch (errno) + switch( errno) { case EEXIST: - sprintf( SM_Error_Msg, "SM_Base_Init : the shared memory segment identifier %d already exists", SM_Instance); + { + LG_LOG_ERROR_1( "The shared memory segment identifier: (%d) already exists", SM_Instance); break; + } case EINVAL: - sprintf( SM_Error_Msg, "SM_Base_Init : the size of the shared memory segment (%d) is out of the system-imposed bounds", sizeof (SMT_Base)); + { + LG_LOG_ERROR_1( "The size of the shared memory segment: (%d) is out of the system-imposed bounds", sizeof( SMT_Base)); break; + } case ENOMEM: - sprintf( SM_Error_Msg, "SM_Base_Init : the amount of memory is not sufficient to create the shared memory segment"); + { + LG_LOG_ERROR_0( "The amount of memory is not sufficient to create the shared memory segment"); break; + } case ENOSPC: - sprintf( SM_Error_Msg, "SM_Base_Init : the number of shared memory segments exceeds the system-imposed limit"); + { + LG_LOG_ERROR_0( "The number of shared memory segments exceeds the system-imposed limit"); break; + } - default : - sprintf( SM_Error_Msg, "SM_Base_Init : unknown error (%d) while creating the shared memory segment", errno); + default: + { + LG_LOG_ERROR_1( "Unknown error: (%d) while creating the shared memory segment", errno); break; + } } - SM_Error_Print(); - rc = SMS_ERRSHM; goto Error1; } + /* On attache le segment de mémoire partagée au processus courant */ errno = 0; SM_Base = shmat( SysMemId, 0, 0); if( errno) { - sprintf( SM_Error_Msg, "SM_Base_Init : unable to attach the first shared memory segment to the current process (error %d)", errno); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to attach the first shared memory segment to the current process, error: (%d)", errno); rc = SMS_ERRSHM; goto Error2; @@ -2628,30 +2467,28 @@ SMT_Status SM_Base_Init ( void ) Size = sizeof (NDT_Root) + sizeof (NDT_Node) + sizeof (SMT_MHH) + 3 * sizeof (NDT_Root) + sizeof (NDT_Node) + sizeof (SMT_DSH); - DataMemId = shmget (IPC_PRIVATE, Size, 0777|IPC_CREAT|IPC_EXCL); + DataMemId = shmget( IPC_PRIVATE, Size, ( 0777 | IPC_CREAT | IPC_EXCL)); if( DataMemId == -1) { - switch (errno) + switch( errno) { case EINVAL: - sprintf( SM_Error_Msg, "SM_Base_Init : the size of the shared memory segment (%d) is out of the system-imposed bounds", Size); + LG_LOG_ERROR_1( "The size of the shared memory segment: (%d) is out of the system-imposed bounds", Size); break; case ENOMEM: - sprintf( SM_Error_Msg, "SM_Base_Init : the amount of memory is not sufficient to create the shared memory segment"); + LG_LOG_ERROR_0( "The amount of memory is not sufficient to create the shared memory segment"); break; case ENOSPC: - sprintf( SM_Error_Msg, "SM_Base_Init : the number of shared memory segments exceeds the system-imposed limit"); + LG_LOG_ERROR_0( "The number of shared memory segments exceeds the system-imposed limit"); break; default : - sprintf( SM_Error_Msg, "SM_Base_Init : unknown error (%d) while creating a shared memory segment", errno); + LG_LOG_ERROR_1( "Unknown error: (%d) while creating a shared memory segment", errno); break; } - SM_Error_Print(); - rc = SMS_ERRSHM; goto Error3; } @@ -2676,15 +2513,14 @@ SMT_Status SM_Base_Init ( void ) errno = 0; #ifndef __hpux - SM_Base->Free = shmat( DataMemId, (void *)((size_t)(SM_Base->Attach) - Size), SHM_RND); + SM_Base->Free = shmat( DataMemId, (void *)( (size_t)(SM_Base->Attach) - Size), SHM_RND); #else SM_Base->Free = shmat( DataMemId, 0, 0); #endif if( errno) { - sprintf( SM_Error_Msg, "SM_Base_Init : unable to attach the second shared memory segment to the current process (error %d)", errno); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to attach the second shared memory segment to the current process: (%d)", errno); rc = SMS_ERRSHM; goto Error4; @@ -2697,8 +2533,7 @@ SMT_Status SM_Base_Init ( void ) rc = ND_DataStruct_Open( &( SM_Base->MHR), 1, &index_type, "MHR_Manager", NULL, "SM_Base_Alloc", NULL, "SM_Base_Free", NULL, TRUE, NULL); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Base_Init : unable to create the MHR structure"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to create the MHR structure"); goto Error4; } @@ -2710,11 +2545,10 @@ SMT_Status SM_Base_Init ( void ) sont effectuées dans la base) */ - rc = SM_Heap_Open_I (HEAP_SYSTEM, &System_Heap, 0, SMD_CREATE, &Locked); + rc = SM_Heap_Open_I( HEAP_SYSTEM, &System_Heap, 0, SMD_CREATE, &Locked); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Base_Init : unable to create the system heap"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to create the system heap"); goto Error5; } @@ -2743,11 +2577,10 @@ SMT_Status SM_Base_Init ( void ) /* Verrouillage de la base en lecture */ - rc = SM_Base_Lock (SMD_READ); + rc = SM_Base_Lock( SMD_READ); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Base_Init : unable to lock the shared memory base for reading"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to lock the shared memory base for reading"); goto Error5; } @@ -2757,17 +2590,21 @@ SMT_Status SM_Base_Init ( void ) /* Gestion d'erreur */ Error5: - ND_DataStruct_Close (SM_Base->MHR); + ND_DataStruct_Close( SM_Base->MHR); + Error4: - shmdt ((void *)(SM_Base->Free)); + shmdt ( (void *)(SM_Base->Free)); + Error3: shmctl (DataMemId, IPC_RMID, 0); + Error2: - shmdt ((void *)SM_Base); + shmdt ( (void *)SM_Base); shmctl (SysMemId, IPC_RMID, 0); SM_Base = NULL; + Error1: - semctl (SemId, 0, IPC_RMID, Sem_Ctl); + semctl( SemId, 0, IPC_RMID, Sem_Ctl); return rc; } @@ -2790,24 +2627,22 @@ SMT_Status SM_Base_End ( void ) /* Retrait du verrou en lecture sur la base */ - rc = SM_Base_Unlock (SMD_READ); + rc = SM_Base_Unlock( SMD_READ); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Base_End : unable to unlock the shared memory base"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to unlock the shared memory base"); return rc; } /* Verrouillage de la base en écriture */ - rc = SM_Base_Lock (SMD_WRITE); + rc = SM_Base_Lock( SMD_WRITE); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Base_End : unable to lock the shared memory base for writing"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to lock the shared memory base for writing"); - SM_Base_Lock (SMD_READ); + SM_Base_Lock( SMD_READ); return rc; } @@ -2821,7 +2656,7 @@ SMT_Status SM_Base_End ( void ) ND_Index_Node_Last_Get( &Node, SM_Base->MHR, NDD_INDEX_PRIMARY); - while (Node) + while( Node) { SMT_MHH * MHH = (SMT_MHH *)(Node->Value); @@ -2842,25 +2677,23 @@ SMT_Status SM_Base_End ( void ) rc = ND_DataStruct_Value_Remove( SM_Base->MHR, MHH); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Base_End : unable to remove heap \"%s\" from the MHR", MHH->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to remove heap: [%s] from the MHR", MHH->Name); - SM_Base_Unlock (SMD_WRITE); - SM_Base_Lock (SMD_READ); + SM_Base_Unlock( SMD_WRITE); + SM_Base_Lock( SMD_READ); return rc; } /* Suppression du heap */ - rc = ND_Value_Free (SM_Base->MHR, MHH); + rc = ND_Value_Free( SM_Base->MHR, MHH); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Base_End : unable to free heap \"%s\"", MHH->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to free heap: [%s]", MHH->Name); - SM_Base_Unlock (SMD_WRITE); - SM_Base_Lock (SMD_READ); + SM_Base_Unlock( SMD_WRITE); + SM_Base_Lock( SMD_READ); return rc; } @@ -2874,54 +2707,68 @@ SMT_Status SM_Base_End ( void ) /* Destruction des segments de mémoire partagée de la base */ - if( shmctl (DataMemId, IPC_RMID, 0) == -1 || shmctl (SysMemId, IPC_RMID, 0) == -1) + if( shmctl( DataMemId, IPC_RMID, 0) == -1 || shmctl( SysMemId, IPC_RMID, 0) == -1) { - switch (errno) + switch( errno) { case EPERM: - sprintf( SM_Error_Msg, "SM_Base_End : current process (%d) is not allowed to destroy the shared memory segment %d or %d", (int)getpid (), SysMemId, DataMemId); + { + LG_LOG_ERROR_3( "Current process: (%d) is not allowed to destroy the shared memory segment: (%d) or (%d)", (int)getpid(), SysMemId, DataMemId); + break; + } case EINVAL: - sprintf( SM_Error_Msg, "SM_Base_End : no shared memory segment exists for identifier %d or %d", SysMemId, DataMemId); + { + LG_LOG_ERROR_2( "No shared memory segment exists for identifier: (%d) or (%d)", SysMemId, DataMemId); + break; + } default : - sprintf( SM_Error_Msg, "SM_Base_End : unknown error (%d) while destroying the shared memory segment %d or %d", errno, SysMemId, DataMemId); - break; - } + { + LG_LOG_ERROR_3( "Unknown error: (%d) while destroying the shared memory segment: (%d) or (%d)", errno, SysMemId, DataMemId); - SM_Error_Print(); + break; + } + } SM_Base = NULL; return SMS_ERRSHM; - } SM_Base = NULL; + /* Destruction du sémaphore de gestion des verrous sur la base */ - if( semctl (SemId, 0, IPC_RMID, Sem_Ctl) == -1) + if( semctl( SemId, 0, IPC_RMID, Sem_Ctl) == -1) { - switch (errno) + switch( errno) { case EPERM: - sprintf( SM_Error_Msg, "SM_Base_End : current process (%d) is not allowed to destroy semaphore %d", (int)getpid (), SemId); + { + LG_LOG_ERROR_2( "Current process: (%d) is not allowed to destroy semaphore: (%d)", (int)getpid (), SemId); + break; + } case EINVAL: - sprintf( SM_Error_Msg, "SM_Base_End : no semaphore corresponds to the identifier %d", SemId); - break; + { + LG_LOG_ERROR_1( "No semaphore corresponds to the identifier: (%d)", SemId); - default : - sprintf( SM_Error_Msg, "SM_Base_End : unknown error (%d) while destroying semaphore %d", errno, SemId); break; + } + + default: + { + LG_LOG_ERROR_2( "Unknown error: (%d) while destroying semaphore: (%d)", errno, SemId); + + break; + } } - SM_Error_Print(); - return SMS_ERRSEM; } @@ -2948,41 +2795,53 @@ SMT_Status SM_Base_Open ( void ) /* Récupération de l'identifiant du segment de mémoire partagée de la base */ - MemId = shmget (SM_Instance, 0, 0); + MemId = shmget( SM_Instance, 0, 0); if( MemId == -1) { - switch (errno) + switch( errno) { case EACCES: - sprintf( SM_Error_Msg, "SM_Base_Open : the shared memory segment %d is not accessible to the current process", SM_Instance); + { + LG_LOG_ERROR_1( "The shared memory segment: (%d) is not accessible to the current process", SM_Instance); + break; + } case EIDRM: - sprintf( SM_Error_Msg, "SM_Base_Open : the shared memory segment %d has been deleted", SM_Instance); + { + LG_LOG_ERROR_1( "The shared memory segment: (%d) has been deleted", SM_Instance); + break; + } case ENOENT: - sprintf( SM_Error_Msg, "SM_Base_Open : no shared memory segment corresponds to the identifier %d", SM_Instance); + { + LG_LOG_ERROR_1( "No shared memory segment corresponds to the identifier: (%d)", SM_Instance); + break; + } - default : - sprintf( SM_Error_Msg, "SM_Base_Open : unknown error %d while retrieving a shared memory segment", errno); + default: + { + LG_LOG_ERROR_1( "Unknown error: (%d) while retrieving a shared memory segment", errno); + break; + } } - SM_Error_Print(); return SMS_ERRSHM; } + /* On attache les segments de mémoire partagée de la base */ errno = 0; SM_Base = shmat( MemId, 0, 0); + if( errno) { - sprintf( SM_Error_Msg, "SM_Base_Open : unable to attach the shared memory segment to the current process (error %d)", errno); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to attach the shared memory segment to the current process, error: (%d)", errno); SM_Base = NULL; @@ -2993,38 +2852,37 @@ SMT_Status SM_Base_Open ( void ) Ptr = shmat (SM_Base->DataMemId, SM_Base->MHR, 0); if( errno) { - sprintf( SM_Error_Msg, "SM_Base_Open : unable to attach the shared memory segment to the current process at the specified address %p (error %d)", SM_Base->MHR, errno); - SM_Error_Print(); + LG_LOG_ERROR_2( "Unable to attach the shared memory segment to the current process at the specified address: (%p) error: (%d)", SM_Base->MHR, errno); - shmdt ((void *)SM_Base); + shmdt( (void *)SM_Base); SM_Base = NULL; return SMS_ERRSHM; } + /* Verrouillage de la base en lecture */ - rc = SM_Base_Lock (SMD_READ); + rc = SM_Base_Lock( SMD_READ); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Base_Open : unable to lock the shared memory base for reading"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to lock the shared memory base for reading"); - shmdt ((void *)SM_Base); + shmdt( (void *)SM_Base); SM_Base = NULL; return rc; } + /* Ouverture du heap système (sans le verrouiller) */ - rc = SM_Heap_Open_I (HEAP_SYSTEM, &System_Heap, 0, SMD_OPEN, &Locked); + rc = SM_Heap_Open_I( HEAP_SYSTEM, &System_Heap, 0, SMD_OPEN, &Locked); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Base_Open : unable to open the system heap"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to open the system heap"); - shmdt ((void *)SM_Base); + shmdt ( (void *)SM_Base); SM_Base = NULL; return rc; @@ -3041,18 +2899,12 @@ SMT_Status SM_Base_Open ( void ) /* Fermeture de la base */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Base_Close ( void ) +SMT_Status SM_Base_Close( void ) { - NDT_Node * Node; + NDT_Node * Node; - if( !SM_Base) - { - sprintf( SM_Error_Msg, "SM_Base_Close : the LIBSHMEM library is not open"); - SM_Error_Print(); - - return SMS_ERRAPI; - } + SM_LIBSHMEM_OPEN_CHECK(); /* Fermeture de tous les heaps (sans déverrouillage) ouverts. @@ -3062,22 +2914,24 @@ SMT_Status SM_Base_Close ( void ) ND_Index_Node_First_Get( &Node, Opened_Heap_List, NDD_INDEX_PRIMARY); - while (Node) + while( Node) { NDT_Node *Next_Node; ND_Index_Node_Next_Get( &Next_Node, Node); - SM_Heap_Close_I ((SMT_Heap *)(Node->Value)); - Node = Next_Node;; + SM_Heap_Close_I( (SMT_Heap *)(Node->Value)); + Node = Next_Node; } + /* Déverrouillage de la base en lecture */ - SM_Base_Unlock (SMD_READ); + SM_Base_Unlock( SMD_READ); + /* Détachement des segments de mémoire partagée de la base */ - shmdt ((void *)SM_Base->MHR); - shmdt ((void *)SM_Base); + shmdt ( (void *)SM_Base->MHR); + shmdt ( (void *)SM_Base); SM_Base = NULL; @@ -3092,17 +2946,16 @@ SMT_Status SM_Base_Close ( void ) /* Pose d'un verrou sur la base */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Base_Lock ( SMT_Flags Lock_Mode ) +SMT_Status SM_Base_Lock( SMT_Flags Lock_Mode ) { SMT_Status rc; if( Lock_Mode & SMD_READ) { - rc = SM_Semaphore_Operate (SM_Base->SemId, SM_SemOp_SSL, 2); + rc = SM_Semaphore_Operate( SM_Base->SemId, SM_SemOp_SSL, 2); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Base_Lock : unable to lock the library base for reading"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to lock the library base for reading"); return rc; } @@ -3110,11 +2963,10 @@ SMT_Status SM_Base_Lock ( SMT_Flags Lock_Mode ) if( Lock_Mode & SMD_WRITE) { - rc = SM_Semaphore_Operate (SM_Base->SemId, SM_SemOp_SEL, 2); + rc = SM_Semaphore_Operate( SM_Base->SemId, SM_SemOp_SEL, 2); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Base_Lock : unable to lock the library base for writing"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to lock the library base for writing"); return rc; } @@ -3131,17 +2983,16 @@ SMT_Status SM_Base_Lock ( SMT_Flags Lock_Mode ) /* Libération d'un verrou sur la base */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Base_Unlock ( SMT_Flags Lock_Mode ) +SMT_Status SM_Base_Unlock( SMT_Flags Lock_Mode ) { SMT_Status rc; if( Lock_Mode & SMD_READ) { - rc = SM_Semaphore_Operate (SM_Base->SemId, SM_SemOp_RSL, 2); + rc = SM_Semaphore_Operate( SM_Base->SemId, SM_SemOp_RSL, 2); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Base_Unlock : unable to unlock the library base which had been locked for reading"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to unlock the library base which had been locked for reading"); return rc; } @@ -3149,11 +3000,10 @@ SMT_Status SM_Base_Unlock ( SMT_Flags Lock_Mode ) if( Lock_Mode & SMD_WRITE) { - rc = SM_Semaphore_Operate (SM_Base->SemId, SM_SemOp_REL, 2); + rc = SM_Semaphore_Operate( SM_Base->SemId, SM_SemOp_REL, 2); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Base_Unlock : unable to unlock the library base which had been locked for writing"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to unlock the library base which had been locked for writing"); return rc; } @@ -3422,13 +3272,15 @@ NDT_Status SM_Opened_Heap_List_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Inde default: { - printf( "ND_Default_Manager() called with an undefined command %d\n", Command); + LG_LOG_ERROR_1( "Manager called with an undefined command: (%d)", Command); + return( NDS_ERRAPI); } } - printf( "ND_Default_Manager() called with command %d (%s)\n", Command, Command_Name); - return( NDS_OK); + LG_LOG_ERROR_1( "Manager internal error in command: (%d)", Command); + + return( NDS_ERRAPI); } @@ -3539,35 +3391,34 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node { case ENOMEM: { - sprintf( SM_Error_Msg, "SM_Heap_Open : the amount of memory is not sufficient to create a new semaphore"); + LG_LOG_ERROR_0( "The amount of memory is not sufficient to create a new semaphore"); break; } case ENOSPC: { - sprintf( SM_Error_Msg, "SM_Heap_Open : the number of semaphores exceeds the system-imposed limit"); + LG_LOG_ERROR_0( "The number of semaphores exceeds the system-imposed limit"); break; } - default : + default: { - sprintf( SM_Error_Msg, "SM_Heap_Open : unknown error (%d) while creating a semaphore", errno); + LG_LOG_ERROR_1( "Unknown error: (%d) while creating a semaphore", errno); break; } } - SM_Error_Print(); return( NDS_ERRMEM); } + /* Initialisation du sémaphore à 1 (équivaut à aucun verrou posé) */ Sem_Ctl.val = 1; if( semctl( SemId, 0, SETVAL, Sem_Ctl)) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to initialize the value of the semaphore %d", SemId); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to initialize the value of the semaphore: (%d)", SemId); rc = SMS_ERRSEM; goto Error3; @@ -3578,8 +3429,7 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node if( ND_Allocator_Exec( (void **)(MHH_Ptr_Ptr), sizeof( SMT_MHH), SM_Base->MHR->Allocator_Name, SM_Base->MHR->Allocator_Ptr, NULL) != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to allocate memory for the heap header"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to allocate memory for the heap header"); rc = SMS_ERRSHM; goto Error3; @@ -3588,14 +3438,14 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node /* Initialisation de la structure du nouveau MHH */ - strcpy((*MHH_Ptr_Ptr)->Name, Prefixed_Name); - (*MHH_Ptr_Ptr)->Writer = getpid(); - (*MHH_Ptr_Ptr)->SemId = SemId; - (*MHH_Ptr_Ptr)->State = SMD_STATE_UNVALIDATED; - (*MHH_Ptr_Ptr)->Segment_Size = ( ( Seg_Size > 0) ? Seg_Size : SEGMENT_DEFAULT_SIZE); - (*MHH_Ptr_Ptr)->Limit_Size = SMD_UNLIMITED; - (*MHH_Ptr_Ptr)->Auto_Compress = SMD_DEFAULT_COMPRESS; - (*MHH_Ptr_Ptr)->Compress_Nb = 0L; + strcpy( ( *MHH_Ptr_Ptr)->Name, Prefixed_Name); + ( *MHH_Ptr_Ptr)->Writer = getpid(); + ( *MHH_Ptr_Ptr)->SemId = SemId; + ( *MHH_Ptr_Ptr)->State = SMD_STATE_UNVALIDATED; + ( *MHH_Ptr_Ptr)->Segment_Size = ( ( Seg_Size > 0) ? Seg_Size : SEGMENT_DEFAULT_SIZE); + ( *MHH_Ptr_Ptr)->Limit_Size = SMD_UNLIMITED; + ( *MHH_Ptr_Ptr)->Auto_Compress = SMD_DEFAULT_COMPRESS; + ( *MHH_Ptr_Ptr)->Compress_Nb = 0L; /* Création de la structure DSR : @@ -3603,11 +3453,10 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node - dans le heap système pour les autres heaps */ - rc = ND_DataStruct_Open( &( (*MHH_Ptr_Ptr)->DSR), 1, &index_type, "SM_DSR_Manager", NULL, SM_Base->MHR->Allocator_Name, NULL, SM_Base->MHR->Deallocator_Name, NULL, TRUE, NULL); + rc = ND_DataStruct_Open( &( ( *MHH_Ptr_Ptr)->DSR), 1, &index_type, "SM_DSR_Manager", NULL, SM_Base->MHR->Allocator_Name, NULL, SM_Base->MHR->Deallocator_Name, NULL, TRUE, NULL); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to create the DSR structure"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to create the DSR structure"); goto Error4; } @@ -3618,11 +3467,10 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node - dans le heap système pour les autres heaps */ - rc = ND_DataStruct_Open( &( (*MHH_Ptr_Ptr)->ACR), 1, &index_type, "SM_ACR_Manager", NULL, SM_Base->MHR->Allocator_Name, NULL, SM_Base->MHR->Deallocator_Name, NULL, TRUE, NULL); + rc = ND_DataStruct_Open( &( ( *MHH_Ptr_Ptr)->ACR), 1, &index_type, "SM_ACR_Manager", NULL, SM_Base->MHR->Allocator_Name, NULL, SM_Base->MHR->Deallocator_Name, NULL, TRUE, NULL); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to create the ACR structure"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to create the ACR structure"); goto Error5; } @@ -3634,35 +3482,32 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node - dans le heap système pour les autres heaps */ - rc = ND_DataStruct_Open( &( (*MHH_Ptr_Ptr)->FCR), 1, &index_type, "SM_FCR_Manager", NULL, SM_Base->MHR->Allocator_Name, NULL, SM_Base->MHR->Deallocator_Name, NULL, TRUE, NULL); + rc = ND_DataStruct_Open( &( ( *MHH_Ptr_Ptr)->FCR), 1, &index_type, "SM_FCR_Manager", NULL, SM_Base->MHR->Allocator_Name, NULL, SM_Base->MHR->Deallocator_Name, NULL, TRUE, NULL); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to create the FCR structure"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to create the FCR structure"); goto Error6; } /*alloction du premier segement de donnee pour le heap*/ - rc = ND_Value_Alloc( (void **)&DSH_Ptr, (*MHH_Ptr_Ptr)->DSR, *MHH_Ptr_Ptr, (*MHH_Ptr_Ptr)->Segment_Size); + rc = ND_Value_Alloc( (void **)&DSH_Ptr, ( *MHH_Ptr_Ptr)->DSR, *MHH_Ptr_Ptr, ( *MHH_Ptr_Ptr)->Segment_Size); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "MHR_Manager : unable to create the DSH structure"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to create the DSH structure"); rc = SMS_ERRSHM; goto Error7; } - rc = ND_DataStruct_Value_Add( (*MHH_Ptr_Ptr)->DSR, DSH_Ptr); + rc = ND_DataStruct_Value_Add( ( *MHH_Ptr_Ptr)->DSR, DSH_Ptr); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to add a data segment to the DSR structure"); - SM_Error_Print(); + LG_LOG_ERROR_0( "Unable to add a data segment to the DSR structure"); goto Error8; } - (*MHH_Ptr_Ptr)->State = SMD_STATE_VALID; + ( *MHH_Ptr_Ptr)->State = SMD_STATE_VALID; return( NDS_OK); @@ -3670,19 +3515,19 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node /* Gestion d'erreur sur création */ Error9: - ND_DataStruct_Value_Remove( (*MHH_Ptr_Ptr)->DSR, DSH_Ptr); + ND_DataStruct_Value_Remove( ( *MHH_Ptr_Ptr)->DSR, DSH_Ptr); Error8: - ND_Value_Free( (*MHH_Ptr_Ptr)->DSR, DSH_Ptr); + ND_Value_Free( ( *MHH_Ptr_Ptr)->DSR, DSH_Ptr); Error7: - ND_Deallocator_Exec( (*MHH_Ptr_Ptr)->FCR, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); + ND_Deallocator_Exec( ( *MHH_Ptr_Ptr)->FCR, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); Error6: - ND_Deallocator_Exec( (*MHH_Ptr_Ptr)->ACR, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); + ND_Deallocator_Exec( ( *MHH_Ptr_Ptr)->ACR, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); Error5: - ND_Deallocator_Exec( (*MHH_Ptr_Ptr)->DSR, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); + ND_Deallocator_Exec( ( *MHH_Ptr_Ptr)->DSR, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); Error4: ND_Deallocator_Exec( *MHH_Ptr_Ptr, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); @@ -3736,7 +3581,7 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node ND_Index_Node_Last_Get( &Node, MHH_Ptr->DSR, NDD_INDEX_PRIMARY); - while (Node) + while( Node) { DSH = (SMT_DSH *)(Node->Value); @@ -3754,8 +3599,7 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node rc = ND_DataStruct_Value_Remove( MHH_Ptr->DSR, DSH); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "MHR_Manager NDD_CMD_VALUE_FREE : unable to remove the shared memory segment (address=%p) from the DSR structure", DSH->Start); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to remove the shared memory segment at address: (%p) from the DSR structure", DSH->Start); if( SM_ERROR(rc)) return rc; } @@ -3765,8 +3609,7 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node rc = ND_Value_Free( MHH_Ptr->DSR, DSH); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, " MHR_Manager NDD_CMD_VALUE_FREE: unable to free the shared memory segment (address=%p)", DSH->Start); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to free the shared memory segment at address: (%p)", DSH->Start); if( SM_ERROR(rc)) return rc; } @@ -3776,11 +3619,10 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node } else { - rc = ND_DataStruct_Close (MHH_Ptr->DSR); + rc = ND_DataStruct_Close( MHH_Ptr->DSR); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "MHR_Manager NDD_CMD_VALUE_FREE : unable to destroy the DSR structure of heap \"%s\"", MHH_Ptr->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to destroy the DSR structure of heap: [%s]", MHH_Ptr->Name); } } @@ -3795,15 +3637,13 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node rc = ND_Deallocator_Exec( MHH_Ptr->ACR, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "MHR_Manager NDD_CMD_VALUE_FREE : unable to free the ACR root of heap \"%s\"", MHH_Ptr->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to free the ACR root of heap: [%s]", MHH_Ptr->Name); } rc = ND_Deallocator_Exec( MHH_Ptr->FCR, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "MHR_Manager NDD_CMD_VALUE_FREE : unable to free the FCR root of heap \"%s\"", MHH_Ptr->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to free the FCR root of heap: [%s]", MHH_Ptr->Name); } /* Suppression du heap de la liste des heaps ouverts */ @@ -3832,15 +3672,14 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node /* Destruction du sémaphore attaché au heap */ - semctl (MHH_Ptr->SemId, 0, IPC_RMID, Sem_Ctl); + semctl( MHH_Ptr->SemId, 0, IPC_RMID, Sem_Ctl); /* Désallocation de la structure du MHH */ rc = ND_Deallocator_Exec( MHH_Ptr, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "MHR_Manager NDD_CMD_VALUE_FREE : unable to free the header of heap \"%s\"", MHH_Ptr->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to free the header of heap: [%s]", MHH_Ptr->Name); } @@ -3994,8 +3833,7 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node if( status = ( SM_Heap_Open_I( heap_name, &heap_ptr, 0, ( SMD_OPEN | SMD_READ), &locked)) != SMS_OK) { - sprintf( SM_Error_Msg, "Error MHR_Manager : unable to open Heap_Name: [%s] for reading", MHH_Ptr->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to open Heap_Name: [%s] for reading", MHH_Ptr->Name); return( status); } @@ -4003,8 +3841,7 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node if( locked != TRUE) { - sprintf( SM_Error_Msg, "Error MHR_Manager : unable to lock Heap_Name: [%s] for reading", MHH_Ptr->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to lock Heap_Name: [%s] for reading", MHH_Ptr->Name); // return( SMS_KO); } @@ -4080,13 +3917,14 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node default: { - printf( "ND_Default_Manager() called with an undefined command %d\n", Command); + LG_LOG_ERROR_1( "Manager called with an undefined command: (%d)", Command); return( NDS_ERRAPI); } } - printf( "ND_Default_Manager() called with command %d (%s)\n", Command, Command_Name); - return( NDS_OK); + LG_LOG_ERROR_1( "Manager internal error in command: (%d)", Command); + + return( NDS_ERRAPI); } @@ -4124,7 +3962,7 @@ SMT_Status SM_MHH_End( SMT_MHH *MHH) ND_Index_Node_Last_Get( &Node, MHH->DSR, NDD_INDEX_PRIMARY); - while (Node) + while( Node) { DSH = (SMT_DSH *)(Node->Value); @@ -4142,8 +3980,7 @@ SMT_Status SM_MHH_End( SMT_MHH *MHH) rc = ND_DataStruct_Value_Remove( MHH->DSR, DSH); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_MHH_End : unable to remove the shared memory segment (address=%p) from the DSR structure", DSH->Start); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to remove the shared memory segment at address: (%p) from the DSR structure", DSH->Start); if( SM_ERROR(rc)) return rc; } @@ -4153,8 +3990,7 @@ SMT_Status SM_MHH_End( SMT_MHH *MHH) rc = ND_Value_Free( MHH->DSR, DSH); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_MHH_End : unable to free the shared memory segment (address=%p)", DSH->Start); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to free the shared memory segment at address: (%p)", DSH->Start); if( SM_ERROR(rc)) return rc; } @@ -4164,11 +4000,10 @@ SMT_Status SM_MHH_End( SMT_MHH *MHH) } else { - rc = ND_DataStruct_Close (MHH->DSR); + rc = ND_DataStruct_Close( MHH->DSR); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_MHH_End : unable to destroy the DSR structure of heap \"%s\"", MHH->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to destroy the DSR structure of heap: [%s]", MHH->Name); } } @@ -4183,15 +4018,13 @@ SMT_Status SM_MHH_End( SMT_MHH *MHH) rc = ND_Deallocator_Exec( MHH->ACR, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_MHH_End : unable to free the ACR root of heap \"%s\"", MHH->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to free the ACR root of heap: [%s]", MHH->Name); } rc = ND_Deallocator_Exec( MHH->FCR, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_MHH_End : unable to free the FCR root of heap \"%s\"", MHH->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to free the FCR root of heap: [%s]", MHH->Name); } /* Suppression du heap de la liste des heaps ouverts */ @@ -4220,15 +4053,14 @@ SMT_Status SM_MHH_End( SMT_MHH *MHH) /* Destruction du sémaphore attaché au heap */ - semctl (MHH->SemId, 0, IPC_RMID, Sem_Ctl); + semctl( MHH->SemId, 0, IPC_RMID, Sem_Ctl); /* Désallocation de la structure du MHH */ rc = ND_Deallocator_Exec( MHH, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_MHH_End : unable to free the header of heap \"%s\"", MHH->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to free the header of heap: [%s]", MHH->Name); } return rc; @@ -4342,12 +4174,11 @@ NDT_Status SM_DSR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node { size_t Current_Size; - ND_DataStruct_Traverse (MHH_Ptr->DSR, NDD_CMD_VALUE_SUM, (void *)&Current_Size); + ND_DataStruct_Traverse( MHH_Ptr->DSR, NDD_CMD_VALUE_SUM, (void *)&Current_Size); if( Current_Size + Segment_Size > MHH_Ptr->Limit_Size) { - sprintf( SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_ALLOC : the heap limit size would be exceeded"); - SM_Error_Print(); + LG_LOG_ERROR_0( "The heap limit size would be exceeded"); *DSH_Ptr_Ptr = NULL; @@ -4359,38 +4190,44 @@ NDT_Status SM_DSR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node if( ND_Allocator_Exec( (void **)DSH_Ptr_Ptr, sizeof (SMT_DSH), MHH_Ptr->DSR->Allocator_Name, MHH_Ptr->DSR->Allocator_Ptr, NULL) != NDS_OK) { - sprintf( SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_ALLOC : unable to allocate memory for the new data segment header"); - SM_Error_Print(); - + LG_LOG_ERROR_0( "Unable to allocate memory for the new data segment header"); + return( NDS_KO); } + /* Création d'un segment de mémoire partagée */ - if( ((*DSH_Ptr_Ptr)->MemId = shmget (IPC_PRIVATE, Segment_Size, 0777|IPC_CREAT|IPC_EXCL)) == -1) + if( ( ( *DSH_Ptr_Ptr)->MemId = shmget (IPC_PRIVATE, Segment_Size, 0777|IPC_CREAT|IPC_EXCL)) == -1) { - switch (errno) + switch( errno) { case EINVAL: - sprintf( SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_ALLOC : the size of the shared memory segment (%d) is out of the system-imposed bounds", Segment_Size); + { + LG_LOG_ERROR_1( "The size of the shared memory segment: (%d) is out of the system-imposed bounds", Segment_Size); break; + } case ENOMEM: - sprintf( SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_ALLOC : the amount of memory is not sufficient to create the shared memory segment"); + { + LG_LOG_ERROR_0( "The amount of memory is not sufficient to create the shared memory segment"); break; + } case ENOSPC: - sprintf( SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_ALLOC : the number of shared memory segments exceeds the system-imposed limit"); + { + LG_LOG_ERROR_0( "The number of shared memory segments exceeds the system-imposed limit"); break; + } - default : - sprintf( SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_ALLOC : unknown error (%d) while creating a shared memory segment", errno); + default: + { + LG_LOG_ERROR_1( "Unknown error: (%d) while creating a shared memory segment", errno); break; + } } - SM_Error_Print(); - - ND_Deallocator_Exec( (*DSH_Ptr_Ptr), MHH_Ptr->DSR->Deallocator_Name, MHH_Ptr->DSR->Deallocator_Ptr, NULL); - + ND_Deallocator_Exec( ( *DSH_Ptr_Ptr), MHH_Ptr->DSR->Deallocator_Name, MHH_Ptr->DSR->Deallocator_Ptr, NULL); + return( NDS_KO); } @@ -4398,50 +4235,51 @@ NDT_Status SM_DSR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node errno = 0; #ifndef __hpux - (*DSH_Ptr_Ptr)->Start = shmat( (*DSH_Ptr_Ptr)->MemId, (void *)((size_t)(SM_Base->Attach) - Segment_Size), SHM_RND); + ( *DSH_Ptr_Ptr)->Start = shmat( ( *DSH_Ptr_Ptr)->MemId, (void *)( (size_t)(SM_Base->Attach) - Segment_Size), SHM_RND); #else - (*DSH_Ptr_Ptr)->Start = shmat( (*DSH_Ptr_Ptr)->MemId, 0, 0); + ( *DSH_Ptr_Ptr)->Start = shmat( ( *DSH_Ptr_Ptr)->MemId, 0, 0); #endif if( errno) { - sprintf( SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_ALLOC : unable to attach the shared memory segment to the current process (error %d)", errno); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to attach the shared memory segment to the current process, error: (%d)", errno); - shmctl ((*DSH_Ptr_Ptr)->MemId, IPC_RMID, 0); + shmctl( ( *DSH_Ptr_Ptr)->MemId, IPC_RMID, 0); ND_Deallocator_Exec( *DSH_Ptr_Ptr, MHH_Ptr->DSR->Deallocator_Name, MHH_Ptr->DSR->Deallocator_Ptr, NULL); return( NDS_KO); } - SM_Base->Attach = (*DSH_Ptr_Ptr)->Start; + SM_Base->Attach = ( *DSH_Ptr_Ptr)->Start; + /* Initialisation des informations de l'entête */ - (*DSH_Ptr_Ptr)->Size = Segment_Size; + ( *DSH_Ptr_Ptr)->Size = Segment_Size; + /* Création d'un chunk libre au début du segment de données */ - Chunk_Node = (NDT_Node *)(*DSH_Ptr_Ptr)->Start; + Chunk_Node = (NDT_Node *)( *DSH_Ptr_Ptr)->Start; - Chunk = (SMT_Chunk *)((size_t)Chunk_Node + sizeof (NDT_Node) ); + Chunk = (SMT_Chunk *)( (size_t)Chunk_Node + sizeof (NDT_Node) ); Chunk_Node->Value = Chunk; - Chunk->Data = (void *)((size_t)Chunk + sizeof (SMT_Chunk) ); + Chunk->Data = (void *)( (size_t)Chunk + sizeof (SMT_Chunk) ); - Chunk->Size = (*DSH_Ptr_Ptr)->Size - sizeof (NDT_Node) - sizeof (SMT_Chunk); + Chunk->Size = ( *DSH_Ptr_Ptr)->Size - sizeof (NDT_Node) - sizeof (SMT_Chunk); + /* Ajout du chunk libre à la liste des chunks libres du heap */ if( ND_Index_Node_Add( MHH_Ptr->FCR, NDD_INDEX_PRIMARY, Chunk_Node) != NDS_OK) { - sprintf( SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_ALLOC : unable to add a first chunk to the FCR structure of heap \"%s\"", MHH_Ptr->Name); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to add a first chunk to the FCR structure of heap: [%s]", MHH_Ptr->Name); - shmctl ((*DSH_Ptr_Ptr)->MemId, IPC_RMID, 0); + shmctl ( ( *DSH_Ptr_Ptr)->MemId, IPC_RMID, 0); - ND_Deallocator_Exec( (*DSH_Ptr_Ptr), MHH_Ptr->DSR->Deallocator_Name, MHH_Ptr->DSR->Deallocator_Ptr, NULL); + ND_Deallocator_Exec( ( *DSH_Ptr_Ptr), MHH_Ptr->DSR->Deallocator_Name, MHH_Ptr->DSR->Deallocator_Ptr, NULL); return( NDS_KO); } @@ -4473,22 +4311,27 @@ NDT_Status SM_DSR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node if( shmctl (DSH_Ptr->MemId, IPC_RMID, 0) == -1) { - switch (errno) + switch( errno) { case EPERM: - sprintf( SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_FREE : current process (%d) is not allowed to destroy the shared memory segment %d", (int)getpid (), DSH_Ptr->MemId); + { + LG_LOG_ERROR_2( "Current process: (%d) is not allowed to destroy the shared memory segment: (%d)", (int)getpid (), DSH_Ptr->MemId); break; + } case EINVAL: - sprintf( SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_FREE : no shared memory segment exists for identifier %d", DSH_Ptr->MemId); + { + LG_LOG_ERROR_1( "No shared memory segment exists for identifier: (%d)", DSH_Ptr->MemId); break; + } - default : - sprintf( SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_FREE: unknown error %d while destroying the shared memory segment %d", errno, DSH_Ptr->MemId); + default: + { + LG_LOG_ERROR_2( "Unknown error: (%d) while destroying the shared memory segment: (%d)", errno, DSH_Ptr->MemId); break; + } } - SM_Error_Print(); return SMS_ERRSHM; } @@ -4498,8 +4341,7 @@ NDT_Status SM_DSR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node rc = ND_Deallocator_Exec( DSH_Ptr, Root_Ptr->Deallocator_Name, Root_Ptr->Deallocator_Ptr, NULL); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_FREE : the data segment header is nul"); - SM_Error_Print(); + LG_LOG_ERROR_0( "The data segment header is nul"); return rc; } @@ -4697,13 +4539,14 @@ NDT_Status SM_DSR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node default: { - printf( "ND_Default_Manager() called with an undefined command %d\n", Command); + LG_LOG_ERROR_1( "Manager called with an undefined command: (%d)", Command); return( NDS_ERRAPI); } } - printf( "ND_Default_Manager() called with command %d (%s)\n", Command, Command_Name); - return( NDS_OK); + LG_LOG_ERROR_1( "Manager internal error in command: (%d)", Command); + + return( NDS_ERRAPI); } @@ -4724,14 +4567,13 @@ SMT_Status SM_DataSegment_Open ( SMT_DSH *DSH) ce segment soient valides. */ - shmdt ((void *)DSH->Start); + shmdt ( (void *)DSH->Start); errno = 0; Ptr = shmat( DSH->MemId, DSH->Start, 0); if( errno) { - sprintf( SM_Error_Msg, "SM_DataSegment_Open : unable to attach the shared memory segment at the specified address %p (error %d)", DSH->Start, errno); - SM_Error_Print(); + LG_LOG_ERROR_2( "Unable to attach the shared memory segment at the specified address: (%p) error: (%d)", DSH->Start, errno); return SMS_ERRSHM; } @@ -4747,11 +4589,11 @@ SMT_Status SM_DataSegment_Open ( SMT_DSH *DSH) /* Fermeture d'un segment de données */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_DataSegment_Close ( SMT_DSH *DSH) +SMT_Status SM_DataSegment_Close( SMT_DSH *DSH) { /* On détache le segment de mémoire partagée du processus courant */ - shmdt ((void *)DSH->Start); + shmdt ( (void *)DSH->Start); return SMS_OK; } @@ -4774,13 +4616,13 @@ size_t SM_DataSegment_Compress ( SMT_DSH *DSH, NDT_Root *FCR) int Found = FALSE; - DSH_End = (void *)((size_t)(DSH->Start) + DSH->Size); + DSH_End = (void *)( (size_t)(DSH->Start) + DSH->Size); /* Recherche du premier chunk libre contenu dans le segment courant */ ND_Index_Node_First_Get( &Node, FCR, NDD_INDEX_PRIMARY); - while (Found == FALSE && Node) + while( Found == FALSE && Node) { if( Node > (NDT_Node *)DSH_End) Node = NULL; else @@ -4796,7 +4638,7 @@ size_t SM_DataSegment_Compress ( SMT_DSH *DSH, NDT_Root *FCR) ND_Index_Node_Next_Get( &Next_Node, Node); - while (Next_Node && (void *)Next_Node < DSH_End) + while( Next_Node && (void *)Next_Node < DSH_End) { Chunk = (SMT_Chunk *)(Node->Value); @@ -4804,9 +4646,9 @@ size_t SM_DataSegment_Compress ( SMT_DSH *DSH, NDT_Root *FCR) /* Si le chunk suivant est "collé" au chunk courant, alors on les fusionne */ - if( Next_Node == (NDT_Node *)((size_t)(Chunk->Data) + Chunk->Size)) + if( Next_Node == (NDT_Node *)( (size_t)(Chunk->Data) + Chunk->Size)) { - ND_Index_Node_Remove (Next_Node); + ND_Index_Node_Remove( Next_Node); Compress = sizeof (SMT_Chunk) + sizeof (NDT_Node); @@ -5124,13 +4966,14 @@ NDT_Status SM_ACR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node default: { - printf( "ND_Default_Manager() called with an undefined command %d\n", Command); + LG_LOG_ERROR_1( "Manager called with an undefined command: (%d)", Command); return( NDS_ERRAPI); } } - printf( "ND_Default_Manager() called with command %d (%s)\n", Command, Command_Name); - return( NDS_OK); + LG_LOG_ERROR_1( "Manager internal error in command: (%d)", Command); + + return( NDS_ERRAPI); } @@ -5425,13 +5268,14 @@ NDT_Status SM_FCR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node default: { - printf( "ND_Default_Manager() called with an undefined command %d\n", Command); + LG_LOG_ERROR_1( "Manager called with an undefined command: (%d)", Command); return( NDS_ERRAPI); } } - printf( "ND_Default_Manager() called with command %d (%s)\n", Command, Command_Name); - return( NDS_OK); + LG_LOG_ERROR_1( "Manager internal error in command: (%d)", Command); + + return( NDS_ERRAPI); } @@ -5448,11 +5292,10 @@ SMT_Status SM_Heap_Lock_Set ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) if( Lock_Mode & SMD_READ) { - rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_SSL, 2); + rc = SM_Semaphore_Operate( MHH->SemId, SM_SemOp_SSL, 2); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock_Set : unable to lock the heap for reading"); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to lock the heap: [%s] for reading", MHH->Name); return rc; } @@ -5460,11 +5303,10 @@ SMT_Status SM_Heap_Lock_Set ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) if( Lock_Mode & SMD_WRITE) { - rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_SEL, 2); + rc = SM_Semaphore_Operate( MHH->SemId, SM_SemOp_SEL, 2); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock_Set : unable to lock the heap for writing"); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to lock the heap: [%s] for writing", MHH->Name); return rc; } @@ -5481,7 +5323,7 @@ SMT_Status SM_Heap_Lock_Set ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) /* Changement d'un verrou sur un heap */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Lock_Change ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) +SMT_Status SM_Heap_Lock_Change( SMT_MHH * MHH, SMT_Flags Lock_Mode ) { SMT_Status rc; @@ -5495,33 +5337,30 @@ SMT_Status SM_Heap_Lock_Change ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) => On passe donc par un déverrouillage intermédiaire. */ - if( (rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_RSL, 2)) != SMS_OK) + if( (rc = SM_Semaphore_Operate( MHH->SemId, SM_SemOp_RSL, 2)) != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock_Change : unable to transform the heap lock for writing"); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to transform the heap: [%s] lock for writing", MHH->Name); return rc; } - if( (rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_SEL, 2)) != SMS_OK) + if( (rc = SM_Semaphore_Operate( MHH->SemId, SM_SemOp_SEL, 2)) != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock_Change : unable to transform the heap lock for writing"); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to transform the heap: [%s] lock for writing", MHH->Name); /* On tente de revenir à l'état de verrouillage précédent */ - SM_Semaphore_Operate (MHH->SemId, SM_SemOp_SSL, 2); + SM_Semaphore_Operate( MHH->SemId, SM_SemOp_SSL, 2); return rc; } } else if( Lock_Mode & SMD_READ) { - rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_TSL, 2); + rc = SM_Semaphore_Operate( MHH->SemId, SM_SemOp_TSL, 2); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock_Change : unable to transform the heap lock for reading"); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to transform the heap: [%s] lock for reading", MHH->Name); return rc; } @@ -5538,17 +5377,16 @@ SMT_Status SM_Heap_Lock_Change ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) /* Libération d'un verrou sur un heap */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Lock_Release ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) +SMT_Status SM_Heap_Lock_Release( SMT_MHH * MHH, SMT_Flags Lock_Mode ) { SMT_Status rc; if( Lock_Mode & SMD_READ) { - rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_RSL, 2); + rc = SM_Semaphore_Operate( MHH->SemId, SM_SemOp_RSL, 2); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock_Release : unable to unlock the heap which had been locked for reading"); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to unlock the heap: [%s] which had been locked for reading", MHH->Name); return rc; } @@ -5556,11 +5394,10 @@ SMT_Status SM_Heap_Lock_Release ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) if( Lock_Mode & SMD_WRITE) { - rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_REL, 2); + rc = SM_Semaphore_Operate( MHH->SemId, SM_SemOp_REL, 2); if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Lock_Release : unable to unlock the heap which had been locked for writing"); - SM_Error_Print(); + LG_LOG_ERROR_1( "Unable to unlock the heap: [%s] which had been locked for writing", MHH->Name); return rc; } @@ -5577,49 +5414,69 @@ SMT_Status SM_Heap_Lock_Release ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) /* Opération sur un sémaphore */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Semaphore_Operate (int SemId, struct sembuf * Operations, unsigned int Nb_Oper) +SMT_Status SM_Semaphore_Operate( int SemId, struct sembuf * Operations, unsigned int Nb_Oper) { - if( semop (SemId, Operations, Nb_Oper) == -1) + if( semop( SemId, Operations, Nb_Oper) == -1) { - switch (errno) + switch( errno) { case EAGAIN: - sprintf( SM_Error_Msg, "SM_Semaphore_Operate : the operation would result in suspension of the calling process but the operations have been defined in no wait mode"); + { + LG_LOG_ERROR_0( "The operation would result in suspension of the calling process but the operations have been defined in no wait mode"); + return SMS_NO_WAIT; - break; + } case EACCES: - sprintf( SM_Error_Msg, "SM_Semaphore_Operate : current process is not allowed to operate on semaphore %d", SemId); + { + LG_LOG_ERROR_1( "Current process is not allowed to operate on semaphore: (%d)", SemId); + break; + } case EIDRM: - sprintf( SM_Error_Msg, "SM_Semaphore_Operate : semaphore %d does not exist", SemId); + { + LG_LOG_ERROR_1( "Semaphore: (%d) does not exist", SemId); + break; + } case EINTR: - sprintf( SM_Error_Msg, "SM_Semaphore_Operate : a signal was received while operating on semaphore %d", SemId); + { + LG_LOG_ERROR_1( "A signal was received while operating on semaphore: (%d)", SemId); + return SMS_ERRSIG; - break; + } case EINVAL: - sprintf( SM_Error_Msg, "SM_Semaphore_Operate : the semaphore identifier %d is incorrect or the number of operations which can be done in UNDO mode exceeds the system-imposed limit", SemId); + { + LG_LOG_ERROR_1( "The semaphore identifier: (%d) is incorrect or the number of operations which can be done in UNDO mode exceeds the system-imposed limit", SemId); + break; + } case ENOSPC: - sprintf( SM_Error_Msg, "SM_Semaphore_Operate : the maximum number of process which can operate on semaphore in UNDO mode has been reached"); + { + LG_LOG_ERROR_1( "The maximum number of process which can operate on semaphore: (%d) in UNDO mode has been reached", SemId); + break; + } case ERANGE: - sprintf( SM_Error_Msg, "SM_Semaphore_Operate: the value of semaphore %d has reached the system-imposed limit", SemId); - break; + { + LG_LOG_ERROR_1( "The value of semaphore: (%d) has reached the system-imposed limit", SemId); - default : - sprintf( SM_Error_Msg, "SM_Semaphore_Operate : unknown error %d while operating on semaphore %d", errno, SemId); break; + } + + default: + { + LG_LOG_ERROR_2( "Unknown error: (%d) while operating on semaphore: (%d)", errno, SemId); + + break; + } } - SM_Error_Print(); - return SMS_ERRSEM; } @@ -5659,6 +5516,7 @@ char *SM_Lock_Status_Get( const char *Type_Name, void *Struct_Ptr) else { strcpy( status, "Unknown"); + return( status); } } @@ -5670,12 +5528,14 @@ char *SM_Lock_Status_Get( const char *Type_Name, void *Struct_Ptr) case 0: { sprintf( status, "Exclusive Lock for PId: (%ld)", writer); + break; } case 1: { sprintf( status, "Unlocked"); + break; } @@ -5689,6 +5549,7 @@ char *SM_Lock_Status_Get( const char *Type_Name, void *Struct_Ptr) { sprintf( status, "Shared Lock Process_Nb: (%d)", i - 1); } + break; } } @@ -5700,19 +5561,6 @@ char *SM_Lock_Status_Get( const char *Type_Name, void *Struct_Ptr) -/*------------------------------------------------------------------------------*/ -/* Routine d'affichage d'un message d'erreur */ -/*------------------------------------------------------------------------------*/ - -void SM_Error_Print( void ) -{ - if( SM_stderr) fprintf( SM_stderr, "Error %s\n", SM_Error_Msg); -} - - - - - /*------------------------------------------------------------------------------*/ /* Add context prefix to heap name */ /*------------------------------------------------------------------------------*/ diff --git a/lib/libshmem.h b/lib/libshmem.h index 53ec662..092feab 100644 --- a/lib/libshmem.h +++ b/lib/libshmem.h @@ -99,6 +99,8 @@ SMT_Heap * System_Heap; NDT_Root * Opened_Heap_List; + + /* Taille par défaut des chunks alloués dans le heap système : Cette taille est fixée à la taille maximale des chunks pouvant @@ -115,6 +117,8 @@ NDT_Root * Opened_Heap_List; #define FREE_CHUNK_LIMIT 3 + + int SM_Instance; char * SM_Context; @@ -168,6 +172,13 @@ typedef union semun unsigned short int * array; } semun; +/*------------------------------------------------------------------------------*/ +/* */ +/*------------------------------------------------------------------------------*/ + +#define SM_LIBSHMEM_OPEN_CHECK() if( !SM_Base) { LG_LOG_ERROR_0( "LibShMem library is not open"); return( SMS_ERRAPI); } +#define SM_HEAP_NAME_CHECK(ptr) if( !(ptr)) { LG_LOG_ERROR_0( "Heap name is undefined"); return( SMS_ERRAPI); } +#define SM_HEAP_CHECK( ptr) if( !(ptr)) { LG_LOG_ERROR_0( "Heap is undefined"); return( SMS_ERRAPI); } @@ -176,127 +187,192 @@ typedef union semun /*------------------------------------------------------------------------------*/ /* Allocation de mémoire dans la base */ /*------------------------------------------------------------------------------*/ + NDT_Status SM_Base_Alloc( void **, size_t, void *); + + /*------------------------------------------------------------------------------*/ /* Désallocation de mémoire dans la base */ /*------------------------------------------------------------------------------*/ + NDT_Status SM_Base_Free( void *, void *); + + /*------------------------------------------------------------------------------*/ /* Allocation de mémoire dans le heap système */ /*------------------------------------------------------------------------------*/ + NDT_Status SM_System_Alloc( void **, size_t, void *); + + /*------------------------------------------------------------------------------*/ /* Désallocation de mémoire dans le heap système */ /*------------------------------------------------------------------------------*/ + NDT_Status SM_System_Free( void *, void *); + + /*------------------------------------------------------------------------------*/ /* Initialisation de la base */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Base_Init (void); + + /*------------------------------------------------------------------------------*/ /* Terminaison de la base */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Base_End (void); + + /*------------------------------------------------------------------------------*/ /* Ouverture de la base */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Base_Open (void); + + /*------------------------------------------------------------------------------*/ /* Fermeture de la base */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Base_Close (void); + + /*------------------------------------------------------------------------------*/ /* Pose d'un verrou sur la base : */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Base_Lock (SMT_Flags); + + /*------------------------------------------------------------------------------*/ /* Libération d'un verrou sur la base : */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Base_Unlock (SMT_Flags); + + /*------------------------------------------------------------------------------*/ /* Fonction manager de la liste des heaps ouverts */ /*------------------------------------------------------------------------------*/ + NDT_Status SM_Opened_Heap_List_Manager ( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); + + /*------------------------------------------------------------------------------*/ /* Fonction manager du MHR (Memory Heap Root) */ /*------------------------------------------------------------------------------*/ + NDT_Status MHR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); + + /*------------------------------------------------------------------------------*/ /* Destruction d'un MHH (Memory Heap Header) */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_MHH_End (SMT_MHH *); + + /*------------------------------------------------------------------------------*/ /* Fonction manager pour un DSR (Data Segment Root) */ /*------------------------------------------------------------------------------*/ + NDT_Status SM_DSR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); + + /*------------------------------------------------------------------------------*/ /* Ouverture d'un segment de données */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_DataSegment_Open (SMT_DSH *); + + /*------------------------------------------------------------------------------*/ /* Fermeture d'un segment de données */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_DataSegment_Close (SMT_DSH *); + + /*------------------------------------------------------------------------------*/ /* Compression d'un segment de données */ /*------------------------------------------------------------------------------*/ + size_t SM_DataSegment_Compress (SMT_DSH *, NDT_Root *); + + /*------------------------------------------------------------------------------*/ /* Fonction manager pour un ACR (Allocated Chunk Root) */ /*------------------------------------------------------------------------------*/ + NDT_Status SM_ACR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); + + /*------------------------------------------------------------------------------*/ /* Fonction manager pour un FCR (Free Chunk Root) */ /*------------------------------------------------------------------------------*/ + NDT_Status SM_FCR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); + + /*------------------------------------------------------------------------------*/ /* Pose d'un verrou sur un heap : */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Lock_Set (SMT_MHH *, SMT_Flags); + + /*------------------------------------------------------------------------------*/ /* Changement d'un verrou sur un heap : */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Lock_Change (SMT_MHH *, SMT_Flags); + + /*------------------------------------------------------------------------------*/ /* Libération d'un verrou sur un heap : */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Lock_Release (SMT_MHH *, SMT_Flags); + + /*------------------------------------------------------------------------------*/ /* Opération sur un sémaphore */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Semaphore_Operate (int, struct sembuf *, unsigned int); + + /*------------------------------------------------------------------------------*/ /* Récupère sous forme explicite l'état d'un verrou */ /*------------------------------------------------------------------------------*/ -char * SM_Lock_Status_Get (const char *, void *); -/*------------------------------------------------------------------------------*/ -/* Routine d'affichage d'un message d'erreur */ -/*------------------------------------------------------------------------------*/ -void SM_Error_Print (void); +char * SM_Lock_Status_Get (const char *, void *); diff --git a/util/smadmin.c b/util/smadmin.c index a620da5..461242c 100644 --- a/util/smadmin.c +++ b/util/smadmin.c @@ -47,6 +47,10 @@ //VER_INFO_EXPORT (smadmin, "$Revision: 2.3 $", "$Name: $", __FILE__, "$Author: agibert $") +#define LGD_MODULE_NAME "sma" + + + #define USAGE "Usage : %s [ --help | --version [-v] | --create | --destroy ]\n" #define QUIT 0 @@ -232,14 +236,24 @@ void Entry_Prompt( void *Out_Ptr, char *Prompt_Ptr, short Type) int main( int argc, char **argv) { - int choice; - char name[ NAME_SIZE]; - int Mode, Locked; - void *ptr; - char answer[ 10]; - SMT_Heap *Heap; - int Nb_Detected, Nb_Corrected; - size_t size; + LGT_Status lg_status; + int choice; + char name[ NAME_SIZE]; + int Mode, Locked; + void *ptr; + char answer[ 10]; + SMT_Heap *Heap; + int Nb_Detected, Nb_Corrected; + size_t size; + + + if( ( lg_status = LG_Library_Open( LGD_LOG_WRITER_DEFAULT, true)) != LGS_OK) + { + fprintf( stderr, "Can't open LibLog library: (%d)\n", lg_status); + return( -1); + } + + LG_LOG_INFO_0( "Start SMAdmin"); /* Lancement de commande d'administration */ @@ -546,5 +560,13 @@ int main( int argc, char **argv) choice = Print_Menu(); } + LG_LOG_INFO_0( "End SMAdmin"); + + if( ( lg_status = LG_Library_Close( true)) != LGS_OK) + { + fprintf( stderr, "Can't close LibLog library: (%d)\n", lg_status); + return( -1); + } + return( 0); }