sem.c (147078) | sem.c (157001) |
---|---|
1/* 2 * Copyright (c) 2000-2001, 2005 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * 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. 8 */ 9 10#include <sm/gen.h> | 1/* 2 * Copyright (c) 2000-2001, 2005 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * 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. 8 */ 9 10#include <sm/gen.h> |
11SM_RCSID("@(#)$Id: sem.c,v 1.12 2005/03/25 21:27:02 ca Exp $") | 11SM_RCSID("@(#)$Id: sem.c,v 1.13 2005/08/12 20:39:59 ca Exp $") |
12 13#if SM_CONF_SEM 14# include <stdlib.h> 15# include <unistd.h> 16# include <sm/sem.h> 17# include <sm/heap.h> | 12 13#if SM_CONF_SEM 14# include <stdlib.h> 15# include <unistd.h> 16# include <sm/sem.h> 17# include <sm/heap.h> |
18# include <errno.h> |
|
18 19/* 20** SM_SEM_START -- initialize semaphores 21** 22** Parameters: 23** key -- key for semaphores. 24** nsem -- number of semaphores. 25** semflg -- flag for semget(), if 0, use a default. --- 6 unchanged lines hidden (view full) --- 32 33int 34sm_sem_start(key, nsem, semflg, owner) 35 key_t key; 36 int nsem; 37 int semflg; 38 bool owner; 39{ | 19 20/* 21** SM_SEM_START -- initialize semaphores 22** 23** Parameters: 24** key -- key for semaphores. 25** nsem -- number of semaphores. 26** semflg -- flag for semget(), if 0, use a default. --- 6 unchanged lines hidden (view full) --- 33 34int 35sm_sem_start(key, nsem, semflg, owner) 36 key_t key; 37 int nsem; 38 int semflg; 39 bool owner; 40{ |
40 int semid, i; | 41 int semid, i, err; |
41 unsigned short *semvals; 42 43 semvals = NULL; 44 if (semflg == 0) 45 semflg = (SEM_A|SEM_R)|((SEM_A|SEM_R) >> 3); 46 if (owner) 47 semflg |= IPC_CREAT|IPC_EXCL; 48 semid = semget(key, nsem, semflg); --- 13 unchanged lines hidden (view full) --- 62 for (i = 0; i < nsem; i++) 63 semvals[i] = 1; 64 if (semctl(semid, 0, SETALL, semarg) < 0) 65 goto error; 66 } 67 return semid; 68 69error: | 42 unsigned short *semvals; 43 44 semvals = NULL; 45 if (semflg == 0) 46 semflg = (SEM_A|SEM_R)|((SEM_A|SEM_R) >> 3); 47 if (owner) 48 semflg |= IPC_CREAT|IPC_EXCL; 49 semid = semget(key, nsem, semflg); --- 13 unchanged lines hidden (view full) --- 63 for (i = 0; i < nsem; i++) 64 semvals[i] = 1; 65 if (semctl(semid, 0, SETALL, semarg) < 0) 66 goto error; 67 } 68 return semid; 69 70error: |
71 err = errno; |
|
70 if (semvals != NULL) 71 sm_free(semvals); 72 if (semid >= 0) 73 sm_sem_stop(semid); | 72 if (semvals != NULL) 73 sm_free(semvals); 74 if (semid >= 0) 75 sm_sem_stop(semid); |
74 return -1; | 76 return (err > 0) ? (0 - err) : -1; |
75} 76 77/* 78** SM_SEM_STOP -- stop using semaphores. 79** 80** Parameters: 81** semid -- id for semaphores. 82** --- 119 unchanged lines hidden --- | 77} 78 79/* 80** SM_SEM_STOP -- stop using semaphores. 81** 82** Parameters: 83** semid -- id for semaphores. 84** --- 119 unchanged lines hidden --- |