Skip to content

Commit

Permalink
TOOLS/VFS: convert stack allocation at vfs_mount() to heap
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-shalev committed Sep 10, 2024
1 parent 38aef67 commit 92fdb9a
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/tools/vfs/vfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

#include "vfs_daemon.h"

#include <ucs/sys/string.h>
#include <ucs/debug/log_def.h>
#include <ucs/debug/memtrack_int.h>
#include <sys/wait.h>
#include <limits.h>
#include <stdlib.h>
Expand Down Expand Up @@ -151,10 +153,17 @@ static const char *vfs_get_process_name(int pid, char *buf, size_t max_length)

int vfs_mount(int pid)
{
char mountpoint[PATH_MAX];
char *mountpoint = NULL;
char mountopts[1024];
char name[NAME_MAX];
int fuse_fd, ret;
ucs_status_t status;

status = ucs_string_alloc_path_buffer(&mountpoint, "mountpoint");
if (status != UCS_OK) {
ret = -ENOMEM;
goto out;
}

/* Add common mount options:
* - File system name (source) : process name and pid
Expand All @@ -168,16 +177,17 @@ int vfs_mount(int pid)
vfs_get_process_name(pid, name, sizeof(name)),
(strlen(g_opts.mount_opts) > 0) ? "," : "", g_opts.mount_opts);
if (ret >= sizeof(mountopts)) {
return -ENOMEM;
ret = -ENOMEM;
goto out;
}

/* Create the mount point directory, and ignore "already exists" error */
vfs_get_mountpoint(pid, mountpoint, sizeof(mountpoint));
vfs_get_mountpoint(pid, mountpoint, PATH_MAX);
ret = mkdir(mountpoint, S_IRWXU);
if ((ret < 0) && (errno != EEXIST)) {
ret = -errno;
vfs_error("failed to create directory '%s': %m", mountpoint);
return ret;
goto out;
}

/* Mount a new FUSE filesystem in the mount point directory */
Expand All @@ -186,11 +196,17 @@ int vfs_mount(int pid)
if (fuse_fd < 0) {
vfs_error("fuse_open_channel(%s,opts=%s) failed: %m", mountpoint,
mountopts);
return fuse_fd;
ret = fuse_fd;
goto out;
}

vfs_log("mounted directory '%s' with fd %d", mountpoint, fuse_fd);
return fuse_fd;

ret = fuse_fd;

out:
ucs_free(mountpoint);
return ret;
}

int vfs_unmount(int pid)
Expand Down

0 comments on commit 92fdb9a

Please sign in to comment.