common: be more informative if set PID-file fails 23647/head
authorWillem Jan Withagen <wjw@digiware.nl>
Mon, 20 Aug 2018 10:31:10 +0000 (12:31 +0200)
committerWillem Jan Withagen <wjw@digiware.nl>
Tue, 21 Aug 2018 13:13:28 +0000 (15:13 +0200)
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 <wjw@digiware.nl>
src/global/pidfile.cc

index de242d779b3639a62c0aac81a534f1bbefa146c4..2de2f54b95a0b8a089d980d68dc780b275a44a37 100644 (file)
@@ -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;