dma: bump man page date
[dragonfly.git] / contrib / sendmail-8.14 / sendmail / shmticklib.c
blob6f5e301d2c708f42a8032d47db7bad313b8ba895
1 /*
2 * Copyright (c) 1999-2000 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
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.
13 #include <sm/gen.h>
14 SM_RCSID("@(#)$Id: shmticklib.c,v 8.14 2001/09/11 04:05:16 gshapiro Exp $")
16 #if _FFR_SHM_STATUS
17 # include <sys/types.h>
18 # include <sys/ipc.h>
19 # include <sys/shm.h>
21 # include "statusd_shm.h"
24 ** SHMTICK -- increment a shared memory variable
26 ** Parameters:
27 ** inc_me -- identity of shared memory segment
28 ** what -- which variable to increment
30 ** Returns:
31 ** none
34 void
35 shmtick(inc_me, what)
36 int inc_me;
37 int what;
39 static int shmid = -1;
40 static STATUSD_SHM *sp = (STATUSD_SHM *)-1;
41 static unsigned int cookie = 0;
43 if (shmid < 0)
45 int size = sizeof(STATUSD_SHM);
47 shmid = shmget(STATUSD_SHM_KEY, size, 0);
48 if (shmid < 0)
49 return;
51 if ((unsigned long *) sp == (unsigned long *)-1)
53 sp = (STATUSD_SHM *) shmat(shmid, NULL, 0);
54 if ((unsigned long *) sp == (unsigned long *) -1)
55 return;
57 if (sp->magic != STATUSD_MAGIC)
60 ** possible race condition, wait for
61 ** statusd to initialize.
64 return;
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];
74 ++(sp->ul[inc_me]);
76 ++(sp->ul[what]);
78 #endif /* _FFR_SHM_STATUS */