Skip to content

Commit

Permalink
mount: Remove files in place of mount points
Browse files Browse the repository at this point in the history
If a mount point is not a directory, systemd will remove() it and then
mkdir_p() the full path.

Signed-off-by: rajmohan r <rajmohan.r@kpit.com>
  • Loading branch information
rajmohanrgithub committed Apr 23, 2024
1 parent 606472d commit 9e5a453
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@ static int mount_set_mount_command(Mount *m, ExecCommand *c, const MountParamete

static void mount_enter_mounting(Mount *m) {
MountParameters *p;
DIR* dp;
bool source_is_dir = true;
int r;

Expand Down Expand Up @@ -1168,6 +1169,16 @@ static void mount_enter_mounting(Mount *m) {
m->control_command_id = MOUNT_EXEC_MOUNT;
m->control_command = m->exec_command + MOUNT_EXEC_MOUNT;

dp = opendir(m->where);
if (!dp) {
//this is not a directory but rather file or link
remove(m->where);
mkdir_p(m->where, m->directory_mode);
}
else {
closedir(dp);
}

/* Create the source directory for bind-mounts if needed */
if (p && mount_is_bind(p)) {
r = mkdir_p_label(p->what, m->directory_mode);
Expand Down

0 comments on commit 9e5a453

Please sign in to comment.