From 4fa39f47f0a76839f48acca3b1268ae6e751e1dc Mon Sep 17 00:00:00 2001 From: Lorenzo Bianchi Date: Mon, 5 Jun 2023 13:11:33 +0200 Subject: [PATCH] adesso funziona perche ho cambiato il processo --- src/custom_msgq.c | 1 + src/custom_sig.c | 18 +++++------------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/custom_msgq.c b/src/custom_msgq.c index c096b8c..4f3bbcc 100644 --- a/src/custom_msgq.c +++ b/src/custom_msgq.c @@ -85,6 +85,7 @@ void rcvPlayer(player_ds *player) { msgRcv(player, sizeof(player_ds) - sizeof(long), PLAYER); } void rcvGame_end(game_end_t *game) { + printf("aspetto game\n"); msgRcv(game, sizeof(game_end_t) - sizeof(long), GAME_END); } diff --git a/src/custom_sig.c b/src/custom_sig.c index 5b6b20c..a1ddd09 100644 --- a/src/custom_sig.c +++ b/src/custom_sig.c @@ -40,24 +40,14 @@ void sigHandlerServer(int sig) { // il giocatore che abbandona mi manda gia il messaggio dicendo che ha vinto l'altro game_end_t game; rcvGame_end(&game); - printf("vince %d\n", game.winner); sndGame_end(&game); - sndGame_end(&game); - kill(_PIDS[0], SIGUSR1); //FIXME: fare una funzione per queste robe perche anche gia scritta a fine F4Server - semOp(_SEMID, SERVER, -1); - kill(_PIDS[1], SIGUSR1); + kill(_PIDS[game.winner], SIGUSR1); // aspetto che i figli ricevano i messaggi - printf("aspettato uno\n"); semOp(_SEMID, SERVER, -1); - - printf("aspettato\n"); - - printf("%d %d\n", _PIDS[0], _PIDS[1]); - - kill(_PIDS[0], SIGTERM); - kill(_PIDS[1], SIGTERM); + + kill(_PIDS[game.winner], SIGTERM); raise(SIGTERM); } @@ -140,6 +130,7 @@ void sigHandlerClient(int sig) { game_end_t game = {.mtype = GAME_END, .winner = ID ^ 1}; sndGame_end(&game); kill(SERVER_PID, SIGUSR1); + kill(getpid(), SIGTERM); } // Terminazione e chiusura terminale @@ -167,6 +158,7 @@ void sigHandlerClient(int sig) { game_end_t winner; rcvGame_end(&winner); printf("messaggio!\n"); + printf("%d %d (%ld)\n", ID, winner.winner, winner.mtype); // printBoard(); if (winner.winner == ID) {