propagate_directory = strjoina("/run/systemd/propagate/", u->id);
if (is_image)
r = mount_image_in_namespace(
- unit_pid->pid,
+ unit_pid,
propagate_directory,
"/run/systemd/incoming/",
src, dest,
c->mount_image_policy ?: &image_policy_service);
else
r = bind_mount_in_namespace(
- unit_pid->pid,
+ unit_pid,
propagate_directory,
"/run/systemd/incoming/",
src, dest,
}
static int mount_in_namespace(
- pid_t target,
+ PidRef *target,
const char *propagate_path,
const char *incoming_path,
const char *src,
pid_t child;
int r;
- assert(target > 0);
assert(propagate_path);
assert(incoming_path);
assert(src);
assert(dest);
assert(!options || is_image);
- r = namespace_open(target, &pidns_fd, &mntns_fd, NULL, NULL, &root_fd);
+ if (!pidref_is_set(target))
+ return -ESRCH;
+
+ r = namespace_open(target->pid, &pidns_fd, &mntns_fd, NULL, NULL, &root_fd);
if (r < 0)
return log_debug_errno(r, "Failed to retrieve FDs of the target process' namespace: %m");
- r = in_same_namespace(target, 0, NAMESPACE_MOUNT);
+ r = in_same_namespace(target->pid, 0, NAMESPACE_MOUNT);
if (r < 0)
return log_debug_errno(r, "Failed to determine if mount namespaces are equal: %m");
/* We can't add new mounts at runtime if the process wasn't started in a namespace */
if (r > 0)
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to activate bind mount in target, not running in a mount namespace");
+ if (pidref_verify(target) < 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(ESRCH), "Failed to verify target process '" PID_FMT "': %m", target->pid);
+
r = chase(src, NULL, 0, &chased_src_path, &chased_src_fd);
if (r < 0)
return log_debug_errno(r, "Failed to resolve source path of %s: %m", src);
}
int bind_mount_in_namespace(
- pid_t target,
+ PidRef * target,
const char *propagate_path,
const char *incoming_path,
const char *src,
}
int mount_image_in_namespace(
- pid_t target,
+ PidRef * target,
const char *propagate_path,
const char *incoming_path,
const char *src,
#include "dissect-image.h"
#include "errno-util.h"
#include "macro.h"
+#include "pidref.h"
int repeat_unmount(const char *path, int flags);
}
DEFINE_TRIVIAL_CLEANUP_FUNC(char*, umount_and_free);
-int bind_mount_in_namespace(pid_t target, const char *propagate_path, const char *incoming_path, const char *src, const char *dest, bool read_only, bool make_file_or_directory);
-int mount_image_in_namespace(pid_t target, const char *propagate_path, const char *incoming_path, const char *src, const char *dest, bool read_only, bool make_file_or_directory, const MountOptions *options, const ImagePolicy *image_policy);
+int bind_mount_in_namespace(PidRef *target, const char *propagate_path, const char *incoming_path, const char *src, const char *dest, bool read_only, bool make_file_or_directory);
+int mount_image_in_namespace(PidRef *target, const char *propagate_path, const char *incoming_path, const char *src, const char *dest, bool read_only, bool make_file_or_directory, const MountOptions *options, const ImagePolicy *image_policy);
int make_mount_point(const char *path);
int fd_make_mount_point(int fd);