shmticklib.c revision 64562
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1999-2000 Sendmail, Inc. and its suppliers. 31541Srgrimes * All rights reserved. 41541Srgrimes * 51541Srgrimes * By using this file, you agree to the terms and conditions set 61541Srgrimes * forth in the LICENSE file which can be found at the top level of 71541Srgrimes * the sendmail distribution. 81541Srgrimes * 91541Srgrimes * Contributed by Exactis.com, Inc. 101541Srgrimes * 111541Srgrimes */ 121541Srgrimes 131541Srgrimes#ifndef lint 141541Srgrimesstatic char id[] = "@(#)$Id: shmticklib.c,v 8.6 2000/02/26 01:32:27 gshapiro Exp $"; 151541Srgrimes#endif /* ! lint */ 161541Srgrimes 171541Srgrimes#if _FFR_SHM_STATUS 181541Srgrimes# if SFIO 191541Srgrimes# include <sfio/stdio.h> 201541Srgrimes# else /* !SFIO */ 211541Srgrimes# include <stdio.h> 221541Srgrimes# endif /* SFIO */ 231541Srgrimes# include <sys/types.h> 241541Srgrimes# include <sys/ipc.h> 251541Srgrimes# include <sys/shm.h> 261541Srgrimes 271541Srgrimes# include "statusd_shm.h" 281541Srgrimes 291541Srgrimes/* 301541Srgrimes** SHMTICK -- increment a shared memory variable 311541Srgrimes** 321541Srgrimes** Parameters: 3314511Shsu** inc_me -- identity of shared memory segment 341541Srgrimes** what -- which variable to increment 351541Srgrimes** 36116182Sobrien** Returns: 37116182Sobrien** none 38116182Sobrien*/ 391541Srgrimes 401541Srgrimesvoid 411541Srgrimesshmtick(inc_me, what) 421541Srgrimes int inc_me; 4331778Seivind int what; 44111899Sdas{ 451541Srgrimes static int shmid = -1; 461541Srgrimes static STATUSD_SHM *sp = (STATUSD_SHM *)-1; 4791140Stanimura static unsigned int cookie = 0; 4891140Stanimura 4991140Stanimura if (shmid < 0) 5024207Sbde { 5124207Sbde int size = sizeof(STATUSD_SHM); 5224207Sbde 531541Srgrimes shmid = shmget(STATUSD_SHM_KEY, size, 0); 541541Srgrimes if (shmid < 0) 551541Srgrimes return; 5624131Sbde } 5729354Speter if ((unsigned long *)sp == (unsigned long *)-1) 581541Srgrimes { 591541Srgrimes sp = (STATUSD_SHM *)shmat(shmid, NULL, 0); 603308Sphk if ((unsigned long *)sp == (unsigned long *)-1) 6149536Sphk return; 621541Srgrimes } 6369774Sphk if (sp->magic != STATUSD_MAGIC) 6412517Sjulian { 6592723Salfred /* 6692723Salfred ** possible race condition, wait for 6792723Salfred ** statusd to initialize. 6892723Salfred */ 6911789Sbde 7012675Sjulian return; 7112675Sjulian } 7212675Sjulian if (what >= STATUSD_LONGS) 7312675Sjulian what = STATUSD_LONGS - 1; 7412675Sjulian if (inc_me >= STATUSD_LONGS) 7512675Sjulian inc_me = STATUSD_LONGS - 1; 7612675Sjulian 7712675Sjulian if (sp->ul[STATUSD_COOKIE] != cookie) 7812675Sjulian { 7929354Speter cookie = sp->ul[STATUSD_COOKIE]; 8012675Sjulian ++(sp->ul[inc_me]); 8138485Sbde } 8247625Sphk ++(sp->ul[what]); 83126080Sphk} 84111815Sphk#endif /* _FFR_SHM_STATUS */ 85111815Sphk