@@ -28,7 +28,6 @@ void get_args(int *argc, char ***argv)
28
28
pr_perror("Unable to open /proc/self/cmdline");
29
29
exit(1);
30
30
}
31
-
32
31
// Read the whole commandline.
33
32
ssize_t contents_size = 0;
34
33
ssize_t contents_offset = 0;
@@ -98,13 +97,12 @@ void nsenter()
98
97
if (strncmp(argv[0], kNsEnter, strlen(kNsEnter)) != 0) {
99
98
return;
100
99
}
101
-
102
- #ifdef PR_SET_CHILD_SUBREAPER
100
+ #ifdef PR_SET_CHILD_SUBREAPER
103
101
if (prctl(PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0) == -1) {
104
102
pr_perror("Failed to set child subreaper");
105
103
exit(1);
106
104
}
107
- #endif
105
+ #endif
108
106
109
107
static const struct option longopts[] = {
110
108
{"nspid", required_argument, NULL, 'n'},
@@ -134,7 +132,7 @@ void nsenter()
134
132
init_pid = strtol(init_pid_str, NULL, 10);
135
133
if ((init_pid == 0 && errno == EINVAL) || errno == ERANGE) {
136
134
pr_perror("Failed to parse PID from \"%s\" with output \"%d\"",
137
- init_pid_str, init_pid);
135
+ init_pid_str, init_pid);
138
136
print_usage();
139
137
exit(1);
140
138
}
@@ -155,6 +153,12 @@ void nsenter()
155
153
exit(1);
156
154
}
157
155
}
156
+ // blocking until the parent placed the process inside correct cgroups.
157
+ unsigned char s;
158
+ if (read(3, &s, 1) != 1 || s != '1') {
159
+ pr_perror("failed to receive synchronization data from parent");
160
+ exit(1);
161
+ }
158
162
// Setns on all supported namespaces.
159
163
char ns_dir[PATH_MAX];
160
164
memset(ns_dir, 0, PATH_MAX);
@@ -173,18 +177,19 @@ void nsenter()
173
177
for (i = 0; i < num; i++) {
174
178
// A zombie process has links on namespaces, but they can't be opened
175
179
struct stat st;
176
- if (fstatat(ns_dir_fd, namespaces[i], &st, AT_SYMLINK_NOFOLLOW) == -1) {
180
+ if (fstatat(ns_dir_fd, namespaces[i], &st, AT_SYMLINK_NOFOLLOW)
181
+ == -1) {
177
182
if (errno == ENOENT)
178
183
continue;
179
184
pr_perror("Failed to stat ns file %s for ns %s",
180
- ns_dir, namespaces[i]);
185
+ ns_dir, namespaces[i]);
181
186
exit(1);
182
187
}
183
188
184
189
int fd = openat(ns_dir_fd, namespaces[i], O_RDONLY);
185
190
if (fd == -1) {
186
191
pr_perror("Failed to open ns file %s for ns %s",
187
- ns_dir, namespaces[i]);
192
+ ns_dir, namespaces[i]);
188
193
exit(1);
189
194
}
190
195
// Set the namespace.
0 commit comments