1 // SPDX-License-Identifier: GPL-2.0
3 * Wait until an inotify event on the given cgroup file.
5 #include <linux/limits.h>
6 #include <sys/inotify.h>
8 #include <sys/ptrace.h>
10 #include <sys/types.h>
19 static const char usage
[] = "Usage: %s [-v] <cgroup_file>\n";
23 static inline void fail_message(char *msg
)
25 fprintf(stderr
, msg
, file
);
29 int main(int argc
, char *argv
[])
33 struct pollfd fds
= { .events
= POLLIN
, };
35 while ((c
= getopt(argc
, argv
, "v")) != -1) {
45 fprintf(stderr
, usage
, cmd
);
49 fd
= open(file
, O_RDONLY
);
51 fail_message("Cgroup file %s not found!\n");
56 fail_message("inotify_init() fails on %s!\n");
57 if (inotify_add_watch(fd
, file
, IN_MODIFY
) < 0)
58 fail_message("inotify_add_watch() fails on %s!\n");
65 int ret
= poll(&fds
, 1, 10000);
73 if ((ret
> 0) && (fds
.revents
& POLLIN
))
77 struct inotify_event events
[10];
81 len
= read(fd
, events
, sizeof(events
));
82 printf("Number of events read = %ld\n",
83 len
/sizeof(struct inotify_event
));