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
444249ea
Unverified
Commit
444249ea
authored
Feb 24, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxccontainer: ongoing_create()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
ef1ab8f1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
21 deletions
+21
-21
lxccontainer.c
src/lxc/lxccontainer.c
+21
-21
No files found.
src/lxc/lxccontainer.c
View file @
444249ea
...
@@ -127,48 +127,48 @@ static bool config_file_exists(const char *lxcpath, const char *cname)
...
@@ -127,48 +127,48 @@ static bool config_file_exists(const char *lxcpath, const char *cname)
return
file_exists
(
fname
);
return
file_exists
(
fname
);
}
}
/*
/* A few functions to help detect when a container creation failed. If a
* A few functions to help detect when a container creation failed.
* container creation was killed partway through, then trying to actually start
* If a container creation was killed partway through, then trying
* that container could harm the host. We detect this by creating a 'partial'
* to actually start that container could harm the host. We detect
* file under the container directory, and keeping an advisory lock. When
* this by creating a 'partial' file under the container directory,
* container creation completes, we remove that file. When we load or try to
* and keeping an advisory lock. When container creation completes,
* start a container, if we find that file, without a flock, we remove the
* we remove that file. When we load or try to start a container, if
* container.
* we find that file, without a flock, we remove the container.
*/
*/
static
int
ongoing_create
(
struct
lxc_container
*
c
)
static
int
ongoing_create
(
struct
lxc_container
*
c
)
{
{
int
len
=
strlen
(
c
->
config_path
)
+
strlen
(
c
->
name
)
+
10
;
char
*
path
=
alloca
(
len
);
int
fd
,
ret
;
int
fd
,
ret
;
size_t
len
;
char
*
path
;
struct
flock
lk
;
struct
flock
lk
;
len
=
strlen
(
c
->
config_path
)
+
strlen
(
c
->
name
)
+
10
;
path
=
alloca
(
len
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/partial"
,
c
->
config_path
,
c
->
name
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/partial"
,
c
->
config_path
,
c
->
name
);
if
(
ret
<
0
||
ret
>=
len
)
{
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
ERROR
(
"Error writing partial pathname"
);
return
-
1
;
return
-
1
;
}
if
(
!
file_exists
(
path
))
if
(
!
file_exists
(
path
))
return
0
;
return
0
;
fd
=
open
(
path
,
O_RDWR
);
fd
=
open
(
path
,
O_RDWR
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
/* give benefit of the doubt */
SYSERROR
(
"Error opening partial file"
);
return
0
;
return
0
;
}
lk
.
l_type
=
F_WRLCK
;
lk
.
l_type
=
F_WRLCK
;
lk
.
l_whence
=
SEEK_SET
;
lk
.
l_whence
=
SEEK_SET
;
lk
.
l_start
=
0
;
lk
.
l_start
=
0
;
lk
.
l_len
=
0
;
lk
.
l_len
=
0
;
lk
.
l_pid
=
-
1
;
lk
.
l_pid
=
-
1
;
if
(
fcntl
(
fd
,
F_GETLK
,
&
lk
)
==
0
&&
lk
.
l_pid
!=
-
1
)
{
ret
=
fcntl
(
fd
,
F_GETLK
,
&
lk
);
close
(
fd
);
if
(
ret
==
0
&&
lk
.
l_pid
!=
-
1
)
{
/* create is still ongoing */
/* create is still ongoing */
close
(
fd
);
return
1
;
return
1
;
}
}
/* create completed but partial is still there. */
close
(
fd
);
/* Create completed but partial is still there. */
return
2
;
return
2
;
}
}
...
...
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