1
1
/*
2
- * Copyright (c) 2019, 2022 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2019, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
39
39
static const char * cg_controller_name[] = { " cpu" , " cpuset" , " cpuacct" , " memory" , " pids" };
40
40
41
41
CgroupSubsystem* CgroupSubsystemFactory::create () {
42
- CgroupV1MemoryController* memory = NULL ;
43
- CgroupV1Controller* cpuset = NULL ;
44
- CgroupV1Controller* cpu = NULL ;
45
- CgroupV1Controller* cpuacct = NULL ;
46
- CgroupV1Controller* pids = NULL ;
42
+ CgroupV1MemoryController* memory = nullptr ;
43
+ CgroupV1Controller* cpuset = nullptr ;
44
+ CgroupV1Controller* cpu = nullptr ;
45
+ CgroupV1Controller* cpuacct = nullptr ;
46
+ CgroupV1Controller* pids = nullptr ;
47
47
CgroupInfo cg_infos[CG_INFO_LENGTH];
48
48
u1 cg_type_flags = INVALID_CGROUPS_GENERIC;
49
49
const char * proc_cgroups = " /proc/cgroups" ;
@@ -54,7 +54,7 @@ CgroupSubsystem* CgroupSubsystemFactory::create() {
54
54
55
55
if (!valid_cgroup) {
56
56
// Could not detect cgroup type
57
- return NULL ;
57
+ return nullptr ;
58
58
}
59
59
assert (is_valid_cgroup (&cg_type_flags), " Expected valid cgroup type" );
60
60
@@ -128,7 +128,7 @@ void CgroupSubsystemFactory::set_controller_paths(CgroupInfo* cg_infos,
128
128
const char * name,
129
129
char * mount_path,
130
130
char * root_path) {
131
- if (cg_infos[controller]._mount_path != NULL ) {
131
+ if (cg_infos[controller]._mount_path != nullptr ) {
132
132
// On some systems duplicate controllers get mounted in addition to
133
133
// the main cgroup controllers most likely under /sys/fs/cgroup. In that
134
134
// case pick the one under /sys/fs/cgroup and discard others.
@@ -154,9 +154,9 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
154
154
const char * proc_self_cgroup,
155
155
const char * proc_self_mountinfo,
156
156
u1* flags) {
157
- FILE *mntinfo = NULL ;
158
- FILE *cgroups = NULL ;
159
- FILE *cgroup = NULL ;
157
+ FILE *mntinfo = nullptr ;
158
+ FILE *cgroups = nullptr ;
159
+ FILE *cgroup = nullptr ;
160
160
char buf[MAXPATHLEN+1 ];
161
161
char *p;
162
162
bool is_cgroupsV2;
@@ -174,13 +174,13 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
174
174
* controllers must have hierarchy ID 0 and the unified controller mounted.
175
175
*/
176
176
cgroups = os::fopen (proc_cgroups, " r" );
177
- if (cgroups == NULL ) {
177
+ if (cgroups == nullptr ) {
178
178
log_debug (os, container)(" Can't open %s, %s" , proc_cgroups, os::strerror (errno));
179
179
*flags = INVALID_CGROUPS_GENERIC;
180
180
return false ;
181
181
}
182
182
183
- while ((p = fgets (buf, MAXPATHLEN, cgroups)) != NULL ) {
183
+ while ((p = fgets (buf, MAXPATHLEN, cgroups)) != nullptr ) {
184
184
char name[MAXPATHLEN+1 ];
185
185
int hierarchy_id;
186
186
int enabled;
@@ -242,15 +242,15 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
242
242
* the host mount point to the local one via /proc/self/mountinfo below.
243
243
*/
244
244
cgroup = os::fopen (proc_self_cgroup, " r" );
245
- if (cgroup == NULL ) {
245
+ if (cgroup == nullptr ) {
246
246
log_debug (os, container)(" Can't open %s, %s" ,
247
247
proc_self_cgroup, os::strerror (errno));
248
248
cleanup (cg_infos);
249
249
*flags = INVALID_CGROUPS_GENERIC;
250
250
return false ;
251
251
}
252
252
253
- while ((p = fgets (buf, MAXPATHLEN, cgroup)) != NULL ) {
253
+ while ((p = fgets (buf, MAXPATHLEN, cgroup)) != nullptr ) {
254
254
char *controllers;
255
255
char *token;
256
256
char *hierarchy_id_str;
@@ -263,11 +263,11 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
263
263
controllers = strsep (&p, " :" );
264
264
cgroup_path = strsep (&p, " \n " );
265
265
266
- if (controllers == NULL ) {
266
+ if (controllers == nullptr ) {
267
267
continue ;
268
268
}
269
269
270
- while (!is_cgroupsV2 && (token = strsep (&controllers, " ," )) != NULL ) {
270
+ while (!is_cgroupsV2 && (token = strsep (&controllers, " ," )) != nullptr ) {
271
271
if (strcmp (token, " memory" ) == 0 ) {
272
272
assert (hierarchy_id == cg_infos[MEMORY_IDX]._hierarchy_id , " /proc/cgroups and /proc/self/cgroup hierarchy mismatch for memory" );
273
273
cg_infos[MEMORY_IDX]._cgroup_path = os::strdup (cgroup_path);
@@ -293,7 +293,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
293
293
continue ;
294
294
}
295
295
for (int i = 0 ; i < CG_INFO_LENGTH; i++) {
296
- assert (cg_infos[i]._cgroup_path == NULL , " cgroup path must only be set once" );
296
+ assert (cg_infos[i]._cgroup_path == nullptr , " cgroup path must only be set once" );
297
297
cg_infos[i]._cgroup_path = os::strdup (cgroup_path);
298
298
}
299
299
}
@@ -303,7 +303,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
303
303
// Find various mount points by reading /proc/self/mountinfo
304
304
// mountinfo format is documented at https://www.kernel.org/doc/Documentation/filesystems/proc.txt
305
305
mntinfo = os::fopen (proc_self_mountinfo, " r" );
306
- if (mntinfo == NULL ) {
306
+ if (mntinfo == nullptr ) {
307
307
log_debug (os, container)(" Can't open %s, %s" ,
308
308
proc_self_mountinfo, os::strerror (errno));
309
309
cleanup (cg_infos);
@@ -313,7 +313,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
313
313
314
314
bool cgroupv2_mount_point_found = false ;
315
315
bool any_cgroup_mounts_found = false ;
316
- while ((p = fgets (buf, MAXPATHLEN, mntinfo)) != NULL ) {
316
+ while ((p = fgets (buf, MAXPATHLEN, mntinfo)) != nullptr ) {
317
317
char tmp_fs_type[MAXPATHLEN+1 ];
318
318
char tmproot[MAXPATHLEN+1 ];
319
319
char tmpmount[MAXPATHLEN+1 ];
@@ -352,7 +352,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
352
352
// Skip cgroup2 fs lines on hybrid or unified hierarchy.
353
353
continue ;
354
354
}
355
- while ((token = strsep (&cptr, " ," )) != NULL ) {
355
+ while ((token = strsep (&cptr, " ," )) != nullptr ) {
356
356
if (strcmp (token, " memory" ) == 0 ) {
357
357
any_cgroup_mounts_found = true ;
358
358
set_controller_paths (cg_infos, MEMORY_IDX, token, tmpmount, tmproot);
@@ -437,7 +437,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
437
437
};
438
438
439
439
void CgroupSubsystemFactory::cleanup (CgroupInfo* cg_infos) {
440
- assert (cg_infos != NULL , " Invariant" );
440
+ assert (cg_infos != nullptr , " Invariant" );
441
441
for (int i = 0 ; i < CG_INFO_LENGTH; i++) {
442
442
os::free (cg_infos[i]._name );
443
443
os::free (cg_infos[i]._cgroup_path );
@@ -557,7 +557,7 @@ jlong CgroupSubsystem::memory_limit_in_bytes() {
557
557
}
558
558
559
559
jlong CgroupSubsystem::limit_from_str (char * limit_str) {
560
- if (limit_str == NULL ) {
560
+ if (limit_str == nullptr ) {
561
561
return OSCONTAINER_ERROR;
562
562
}
563
563
// Unlimited memory in cgroups is the literal string 'max' for
0 commit comments