Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lxcfs read null #640

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/lxcfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,9 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
#endif
{
int ret;
enum lxcfs_virt_t type;

type = file_info_type(fi);

if (strcmp(path, "/") == 0) {
if (dir_filler(filler, buf, ".", 0) != 0 ||
Expand All @@ -755,21 +758,21 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
return 0;
}

if (cgroup_is_enabled && strncmp(path, "/cgroup", 7) == 0) {
if (cgroup_is_enabled && LXCFS_TYPE_CGROUP(type)) {
up_users();
ret = do_cg_readdir(path, buf, filler, offset, fi);
down_users();
return ret;
}

if (strcmp(path, "/proc") == 0) {
if (LXCFS_TYPE_PROC(type)) {
up_users();
ret = do_proc_readdir(path, buf, filler, offset, fi);
down_users();
return ret;
}

if (strncmp(path, "/sys", 4) == 0) {
if (LXCFS_TYPE_SYS(type)) {
up_users();
ret = do_sys_readdir(path, buf, filler, offset, fi);
down_users();
Expand Down Expand Up @@ -876,44 +879,53 @@ static int lxcfs_read(const char *path, char *buf, size_t size, off_t offset,
struct fuse_file_info *fi)
{
int ret;
enum lxcfs_virt_t type;

type = file_info_type(fi);

if (cgroup_is_enabled && strncmp(path, "/cgroup", 7) == 0) {
if (cgroup_is_enabled && LXCFS_TYPE_CGROUP(type)) {
up_users();
ret = do_cg_read(path, buf, size, offset, fi);
down_users();
return ret;
}

if (strncmp(path, "/proc", 5) == 0) {
if (LXCFS_TYPE_PROC(type)) {
up_users();
ret = do_proc_read(path, buf, size, offset, fi);
down_users();
return ret;
}

if (strncmp(path, "/sys", 4) == 0) {
if (LXCFS_TYPE_SYS(type)) {
up_users();
ret = do_sys_read(path, buf, size, offset, fi);
down_users();
return ret;
}

lxcfs_error("unknown file type: path=%s, type=%d, fi->fh=%" PRIu64,
path, type, fi->fh);

return -EINVAL;
}

int lxcfs_write(const char *path, const char *buf, size_t size, off_t offset,
struct fuse_file_info *fi)
{
int ret;
enum lxcfs_virt_t type;

type = file_info_type(fi);

if (cgroup_is_enabled && strncmp(path, "/cgroup", 7) == 0) {
if (cgroup_is_enabled && LXCFS_TYPE_CGROUP(type)) {
up_users();
ret = do_cg_write(path, buf, size, offset, fi);
down_users();
return ret;
}

if (strncmp(path, "/sys", 4) == 0) {
if (LXCFS_TYPE_SYS(type)) {
up_users();
ret = do_sys_write(path, buf, size, offset, fi);
down_users();
Expand Down