File tree Expand file tree Collapse file tree 3 files changed +49
-57
lines changed
tools/testing/selftests/cgroup Expand file tree Collapse file tree 3 files changed +49
-57
lines changed Original file line number Diff line number Diff line change 5
5
#include <errno.h>
6
6
#include <fcntl.h>
7
7
#include <linux/limits.h>
8
+ #include <poll.h>
8
9
#include <signal.h>
9
10
#include <stdio.h>
10
11
#include <stdlib.h>
11
12
#include <string.h>
13
+ #include <sys/inotify.h>
12
14
#include <sys/stat.h>
13
15
#include <sys/types.h>
14
16
#include <sys/wait.h>
@@ -580,3 +582,48 @@ int clone_into_cgroup_run_wait(const char *cgroup)
580
582
(void )clone_reap (pid , WEXITED );
581
583
return 0 ;
582
584
}
585
+
586
+ int cg_prepare_for_wait (const char * cgroup )
587
+ {
588
+ int fd , ret = -1 ;
589
+
590
+ fd = inotify_init1 (0 );
591
+ if (fd == -1 )
592
+ return fd ;
593
+
594
+ ret = inotify_add_watch (fd , cg_control (cgroup , "cgroup.events" ),
595
+ IN_MODIFY );
596
+ if (ret == -1 ) {
597
+ close (fd );
598
+ fd = -1 ;
599
+ }
600
+
601
+ return fd ;
602
+ }
603
+
604
+ int cg_wait_for (int fd )
605
+ {
606
+ int ret = -1 ;
607
+ struct pollfd fds = {
608
+ .fd = fd ,
609
+ .events = POLLIN ,
610
+ };
611
+
612
+ while (true) {
613
+ ret = poll (& fds , 1 , 10000 );
614
+
615
+ if (ret == -1 ) {
616
+ if (errno == EINTR )
617
+ continue ;
618
+
619
+ break ;
620
+ }
621
+
622
+ if (ret > 0 && fds .revents & POLLIN ) {
623
+ ret = 0 ;
624
+ break ;
625
+ }
626
+ }
627
+
628
+ return ret ;
629
+ }
Original file line number Diff line number Diff line change @@ -54,3 +54,5 @@ extern pid_t clone_into_cgroup(int cgroup_fd);
54
54
extern int clone_reap (pid_t pid , int options );
55
55
extern int clone_into_cgroup_run_wait (const char * cgroup );
56
56
extern int dirfd_open_opath (const char * dir );
57
+ extern int cg_prepare_for_wait (const char * cgroup );
58
+ extern int cg_wait_for (int fd );
Original file line number Diff line number Diff line change 7
7
#include <unistd.h>
8
8
#include <stdio.h>
9
9
#include <errno.h>
10
- #include <poll.h>
11
10
#include <stdlib.h>
12
- #include <sys/inotify.h>
13
11
#include <string.h>
14
12
#include <sys/wait.h>
15
13
@@ -54,61 +52,6 @@ static int cg_freeze_nowait(const char *cgroup, bool freeze)
54
52
return cg_write (cgroup , "cgroup.freeze" , freeze ? "1" : "0" );
55
53
}
56
54
57
- /*
58
- * Prepare for waiting on cgroup.events file.
59
- */
60
- static int cg_prepare_for_wait (const char * cgroup )
61
- {
62
- int fd , ret = -1 ;
63
-
64
- fd = inotify_init1 (0 );
65
- if (fd == -1 ) {
66
- debug ("Error: inotify_init1() failed\n" );
67
- return fd ;
68
- }
69
-
70
- ret = inotify_add_watch (fd , cg_control (cgroup , "cgroup.events" ),
71
- IN_MODIFY );
72
- if (ret == -1 ) {
73
- debug ("Error: inotify_add_watch() failed\n" );
74
- close (fd );
75
- fd = -1 ;
76
- }
77
-
78
- return fd ;
79
- }
80
-
81
- /*
82
- * Wait for an event. If there are no events for 10 seconds,
83
- * treat this an error.
84
- */
85
- static int cg_wait_for (int fd )
86
- {
87
- int ret = -1 ;
88
- struct pollfd fds = {
89
- .fd = fd ,
90
- .events = POLLIN ,
91
- };
92
-
93
- while (true) {
94
- ret = poll (& fds , 1 , 10000 );
95
-
96
- if (ret == -1 ) {
97
- if (errno == EINTR )
98
- continue ;
99
- debug ("Error: poll() failed\n" );
100
- break ;
101
- }
102
-
103
- if (ret > 0 && fds .revents & POLLIN ) {
104
- ret = 0 ;
105
- break ;
106
- }
107
- }
108
-
109
- return ret ;
110
- }
111
-
112
55
/*
113
56
* Attach a task to the given cgroup and wait for a cgroup frozen event.
114
57
* All transient events (e.g. populated) are ignored.
You can’t perform that action at this time.
0 commit comments