2 * Copyright (c) 1999-2000 Sendmail, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
9 * Contributed by Exactis.com, Inc.
14 SM_RCSID("@(#)$Id: shmticklib.c,v 8.14 2001/09/11 04:05:16 gshapiro Exp $")
17 # include <sys/types.h>
21 # include "statusd_shm.h"
24 ** SHMTICK -- increment a shared memory variable
27 ** inc_me -- identity of shared memory segment
28 ** what -- which variable to increment
39 static int shmid = -1;
40 static STATUSD_SHM *sp = (STATUSD_SHM *)-1;
41 static unsigned int cookie = 0;
45 int size = sizeof(STATUSD_SHM);
47 shmid = shmget(STATUSD_SHM_KEY, size, 0);
51 if ((unsigned long *) sp == (unsigned long *)-1)
53 sp = (STATUSD_SHM *) shmat(shmid, NULL, 0);
54 if ((unsigned long *) sp == (unsigned long *) -1)
57 if (sp->magic != STATUSD_MAGIC)
60 ** possible race condition, wait for
61 ** statusd to initialize.
66 if (what >= STATUSD_LONGS)
67 what = STATUSD_LONGS - 1;
68 if (inc_me >= STATUSD_LONGS)
69 inc_me = STATUSD_LONGS - 1;
71 if (sp->ul[STATUSD_COOKIE] != cookie)
73 cookie = sp->ul[STATUSD_COOKIE];
78 #endif /* _FFR_SHM_STATUS */