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
a065524e
Unverified
Commit
a065524e
authored
Jun 14, 2021
by
Christian Brauner
Committed by
GitHub
Jun 14, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3865 from brauner/2021-06-14.listen_fds
Add support for LISTEN_FDS environment variable.
parents
51bbca90
46abf219
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
1 deletion
+36
-1
lxccontainer.h
src/lxc/lxccontainer.h
+2
-1
start.c
src/lxc/start.c
+34
-0
No files found.
src/lxc/lxccontainer.h
View file @
a065524e
...
@@ -223,7 +223,8 @@ struct lxc_container {
...
@@ -223,7 +223,8 @@ struct lxc_container {
/*!
/*!
* \brief Change whether the container wishes all file descriptors
* \brief Change whether the container wishes all file descriptors
* to be closed on startup.
* to be closed on startup. The LISTEN_FDS environment variable
* can be set to keep inherited file descriptors open.
*
*
* \param c Container.
* \param c Container.
* \param state Value for the close_all_fds bit (0 or 1).
* \param state Value for the close_all_fds bit (0 or 1).
...
...
src/lxc/start.c
View file @
a065524e
...
@@ -212,6 +212,31 @@ static bool match_dlog_fds(struct dirent *direntp)
...
@@ -212,6 +212,31 @@ static bool match_dlog_fds(struct dirent *direntp)
}
}
#endif
#endif
/* Parses the LISTEN_FDS environment variable value.
* The returned value is the highest fd number up to which the
* file descriptors must be passed to the container process.
*
* For example, if LISTEN_FDS=2 then 4 is returned and file descriptors 3 and 4
* MUST be passed to the container process (in addition to the standard streams)
* to support [socket activation][systemd-listen-fds].
*/
static
unsigned
int
get_listen_fds_max
(
void
)
{
int
ret
;
unsigned
int
num_fds
;
const
char
*
val
;
val
=
getenv
(
"LISTEN_FDS"
);
if
(
!
val
)
return
0
;
ret
=
lxc_safe_uint
(
val
,
&
num_fds
);
if
(
ret
<
0
)
return
syserror_ret
(
0
,
"Failed to parse
\"
LISTEN_FDS=%s
\"
environment variable"
,
val
);
return
log_trace
(
num_fds
,
"Parsed
\"
LISTEN_FDS=%s
\"
environment variable"
,
val
);
}
int
lxc_check_inherited
(
struct
lxc_conf
*
conf
,
bool
closeall
,
int
lxc_check_inherited
(
struct
lxc_conf
*
conf
,
bool
closeall
,
int
*
fds_to_ignore
,
size_t
len_fds
)
int
*
fds_to_ignore
,
size_t
len_fds
)
{
{
...
@@ -219,10 +244,13 @@ int lxc_check_inherited(struct lxc_conf *conf, bool closeall,
...
@@ -219,10 +244,13 @@ int lxc_check_inherited(struct lxc_conf *conf, bool closeall,
size_t
i
;
size_t
i
;
DIR
*
dir
;
DIR
*
dir
;
struct
dirent
*
direntp
;
struct
dirent
*
direntp
;
unsigned
int
listen_fds_max
;
if
(
conf
&&
conf
->
close_all_fds
)
if
(
conf
&&
conf
->
close_all_fds
)
closeall
=
true
;
closeall
=
true
;
listen_fds_max
=
get_listen_fds_max
();
/*
/*
* Disable syslog at this point to avoid the above logging
* Disable syslog at this point to avoid the above logging
* function to open a new fd and make the check_inherited function
* function to open a new fd and make the check_inherited function
...
@@ -289,6 +317,12 @@ restart:
...
@@ -289,6 +317,12 @@ restart:
continue
;
continue
;
#endif
#endif
if
(
fd
<=
listen_fds_max
)
{
INFO
(
"Inheriting fd %d (using the LISTEN_FDS environment variable)"
,
fd
);
continue
;
}
if
(
closeall
)
{
if
(
closeall
)
{
if
(
close
(
fd
))
if
(
close
(
fd
))
SYSINFO
(
"Closed inherited fd %d"
,
fd
);
SYSINFO
(
"Closed inherited fd %d"
,
fd
);
...
...
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