]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
preforker: prevent call to 'write' on an fd that was already closed, plus minor code... 10949/head
authorAvner BenHanoch <avnerb@mellanox.com>
Thu, 1 Sep 2016 08:49:13 +0000 (11:49 +0300)
committerAvner BenHanoch <avnerb@mellanox.com>
Thu, 1 Sep 2016 08:49:13 +0000 (11:49 +0300)
upon ceph_mon parent exiting it calls prefork.exit(err) that was resulting in
writing the exit status to fd[1] whis was previously closed in this process.
for fixing it, I guarded the call to 'signal_exit(r)' with 'if (is_child())'

on the way, I provided 2 minor code fixups in this file

Signed-off-by: Avner BenHanoch <avnerb@mellanox.com>
src/common/Preforker.h

index 446f1c97f2babdf2225e979c4f2ea75022f775f1..cc8ed46bc7a13538db14fbe39051742ce28167c0 100644 (file)
@@ -39,7 +39,7 @@ public:
 
   int prefork(std::string &err) {
     assert(!forked);
-    int r = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
+    int r = ::socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
     std::ostringstream oss;
     if (r < 0) {
       oss << "[" << getpid() << "]: unable to create socketpair: " << cpp_strerror(errno);
@@ -56,7 +56,7 @@ public:
       err = oss.str();
       return r;
     }
-    if (childpid == 0) {
+    if (is_child()) {
       ::close(fd[0]);
     } else {
       ::close(fd[1]);
@@ -117,7 +117,8 @@ public:
     return r;
   }
   void exit(int r) {
-    signal_exit(r);
+    if (is_child())
+        signal_exit(r);
     ::exit(r);
   }