Skip to content

Commit 68fa858

Browse files
authored
Merge pull request #640 from DevonSchwartz/fix_lxcfs_read_null
Fix lxcfs read null
2 parents a280a2e + bcb1b0a commit 68fa858

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/lxcfs.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,9 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
746746
#endif
747747
{
748748
int ret;
749+
enum lxcfs_virt_t type;
750+
751+
type = file_info_type(fi);
749752

750753
if (strcmp(path, "/") == 0) {
751754
if (dir_filler(filler, buf, ".", 0) != 0 ||
@@ -758,21 +761,21 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
758761
return 0;
759762
}
760763

761-
if (cgroup_is_enabled && strncmp(path, "/cgroup", 7) == 0) {
764+
if (cgroup_is_enabled && LXCFS_TYPE_CGROUP(type)) {
762765
up_users();
763766
ret = do_cg_readdir(path, buf, filler, offset, fi);
764767
down_users();
765768
return ret;
766769
}
767770

768-
if (strcmp(path, "/proc") == 0) {
771+
if (LXCFS_TYPE_PROC(type)) {
769772
up_users();
770773
ret = do_proc_readdir(path, buf, filler, offset, fi);
771774
down_users();
772775
return ret;
773776
}
774777

775-
if (strncmp(path, "/sys", 4) == 0) {
778+
if (LXCFS_TYPE_SYS(type)) {
776779
up_users();
777780
ret = do_sys_readdir(path, buf, filler, offset, fi);
778781
down_users();
@@ -879,44 +882,53 @@ static int lxcfs_read(const char *path, char *buf, size_t size, off_t offset,
879882
struct fuse_file_info *fi)
880883
{
881884
int ret;
885+
enum lxcfs_virt_t type;
886+
887+
type = file_info_type(fi);
882888

883-
if (cgroup_is_enabled && strncmp(path, "/cgroup", 7) == 0) {
889+
if (cgroup_is_enabled && LXCFS_TYPE_CGROUP(type)) {
884890
up_users();
885891
ret = do_cg_read(path, buf, size, offset, fi);
886892
down_users();
887893
return ret;
888894
}
889895

890-
if (strncmp(path, "/proc", 5) == 0) {
896+
if (LXCFS_TYPE_PROC(type)) {
891897
up_users();
892898
ret = do_proc_read(path, buf, size, offset, fi);
893899
down_users();
894900
return ret;
895901
}
896902

897-
if (strncmp(path, "/sys", 4) == 0) {
903+
if (LXCFS_TYPE_SYS(type)) {
898904
up_users();
899905
ret = do_sys_read(path, buf, size, offset, fi);
900906
down_users();
901907
return ret;
902908
}
903909

910+
lxcfs_error("unknown file type: path=%s, type=%d, fi->fh=%" PRIu64,
911+
path, type, fi->fh);
912+
904913
return -EINVAL;
905914
}
906915

907916
int lxcfs_write(const char *path, const char *buf, size_t size, off_t offset,
908917
struct fuse_file_info *fi)
909918
{
910919
int ret;
920+
enum lxcfs_virt_t type;
921+
922+
type = file_info_type(fi);
911923

912-
if (cgroup_is_enabled && strncmp(path, "/cgroup", 7) == 0) {
924+
if (cgroup_is_enabled && LXCFS_TYPE_CGROUP(type)) {
913925
up_users();
914926
ret = do_cg_write(path, buf, size, offset, fi);
915927
down_users();
916928
return ret;
917929
}
918930

919-
if (strncmp(path, "/sys", 4) == 0) {
931+
if (LXCFS_TYPE_SYS(type)) {
920932
up_users();
921933
ret = do_sys_write(path, buf, size, offset, fi);
922934
down_users();

0 commit comments

Comments
 (0)