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
85c279bb
Unverified
Commit
85c279bb
authored
May 13, 2020
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start: cleanup file descriptor inheritance
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
a42abcce
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
10 deletions
+15
-10
lxccontainer.c
src/lxc/lxccontainer.c
+2
-10
start.c
src/lxc/start.c
+4
-0
start.h
src/lxc/start.h
+9
-0
No files found.
src/lxc/lxccontainer.c
View file @
85c279bb
...
@@ -865,7 +865,6 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
...
@@ -865,7 +865,6 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
NULL
,
NULL
,
};
};
char
**
init_cmd
=
NULL
;
char
**
init_cmd
=
NULL
;
int
keepfds
[
3
]
=
{
-
EBADF
,
-
EBADF
,
-
EBADF
};
/* container does exist */
/* container does exist */
if
(
!
c
)
if
(
!
c
)
...
@@ -996,10 +995,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
...
@@ -996,10 +995,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
_exit
(
EXIT_FAILURE
);
_exit
(
EXIT_FAILURE
);
}
}
keepfds
[
0
]
=
handler
->
conf
->
maincmd_fd
;
ret
=
inherit_fds
(
handler
,
true
);
keepfds
[
1
]
=
handler
->
state_socket_pair
[
0
];
keepfds
[
2
]
=
handler
->
state_socket_pair
[
1
];
ret
=
lxc_check_inherited
(
conf
,
true
,
keepfds
,
ARRAY_SIZE
(
keepfds
));
if
(
ret
<
0
)
if
(
ret
<
0
)
_exit
(
EXIT_FAILURE
);
_exit
(
EXIT_FAILURE
);
...
@@ -1084,13 +1080,9 @@ reboot:
...
@@ -1084,13 +1080,9 @@ reboot:
ret
=
1
;
ret
=
1
;
goto
on_error
;
goto
on_error
;
}
}
}
else
{
keepfds
[
1
]
=
handler
->
state_socket_pair
[
0
];
keepfds
[
2
]
=
handler
->
state_socket_pair
[
1
];
}
}
keepfds
[
0
]
=
handler
->
conf
->
maincmd_fd
;
ret
=
inherit_fds
(
handler
,
c
->
daemonize
);
ret
=
lxc_check_inherited
(
conf
,
c
->
daemonize
,
keepfds
,
ARRAY_SIZE
(
keepfds
));
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
lxc_put_handler
(
handler
);
lxc_put_handler
(
handler
);
ret
=
1
;
ret
=
1
;
...
...
src/lxc/start.c
View file @
85c279bb
...
@@ -627,6 +627,7 @@ struct lxc_handler *lxc_init_handler(struct lxc_handler *old,
...
@@ -627,6 +627,7 @@ struct lxc_handler *lxc_init_handler(struct lxc_handler *old,
const
char
*
name
,
struct
lxc_conf
*
conf
,
const
char
*
name
,
struct
lxc_conf
*
conf
,
const
char
*
lxcpath
,
bool
daemonize
)
const
char
*
lxcpath
,
bool
daemonize
)
{
{
int
nr_keep_fds
=
0
;
int
ret
;
int
ret
;
struct
lxc_handler
*
handler
;
struct
lxc_handler
*
handler
;
...
@@ -680,6 +681,8 @@ struct lxc_handler *lxc_init_handler(struct lxc_handler *old,
...
@@ -680,6 +681,8 @@ struct lxc_handler *lxc_init_handler(struct lxc_handler *old,
TRACE
(
"Created anonymous pair {%d,%d} of unix sockets"
,
TRACE
(
"Created anonymous pair {%d,%d} of unix sockets"
,
handler
->
state_socket_pair
[
0
],
handler
->
state_socket_pair
[
0
],
handler
->
state_socket_pair
[
1
]);
handler
->
state_socket_pair
[
1
]);
handler
->
keep_fds
[
nr_keep_fds
++
]
=
handler
->
state_socket_pair
[
0
];
handler
->
keep_fds
[
nr_keep_fds
++
]
=
handler
->
state_socket_pair
[
1
];
}
}
if
(
handler
->
conf
->
reboot
==
REBOOT_NONE
)
{
if
(
handler
->
conf
->
reboot
==
REBOOT_NONE
)
{
...
@@ -688,6 +691,7 @@ struct lxc_handler *lxc_init_handler(struct lxc_handler *old,
...
@@ -688,6 +691,7 @@ struct lxc_handler *lxc_init_handler(struct lxc_handler *old,
ERROR
(
"Failed to set up command socket"
);
ERROR
(
"Failed to set up command socket"
);
goto
on_error
;
goto
on_error
;
}
}
handler
->
keep_fds
[
nr_keep_fds
++
]
=
handler
->
conf
->
maincmd_fd
;
}
}
TRACE
(
"Unix domain socket %d for command server is ready"
,
TRACE
(
"Unix domain socket %d for command server is ready"
,
...
...
src/lxc/start.h
View file @
85c279bb
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include <sys/un.h>
#include <sys/un.h>
#include "conf.h"
#include "conf.h"
#include "macro.h"
#include "namespace.h"
#include "namespace.h"
#include "state.h"
#include "state.h"
...
@@ -122,6 +123,9 @@ struct lxc_handler {
...
@@ -122,6 +123,9 @@ struct lxc_handler {
int
exit_status
;
int
exit_status
;
struct
cgroup_ops
*
cgroup_ops
;
struct
cgroup_ops
*
cgroup_ops
;
/* Internal fds that always need to stay open. */
int
keep_fds
[
3
];
};
};
struct
execute_args
{
struct
execute_args
{
...
@@ -160,6 +164,11 @@ extern void lxc_end(struct lxc_handler *handler);
...
@@ -160,6 +164,11 @@ extern void lxc_end(struct lxc_handler *handler);
*/
*/
extern
int
lxc_check_inherited
(
struct
lxc_conf
*
conf
,
bool
closeall
,
extern
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
);
static
inline
int
inherit_fds
(
struct
lxc_handler
*
handler
,
bool
closeall
)
{
return
lxc_check_inherited
(
handler
->
conf
,
closeall
,
handler
->
keep_fds
,
ARRAY_SIZE
(
handler
->
keep_fds
));
}
extern
int
__lxc_start
(
struct
lxc_handler
*
,
struct
lxc_operations
*
,
void
*
,
extern
int
__lxc_start
(
struct
lxc_handler
*
,
struct
lxc_operations
*
,
void
*
,
const
char
*
,
bool
,
int
*
);
const
char
*
,
bool
,
int
*
);
...
...
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