IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

Erreur de segmentation après affichage d'un tableau d'entier


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Rédacteur/Modérateur
    Avatar de Trap D
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    4 943
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 4 943
    Par défaut
    Citation Envoyé par NeilaK
    Une petite remarque pour Trap D : je n'ai pas écris tout le code moi même, c'est un code libre d'un compopsant logiciel formé par des modules kernel écrits en C. Mon rôle consiste à le modifier pour qu'il prenne en charge un protocole que j'ai défini, je ne peux pas donc tout vérifier.
    Ma remarque n'était pas contre toi. Je sais bien que tu n'as pas tout écrit, c'est peut-être le danger de ce genre de code libre, il n'est pas forcément bien écrit, et si chacun y ajoute sa patte, ça peut amener à des incohérences.
    "La haine seule fait des choix" - Koan Zen
    "Il ne faut pas être meilleur que les autres, il faut être meilleur que soi." Albert Jacquard
    "Ceux qui savent où ils ont posé leur parapluie ne sont pas alcooliques." - pgibonne.
    Faites du Prolog, ça vous changera les idées !
    Ma page Prolog
    Mes codes sources commentés

    Mon avatar : La Madeleine à la veilleuse de Georges de La Tour

  2. #2
    Membre averti
    Inscrit en
    Février 2004
    Messages
    40
    Détails du profil
    Informations forums :
    Inscription : Février 2004
    Messages : 40
    Par défaut
    Je suis désolée de mettre le code directement sur le forum, j'aipas un autre choix
    Voici le code du fichier TTCBneighborhood.c que j'ai programmé moi même
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    /* Agreement test */
     
    #include "tcb/tcb.h"
    #include "tcb/ttcb.h"
    #include <sys/time.h>
     
    #include <unistd.h>
    #include <stdlib.h>
     
    descriptor_t descriptor;
     
    /*DEFINE THE AGREEMENT TYPE HERE.
      TTCB_TBA_RMULTICAST | TTCB_TBA_MAJORITY | TTCB_TBA_AND | TTCB_TBA_OR | TTCB_TBA_XOR
    */
     
    // a tester : un autre multicast qui ne propose rien, voir le résultat du premier
    #define AGREEMENT_TYPE TTCB_TBA_AND
    #define periodicNeighborhood 1
     
     
    void printMask(mask_t mask, int len)  // prints a mask returned by decide
    {
    	int i;
    	mask_t bit = 1;
     
    	for (i = 0; i < len; i++) {
    		if ((bit & mask) == 0) printf("0"); else printf("1");
    		bit = bit << 1;
    	}
    }
     
     
     
    int main()
    {
    	propose_out_t outp;
    	decide_out_t outd;
    	timestamp_out_t ts_out;
    	error_out_t err_out;
    	unsigned i,eid;
    	int curr_time;
    	int size_elist,size_nomlist,size_PKlist;
     
    	elist_t elist;
     
    	nomlist_t nomlist;
    	PKlist_t PKlist;
     
    	value_t value;
    	TCBtimestamp tstart;
    	TCBtimestamp globalTimestamp;
     
    	int TTCBerror;
    ///My added variables
    	char TimestampString[20];
    	char eidString[20];
    	//for kernel info 29_12_05
    	tcb_kernel_info_t krn_info;
    	int ret ;
    	int number_of_machines ;
    	int lenneighlist; // longuer du tableau des id
    	int k;
     
    	//for kernel info 29_12_05
     
    // TTCB id
     	//char* TTCBIDString[20];
    	char TTCBIDString[20];
     
    	//for the corresponding TTCB identification
    	nom_t Iam;
    	RSA_public_key MyPK;
     
    	// TTCB identifications given by the user
     
    	char* TTCBnom; //nom du TTCB comme chaine de caractère
    	char* TTCBPKString ; //cle publique du ttcb
    	char* EntityID ; // l'identifiant d'une entité participante
    	char * intermediaire[20]; // les tokens intermediaires
    // pour neighborhood
    	char TTCBnomN[7]; //nom du TTCB comme chaine de caractère
    	char TTCBPKStringN[20] ; //cle publique du ttcb
    	char EntityIDN[2] ; // l'identifiant d'une entité participante
     
    	int a,b,c;
     
    	char* concatString;
    	char* concatString2;
    	char* concatString3;
    	char* concatString4;
    	char* concatString5;
    	char* concatString6;
     
     
    	int tailleTimestamp;
    	int tailleEid;
    	int j =1;
     
    	int proposed; //boolean value for the proposition
     
    // If descriptor is declared global, this is not necessary!
    while (j==1){
    	memset(&descriptor,0, sizeof(descriptor_t));
     
    	if ( (TTCBerror = openTCBConnection(&descriptor))<OK) {
    		printTCBerror(TTCBerror);
    		exit(1);
    		return 1;
    	}
    	//printf("My eid is: %u  (ltid=%u ind=%u)\n", descriptor.eid, descriptor.eid /256, descriptor.eid %256);
     
    	Iam=descriptor.nom;
    	printf ("My name is %s \n", Iam);
    	MyPK=descriptor.TTCB_PublicKey;
    	printf("My PK is %u \n",MyPK);
    	eid=descriptor.eid;
    	printf("My eid is %u \n",eid);
     
     
    // This periodic treatment is always done for ttcb neighborhood
    // Dans le cas ou tstart = 1, ça fait référence à la partie du TTCB neighborhood
    while (periodicNeighborhood)
     
    {
     if (eid!=0) // L'entité 0 ne doit pas proposer
    	{
    	// ajouté le 29_12_05 : je veux récuperer l'info du kernel
     
    	// gather TTCB kernel info
    	ret = getTCBKernelInfo(&descriptor, &krn_info);
     
    	if (ret < 0){
    		closeTCBConnection(&descriptor);
    		printTCBerror(ret);
    		printf("On getting TTCB kernel info...\n");
    		exit(1);
    	}
     
    	number_of_machines = krn_info.number_of_system_machines;
    	printf ("Kernel Info : Le nombre de machines est %d \n ",krn_info.number_of_system_machines);
    	lenneighlist=krn_info.TCBlenneighlist;
    	printf ("Kernel Info : Le nombre d'entités impliquées est %d \n ",lenneighlist);
    	for (k=0;k<lenneighlist;k++)
     
    	printf ("Agreement Kernel Info : L'entité est %d \n ",&krn_info.TCBneighlist[k]);//works but non correspondent value
    	printf ("Agreement Kernel Info : L'entité est %d \n ",krn_info.TCBneighlist[k]);//erreur segmentation
    	//Fin afficher les "kernel info" entités reçues à partir du kernel 02_01_2006
     
    	// Chaque agent entre automatiquement en agrément avec tous les TTCBs présents  ( 3 TTCBs sont présents)
    	//usleep(60000);
    	printf (" Its time for the TTCB neighborhood phase ");
     
    	a=sprintf(TTCBnomN,"%s",Iam);
    	b=sprintf(TTCBPKStringN,"%d",MyPK);
    	c=sprintf(EntityIDN,"%u",eid);
     
    	if( (a>7) || (b > 20) ||(c>2) || (tailleTimestamp>20))
    	{
       		printf("Not enouhgh memory has been allocated to the strings \n");
    	}
     
    	else
           {
    	for (i=0;i<3;i++)
    	  { elist[i] =i+1;
    	   printf("The eid added to the elist is %u \n",elist[i]);
    	    nomlist[i]= TTCBnomN;
    	   // PKlist[i] =TTCBPKStringN;
    	  }
     
    	elist[i+1] = END_ELIST;
    	size_elist = i+1;
    	size_nomlist = i+1;
    	size_PKlist = i+1;
     
    	// the tstart is also nedded for identifying the agreement
    	tstart = 1;
    	// Get the global timestamp
    	TTCBerror = getTCBGlobalTimestamp(&descriptor, &globalTimestamp); //call TTCB
    	if (TTCBerror < 0) {
    		print_error_TTCB(TTCBerror);
    		goto finalize;
    	}
    	printf("Current time is %lld s.\n ", globalTimestamp/1000000000);
    	tailleTimestamp = sprintf (TimestampString,"%lld",globalTimestamp);
    	printf("result of timestamp conversion %s \n", TimestampString);
     
     
    			//Affichage
    		printf("****************** Verif ******************* \n");
    		printf("result of ttcb identity conversion %s \n", TTCBnomN);
    		printf("result of ttcb pk conversion %s \n", TTCBPKStringN);
    		printf("result of eid conversion %s \n", EntityIDN);
     
    		concatString5=strcat(TimestampString,"*");
     
    		concatString6=strcat(concatString5,EntityIDN);
     
    		concatString=strcat(concatString6,"*");
    		//printf("result of the first concat is %s \n", concatString);
     
    		concatString2 = strcat(concatString,TTCBnomN);
    		concatString3 = strcat(concatString2,"*");
    		strcpy((char *)value,concatString3 );
    		memcpy(value,concatString3, sizeof(value_t));
    		printf("the value proposed is %s \n", value);
     
     
    	} // end if( (a>7) || (b > 20) ||(c>2) || (tailleTimestamp>20))
     
    	printf("I am calling TTCB for propose \n");
    	propose(&descriptor, elist, nomlist, PKlist, tstart, AGREEMENT_TYPE , value, &outp); //call TTCB
    	printf("TTCB called for propose \n");
    	if (outp.error < 0) {
    	  print_error_TTCB(outp.error);
    	  goto finalize;
    	}
     
    	// decide value
            do {
     
    	  decide(&descriptor, outp.tag, &outd); //call TTCB
    	  usleep(300);
     
            } while (outd.error == AGREEMENT_RUNNING);
     
    	if (outd.error < 0) {
    	  print_error_TTCB(outd.error);
    	  goto finalize;
    	}
    	printf("PropTimeStamp received by the decide routine is %lld \n ", outd.prop);
    	printf("Kernel info : derniere entite %d \n ", outd.test);
    	//here
    	printf("Value received by the decide routine is %s \n ", outd.receivedvalue);
    	printf("Decide ok. Value decided: %s proposed-ok: ", outd.value);
    	printMask(outd.mask1, size_elist);
    	printf("  proposed-any: ");
    	printMask(outd.mask2, size_elist);
    	printf("\n");
    	usleep(300);
    	//usleep(60000); 6 ms
     
    }// Fin  if (eid!=0) // L'entité 0 ne doit pas proposer
     
    }// Fin while (periodicNeighborhood)
     
    // End periodic neihborhood treatment
     
     
     finalize:
            printf("Going to close connection!\n");
            closeTTCBConnection(&descriptor, &err_out); //call TTCB
    	printf("Ending...\n\n");
    	return 0;
    }// fin while j ==1
    }
    Voici maitenant le code du module kernel tcb_module.c, j'ai principalement modifié la fonction ttcbpropose et ttcbdecide , je vais juste mettre le code de ttcbdecide car le fichier est très long

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    #ifdef DIST_AGREEMENT
    void TTCBdecide(int fifo, decide_in_t *in)
    {
    	value_t copy;
     
    	char * tokenPropTime;
     
    	int tailleEid ; //for kernel info 29_12_05
     
    	char concatString[60] = "+";
    	char  intermediaire[20];
    	char * existingID;
     
    	short i, j;
    	decide_out_t out;
    	TCBtimestamp actTime,PropTimeStamp;
    	mask_t bit = 01;
    	short all_proposed = 1;
    	unsigned long long max_time;
    	unsigned short Rindex;
    	int MaxIndex; /* This indicates the index of the most voted value */
    	int MaxValues; /* This indicates the number of values proposed */
    	int cycling; /* Just a cycling variable for a loop */
     
    	int ValueFound=0;
    	struct {
    		value_t value;
    		char number; // n. of times this value was proposed
    	} valuestable[MAX_SIZE_ELIST]; // vtable[i] has the value correspondent to the entity in elist[i]
    //TCBtimestamp temp_prop, temp_dec, temp_t2;
     
    	out.error = 0;
     
    	Rindex = EIDtoINDEX(in->eid);
     
    	if ((i = search_CDTable_tag(in->tag)) == -1) {
    		out.error = INVALID_TAG;
    		DEBUG_MSG(SERVICE_LEVEL," INVALID_TAG\n");
    		process_output(fifo, (out_hdr_t *)&out, sizeof(out), in->eid, entities_data[Rindex].protection, entities_data[Rindex].secret, entities_data[Rindex].seq);
    		return;
    	}
     
    	for (j = 0; ((j < MAX_SIZE_ELIST) && (CDTable[i].elist[j] != END_ELIST)); j++) {
    		if (CDTable[i].vtable[j].is_free == 1)
    			all_proposed = 0;
    	}
    	TCBenter_in_critical_section();
    	actTime=get_vclock();
    	TCBleave_critical_section();
    //if ((all_proposed == 1) || (actTime > (CDTable[i].tstart + 13 000 000))) {
    // NOTA: 13 ms = periodo de envio + recepcao + Tmsg + relogio (Miguel)
    /*
      NOTA: Pedro Martins
     
      Miguel, tinhas 13 ms hardcoded, o que nao e nada bom :-) Mudei isso!!!!!
     
    */
    	//para ficar coerente como o crash detector
    	//max_time=READ_PERIOD+1000000+(SEND_PERIOD*(NETWORK_OMISSION_DEGREE+1))+SECURITY_MARGIN_FOR_NODE_CRASH_DETECTION+((2*MAXIMUM_ROUNDTRIP*1000)-(MINIMUM_DELIVERY_DELAY*1000));
    	max_time=15000000000; //max_time has to be reevaluated because the difference here is between the value proposed by the initior of the agreement
     
     
    ////////////////////////////////////////////////// My Modified section /////////////////////
    	/*here I will not compare tsatrt with acttime but i will rather compare the value proposed with the actime
    	to detect malicious entities*/
     
    	// Fisrt I need to extract the content of the proposed time value
     	if (CDTable[i].vtable[0].is_free == 0)
     
    	{memcpy(copy,CDTable[i].vtable[0].value,sizeof(value_t));
    	tokenPropTime=strtok(copy,"*");
    	//the proposed value must be converted into a timestamp
    	PropTimeStamp= simple_strtoull(tokenPropTime,NULL,10);
     
    	if ((all_proposed == 1) || (actTime > (PropTimeStamp + max_time)))
    	{
     
    	  DEBUG_MSG(DECISAO_LEVEL,"XX ALL_PROPOSED: %d IN_TIME?%d\n", all_proposed, (actTime >(PropTimeStamp + max_time))  );
    	  out.mask1 = 0;
    	  out.mask2 = 0;
     
    	  switch(CDTable[i].decision) {
     
    	  case TTCB_TBA_RMULTICAST:
    		// Begin Multicast
    	    DEBUG_MSG(DECISAO_LEVEL,"Going for MULTICAST decision\n");
    	    if (CDTable[i].vtable[0].is_free == 1)
    	     {
    	      out.error = DID_NOT_PROPOSE; // first element in elist did not propose
    	      DEBUG_MSG(DECISAO_LEVEL," DID_NOT_PROPOSE\n");
    	      process_output(fifo, (out_hdr_t *)&out, sizeof(out), in->eid, entities_data[Rindex].protection, entities_data[Rindex].secret, entities_data[Rindex].seq);
    	      return;
    	    }
     
    	    // Ajouté par moi : les valeurs qui ont été proposées ainsi que le timestamp de la proposition
     
    	    memcpy(out.value, CDTable[i].vtable[0].value, sizeof(value_t));
    	    memcpy(out.receivedvalue, CDTable[i].vtable[0].value, sizeof(value_t));
    	    out.prop= PropTimeStamp;
     
     
     
    	  printk ("Hi I am in decide, received timestamp = %lld", PropTimeStamp);
     
    	    for (j = 0; (j < MAX_SIZE_ELIST) && (CDTable[i].elist[j] != END_ELIST); j++)
    	     {
    	      if (CDTable[i].vtable[j].is_free == 0) {
    		out.mask2 |= bit;
    		if (memcmp(CDTable[i].vtable[j].value, out.value, sizeof(value_t)) == 0)
    		  out.mask1 |= bit;
    	      }
    	      bit = bit << 1;
    	    }
    	    DEBUG_MSG(DECISAO_LEVEL,"Chose value [%s]. Sending it.\n", out.value);
    	    break;
    	    // end if Multicast
     
     
      case TTCB_TBA_AND: // c'est ce que j'appelle à partir de l'autre fichier ttcbneighborhood.c
     
    	  // Begin AND decision for TTCB neighborhood
     
    	    DEBUG_MSG(DECISAO_LEVEL,"Going for AND decision\n");
     
    	    for (j = 0; (j < MAX_SIZE_ELIST) && (CDTable[i].elist[j] != END_ELIST); j++)
    	      {
     
    			if (CDTable[i].vtable[j].is_free == 0)
    		  {
     
    			// je vais programmer en supposant qu'il y a 1 seul TTCB --> il faut extraire les entités
     
    			memcpy(intermediaire, CDTable[i].vtable[j].value, 20);
    			tokenPropTime=strtok(intermediaire,"*");
     
    			existingID = strtok(NULL,"*");
     
    			//kernel info 29_12_05
    			tailleEid = sscanf (existingID,"%d",&neighlist[j]); // works
    			kern_info.TCBneighlist=neighlist;// works
    			kern_info.TCBlenneighlist=j+1;
    			// fin kernel info 29_12_05
     
    			//Concaténation des propositions
    		    strcat(concatString,CDTable[i].vtable[j].value);
    			strcat(concatString,"-");
    			strcat(concatString,existingID);
    			strcat(concatString,"+");
    			strcpy((char *)out.value, concatString);
    			out.test=kern_info.TCBneighlist[j];//works OK
     
    		  }
    	      }
     
    	    DEBUG_MSG(DECISAO_LEVEL,"The most voted value was %s\n",out.value);
    	    for (j = 0; (j < MAX_SIZE_ELIST) && (CDTable[i].elist[j] != END_ELIST); j++) {
    	      if (CDTable[i].vtable[j].is_free == 0) {
    		out.mask2 |= bit;
    		if (memcmp(CDTable[i].vtable[j].value, out.value, sizeof(value_t)) == 0)
    		  out.mask1 |= bit;
    	      }
    	      bit = bit << 1;
    	    }
     
    	    break;
     
    	  case TTCB_TBA_OR:
    	    DEBUG_MSG(DECISAO_LEVEL,"Going for AND decision\n");
     
    	    // Make the out.value a null element. Since we are talking
    	    // about 160 bits, there is no long enough constant, so we
    	    // must make it like this.
    	    for(cycling=0;cycling<sizeof(value_t); cycling++)
    	      {
    		out.value[cycling]=0x00;
    	      }
     
    	    for (j = 0; (j < MAX_SIZE_ELIST) && (CDTable[i].elist[j] != END_ELIST); j++)
    	      {
    		if (CDTable[i].vtable[j].is_free == 0)
    		  {
    		    for(cycling=0;cycling<sizeof(value_t); cycling++)
    		      {
    			out.value[cycling] |= CDTable[i].vtable[j].value[cycling];
    		      }
    		  }
    	      }
     
    	    DEBUG_MSG(DECISAO_LEVEL,"The most voted value was %s\n",out.value);
    	    for (j = 0; (j < MAX_SIZE_ELIST) && (CDTable[i].elist[j] != END_ELIST); j++) {
    	      if (CDTable[i].vtable[j].is_free == 0) {
    		out.mask2 |= bit;
    		if (memcmp(CDTable[i].vtable[j].value, out.value, sizeof(value_t)) == 0)
    		  out.mask1 |= bit;
    	      }
    	      bit = bit << 1;
    	    }
     
    	    break;
     
    	  case TTCB_TBA_XOR:
    	    DEBUG_MSG(DECISAO_LEVEL,"Going for XOR decision\n");
     
    	    ValueFound = 0;
    	    // Make the out.value a null element. Since we are talking
    	    // about 160 bits, there is no long enough constant, so we
    	    // must make it like this.
     
    	    //For the XOR case, we can not have a null element, so this is not necessary.
    	    //Instead, we must equal it to the first decided value, and go on from there.
     
    	    //	    for(cycling=0;cycling<sizeof(value_t); cycling++)
    	    //{
    	    //out.value[cycling]=0xFF;
    	    //}
     
    	    for (j = 0; (j < MAX_SIZE_ELIST) && (CDTable[i].elist[j] != END_ELIST); j++)
    	      {
    		if (CDTable[i].vtable[j].is_free == 0)
    		  {
    		    if(ValueFound==0)
    		      {
    			memcpy(out.value, CDTable[i].vtable[j].value, sizeof(value_t));
    			ValueFound=1;
    		      }
    		    else
    		      {
    			for(cycling=0;cycling<sizeof(value_t); cycling++)
    			  {
    			    out.value[cycling] ^= CDTable[i].vtable[j].value[cycling];
    			  }
    		      }
    		  }
    	      }
     
    	    DEBUG_MSG(DECISAO_LEVEL,"The most voted value was %s\n",out.value);
    	    for (j = 0; (j < MAX_SIZE_ELIST) && (CDTable[i].elist[j] != END_ELIST); j++) {
    	      if (CDTable[i].vtable[j].is_free == 0) {
    		out.mask2 |= bit;
    		if (memcmp(CDTable[i].vtable[j].value, out.value, sizeof(value_t)) == 0)
    		  out.mask1 |= bit;
    	      }
    	      bit = bit << 1;
    	    }
     
    	    break;
     
    	  default:
    	    DEBUG_MSG(DECISAO_LEVEL,"INVALID DECISION type\n ");
    	  }// end switch
    	  //temp_time3 = get_vclock();
    	  //temp_prop = temp_time1 - temp_time0; // Tprop
    	  //temp_dec = temp_time3 - temp_time2; // Tdec
    	  //temp_t2 = temp_time3 - temp_time0;   // T2
    	  //memcpy(out.value, &temp_t2, sizeof(temp_time0));
    	  //memcpy(&(out.value[8]), &temp_prop, sizeof(temp_time0));
    	  //memcpy(&(out.value[16]), &temp_dec, sizeof(temp_time0));
     
    	  process_output(fifo, (out_hdr_t *)&out, sizeof(out), in->eid, entities_data[Rindex].protection, entities_data[Rindex].secret, entities_data[Rindex].seq);
     
    	}// end if all proposed
    	//} // end if the proposed value was !=0
    	else {
    	  out.error = AGREEMENT_RUNNING;
    	  DEBUG_MSG(SERVICE_LEVEL,"AGREEMENT_RUNNING or \n");
    	  process_output(fifo, (out_hdr_t *)&out, sizeof(out), in->eid, entities_data[Rindex].protection, entities_data[Rindex].secret, entities_data[Rindex].seq);
    	}
     
    	DEBUG_MSG(INTERNAL_LEVEL,"Going to return from TTCBdecide.\n");
    	return;
    	}// end if if (CDTable[i].vtable[0].is_free == 0)
    	else
    	{     out.error = DID_NOT_PROPOSE; // first element in elist did not propose
    	      DEBUG_MSG(DECISAO_LEVEL," DID_NOT_PROPOSE\n");
    	      process_output(fifo, (out_hdr_t *)&out, sizeof(out), in->eid, entities_data[Rindex].protection, entities_data[Rindex].secret, entities_data[Rindex].seq);
    	      return;
    	}
    }
    #endif // DIST_AGREEMENT
    Enfin, la structure tcb_kernel_info_t se trouve dans le fichier share_app_tcb.h qu'il est inutile de mettre en totalité
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    /*
    ------------------
    (T)TCB kernel info
    ------------------
    */
     
    typedef struct{
    	int version; 		//kernel version
    	int sub_version;	//sub version
    	int ttcb_extentions;	//TTCB enabled?
     
    	int number_of_system_machines; //number of machines
     
    // TO BE EXTENDED !!!
    //je les ai ajouté extension 29_12_05
    	int* TCBneighlist ; // list of TTCB neighbors
    	int TCBlenneighlist; // longueur de la liste
    }
    tcb_kernel_info_t;

  3. #3
    Expert confirmé

    Avatar de fearyourself
    Homme Profil pro
    Ingénieur Informaticien Senior
    Inscrit en
    Décembre 2005
    Messages
    5 121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Ingénieur Informaticien Senior
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2005
    Messages : 5 121
    Par défaut
    Je te propose de tester deux choses:

    D'abord:

    Dans ton main au début:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    kern_info.TCBNeighlist = NULL;
    kern_info.TCBlenneighlist = 0;
    Si cela ne marche pas, regarde à quel niveau (pour quel entier, ton programme fais un segmentation fault dans ta boucle...)


    Sinon:

    Modifier ton main comme ceci:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    kern_info.TCBNeighlist = malloc(sizeof((*kern_info.TCBNeighlist)*20);
    if(kern_info.TCBNeightlist==NULL)
       {
        printf("Erreur d'allocation\n");
        return 1;
       }
    kern_info.TCBlenneighlist = 0;
    Et modifier la ligne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    kern_info.TCBneighlist=neighlist;// works 
    kern_info.TCBlenneighlist=j+1;
    en

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    if(j<20)
      {
       kern_info.TCBneighlist[j] =neighlist[j];
       kern_info.TCBlenneighlist=j+1; 
       }

    Mais surtout voir pour quel entier et à quel moment cela fait un segmentation fault...
    Jc

  4. #4
    Membre averti
    Inscrit en
    Février 2004
    Messages
    40
    Détails du profil
    Informations forums :
    Inscription : Février 2004
    Messages : 40
    Par défaut
    Salut
    J'ai essayé les modifications
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    kern_info.TCBNeighlist = malloc(sizeof((*kern_info.TCBNeighlist)*20); 
    if(kern_info.TCBNeightlist==NULL) 
       { 
        printf("Erreur d'allocation\n"); 
        return 1; 
       } 
    kern_info.TCBlenneighlist = 0;
    au sein du fichier module kernel tcb_module.c mais l'erreur de segmentation est au niveau du fichier ttcbneighborhood.c à la ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    for (k=0;k<lenneighlist;k++) 
     
       printf ("Agreement Kernel Info : L'entité est %d \n ",krn_info.TCBneighlist[k]);//erreur de segmentation
    c'est à dire lorsque j'essaie d'afficher le contenu du tableau d'entiers qui est (je le répète) a été correctement modifié au sein du ttcb_module.c au sein de la fonction decide
    Je crois qu'au lieu de définir un tableau d'entiers dans la structure
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    typedef struct{ 
       int version;       //kernel version 
       int sub_version;   //sub version 
       int ttcb_extentions;   //TTCB enabled? 
     
       int number_of_system_machines; //number of machines 
     
    // TO BE EXTENDED !!! 
    //je les ai ajouté extension 29_12_05 
       int* TCBneighlist ; // list of TTCB neighbors 
       int TCBlenneighlist; // longueur de la liste 
    } 
    tcb_kernel_info_t;
    je définirai plutot un tableau de caractères
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    ------------------ 
    (T)TCB kernel info 
    ------------------ 
    */ 
     
    typedef struct{ 
       int version;       //kernel version 
       int sub_version;   //sub version 
       int ttcb_extentions;   //TTCB enabled? 
     
       int number_of_system_machines; //number of machines 
     
    // TO BE EXTENDED !!! 
    //je les ai ajouté extension 29_12_05 
       char TCBneighlist[20] ; // list of TTCB neighbors 
       int TCBlenneighlist; // longueur de la liste 
    } 
    tcb_kernel_info_t;
    et j'afficherai le résultat au sein de ttcbneighborhood.c comme étatnt une chaine de caractères puis j'extrairai les entités une à une
    j'essaierai ceci (car je ne peux plus m'attarder sur ce détail, je dois respecter une certaine échéance )et je vous tiendrai au courant du résultat

Discussions similaires

  1. erreur lors de l'affichage d'un tableau
    Par romrom12 dans le forum Langage
    Réponses: 6
    Dernier message: 01/05/2012, 00h05
  2. Réponses: 11
    Dernier message: 29/11/2011, 15h15
  3. erreur d'affichage pour on tableau de bord
    Par nidhal fekih dans le forum Flash
    Réponses: 0
    Dernier message: 29/07/2008, 22h07
  4. Réponses: 5
    Dernier message: 04/11/2007, 14h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo