From 68c9d9a2e1313a59ccc19c932c93a000398517b6 Mon Sep 17 00:00:00 2001 From: Willem Jan Withagen Date: Mon, 20 Aug 2018 12:31:10 +0200 Subject: [PATCH] common: be more informative if set PID-file fails The errors returned by fcntl(...F_SETLK...) can be: - -1 for any odd error - EAGAIN if locking does not work because the file is already locked. Differentiate in these to be more informative on what is going on. Signed-off-by: Willem Jan Withagen --- src/global/pidfile.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/global/pidfile.cc b/src/global/pidfile.cc index de242d779b36..2de2f54b95a0 100644 --- a/src/global/pidfile.cc +++ b/src/global/pidfile.cc @@ -171,8 +171,14 @@ int pidfh::open(const ConfigProxy& conf) }; int r = ::fcntl(pf_fd, F_SETLK, &l); if (r < 0) { - derr << __func__ << ": failed to lock pidfile " - << pf_path << " because another process locked it." << dendl; + if (errno == EAGAIN || errno == EACCES) { + derr << __func__ << ": failed to lock pidfile " + << pf_path << " because another process locked it" + << "': " << cpp_strerror(errno) << dendl; + } else { + derr << __func__ << ": failed to lock pidfile " + << pf_path << "': " << cpp_strerror(errno) << dendl; + } ::close(pf_fd); reset(); return -errno; -- 2.47.3