Porting to SunOS 5.8:

- Include all header files necessary
- Check for flock() function
This commit is contained in:
Guus Sliepen 2000-11-07 22:33:33 +00:00
parent 7d0f82bd4b
commit 56bd0864e4
2 changed files with 9 additions and 3 deletions

View file

@ -32,6 +32,8 @@
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <sys/types.h>
#include <fcntl.h>
/* read_pid
*
@ -93,13 +95,15 @@ int write_pid (char *pidfile)
fprintf(stderr, "Can't open or create %s.\n", pidfile);
return 0;
}
#ifdef HAVE_FLOCK
if (flock(fd, LOCK_EX|LOCK_NB) == -1) {
fscanf(f, "%d", &pid);
fclose(f);
printf("Can't lock, lock is held by pid %d.\n", pid);
return 0;
}
#endif
pid = getpid();
if (!fprintf(f,"%d\n", pid)) {
@ -109,11 +113,13 @@ int write_pid (char *pidfile)
}
fflush(f);
#ifdef HAVE_FLOCK
if (flock(fd, LOCK_UN) == -1) {
printf("Can't unlock pidfile %s, %s.\n", pidfile, strerror(errno));
close(fd);
return 0;
}
#endif
close(fd);
return pid;