httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Terbush <ra...@zyzzyva.com>
Subject Re: [PATCH] SysV semaphores
Date Wed, 06 Aug 1997 18:25:47 GMT
One minor drawback of using semaphores as a default on FreeBSD is 
the fact that semaphore support needs to be compiled into the 
kernel. It would probably be silly for someone not to have this compiled
in, but could lead to some bug reports. (probably fewer than /var/tmp
vs. /usr/tmp lock directory)


> Pierre-Yves Kerembellec submitted code to me which implements SysV-style
> semaphores.  I made one change, to use IPC_PRIVATE forcing the system to
> allocate a key_t.  He says it works for him on Solaris 2.5.1 (x86 and
> Sparc) and on FreeBSD.  It might still work with my change, dunno ;)
> It works on my Linux 2.0.30 system.
> 
> This stuff is (in theory) better than using lock files because it doesn't
> require the LockFile to be placed anywhere special.  It also doesn't
> have any other unwanted interactions with the fs or NFS.
> 
> I'm curious, I think we want SEM_UNDO on both semop calls.  I haven't
> looked at the linux kernel code ... maybe someone more familiar with
> these things can tell me.  I'm concerned that with SEM_UNDO only on
> the acquire code we'll end up with a huge undo count that will all be
> applied when the process exits...
> 
> Dean
> 
> Index: CHANGES
> ===================================================================
> RCS file: /export/home/cvs/apache/src/CHANGES,v
> retrieving revision 1.385
> diff -u -r1.385 CHANGES
> --- CHANGES	1997/08/05 10:49:39	1.385
> +++ CHANGES	1997/08/06 01:53:08
> @@ -1,5 +1,9 @@
>  Changes with Apache 1.3a2
>  
> +  *) Use SysV-style semaphores for serialization on Solaris 2.x, Linux 2.x,
> +     FreeBSD/BSDI.
> +     [Pierre-Yves Kerembellec <Pierre-Yves.Kerembellec@vtcom.fr>]
> +
>    *) Enhanced and cleaned up the URL rewriting engine of mod_rewrite:
>       First the grouped parts of RewriteRule pattern matches (parenthesis!) can
>       be accessed now via backreferences $1..$9 in RewriteConds test-against
> Index: conf.h
> ===================================================================
> RCS file: /export/home/cvs/apache/src/conf.h,v
> retrieving revision 1.121
> diff -u -r1.121 conf.h
> --- conf.h	1997/07/27 20:07:16	1.121
> +++ conf.h	1997/08/06 01:53:08
> @@ -100,7 +100,8 @@
>  #define HAVE_SYS_RESOURCE_H
>  #define bzero(a,b) memset(a,0,b)
>  #define JMP_BUF sigjmp_buf
> -#define USE_FCNTL_SERIALIZED_ACCEPT
> +/*#define USE_FCNTL_SERIALIZED_ACCEPT*/
> +#define USE_SYSVSEM_SERIALIZED_ACCEPT
>  #define HAVE_MMAP
>  #define HAVE_CRYPT_H
>  int gethostname(char *name, int namelen);
> @@ -269,8 +270,10 @@
>  #define HAVE_SHMGET
>  #define HAVE_SYS_RESOURCE_H
>  typedef int rlim_t;
> -#endif
> +#define USE_SYSVSEM_SERIALIZED_ACCEPT
> +#else
>  #define USE_FCNTL_SERIALIZED_ACCEPT
> +#endif
>  #undef HAVE_GMTOFF
>  #undef NO_KILLPG
>  #undef NO_SETSID
> @@ -424,7 +427,8 @@
>  (defined(__FreeBSD_version) && (__FreeBSD_version < 220000))
>  typedef quad_t rlim_t;
>  #endif
> -#define USE_FLOCK_SERIALIZED_ACCEPT
> +/*#define USE_FLOCK_SERIALIZED_ACCEPT*/
> +#define USE_SYSVSEM_SERIALIZED_ACCEPT
>  
>  #elif defined(QNX)
>  #ifndef crypt
> Index: http_main.c
> ===================================================================
> RCS file: /export/home/cvs/apache/src/http_main.c,v
> retrieving revision 1.197
> diff -u -r1.197 http_main.c
> --- http_main.c	1997/08/05 06:02:41	1.197
> +++ http_main.c	1997/08/06 01:53:09
> @@ -261,7 +261,57 @@
>  }
>  #endif
>  
> -#if defined(USE_FCNTL_SERIALIZED_ACCEPT)
> +#if defined(USE_SYSVSEM_SERIALIZED_ACCEPT)
> +
> +#include <sys/types.h>
> +#include <sys/ipc.h>
> +#include <sys/sem.h>
> +
> +static   int sem_id = -1;
> +
> +void accept_mutex_init(pool *p)
> +{
> +    sem_id = semget(IPC_PRIVATE, 1, IPC_CREAT | IPC_EXCL | 0666);
> +    if (sem_id < 0) {
> +	log_unixerr ("semget", "IPC_PRIVATE", "Cannot create semaphore",
> +	    server_conf);
> +	exit (1);
> +    }
> +    if (semctl(sem_id, 0, SETVAL, 1) < 0) {
> +	log_unixerr ("semctl", "SETVAL", "Cannot initialize semaphore\n",
> +	    server_conf);
> +        exit(1);
> +    }
> +}
> +
> +void accept_mutex_on()
> +{
> +    struct sembuf op;
> +
> +    op.sem_num = 0;
> +    op.sem_op  = -1;
> +    op.sem_flg = SEM_UNDO;
> +    if (semop(sem_id, &op, 1) < 0) {
> +	log_unixerr ("semop", "accept_mutex_on", "Cannot get lock",
> +	    server_conf);
> +        exit (1);
> +    }
> +}
> +
> +void accept_mutex_off()
> +{
> +    struct sembuf op;
> +
> +    op.sem_num = 0;
> +    op.sem_op  = 1;
> +    op.sem_flg = 0;
> +    if (semop(sem_id, &op, 1) < 0) {
> +	log_unixerr ("semop", "accept_mutex_off", "Cannot release lock",
> +	    server_conf);
> +        exit (1);
> +    }
> +}
> +#elif defined(USE_FCNTL_SERIALIZED_ACCEPT)
>  static struct flock lock_it;
>  static struct flock unlock_it;
>  
> @@ -366,6 +416,7 @@
>  	exit(1);
>      }
>  }
> +
>  #else
>  /* Default --- no serialization.  Other methods *could* go here,
>   * as #elifs...



Mime
View raw message