[sheepdog] [PATCH] sheep: lock against concurrent access to the log file
Christoph Hellwig
hch at infradead.org
Fri May 18 13:44:17 CEST 2012
I'm currently debugging a problem where a logger stays around even after the
sheep was killed. Lock access to the log file to make debugging cases like
this easier.
Signed-off-by: Christoph Hellwig <hch at lst.de>
diff --git a/lib/logger.c b/lib/logger.c
index 5bce85c..b15ecc5 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -424,6 +424,18 @@ notrace int log_init(char *program_name, int size, int to_stdout, int level,
syslog(LOG_ERR, "failed to open %s\n", outfile);
return 1;
}
+
+ if (lockf(fd, F_TLOCK, 1) < 0) {
+ if (errno == EACCES || errno == EAGAIN) {
+ eprintf("another sheep daemon "
+ "is using %s\n", outfile);
+ } else {
+ eprintf("unable to get a lock "
+ "on the log file %s (%s)\n",
+ outfile, strerror(errno));
+ }
+ return 1;
+ }
} else {
fd = -1;
openlog(log_name, LOG_CONS | LOG_PID, LOG_DAEMON);
More information about the sheepdog
mailing list