shmticklib.c revision 261363
1231200Smm/* 2231200Smm * Copyright (c) 1999-2000 Proofpoint, Inc. and its suppliers. 3231200Smm * All rights reserved. 4231200Smm * 5231200Smm * By using this file, you agree to the terms and conditions set 6231200Smm * forth in the LICENSE file which can be found at the top level of 7231200Smm * the sendmail distribution. 8231200Smm * 9231200Smm * Contributed by Exactis.com, Inc. 10231200Smm * 11231200Smm */ 12231200Smm 13231200Smm#include <sm/gen.h> 14231200SmmSM_RCSID("@(#)$Id: shmticklib.c,v 8.15 2013/11/22 20:51:56 ca Exp $") 15231200Smm 16231200Smm#if _FFR_SHM_STATUS 17231200Smm# include <sys/types.h> 18231200Smm# include <sys/ipc.h> 19231200Smm# include <sys/shm.h> 20231200Smm 21231200Smm# include "statusd_shm.h" 22231200Smm 23231200Smm/* 24231200Smm** SHMTICK -- increment a shared memory variable 25231200Smm** 26231200Smm** Parameters: 27231200Smm** inc_me -- identity of shared memory segment 28231200Smm** what -- which variable to increment 29231200Smm** 30231200Smm** Returns: 31231200Smm** none 32231200Smm*/ 33231200Smm 34231200Smmvoid 35231200Smmshmtick(inc_me, what) 36231200Smm int inc_me; 37231200Smm int what; 38231200Smm{ 39231200Smm static int shmid = -1; 40231200Smm static STATUSD_SHM *sp = (STATUSD_SHM *)-1; 41231200Smm static unsigned int cookie = 0; 42231200Smm 43231200Smm if (shmid < 0) 44231200Smm { 45231200Smm int size = sizeof(STATUSD_SHM); 46231200Smm 47231200Smm shmid = shmget(STATUSD_SHM_KEY, size, 0); 48231200Smm if (shmid < 0) 49231200Smm return; 50231200Smm } 51231200Smm if ((unsigned long *) sp == (unsigned long *)-1) 52231200Smm { 53231200Smm sp = (STATUSD_SHM *) shmat(shmid, NULL, 0); 54318483Smm if ((unsigned long *) sp == (unsigned long *) -1) 55231200Smm return; 56231200Smm } 57231200Smm if (sp->magic != STATUSD_MAGIC) 58231200Smm { 59231200Smm /* 60231200Smm ** possible race condition, wait for 61302001Smm ** statusd to initialize. 62231200Smm */ 63231200Smm 64231200Smm return; 65231200Smm } 66231200Smm if (what >= STATUSD_LONGS) 67231200Smm what = STATUSD_LONGS - 1; 68231200Smm if (inc_me >= STATUSD_LONGS) 69231200Smm inc_me = STATUSD_LONGS - 1; 70231200Smm 71231200Smm if (sp->ul[STATUSD_COOKIE] != cookie) 72231200Smm { 73231200Smm cookie = sp->ul[STATUSD_COOKIE]; 74231200Smm ++(sp->ul[inc_me]); 75231200Smm } 76231200Smm ++(sp->ul[what]); 77231200Smm} 78231200Smm#endif /* _FFR_SHM_STATUS */ 79231200Smm