Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
15418afe
Unverified
Commit
15418afe
authored
Oct 03, 2018
by
Wolfgang Bumiller
Committed by
GitHub
Oct 03, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2670 from brauner/2018-10-03/cgfsng_fix_race
cgfsng: close tiny race window
parents
c5e7a7ac
ef185360
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
20 deletions
+51
-20
cgfsng.c
src/lxc/cgroups/cgfsng.c
+39
-13
utils.c
src/lxc/utils.c
+12
-7
No files found.
src/lxc/cgroups/cgfsng.c
View file @
15418afe
...
@@ -1257,22 +1257,53 @@ on_error:
...
@@ -1257,22 +1257,53 @@ on_error:
return
bret
;
return
bret
;
}
}
static
bool
monitor_create_path_for_hierarchy
(
struct
hierarchy
*
h
,
char
*
cgnam
e
)
static
int
mkdir_eexist_on_last
(
const
char
*
dir
,
mode_t
mod
e
)
{
{
const
char
*
tmp
=
dir
;
const
char
*
orig
=
dir
;
size_t
orig_len
;
orig_len
=
strlen
(
dir
);
do
{
int
ret
;
int
ret
;
size_t
cur_len
;
char
*
makeme
;
h
->
monitor_full_path
=
must_make_path
(
h
->
mountpoint
,
h
->
container_base_path
,
cgname
,
NULL
);
dir
=
tmp
+
strspn
(
tmp
,
"/"
);
if
(
dir_exists
(
h
->
monitor_full_path
))
{
tmp
=
dir
+
strcspn
(
dir
,
"/"
);
ERROR
(
"The cgroup
\"
%s
\"
already existed"
,
h
->
monitor_full_path
);
return
false
;
errno
=
ENOMEM
;
cur_len
=
dir
-
orig
;
makeme
=
strndup
(
orig
,
cur_len
);
if
(
!
makeme
)
return
-
1
;
ret
=
mkdir
(
makeme
,
mode
);
if
(
ret
<
0
)
{
if
((
errno
!=
EEXIST
)
||
(
orig_len
==
cur_len
))
{
SYSERROR
(
"Failed to create directory
\"
%s
\"
"
,
makeme
);
free
(
makeme
);
return
-
1
;
}
}
}
free
(
makeme
);
}
while
(
tmp
!=
dir
);
return
0
;
}
static
bool
monitor_create_path_for_hierarchy
(
struct
hierarchy
*
h
,
char
*
cgname
)
{
int
ret
;
if
(
!
cg_legacy_handle_cpuset_hierarchy
(
h
,
cgname
))
{
if
(
!
cg_legacy_handle_cpuset_hierarchy
(
h
,
cgname
))
{
ERROR
(
"Failed to handle legacy cpuset controller"
);
ERROR
(
"Failed to handle legacy cpuset controller"
);
return
false
;
return
false
;
}
}
ret
=
mkdir_p
(
h
->
monitor_full_path
,
0755
);
h
->
monitor_full_path
=
must_make_path
(
h
->
mountpoint
,
h
->
container_base_path
,
cgname
,
NULL
);
ret
=
mkdir_eexist_on_last
(
h
->
monitor_full_path
,
0755
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to create cgroup
\"
%s
\"
"
,
h
->
monitor_full_path
);
ERROR
(
"Failed to create cgroup
\"
%s
\"
"
,
h
->
monitor_full_path
);
return
false
;
return
false
;
...
@@ -1285,18 +1316,13 @@ static bool container_create_path_for_hierarchy(struct hierarchy *h, char *cgnam
...
@@ -1285,18 +1316,13 @@ static bool container_create_path_for_hierarchy(struct hierarchy *h, char *cgnam
{
{
int
ret
;
int
ret
;
h
->
container_full_path
=
must_make_path
(
h
->
mountpoint
,
h
->
container_base_path
,
cgname
,
NULL
);
if
(
dir_exists
(
h
->
container_full_path
))
{
ERROR
(
"The cgroup
\"
%s
\"
already existed"
,
h
->
container_full_path
);
return
false
;
}
if
(
!
cg_legacy_handle_cpuset_hierarchy
(
h
,
cgname
))
{
if
(
!
cg_legacy_handle_cpuset_hierarchy
(
h
,
cgname
))
{
ERROR
(
"Failed to handle legacy cpuset controller"
);
ERROR
(
"Failed to handle legacy cpuset controller"
);
return
false
;
return
false
;
}
}
ret
=
mkdir_p
(
h
->
container_full_path
,
0755
);
h
->
container_full_path
=
must_make_path
(
h
->
mountpoint
,
h
->
container_base_path
,
cgname
,
NULL
);
ret
=
mkdir_eexist_on_last
(
h
->
container_full_path
,
0755
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to create cgroup
\"
%s
\"
"
,
h
->
container_full_path
);
ERROR
(
"Failed to create cgroup
\"
%s
\"
"
,
h
->
container_full_path
);
return
false
;
return
false
;
...
...
src/lxc/utils.c
View file @
15418afe
...
@@ -221,26 +221,31 @@ extern int get_u16(unsigned short *val, const char *arg, int base)
...
@@ -221,26 +221,31 @@ extern int get_u16(unsigned short *val, const char *arg, int base)
return
0
;
return
0
;
}
}
extern
int
mkdir_p
(
const
char
*
dir
,
mode_t
mode
)
int
mkdir_p
(
const
char
*
dir
,
mode_t
mode
)
{
{
const
char
*
tmp
=
dir
;
const
char
*
tmp
=
dir
;
const
char
*
orig
=
dir
;
const
char
*
orig
=
dir
;
do
{
int
ret
;
char
*
makeme
;
char
*
makeme
;
do
{
dir
=
tmp
+
strspn
(
tmp
,
"/"
);
dir
=
tmp
+
strspn
(
tmp
,
"/"
);
tmp
=
dir
+
strcspn
(
dir
,
"/"
);
tmp
=
dir
+
strcspn
(
dir
,
"/"
);
errno
=
ENOMEM
;
makeme
=
strndup
(
orig
,
dir
-
orig
);
makeme
=
strndup
(
orig
,
dir
-
orig
);
if
(
*
makeme
)
{
if
(
!
makeme
)
if
(
mkdir
(
makeme
,
mode
)
&&
errno
!=
EEXIST
)
{
return
-
1
;
SYSERROR
(
"failed to create directory '%s'"
,
makeme
);
ret
=
mkdir
(
makeme
,
mode
);
if
(
ret
<
0
&&
errno
!=
EEXIST
)
{
SYSERROR
(
"Failed to create directory
\"
%s
\"
"
,
makeme
);
free
(
makeme
);
free
(
makeme
);
return
-
1
;
return
-
1
;
}
}
}
free
(
makeme
);
free
(
makeme
);
}
while
(
tmp
!=
dir
);
}
while
(
tmp
!=
dir
);
return
0
;
return
0
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment