deallocreporter.c (1641B)
1 /************************************************************************* 2 * This file is part of Crosroads 1.23, a load balancer and fail over 3 * utility for TCP. Copyright (c) Karel Kubat, distributed under GPL. 4 * Visit http://crossroads.e-tunity.com for information. 5 *************************************************************************/ 6 #include "crossroads.h" 7 8 void dealloc_reporter (Service *s) { 9 int shmid; 10 11 msg ("Freeing reporting memory for service %s (key %d)", 12 s->name, s->shmkey); 13 14 /* Get the shared memory ID. If this fails and we're in stage 0, 15 * then ignore the error. The true handler will have already released it. 16 */ 17 if ( (shmid = shmget (s->shmkey, sizeof(Servicereport), 18 0644) ) >= 0) { 19 msg ("Got existing shm at id %d", shmid); 20 /* Mark to be released. If this fails then warn. */ 21 if (shmctl (shmid, IPC_RMID, 0) < 0 && program_stage != stage_main) 22 warning ("WARNING: Cannot mark shared memory as destructable: %s " 23 "Root might need to 'ipcrm -m %d' and " 24 "'ipcrm -s %d' to clean up!", 25 strerror(errno), shmid, semid); 26 if (semctl (semid, 0, IPC_RMID) < 0 && program_stage != stage_main) 27 warning ("WARNING: Cannot remove semaphore: %s " 28 "Root might need to 'ipcrm -s %d' to clean up!", 29 strerror(errno), semid); 30 } 31 else if (program_stage != stage_main) { 32 /* Errno 2 means that the shm block was already removed (by a 33 * different listener) Don't warn if that's the case. 34 */ 35 if (errno != 2) 36 warning ("Cannot get shared memory for service %s (key %d: %d/%s)", 37 s->name, s->shmkey, errno, strerror(errno)); 38 } 39 }