]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: Fix respawn (add path resolution) 1671/head
authorJohn Spray <john.spray@inktank.com>
Mon, 14 Apr 2014 16:14:42 +0000 (17:14 +0100)
committerJohn Spray <john.spray@inktank.com>
Tue, 15 Apr 2014 11:28:09 +0000 (12:28 +0100)
Previously assumed that ceph-mds executable was in
PWD - now use /proc/self/exe to find the
executable whereever it may be.  Leave in old version
as a fallback for non-linux environments.

Also add a 'respawn' command so that it's easy to test
respawn with `ceph mds tell <id> respawn`

Fixes: #7966
src/mds/MDS.cc

index 15af84f840dfc2d9d202a1e0d16a6ce6afab071d..e717dd7f762b9007e5b05f2cdac72f14ce948afa 100644 (file)
@@ -749,6 +749,9 @@ void MDS::handle_command(MMonCommand *m)
   else if (m->cmd[0] == "exit") {
     suicide();
   }
+  else if (m->cmd[0] == "respawn") {
+    respawn();
+  }
   else if (m->cmd[0] == "session" && m->cmd[1] == "kill") {
     Session *session = sessionmap.get_session(entity_name_t(CEPH_ENTITY_TYPE_CLIENT,
                                                            strtol(m->cmd[2].c_str(), 0, 10)));
@@ -1696,13 +1699,25 @@ void MDS::respawn()
   }
   new_argv[orig_argc] = NULL;
 
-  char buf[PATH_MAX];
-  char *cwd = getcwd(buf, sizeof(buf));
-  assert(cwd);
-  dout(1) << " cwd " << cwd << dendl;
+  /* Determine the path to our executable, try to read
+   * linux-specific /proc/ path first */
+  char exe_path[PATH_MAX];
+  ssize_t exe_path_bytes = readlink("/proc/self/exe", exe_path, sizeof(exe_path));
+  if (exe_path_bytes == -1) {
+    /* Print CWD for the user's interest */
+    char buf[PATH_MAX];
+    char *cwd = getcwd(buf, sizeof(buf));
+    assert(cwd);
+    dout(1) << " cwd " << cwd << dendl;
+
+    /* Fall back to a best-effort: just running in our CWD */
+    strncpy(exe_path, orig_argv[0], sizeof(exe_path));
+  }
+
+  dout(1) << " exe_path " << exe_path << dendl;
 
   unblock_all_signals(NULL);
-  execv(orig_argv[0], new_argv);
+  execv(exe_path, new_argv);
 
   dout(0) << "respawn execv " << orig_argv[0]
          << " failed with " << cpp_strerror(errno) << dendl;