Elkeid
Elkeid copied to clipboard
fix: os.Stat returns ENOENT when checking the symlink file's stat of …
fixed os.Stat returns ENOENT when checking the symlink file's stat of a container using /proc/*/root.
Summary
This PR fixes/implements the following bugs/features
- [ ] Bug
os.StatreturnsENOENTwhen checking the symlink file's stat of a container using/proc/*/root
Test plan (required)
- run
mysql:5.7.31image on host with collector running
docker run -e MYSQL_ROOT_PASSWORD=abc12345 mysql@sha256:b3dc8d10307ab7b9ca1a7981b1601a67e176408be618fc4216d137be37dae10b
- Collector's AppRule of mysql checking file
/etc/mysql/my.cnfsymlinked to/etc/alternatives/my.cnf
root@601d2bfcb7e3:~# stat /etc/mysql/my.cnf
File: /etc/mysql/my.cnf -> /etc/alternatives/my.cnf
Size: 24 Blocks: 0 IO Block: 4096 symbolic link
Device: 40h/64d Inode: 4748407 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-10-13 08:03:29.000000000 +0000
Modify: 2020-10-13 08:03:29.000000000 +0000
Change: 2023-06-15 08:19:26.938384681 +0000
Birth: -
root@601d2bfcb7e3:~#
- check file's stat using
os.Statwill returnENOENT, should be useos.Lstatto check symlink file in container, because file/etc/alternatives/my.cnfnot available on host, see https://pkg.go.dev/os#Lstat for more infos.