Skip to content

Commit f21a34c

Browse files
committed
Fix no_warnings rule
1 parent 57c742d commit f21a34c

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/cgroup.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static void set_cgroup_v1(const struct CONTAINER *_Nonnull container)
143143
char memory_cgroup_limit_path[PATH_MAX] = { '\0' };
144144
sprintf(memory_cgroup_limit_path, "/sys/fs/cgroup/memory/%d/memory.limit_in_bytes", container->container_id);
145145
fd = open(memory_cgroup_limit_path, O_RDWR | O_CLOEXEC);
146-
if (fd < 0) {
146+
if (fd < 0 && !container->no_warnings) {
147147
warning("{yellow}Set memory limit failed{clear}\n");
148148
goto cpuset;
149149
}
@@ -157,7 +157,7 @@ static void set_cgroup_v1(const struct CONTAINER *_Nonnull container)
157157
sprintf(memory_cgroup_procs_path, "/sys/fs/cgroup/memory/%d/cgroup.procs", container->container_id);
158158
// Add pid to container_id memory cgroup.
159159
fd = open(memory_cgroup_procs_path, O_RDWR | O_CLOEXEC);
160-
if (fd < 0) {
160+
if (fd < 0 && !container->no_warnings) {
161161
warning("{yellow}Set memory limit failed{clear}\n");
162162
goto cpuset;
163163
}
@@ -170,7 +170,7 @@ static void set_cgroup_v1(const struct CONTAINER *_Nonnull container)
170170
char cpuset_cgroup_mems_path[PATH_MAX] = { '\0' };
171171
sprintf(cpuset_cgroup_mems_path, "/sys/fs/cgroup/cpuset/%d/cpuset.mems", container->container_id);
172172
fd = open(cpuset_cgroup_mems_path, O_RDWR | O_CLOEXEC);
173-
if (fd < 0) {
173+
if (fd < 0 && !container->no_warnings) {
174174
warning("{yellow}Set cpuset limit failed{clear}\n");
175175
// Do not keep the apifs mounted.
176176
umount2("/sys/fs/cgroup", MNT_DETACH | MNT_FORCE);
@@ -181,7 +181,7 @@ static void set_cgroup_v1(const struct CONTAINER *_Nonnull container)
181181
char cpuset_cgroup_cpus_path[PATH_MAX] = { '\0' };
182182
sprintf(cpuset_cgroup_cpus_path, "/sys/fs/cgroup/cpuset/%d/cpuset.cpus", container->container_id);
183183
fd = open(cpuset_cgroup_cpus_path, O_RDWR | O_CLOEXEC);
184-
if (fd < 0) {
184+
if (fd < 0 && !container->no_warnings) {
185185
warning("{yellow}Set cpuset limit failed{clear}\n");
186186
// Do not keep the apifs mounted.
187187
umount2("/sys/fs/cgroup", MNT_DETACH | MNT_FORCE);
@@ -197,7 +197,7 @@ static void set_cgroup_v1(const struct CONTAINER *_Nonnull container)
197197
sprintf(cpuset_cgroup_procs_path, "/sys/fs/cgroup/cpuset/%d/cgroup.procs", container->container_id);
198198
// Add pid to container_id cpuset cgroup.
199199
fd = open(cpuset_cgroup_procs_path, O_RDWR | O_CLOEXEC);
200-
if (fd < 0) {
200+
if (fd < 0 && !container->no_warnings) {
201201
warning("{yellow}Set cpuset limit failed{clear}\n");
202202
// Do not keep the apifs mounted.
203203
umount2("/sys/fs/cgroup", MNT_DETACH | MNT_FORCE);
@@ -224,7 +224,7 @@ static void set_cgroup_v2(const struct CONTAINER *_Nonnull container)
224224
sprintf(cgroup_procs_path, "/sys/fs/cgroup/%d/cgroup.procs", container->container_id);
225225
// Add pid to container_id cgroup.
226226
int fd = open(cgroup_procs_path, O_RDWR | O_CLOEXEC);
227-
if (fd < 0) {
227+
if (fd < 0 && !container->no_warnings) {
228228
warning("{yellow}Set cgroup.procs failed{clear}\n");
229229
// Do not keep the apifs mounted.
230230
umount2("/sys/fs/cgroup", MNT_DETACH | MNT_FORCE);
@@ -238,7 +238,7 @@ static void set_cgroup_v2(const struct CONTAINER *_Nonnull container)
238238
char cgroup_memlimit_path[PATH_MAX] = { '\0' };
239239
sprintf(cgroup_memlimit_path, "/sys/fs/cgroup/%d/memory.high", container->container_id);
240240
fd = open(cgroup_memlimit_path, O_RDWR | O_CLOEXEC);
241-
if (fd < 0) {
241+
if (fd < 0 && !container->no_warnings) {
242242
warning("{yellow}Set memory limit failed{clear}\n");
243243
// Do not keep the apifs mounted.
244244
umount2("/sys/fs/cgroup", MNT_DETACH | MNT_FORCE);
@@ -255,7 +255,7 @@ static void set_cgroup_v2(const struct CONTAINER *_Nonnull container)
255255
char cgroup_cpuset_path[PATH_MAX] = { '\0' };
256256
sprintf(cgroup_cpuset_path, "/sys/fs/cgroup/%d/cpuset.cpus", container->container_id);
257257
fd = open(cgroup_cpuset_path, O_RDWR | O_CLOEXEC);
258-
if (fd < 0) {
258+
if (fd < 0 && !container->no_warnings) {
259259
warning("{yellow}Set cpu limit failed{clear}\n");
260260
// Do not keep the apifs mounted.
261261
umount2("/sys/fs/cgroup", MNT_DETACH | MNT_FORCE);

src/rurienv.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ static char *build_container_info(const struct CONTAINER *_Nonnull container)
104104
// work_dir.
105105
ret = k2v_add_comment(ret, "Work directory.");
106106
ret = k2v_add_config(char, ret, "work_dir", container->work_dir);
107+
// no_warnings
108+
ret = k2v_add_comment(ret, "Do not show warnings.");
109+
ret = k2v_add_config(bool, ret, "no_warnings", container->no_warnings);
107110
// extra_mountpoint.
108111
for (int i = 0; true; i++) {
109112
if (container->extra_mountpoint[i] == NULL) {
@@ -247,7 +250,7 @@ struct CONTAINER *read_info(struct CONTAINER *_Nullable container, const char *_
247250
log("{base}pid %d is not a ruri process.\n", k2v_get_key(int, "ns_pid", buf));
248251
// Unset immutable flag of .rurienv.
249252
fd = open(file, O_RDONLY | O_CLOEXEC);
250-
if (fd < 0) {
253+
if (fd < 0 && !container->no_warnings) {
251254
warning("{yellow}Open .rurienv failed{clear}\n");
252255
}
253256
int attr = 0;
@@ -285,6 +288,8 @@ struct CONTAINER *read_info(struct CONTAINER *_Nullable container, const char *_
285288
container->just_chroot = k2v_get_key(bool, "just_chroot", buf);
286289
// Get work_dir.
287290
container->work_dir = k2v_get_key(char, "work_dir", buf);
291+
// Get no_warnings.
292+
container->no_warnings = k2v_get_key(bool, "no_warnings", buf);
288293
// Get env.
289294
int envlen = k2v_get_key(char_array, "env", buf, container->env, MAX_ENVS);
290295
container->env[envlen] = NULL;

0 commit comments

Comments
 (0)