summaryrefslogtreecommitdiffstats
path: root/liblock
diff options
context:
space:
mode:
authorSam Varshavchik2014-07-13 09:57:18 -0400
committerSam Varshavchik2014-07-13 09:57:18 -0400
commita66c0ebff9c406db9e041d9ba77385887e367691 (patch)
treede5970fdd4bf626b0fa9c1484f5bfda199d3e193 /liblock
parentcb36699e35c7f027f2d3a6efe5b05ecf8907b6bf (diff)
downloadcourier-libs-a66c0ebff9c406db9e041d9ba77385887e367691.tar.bz2
Minor compilation fixes. Basd on patch from Giovanni Bechis <giovanni@paclan.it>
Diffstat (limited to 'liblock')
-rw-r--r--liblock/locktest.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/liblock/locktest.c b/liblock/locktest.c
index 596d28a..eb5cc4a 100644
--- a/liblock/locktest.c
+++ b/liblock/locktest.c
@@ -1,10 +1,8 @@
/*
-** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for
+** Copyright 1998 - 2014 Double Precision, Inc. See COPYING for
** distribution information.
*/
-/* $Id */
-
#include "liblock.h"
#if USE_FCNTL
#include "lockfcntl.c"
@@ -17,14 +15,30 @@
#endif
#include <signal.h>
#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
int main()
{
+#define FILENAME "courier-imap.locktest.XXXXXXXXXX"
int fd[2];
pid_t p;
int s;
int f;
+ char *name;
+ const char *tmpdir;
+ if ((tmpdir = (char *)getenv("TMPDIR")) == NULL || !*tmpdir)
+ tmpdir = "/tmp";
+
+ if ((name=malloc(strlen(tmpdir)+sizeof(FILENAME)+1)) == NULL)
+ {
+ perror("get filename");
+ exit(1);
+ }
+
+ (void)sprintf(name, "%s/%s", tmpdir, FILENAME);
+
signal(SIGCHLD, SIG_DFL);
if (pipe(fd))
{
@@ -32,6 +46,12 @@ int f;
return (1);
}
+ if ((f=mkstemp(name)) < 0)
+ {
+ perror("open");
+ exit(1);
+ }
+
if ((p=fork()) == (pid_t)-1)
{
perror("fork");
@@ -46,7 +66,7 @@ int f;
read(fd[0], &c, 1);
close(fd[0]);
- if ((f=open("conftest.lock", O_RDWR|O_CREAT, 0644)) < 0)
+ if ((f=open(name, O_RDWR)) < 0)
{
perror("open");
exit(1);
@@ -56,22 +76,18 @@ int f;
if (ll_lockfd(f, ll_writelock, 0, 0))
{
close(f);
+ unlink(name);
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);
+ unlink(name);
exit(1);
}
close(fd[1]);