diff options
| author | Sam Varshavchik | 2013-08-19 16:39:41 -0400 | 
|---|---|---|
| committer | Sam Varshavchik | 2013-08-25 14:43:51 -0400 | 
| commit | 9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch) | |
| tree | 7a81a04cb51efb078ee350859a64be2ebc6b8813 /liblock/locktest.c | |
| parent | a9520698b770168d1f33d6301463bb70a19655ec (diff) | |
| download | courier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2 | |
Initial checkin
Imported from subversion report, converted to git. Updated all paths in
scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'liblock/locktest.c')
| -rw-r--r-- | liblock/locktest.c | 84 | 
1 files changed, 84 insertions, 0 deletions
| diff --git a/liblock/locktest.c b/liblock/locktest.c new file mode 100644 index 0000000..596d28a --- /dev/null +++ b/liblock/locktest.c @@ -0,0 +1,84 @@ +/* +** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for +** distribution information. +*/ + +/* $Id */ + +#include	"liblock.h" +#if	USE_FCNTL +#include	"lockfcntl.c" +#endif +#if	USE_FLOCK +#include	"lockflock.c" +#endif +#if	USE_LOCKF +#include	"locklockf.c" +#endif +#include	<signal.h> +#include	<stdlib.h> + +int main() +{ +int	fd[2]; +pid_t	p; +int	s; +int	f; + +	signal(SIGCHLD, SIG_DFL); +	if (pipe(fd)) +	{ +		perror("pipe"); +		return (1); +	} + +	if ((p=fork()) == (pid_t)-1) +	{ +		perror("fork"); +		return (1); +	} + +	if (p == 0) +	{ +	char	c; + +		close(fd[1]); +		read(fd[0], &c, 1); +		close(fd[0]); + +		if ((f=open("conftest.lock", O_RDWR|O_CREAT, 0644)) < 0) +		{ +			perror("open"); +			exit(1); +		} +		alarm(5); + +		if (ll_lockfd(f, ll_writelock, 0, 0)) +		{ +			close(f); +			exit(0); +		} +		close(f); +		exit(1); +	} +	 +	if ((f=open("conftest.lock", O_RDWR|O_CREAT, 0644)) < 0) +	{ +		perror("open"); +		exit(1); +	} + +	if (ll_lockfd(f, ll_writelock, 0, 0)) +	{ +		perror("lock"); +		close(f); +		exit(1); +	} +	close(fd[1]); +	close(fd[0]); +	while (wait(&s) != p) +		; +	if (s == 0) +		exit(0); +	exit(1); +} | 
