@@ -19,13 +19,15 @@ type observer struct {
1919 lock sync.Mutex
2020 inodeToPath map [int ]* resolved
2121 pathToInode map [string ]int
22+ cgroupChans []chan <- ChangeNotification
2223}
2324
2425func newObserver (initial map [int ]string ) * observer {
2526 observer := observer {
2627 lock : sync.Mutex {},
2728 inodeToPath : map [int ]* resolved {},
2829 pathToInode : map [string ]int {},
30+ cgroupChans : []chan <- ChangeNotification {},
2931 }
3032
3133 for inode , name := range initial {
@@ -83,6 +85,12 @@ func (o *observer) add(inode int, path string) {
8385
8486 o .inodeToPath [inode ] = r
8587 o .pathToInode [path ] = inode
88+ for _ , ch := range o .cgroupChans {
89+ ch <- ChangeNotification {
90+ ID : inode ,
91+ Path : path ,
92+ }
93+ }
8694}
8795
8896func (o * observer ) remove (path string ) {
@@ -96,6 +104,13 @@ func (o *observer) remove(path string) {
96104
97105 r := o .inodeToPath [inode ]
98106 r .dead = time .Now ()
107+ for _ , ch := range o .cgroupChans {
108+ ch <- ChangeNotification {
109+ ID : inode ,
110+ Path : path ,
111+ Remove : true ,
112+ }
113+ }
99114}
100115
101116func (o * observer ) lookup (inode int ) string {
@@ -113,3 +128,17 @@ func (o *observer) lookup(inode int) string {
113128
114129 return r .path
115130}
131+
132+ func (o * observer ) subscribeCgroupChange (ch chan <- ChangeNotification ) error {
133+ o .cgroupChans = append (o .cgroupChans , ch )
134+ // send the initial cgroup mapping
135+ go func () {
136+ for path , inode := range o .pathToInode {
137+ ch <- ChangeNotification {
138+ ID : inode ,
139+ Path : path ,
140+ }
141+ }
142+ }()
143+ return nil
144+ }
0 commit comments