ã¡ã¢ç¨åº¦ã«ã
è¿½è¨ @ 2021/04/20 12:41
inodeçªå·ã¨åãã«ãªãããã«ãªã£ã¦ãããããããªã®ã§ã
cgpath = ARGV[0] puts File::Stat.new(cgpath).ino
ããã ãã§ããã§ã... 以ä¸ã¯ãæ§é ä½ãã£ã¹ãã®ä¾ã¨ãã¦æ®ãã
ãã®å®è£ ã«ããã¨
name_to_handle_at
ãã¤ãã£ã¦cgroupã表ããã£ã¬ã¯ã㪠ã®ãã¡ã¤ã«ãã³ãã«ãåã- ãã¡ã¤ã«ãã³ãã«ã以ä¸ã®æ§é ä½ã«ãã£ã¹ããã
struct cgid_file_handle { unsigned int handle_bytes; int handle_type; uint64_t cgid; };
- ããããã¨
handle->cgid
ã«å ¥ã£ã¦ã
ã¨ããæãã£ã½ãããªã®ã§è¨èªãé¸ã°ãå®è£ ã§ãããRubyã®ãããªã¹ã¯ãªããè¨èªãªãffiï¼fiddleï¼ã使ã£ã¦ããããæã:
require 'fiddle/import' module Glibc extend Fiddle::Importer dlload 'libc.so.6' extern 'int name_to_handle_at(int dirfd, const char *pathname, vod *handle, int *mount_id, int flags)' end AT_FDCWD = -100 # ãã®å¤ãããããããªã®... cgpath = ARGV[0] handle = Fiddle::Pointer.malloc(16) handle[0, 16] = [8, 0, 0].pack("I I Q") mount_id = Fiddle::Pointer.malloc(4) if Glibc.name_to_handle_at(-100, cgpath, handle, mount_id, 0) < 0 raise SystemCallError.new Fiddle.last_error end cgid = handle[0, 16].unpack("I I Q").last puts "cgid of #{cgpath}: #{cgid}"
åãã¦ããã
$ sudo ruby /tmp/getcgid.rb /sys/fs/cgroup/unified/system.slice/docker-af6e1e860a07152351fc3b549479b08f45d0e484564dbbb3330a43d8c7686e94.scope cgid of /sys/fs/cgroup/unified/system.slice/docker-af6e1e860a07152351fc3b549479b08f45d0e484564dbbb3330a43d8c7686e94.scope: 4863
å®éãã®IDã§çµãè¾¼ãã ããã¡ããã¨ãã®ã³ã³ããã®ã¤ãã³ãã ãåãã¦ãã¿ããã
$ sudo bpftrace -e \ 'tracepoint:syscalls:sys_enter_clone / cgroup == 4863 / { printf("Hola!\n"); } ' Attaching 1 probe... Hola! Hola! ...