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
c4fb13e9
Unverified
Commit
c4fb13e9
authored
Feb 22, 2019
by
Stéphane Graber
Committed by
GitHub
Feb 22, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2867 from brauner/2019-02-19/cleanup_macros
tree-wide: cleanup macros
parents
8d36ef3b
19a3e906
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
71 deletions
+24
-71
attach.c
src/lxc/attach.c
+17
-60
commands_utils.c
src/lxc/commands_utils.c
+7
-11
conf.c
src/lxc/conf.c
+0
-0
No files found.
src/lxc/attach.c
View file @
c4fb13e9
...
...
@@ -125,14 +125,8 @@ static struct lxc_proc_context_info *lxc_proc_get_context_info(pid_t pid)
static
inline
void
lxc_proc_close_ns_fd
(
struct
lxc_proc_context_info
*
ctx
)
{
int
i
;
for
(
i
=
0
;
i
<
LXC_NS_MAX
;
i
++
)
{
if
(
ctx
->
ns_fd
[
i
]
<
0
)
continue
;
close
(
ctx
->
ns_fd
[
i
]);
ctx
->
ns_fd
[
i
]
=
-
EBADF
;
for
(
int
i
=
0
;
i
<
LXC_NS_MAX
;
i
++
)
{
__do_close_prot_errno
int
fd
=
ctx
->
ns_fd
[
i
];
}
}
...
...
@@ -163,7 +157,8 @@ static void lxc_proc_put_context_info(struct lxc_proc_context_info *ctx)
*/
static
int
in_same_namespace
(
pid_t
pid1
,
pid_t
pid2
,
const
char
*
ns
)
{
int
ns_fd1
=
-
1
,
ns_fd2
=
-
1
,
ret
=
-
1
;
__do_close_prot_errno
int
ns_fd1
=
-
1
,
ns_fd2
=
-
1
;
int
ret
=
-
1
;
int
saved_errno
;
struct
stat
ns_st1
,
ns_st2
;
...
...
@@ -175,42 +170,27 @@ static int in_same_namespace(pid_t pid1, pid_t pid2, const char *ns)
if
(
errno
==
ENOENT
)
return
-
EINVAL
;
goto
out
;
return
-
1
;
}
ns_fd2
=
lxc_preserve_ns
(
pid2
,
ns
);
if
(
ns_fd2
<
0
)
goto
out
;
return
-
1
;
ret
=
fstat
(
ns_fd1
,
&
ns_st1
);
if
(
ret
<
0
)
goto
out
;
return
-
1
;
ret
=
fstat
(
ns_fd2
,
&
ns_st2
);
if
(
ret
<
0
)
goto
out
;
return
-
1
;
/* processes are in the same namespace */
if
((
ns_st1
.
st_dev
==
ns_st2
.
st_dev
)
&&
(
ns_st1
.
st_ino
==
ns_st2
.
st_ino
))
{
ret
=
-
EINVAL
;
goto
out
;
}
if
((
ns_st1
.
st_dev
==
ns_st2
.
st_dev
)
&&
(
ns_st1
.
st_ino
==
ns_st2
.
st_ino
))
return
-
EINVAL
;
/* processes are in different namespaces */
ret
=
ns_fd2
;
ns_fd2
=
-
1
;
out:
saved_errno
=
errno
;
if
(
ns_fd1
>=
0
)
close
(
ns_fd1
);
if
(
ns_fd2
>=
0
)
close
(
ns_fd2
);
errno
=
saved_errno
;
return
ret
;
return
move_fd
(
ns_fd2
);
}
static
int
lxc_attach_to_ns
(
pid_t
pid
,
struct
lxc_proc_context_info
*
ctx
)
...
...
@@ -710,15 +690,8 @@ struct attach_clone_payload {
static
void
lxc_put_attach_clone_payload
(
struct
attach_clone_payload
*
p
)
{
if
(
p
->
ipc_socket
>=
0
)
{
close
(
p
->
ipc_socket
);
p
->
ipc_socket
=
-
EBADF
;
}
if
(
p
->
terminal_slave_fd
>=
0
)
{
close
(
p
->
terminal_slave_fd
);
p
->
terminal_slave_fd
=
-
EBADF
;
}
__do_close_prot_errno
int
ipc_socket
=
p
->
ipc_socket
;
__do_close_prot_errno
int
terminal_slave_fd
=
p
->
terminal_slave_fd
;
if
(
p
->
init_ctx
)
{
lxc_proc_put_context_info
(
p
->
init_ctx
);
...
...
@@ -1011,38 +984,22 @@ static int lxc_attach_terminal_mainloop_init(struct lxc_terminal *terminal,
static
inline
void
lxc_attach_terminal_close_master
(
struct
lxc_terminal
*
terminal
)
{
if
(
terminal
->
master
<
0
)
return
;
close
(
terminal
->
master
);
terminal
->
master
=
-
EBADF
;
close_prot_errno_disarm
(
terminal
->
master
);
}
static
inline
void
lxc_attach_terminal_close_slave
(
struct
lxc_terminal
*
terminal
)
{
if
(
terminal
->
slave
<
0
)
return
;
close
(
terminal
->
slave
);
terminal
->
slave
=
-
EBADF
;
close_prot_errno_disarm
(
terminal
->
slave
);
}
static
inline
void
lxc_attach_terminal_close_peer
(
struct
lxc_terminal
*
terminal
)
{
if
(
terminal
->
peer
<
0
)
return
;
close
(
terminal
->
peer
);
terminal
->
peer
=
-
EBADF
;
close_prot_errno_disarm
(
terminal
->
peer
);
}
static
inline
void
lxc_attach_terminal_close_log
(
struct
lxc_terminal
*
terminal
)
{
if
(
terminal
->
log_fd
<
0
)
return
;
close
(
terminal
->
log_fd
);
terminal
->
log_fd
=
-
EBADF
;
close_prot_errno_disarm
(
terminal
->
log_fd
);
}
int
lxc_attach
(
const
char
*
name
,
const
char
*
lxcpath
,
...
...
src/lxc/commands_utils.c
View file @
c4fb13e9
...
...
@@ -82,8 +82,8 @@ int lxc_cmd_sock_rcv_state(int state_client_fd, int timeout)
int
lxc_cmd_sock_get_state
(
const
char
*
name
,
const
char
*
lxcpath
,
lxc_state_t
states
[
MAX_STATE
],
int
timeout
)
{
__do_close_prot_errno
int
state_client_fd
=
-
EBADF
;
int
ret
;
int
state_client_fd
;
ret
=
lxc_cmd_add_state_client
(
name
,
lxcpath
,
states
,
&
state_client_fd
);
if
(
ret
<
0
)
...
...
@@ -92,9 +92,7 @@ int lxc_cmd_sock_get_state(const char *name, const char *lxcpath,
if
(
ret
<
MAX_STATE
)
return
ret
;
ret
=
lxc_cmd_sock_rcv_state
(
state_client_fd
,
timeout
);
close
(
state_client_fd
);
return
ret
;
return
lxc_cmd_sock_rcv_state
(
state_client_fd
,
timeout
);
}
int
lxc_make_abstract_socket_name
(
char
*
path
,
size_t
pathlen
,
...
...
@@ -193,9 +191,9 @@ int lxc_cmd_connect(const char *name, const char *lxcpath,
int
lxc_add_state_client
(
int
state_client_fd
,
struct
lxc_handler
*
handler
,
lxc_state_t
states
[
MAX_STATE
])
{
__do_free
struct
lxc_state_client
*
newclient
=
NULL
;
__do_free
struct
lxc_list
*
tmplist
=
NULL
;
int
state
;
struct
lxc_state_client
*
newclient
;
struct
lxc_list
*
tmplist
;
newclient
=
malloc
(
sizeof
(
*
newclient
));
if
(
!
newclient
)
...
...
@@ -206,21 +204,19 @@ int lxc_add_state_client(int state_client_fd, struct lxc_handler *handler,
newclient
->
clientfd
=
state_client_fd
;
tmplist
=
malloc
(
sizeof
(
*
tmplist
));
if
(
!
tmplist
)
{
free
(
newclient
);
if
(
!
tmplist
)
return
-
ENOMEM
;
}
state
=
handler
->
state
;
if
(
states
[
state
]
!=
1
)
{
lxc_list_add_elem
(
tmplist
,
newclient
);
lxc_list_add_tail
(
&
handler
->
conf
->
state_clients
,
tmplist
);
}
else
{
free
(
newclient
);
free
(
tmplist
);
return
state
;
}
TRACE
(
"Added state client %d to state client list"
,
state_client_fd
);
move_ptr
(
newclient
);
move_ptr
(
tmplist
);
return
MAX_STATE
;
}
src/lxc/conf.c
View file @
c4fb13e9
This diff is collapsed.
Click to expand it.
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