Skip to content

Commit

Permalink
Use /proc/self/mountinfo instead of /proc/1/mountinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
bongole committed Mar 30, 2024
1 parent 8bb7228 commit 845580b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/aws/rails/middleware/ebs_sqs_active_job_middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def in_docker_containr_with_cgroup1?
end

def in_docker_containr_with_cgroup2?
File.exist?('/proc/1/mountinfo') && File.read('/proc/1/mountinfo') =~ %r{/docker/containers/}
File.exist?('/proc/self/mountinfo') && File.read('/proc/self/mountinfo') =~ %r{/docker/containers/}
end

def default_gw_ips
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ module Rails
0::/
CONTENT

proc_1_mountinfo = <<~CONTENT
proc_self_mountinfo = <<~CONTENT
355 354 0:21 / /sys/fs/cgroup ro,nosuid,nodev,noexec,relatime - cgroup2 cgroup rw,nsdelegate
356 352 0:74 / /dev/mqueue rw,nosuid,nodev,noexec,relatime - mqueue mqueue rw
357 352 0:79 / /dev/shm rw,nosuid,nodev,noexec,relatime - tmpfs shm rw,size=65536k
Expand All @@ -166,8 +166,8 @@ module Rails

expect(File).to receive(:exist?).with('/proc/1/cgroup').and_return(true)
expect(File).to receive(:read).with('/proc/1/cgroup').and_return(proc_1_cgroup)
expect(File).to receive(:exist?).with('/proc/1/mountinfo').and_return(true)
expect(File).to receive(:read).with('/proc/1/mountinfo').and_return(proc_1_mountinfo)
expect(File).to receive(:exist?).with('/proc/self/mountinfo').and_return(true)
expect(File).to receive(:read).with('/proc/self/mountinfo').and_return(proc_self_mountinfo)

response = test_middleware.call(mock_rack_env)

Expand Down

0 comments on commit 845580b

Please sign in to comment.