164562Sgshapiro/* 2261194Sgshapiro * Copyright (c) 1999-2000 Proofpoint, Inc. and its suppliers. 364562Sgshapiro * All rights reserved. 464562Sgshapiro * 564562Sgshapiro * By using this file, you agree to the terms and conditions set 664562Sgshapiro * forth in the LICENSE file which can be found at the top level of 764562Sgshapiro * the sendmail distribution. 864562Sgshapiro * 964562Sgshapiro * Contributed by Exactis.com, Inc. 1064562Sgshapiro * 1164562Sgshapiro */ 1264562Sgshapiro 1390792Sgshapiro#include <sm/gen.h> 14266527SgshapiroSM_RCSID("@(#)$Id: shmticklib.c,v 8.15 2013-11-22 20:51:56 ca Exp $") 1564562Sgshapiro 1664562Sgshapiro#if _FFR_SHM_STATUS 1764562Sgshapiro# include <sys/types.h> 1864562Sgshapiro# include <sys/ipc.h> 1964562Sgshapiro# include <sys/shm.h> 2064562Sgshapiro 2164562Sgshapiro# include "statusd_shm.h" 2264562Sgshapiro 2390792Sgshapiro/* 2464562Sgshapiro** SHMTICK -- increment a shared memory variable 2564562Sgshapiro** 2664562Sgshapiro** Parameters: 2764562Sgshapiro** inc_me -- identity of shared memory segment 2864562Sgshapiro** what -- which variable to increment 2964562Sgshapiro** 3064562Sgshapiro** Returns: 3164562Sgshapiro** none 3264562Sgshapiro*/ 3364562Sgshapiro 3464562Sgshapirovoid 3564562Sgshapiroshmtick(inc_me, what) 3664562Sgshapiro int inc_me; 3764562Sgshapiro int what; 3864562Sgshapiro{ 3964562Sgshapiro static int shmid = -1; 4064562Sgshapiro static STATUSD_SHM *sp = (STATUSD_SHM *)-1; 4164562Sgshapiro static unsigned int cookie = 0; 4264562Sgshapiro 4364562Sgshapiro if (shmid < 0) 4464562Sgshapiro { 4564562Sgshapiro int size = sizeof(STATUSD_SHM); 4664562Sgshapiro 4764562Sgshapiro shmid = shmget(STATUSD_SHM_KEY, size, 0); 4864562Sgshapiro if (shmid < 0) 4964562Sgshapiro return; 5064562Sgshapiro } 5190792Sgshapiro if ((unsigned long *) sp == (unsigned long *)-1) 5264562Sgshapiro { 5390792Sgshapiro sp = (STATUSD_SHM *) shmat(shmid, NULL, 0); 5490792Sgshapiro if ((unsigned long *) sp == (unsigned long *) -1) 5564562Sgshapiro return; 5664562Sgshapiro } 5764562Sgshapiro if (sp->magic != STATUSD_MAGIC) 5864562Sgshapiro { 5964562Sgshapiro /* 6064562Sgshapiro ** possible race condition, wait for 6164562Sgshapiro ** statusd to initialize. 6264562Sgshapiro */ 6364562Sgshapiro 6464562Sgshapiro return; 6564562Sgshapiro } 6664562Sgshapiro if (what >= STATUSD_LONGS) 6764562Sgshapiro what = STATUSD_LONGS - 1; 6864562Sgshapiro if (inc_me >= STATUSD_LONGS) 6964562Sgshapiro inc_me = STATUSD_LONGS - 1; 7064562Sgshapiro 7164562Sgshapiro if (sp->ul[STATUSD_COOKIE] != cookie) 7264562Sgshapiro { 7364562Sgshapiro cookie = sp->ul[STATUSD_COOKIE]; 7464562Sgshapiro ++(sp->ul[inc_me]); 7564562Sgshapiro } 7664562Sgshapiro ++(sp->ul[what]); 7764562Sgshapiro} 7864562Sgshapiro#endif /* _FFR_SHM_STATUS */ 79