{"action":"created","comment":{"url":"https://api.github.com/repos/docker/docker/pulls/comments/32657397","id":32657397,"diff_hunk":"@@ -13,82 +13,83 @@ import (\n \n // New returns a new SysInfo, using the filesystem to detect which features the kernel supports.\n func New(quiet bool) *SysInfo {\n+\t// Check if Devices cgroup is mounted, it is hard requirement for container security.\n+\tif _, err := cgroups.FindCgroupMountpoint(\"devices\"); err != nil {\n+\t\tlogrus.Fatalf(\"Error mounting devices cgroup: %v\", err)\n+\t}\n+\n \tsysInfo := &SysInfo{}\n-\tif cgroupMemoryMountpoint, err := cgroups.FindCgroupMountpoint(\"memory\"); err != nil {\n+\tsysInfo.cgroupMemInfo = checkCgroupMem(quiet)\n+\tsysInfo.cgroupCpuInfo = checkCgroupCpu(quiet)\n+\n+\tsysInfo.IPv4ForwardingDisabled = !readProcBool(\"/proc/sys/net/ipv4/ip_forward\")\n+\tsysInfo.BridgeNfCallIptablesDisabled = !readProcBool(\"/proc/sys/net/bridge/bridge-nf-call-iptables\")\n+\tsysInfo.BridgeNfCallIp6tablesDisabled = !readProcBool(\"/proc/sys/net/bridge/bridge-nf-call-ip6tables\")\n+\n+\t// Check if AppArmor is supported.\n+\tif _, err := os.Stat(\"/sys/kernel/security/apparmor\"); !os.IsNotExist(err) {\n+\t\tsysInfo.AppArmor = true\n+\t}\n+\n+\treturn sysInfo\n+}\n+\n+func checkCgroupMem(quiet bool) *cgroupMemInfo {\n+\tinfo := &cgroupMemInfo{}\n+\tmountPoint, err := cgroups.FindCgroupMountpoint(\"memory\")\n+\tif err != nil {\n \t\tif !quiet {\n \t\t\tlogrus.Warnf(\"Your kernel does not support cgroup memory limit: %v\", err)\n \t\t}\n-\t} else {\n-\t\t// If memory cgroup is mounted, MemoryLimit is always enabled.\n-\t\tsysInfo.MemoryLimit = true\n-\n-\t\t_, err1 := ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, \"memory.memsw.limit_in_bytes\"))\n-\t\tsysInfo.SwapLimit = err1 == nil\n-\t\tif !sysInfo.SwapLimit && !quiet {\n-\t\t\tlogrus.Warn(\"Your kernel does not support swap memory limit.\")\n-\t\t}\n+\t\treturn nil\n+\t}\n+\tinfo.MemoryLimit = true\n \n-\t\t_, err = ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, \"memory.oom_control\"))\n-\t\tsysInfo.OomKillDisable = err == nil\n-\t\tif !sysInfo.OomKillDisable && !quiet {\n-\t\t\tlogrus.Warnf(\"Your kernel does not support oom control.\")\n-\t\t}\n+\tinfo.SwapLimit = cgroupEnabled(mountPoint, \"memory.memsw.limit_in_bytes\")\n+\tif !quiet && !info.SwapLimit {\n+\t\tlogrus.Warn(\"Your kernel does not support swap memory limit.\")\n \t}\n+\tinfo.OomKillDisable = cgroupEnabled(mountPoint, \"memory.oom_control\")\n+\tif !quiet && !info.OomKillDisable {\n+\t\tlogrus.Warnf(\"Your kernel does not support oom control.\")\n+\t}\n+\n+\treturn info\n+}\n \n-\tif cgroupCpuMountpoint, err := cgroups.FindCgroupMountpoint(\"cpu\"); err != nil {\n+func checkCgroupCpu(quiet bool) *cgroupCpuInfo {\n+\tinfo := &cgroupCpuInfo{}\n+\tmountPoint, err := cgroups.FindCgroupMountpoint(\"cpu\")\n+\tif err != nil {\n \t\tif !quiet {\n-\t\t\tlogrus.Warnf(\"%v\", err)\n-\t\t}\n-\t} else {\n-\t\t_, err := ioutil.ReadFile(path.Join(cgroupCpuMountpoint, \"cpu.cfs_period_us\"))\n-\t\tsysInfo.CpuCfsPeriod = err == nil\n-\t\tif !sysInfo.CpuCfsPeriod && !quiet {\n-\t\t\tlogrus.Warn(\"Your kernel does not support cgroup cfs period\")\n-\t\t}\n-\t\t_, err = ioutil.ReadFile(path.Join(cgroupCpuMountpoint, \"cpu.cfs_quota_us\"))\n-\t\tsysInfo.CpuCfsQuota = err == nil\n-\t\tif !sysInfo.CpuCfsQuota && !quiet {\n-\t\t\tlogrus.Warn(\"Your kernel does not support cgroup cfs quotas\")\n+\t\t\tlogrus.Warn(err)\n \t\t}\n+\t\treturn nil\n \t}\n \n-\t// Checek if ipv4_forward is disabled.\n-\tif data, err := ioutil.ReadFile(\"/proc/sys/net/ipv4/ip_forward\"); os.IsNotExist(err) {\n-\t\tsysInfo.IPv4ForwardingDisabled = true\n-\t} else {\n-\t\tif enabled, _ := strconv.Atoi(strings.TrimSpace(string(data))); enabled == 0 {\n-\t\t\tsysInfo.IPv4ForwardingDisabled = true\n-\t\t} else {\n-\t\t\tsysInfo.IPv4ForwardingDisabled = false\n-\t\t}\n+\tinfo.CpuCfsPeriod = cgroupEnabled(mountPoint, \"cpu.cfs_period_us\")\n+\tif !quiet && !info.CpuCfsPeriod {\n+\t\tlogrus.Warn(\"Your kernel does not support cgroup cfs period\")\n \t}\n \n-\t// Check if bridge-nf-call-iptables is disabled.\n-\tif data, err := ioutil.ReadFile(\"/proc/sys/net/bridge/bridge-nf-call-iptables\"); os.IsNotExist(err) {\n-\t\tsysInfo.BridgeNfCallIptablesDisabled = true\n-\t} else {\n-\t\tenabled, _ := strconv.Atoi(strings.TrimSpace(string(data)))\n-\t\tsysInfo.BridgeNfCallIptablesDisabled = enabled == 0\n-\t}\n-\t// Check if bridge-nf-call-ip6tables is disabled.\n-\tif data, err := ioutil.ReadFile(\"/proc/sys/net/bridge/bridge-nf-call-ip6tables\"); os.IsNotExist(err) {\n-\t\tsysInfo.BridgeNfCallIp6tablesDisabled = true\n-\t} else {\n-\t\tenabled, _ := strconv.Atoi(strings.TrimSpace(string(data)))\n-\t\tsysInfo.BridgeNfCallIp6tablesDisabled = enabled == 0\n+\tinfo.CpuCfsQuota = cgroupEnabled(mountPoint, \"cpu.cfs_quota_us\")\n+\tif !quiet && !info.CpuCfsQuota {\n+\t\tlogrus.Warn(\"Your kernel does not support cgroup cfs quotas\")\n \t}\n+\treturn info\n+}\n \n-\t// Check if AppArmor is supported.\n-\tif _, err := os.Stat(\"/sys/kernel/security/apparmor\"); os.IsNotExist(err) {\n-\t\tsysInfo.AppArmor = false\n-\t} else {\n-\t\tsysInfo.AppArmor = true\n-\t}\n+func cgroupEnabled(mountPoint, name string) bool {\n+\t_, err := ioutil.ReadFile(path.Join(mountPoint, name))\n+\treturn err == nil\n+}\n \n-\t// Check if Devices cgroup is mounted, it is hard requirement for container security.\n-\tif _, err := cgroups.FindCgroupMountpoint(\"devices\"); err != nil {\n-\t\tlogrus.Fatalf(\"Error mounting devices cgroup: %v\", err)\n+func readProcBool(path string) bool {\n+\tval, err := ioutil.ReadFile(path)\n+\tif err != nil {\n+\t\treturn false\n \t}\n \n-\treturn sysInfo\n+\tenabled, _ := strconv.Atoi(strings.TrimSpace(string(val)))","path":"pkg/sysinfo/sysinfo_linux.go","position":141,"original_position":141,"commit_id":"5387cb503d3e0203f8c2d023aae398e19ddc77ac","original_commit_id":"5387cb503d3e0203f8c2d023aae398e19ddc77ac","user":{"login":"LK4D4","id":101445,"avatar_url":"https://avatars.githubusercontent.com/u/101445?v=3","gravatar_id":"","url":"https://api.github.com/users/LK4D4","html_url":"https://github.com/LK4D4","followers_url":"https://api.github.com/users/LK4D4/followers","following_url":"https://api.github.com/users/LK4D4/following{/other_user}","gists_url":"https://api.github.com/users/LK4D4/gists{/gist_id}","starred_url":"https://api.github.com/users/LK4D4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LK4D4/subscriptions","organizations_url":"https://api.github.com/users/LK4D4/orgs","repos_url":"https://api.github.com/users/LK4D4/repos","events_url":"https://api.github.com/users/LK4D4/events{/privacy}","received_events_url":"https://api.github.com/users/LK4D4/received_events","type":"User","site_admin":false},"body":"how about `return string(val) == \"1\"`?","created_at":"2015-06-17T18:17:41Z","updated_at":"2015-06-17T18:17:41Z","html_url":"https://github.com/docker/docker/pull/13978#discussion_r32657397","pull_request_url":"https://api.github.com/repos/docker/docker/pulls/13978","_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/comments/32657397"},"html":{"href":"https://github.com/docker/docker/pull/13978#discussion_r32657397"},"pull_request":{"href":"https://api.github.com/repos/docker/docker/pulls/13978"}}},"pull_request":{"url":"https://api.github.com/repos/docker/docker/pulls/13978","id":37860939,"html_url":"https://github.com/docker/docker/pull/13978","diff_url":"https://github.com/docker/docker/pull/13978.diff","patch_url":"https://github.com/docker/docker/pull/13978.patch","issue_url":"https://api.github.com/repos/docker/docker/issues/13978","number":13978,"state":"open","locked":false,"title":"cleanup sysinfo package","user":{"login":"cpuguy83","id":799078,"avatar_url":"https://avatars.githubusercontent.com/u/799078?v=3","gravatar_id":"","url":"https://api.github.com/users/cpuguy83","html_url":"https://github.com/cpuguy83","followers_url":"https://api.github.com/users/cpuguy83/followers","following_url":"https://api.github.com/users/cpuguy83/following{/other_user}","gists_url":"https://api.github.com/users/cpuguy83/gists{/gist_id}","starred_url":"https://api.github.com/users/cpuguy83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpuguy83/subscriptions","organizations_url":"https://api.github.com/users/cpuguy83/orgs","repos_url":"https://api.github.com/users/cpuguy83/repos","events_url":"https://api.github.com/users/cpuguy83/events{/privacy}","received_events_url":"https://api.github.com/users/cpuguy83/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-06-17T02:38:42Z","updated_at":"2015-06-17T18:17:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fc70bba898830d5124d5fef56652f2100c848e3e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/docker/docker/pulls/13978/commits","review_comments_url":"https://api.github.com/repos/docker/docker/pulls/13978/comments","review_comment_url":"https://api.github.com/repos/docker/docker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/docker/issues/13978/comments","statuses_url":"https://api.github.com/repos/docker/docker/statuses/5387cb503d3e0203f8c2d023aae398e19ddc77ac","head":{"label":"cpuguy83:cleanup_sysinfo","ref":"cleanup_sysinfo","sha":"5387cb503d3e0203f8c2d023aae398e19ddc77ac","user":{"login":"cpuguy83","id":799078,"avatar_url":"https://avatars.githubusercontent.com/u/799078?v=3","gravatar_id":"","url":"https://api.github.com/users/cpuguy83","html_url":"https://github.com/cpuguy83","followers_url":"https://api.github.com/users/cpuguy83/followers","following_url":"https://api.github.com/users/cpuguy83/following{/other_user}","gists_url":"https://api.github.com/users/cpuguy83/gists{/gist_id}","starred_url":"https://api.github.com/users/cpuguy83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpuguy83/subscriptions","organizations_url":"https://api.github.com/users/cpuguy83/orgs","repos_url":"https://api.github.com/users/cpuguy83/repos","events_url":"https://api.github.com/users/cpuguy83/events{/privacy}","received_events_url":"https://api.github.com/users/cpuguy83/received_events","type":"User","site_admin":false},"repo":{"id":15300899,"name":"docker","full_name":"cpuguy83/docker","owner":{"login":"cpuguy83","id":799078,"avatar_url":"https://avatars.githubusercontent.com/u/799078?v=3","gravatar_id":"","url":"https://api.github.com/users/cpuguy83","html_url":"https://github.com/cpuguy83","followers_url":"https://api.github.com/users/cpuguy83/followers","following_url":"https://api.github.com/users/cpuguy83/following{/other_user}","gists_url":"https://api.github.com/users/cpuguy83/gists{/gist_id}","starred_url":"https://api.github.com/users/cpuguy83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpuguy83/subscriptions","organizations_url":"https://api.github.com/users/cpuguy83/orgs","repos_url":"https://api.github.com/users/cpuguy83/repos","events_url":"https://api.github.com/users/cpuguy83/events{/privacy}","received_events_url":"https://api.github.com/users/cpuguy83/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cpuguy83/docker","description":"Docker - the open-source application container engine","fork":true,"url":"https://api.github.com/repos/cpuguy83/docker","forks_url":"https://api.github.com/repos/cpuguy83/docker/forks","keys_url":"https://api.github.com/repos/cpuguy83/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cpuguy83/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cpuguy83/docker/teams","hooks_url":"https://api.github.com/repos/cpuguy83/docker/hooks","issue_events_url":"https://api.github.com/repos/cpuguy83/docker/issues/events{/number}","events_url":"https://api.github.com/repos/cpuguy83/docker/events","assignees_url":"https://api.github.com/repos/cpuguy83/docker/assignees{/user}","branches_url":"https://api.github.com/repos/cpuguy83/docker/branches{/branch}","tags_url":"https://api.github.com/repos/cpuguy83/docker/tags","blobs_url":"https://api.github.com/repos/cpuguy83/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cpuguy83/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cpuguy83/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/cpuguy83/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cpuguy83/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/cpuguy83/docker/languages","stargazers_url":"https://api.github.com/repos/cpuguy83/docker/stargazers","contributors_url":"https://api.github.com/repos/cpuguy83/docker/contributors","subscribers_url":"https://api.github.com/repos/cpuguy83/docker/subscribers","subscription_url":"https://api.github.com/repos/cpuguy83/docker/subscription","commits_url":"https://api.github.com/repos/cpuguy83/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/cpuguy83/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/cpuguy83/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/cpuguy83/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/cpuguy83/docker/contents/{+path}","compare_url":"https://api.github.com/repos/cpuguy83/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cpuguy83/docker/merges","archive_url":"https://api.github.com/repos/cpuguy83/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cpuguy83/docker/downloads","issues_url":"https://api.github.com/repos/cpuguy83/docker/issues{/number}","pulls_url":"https://api.github.com/repos/cpuguy83/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/cpuguy83/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/cpuguy83/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cpuguy83/docker/labels{/name}","releases_url":"https://api.github.com/repos/cpuguy83/docker/releases{/id}","created_at":"2013-12-19T02:58:40Z","updated_at":"2015-04-27T13:11:12Z","pushed_at":"2015-06-17T13:42:20Z","git_url":"git://github.com/cpuguy83/docker.git","ssh_url":"git@github.com:cpuguy83/docker.git","clone_url":"https://github.com/cpuguy83/docker.git","svn_url":"https://github.com/cpuguy83/docker","homepage":"http://www.docker.io","size":61180,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"docker:master","ref":"master","sha":"9ad87523c03fb0d313a4170a7f595a95b3d8497b","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":7691631,"name":"docker","full_name":"docker/docker","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/docker","description":"Docker - the open-source application container engine","fork":false,"url":"https://api.github.com/repos/docker/docker","forks_url":"https://api.github.com/repos/docker/docker/forks","keys_url":"https://api.github.com/repos/docker/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/docker/teams","hooks_url":"https://api.github.com/repos/docker/docker/hooks","issue_events_url":"https://api.github.com/repos/docker/docker/issues/events{/number}","events_url":"https://api.github.com/repos/docker/docker/events","assignees_url":"https://api.github.com/repos/docker/docker/assignees{/user}","branches_url":"https://api.github.com/repos/docker/docker/branches{/branch}","tags_url":"https://api.github.com/repos/docker/docker/tags","blobs_url":"https://api.github.com/repos/docker/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/docker/languages","stargazers_url":"https://api.github.com/repos/docker/docker/stargazers","contributors_url":"https://api.github.com/repos/docker/docker/contributors","subscribers_url":"https://api.github.com/repos/docker/docker/subscribers","subscription_url":"https://api.github.com/repos/docker/docker/subscription","commits_url":"https://api.github.com/repos/docker/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/docker/contents/{+path}","compare_url":"https://api.github.com/repos/docker/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/docker/merges","archive_url":"https://api.github.com/repos/docker/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/docker/downloads","issues_url":"https://api.github.com/repos/docker/docker/issues{/number}","pulls_url":"https://api.github.com/repos/docker/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/docker/labels{/name}","releases_url":"https://api.github.com/repos/docker/docker/releases{/id}","created_at":"2013-01-18T18:10:57Z","updated_at":"2015-06-17T17:30:14Z","pushed_at":"2015-06-17T17:50:11Z","git_url":"git://github.com/docker/docker.git","ssh_url":"git@github.com:docker/docker.git","clone_url":"https://github.com/docker/docker.git","svn_url":"https://github.com/docker/docker","homepage":"http://www.docker.com","size":214460,"stargazers_count":22464,"watchers_count":22464,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5418,"mirror_url":null,"open_issues_count":1007,"forks":5418,"open_issues":1007,"watchers":22464,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/13978"},"html":{"href":"https://github.com/docker/docker/pull/13978"},"issue":{"href":"https://api.github.com/repos/docker/docker/issues/13978"},"comments":{"href":"https://api.github.com/repos/docker/docker/issues/13978/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/docker/pulls/13978/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/docker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/docker/pulls/13978/commits"},"statuses":{"href":"https://api.github.com/repos/docker/docker/statuses/5387cb503d3e0203f8c2d023aae398e19ddc77ac"}}}}