From: John Carr Date: Sun, 23 Feb 1992 12:29:25 +0000 (+0000) Subject: Support POSIX file locking. X-Git-Tag: krb5-1.0-beta2~217 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e91e2a575a8569512bd6c07a0e1a55e11bca4f6e;p=krb5.git Support POSIX file locking. Use fstat() instead of stat(). git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2245 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/slave/kprop.c b/src/slave/kprop.c index 70a3f2c09..04472f7c2 100644 --- a/src/slave/kprop.c +++ b/src/slave/kprop.c @@ -176,7 +176,7 @@ void get_tickets() { char my_host_name[MAXHOSTNAMELEN]; char buf[BUFSIZ]; - char *cp, *strcpy(), *krb_get_phost(); + char *cp; struct hostent *hp; krb5_address **my_addresses; krb5_error_code retval; @@ -408,18 +408,33 @@ open_database(data_fn, size) struct stat stbuf, stbuf_ok; char *data_ok_fn; static char ok[] = ".dump_ok"; - + if ((fd = open(data_fn, O_RDONLY)) < 0) { - com_err(progname, 0, "While trying to open %s", + com_err(progname, errno, "while trying to open %s", data_fn); exit(1); } - if (flock(fd, LOCK_SH | LOCK_NB)) { - com_err(progname, errno, "while trying to flock %s", - data_fn); + +#ifdef POSIX_FILE_LOCKS + if (lockf(fd, LOCK_SH | LOCK_NB, 0) < 0) { + if (errno == EWOULDBLOCK || errno == EAGAIN) + com_err(progname, 0, "database locked"); + else + com_err(progname, errno, "while trying to flock %s", + data_fn); + exit(1); + } +#else + if (flock(fd, LOCK_SH | LOCK_NB) < 0) { + if (errno == EWOULDBLOCK || errno == EAGAIN) + com_err(progname, 0, "database locked"); + else + com_err(progname, errno, "while trying to flock %s", + data_fn); exit(1); } - if (stat(data_fn, &stbuf)) { +#endif + if (fstat(fd, &stbuf)) { com_err(progname, errno, "while trying to stat %s", data_fn); exit(1);