#include <errno.h>
#include <stdio.h>
+#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/statvfs.h>
#include <sys/auxv.h>
#include <sys/xattr.h>
#include <unistd.h>
+#if WANT_LINUX_FS_H
+# include <linux/fs.h>
+#endif
#include "sd-daemon.h"
#include "sd-journal.h"
return 0;
}
-static int gather_pid_mount_tree_fd(const Context *context) {
- _cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF;
+static int gather_pid_mount_tree_fd(const Context *context, int *ret_fd) {
+ /* Don't bother preparing environment if we can't pass it to libdwfl. */
+#if !HAVE_DWFL_SET_SYSROOT
+ *ret_fd = -EOPNOTSUPP;
+ log_debug("dwfl_set_sysroot() is not supported.");
+#else
+ _cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF, fd = -EBADF;
_cleanup_close_pair_ int pair[2] = EBADF_PAIR;
- int fd = -EBADF, r;
- pid_t child;
+ int r;
assert(context);
+ assert(ret_fd);
- /* Don't bother preparing environment if we can't pass it to libdwfl. */
-#if !HAVE_DWFL_SET_SYSROOT
- return -EOPNOTSUPP;
-#endif
-
- if (!arg_access_container)
- return -EOPNOTSUPP;
+ if (!arg_access_container) {
+ *ret_fd = -EHOSTDOWN;
+ log_debug("EnterNamespace=no so we won't use mount tree of the crashed process for generating backtrace.");
+ return 0;
+ }
if (socketpair(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, pair) < 0)
return log_error_errno(errno, "Failed to create socket pair: %m");
- r = namespace_open(context->pid, NULL, &mntns_fd, NULL, NULL, &root_fd);
+ r = namespace_open(context->pid,
+ /* ret_pidns_fd= */ NULL,
+ &mntns_fd,
+ /* ret_netns_fd= */ NULL,
+ /* ret_userns_fd= */ NULL,
+ &root_fd);
if (r < 0)
return log_error_errno(r, "Failed to open mount namespace of crashing process: %m");
if (fd < 0)
return log_error_errno(fd, "Failed to receive mount tree: %m");
- return fd;
+ *ret_fd = TAKE_FD(fd);
+#endif
+ return 0;
}
static int process_kernel(int argc, char* argv[]) {
if (r >= 0)
return 0;
- r = gather_pid_mount_tree_fd(&context);
- if (r < 0 && r != -EOPNOTSUPP)
+ r = gather_pid_mount_tree_fd(&context, &mount_tree_fd);
+ if (r < 0)
log_warning_errno(r, "Failed to access the mount tree of a container, ignoring: %m");
- else
- mount_tree_fd = r;
}
/* If this is PID 1 disable coredump collection, we'll unlikely be able to process