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
a529bc25
Unverified
Commit
a529bc25
authored
Dec 25, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mainloop: add mainloop macros
This makes it clearer why handlers return what value. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
c326c196
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
33 deletions
+50
-33
console.c
src/lxc/console.c
+37
-24
console.h
src/lxc/console.h
+2
-0
mainloop.c
src/lxc/mainloop.c
+7
-8
mainloop.h
src/lxc/mainloop.h
+3
-0
start.h
src/lxc/start.h
+1
-1
No files found.
src/lxc/console.c
View file @
a529bc25
...
@@ -122,7 +122,7 @@ int lxc_console_cb_signal_fd(int fd, uint32_t events, void *cbdata,
...
@@ -122,7 +122,7 @@ int lxc_console_cb_signal_fd(int fd, uint32_t events, void *cbdata,
if
(
siginfo
.
ssi_signo
==
SIGTERM
)
{
if
(
siginfo
.
ssi_signo
==
SIGTERM
)
{
DEBUG
(
"Received SIGTERM. Detaching from the console"
);
DEBUG
(
"Received SIGTERM. Detaching from the console"
);
return
1
;
return
LXC_MAINLOOP_CLOSE
;
}
}
if
(
siginfo
.
ssi_signo
==
SIGWINCH
)
if
(
siginfo
.
ssi_signo
==
SIGWINCH
)
...
@@ -204,8 +204,8 @@ void lxc_console_signal_fini(struct lxc_tty_state *ts)
...
@@ -204,8 +204,8 @@ void lxc_console_signal_fini(struct lxc_tty_state *ts)
free
(
ts
);
free
(
ts
);
}
}
static
int
lxc_console_cb_con
(
int
fd
,
uint32_t
events
,
void
*
data
,
int
lxc_console_cb_con
(
int
fd
,
uint32_t
events
,
void
*
data
,
struct
lxc_epoll_descr
*
descr
)
struct
lxc_epoll_descr
*
descr
)
{
{
struct
lxc_console
*
console
=
(
struct
lxc_console
*
)
data
;
struct
lxc_console
*
console
=
(
struct
lxc_console
*
)
data
;
char
buf
[
LXC_CONSOLE_BUFFER_SIZE
];
char
buf
[
LXC_CONSOLE_BUFFER_SIZE
];
...
@@ -225,7 +225,7 @@ static int lxc_console_cb_con(int fd, uint32_t events, void *data,
...
@@ -225,7 +225,7 @@ static int lxc_console_cb_con(int fd, uint32_t events, void *data,
return
0
;
return
0
;
}
}
close
(
fd
);
close
(
fd
);
return
1
;
return
LXC_MAINLOOP_CLOSE
;
}
}
if
(
fd
==
console
->
peer
)
if
(
fd
==
console
->
peer
)
...
@@ -259,27 +259,36 @@ static int lxc_console_cb_con(int fd, uint32_t events, void *data,
...
@@ -259,27 +259,36 @@ static int lxc_console_cb_con(int fd, uint32_t events, void *data,
return
0
;
return
0
;
}
}
static
void
lxc_console_mainloop_add_peer
(
struct
lxc_console
*
console
)
static
int
lxc_console_mainloop_add_peer
(
struct
lxc_console
*
console
)
{
{
int
ret
;
if
(
console
->
peer
>=
0
)
{
if
(
console
->
peer
>=
0
)
{
if
(
lxc_mainloop_add_handler
(
console
->
descr
,
console
->
peer
,
ret
=
lxc_mainloop_add_handler
(
console
->
descr
,
console
->
peer
,
lxc_console_cb_con
,
console
))
lxc_console_cb_con
,
console
);
if
(
ret
<
0
)
{
WARN
(
"Failed to add console peer handler to mainloop"
);
WARN
(
"Failed to add console peer handler to mainloop"
);
return
-
1
;
}
}
}
if
(
console
->
tty_state
&&
console
->
tty_state
->
sigfd
!=
-
1
)
{
if
(
!
console
->
tty_state
||
console
->
tty_state
->
sigfd
<
0
)
if
(
lxc_mainloop_add_handler
(
console
->
descr
,
return
0
;
console
->
tty_state
->
sigfd
,
lxc_console_cb_signal_fd
,
ret
=
lxc_mainloop_add_handler
(
console
->
descr
,
console
->
tty_state
->
sigfd
,
console
->
tty_state
))
{
lxc_console_cb_signal_fd
,
console
->
tty_state
);
WARN
(
"Failed to add signal handler to mainloop"
);
if
(
ret
<
0
)
{
}
WARN
(
"Failed to add signal handler to mainloop"
);
return
-
1
;
}
}
return
0
;
}
}
extern
int
lxc_console_mainloop_add
(
struct
lxc_epoll_descr
*
descr
,
extern
int
lxc_console_mainloop_add
(
struct
lxc_epoll_descr
*
descr
,
struct
lxc_conf
*
conf
)
struct
lxc_conf
*
conf
)
{
{
int
ret
;
struct
lxc_console
*
console
=
&
conf
->
console
;
struct
lxc_console
*
console
=
&
conf
->
console
;
if
(
!
conf
->
rootfs
.
path
)
{
if
(
!
conf
->
rootfs
.
path
)
{
...
@@ -303,7 +312,9 @@ extern int lxc_console_mainloop_add(struct lxc_epoll_descr *descr,
...
@@ -303,7 +312,9 @@ extern int lxc_console_mainloop_add(struct lxc_epoll_descr *descr,
* does attach to it in lxc_console_allocate()
* does attach to it in lxc_console_allocate()
*/
*/
console
->
descr
=
descr
;
console
->
descr
=
descr
;
lxc_console_mainloop_add_peer
(
console
);
ret
=
lxc_console_mainloop_add_peer
(
console
);
if
(
ret
<
0
)
return
-
1
;
return
0
;
return
0
;
}
}
...
@@ -412,7 +423,9 @@ static int lxc_console_peer_proxy_alloc(struct lxc_console *console, int sockfd)
...
@@ -412,7 +423,9 @@ static int lxc_console_peer_proxy_alloc(struct lxc_console *console, int sockfd)
console
->
tty_state
=
ts
;
console
->
tty_state
=
ts
;
console
->
peer
=
console
->
peerpty
.
slave
;
console
->
peer
=
console
->
peerpty
.
slave
;
console
->
peerpty
.
busy
=
sockfd
;
console
->
peerpty
.
busy
=
sockfd
;
lxc_console_mainloop_add_peer
(
console
);
ret
=
lxc_console_mainloop_add_peer
(
console
);
if
(
ret
<
0
)
goto
err1
;
DEBUG
(
"%d %s peermaster:%d sockfd:%d"
,
lxc_raw_getpid
(),
__FUNCTION__
,
console
->
peerpty
.
master
,
sockfd
);
DEBUG
(
"%d %s peermaster:%d sockfd:%d"
,
lxc_raw_getpid
(),
__FUNCTION__
,
console
->
peerpty
.
master
,
sockfd
);
return
0
;
return
0
;
...
@@ -794,10 +807,10 @@ int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata,
...
@@ -794,10 +807,10 @@ int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata,
char
c
;
char
c
;
if
(
fd
!=
ts
->
stdinfd
)
if
(
fd
!=
ts
->
stdinfd
)
return
1
;
return
LXC_MAINLOOP_CLOSE
;
if
(
lxc_read_nointr
(
ts
->
stdinfd
,
&
c
,
1
)
<=
0
)
if
(
lxc_read_nointr
(
ts
->
stdinfd
,
&
c
,
1
)
<=
0
)
return
1
;
return
LXC_MAINLOOP_CLOSE
;
if
(
ts
->
escape
>=
1
)
{
if
(
ts
->
escape
>=
1
)
{
/* we want to exit the console with Ctrl+a q */
/* we want to exit the console with Ctrl+a q */
...
@@ -807,13 +820,13 @@ int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata,
...
@@ -807,13 +820,13 @@ int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata,
}
}
if
(
c
==
'q'
&&
ts
->
saw_escape
)
if
(
c
==
'q'
&&
ts
->
saw_escape
)
return
1
;
return
LXC_MAINLOOP_CLOSE
;
ts
->
saw_escape
=
0
;
ts
->
saw_escape
=
0
;
}
}
if
(
lxc_write_nointr
(
ts
->
masterfd
,
&
c
,
1
)
<=
0
)
if
(
lxc_write_nointr
(
ts
->
masterfd
,
&
c
,
1
)
<=
0
)
return
1
;
return
LXC_MAINLOOP_CLOSE
;
return
0
;
return
0
;
}
}
...
@@ -826,17 +839,17 @@ int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata,
...
@@ -826,17 +839,17 @@ int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata,
int
r
,
w
;
int
r
,
w
;
if
(
fd
!=
ts
->
masterfd
)
if
(
fd
!=
ts
->
masterfd
)
return
1
;
return
LXC_MAINLOOP_CLOSE
;
r
=
lxc_read_nointr
(
fd
,
buf
,
sizeof
(
buf
));
r
=
lxc_read_nointr
(
fd
,
buf
,
sizeof
(
buf
));
if
(
r
<=
0
)
if
(
r
<=
0
)
return
1
;
return
LXC_MAINLOOP_CLOSE
;
w
=
lxc_write_nointr
(
ts
->
stdoutfd
,
buf
,
r
);
w
=
lxc_write_nointr
(
ts
->
stdoutfd
,
buf
,
r
);
if
(
w
<=
0
)
{
if
(
w
<=
0
)
{
return
1
;
return
LXC_MAINLOOP_CLOSE
;
}
else
if
(
w
!=
r
)
{
}
else
if
(
w
!=
r
)
{
SYSERROR
(
"
f
ailed to write"
);
SYSERROR
(
"
F
ailed to write"
);
return
1
;
return
1
;
}
}
...
...
src/lxc/console.h
View file @
a529bc25
...
@@ -223,5 +223,7 @@ extern void lxc_console_signal_fini(struct lxc_tty_state *ts);
...
@@ -223,5 +223,7 @@ extern void lxc_console_signal_fini(struct lxc_tty_state *ts);
extern
int
lxc_console_write_ringbuffer
(
struct
lxc_console
*
console
);
extern
int
lxc_console_write_ringbuffer
(
struct
lxc_console
*
console
);
extern
int
lxc_console_create_log_file
(
struct
lxc_console
*
console
);
extern
int
lxc_console_create_log_file
(
struct
lxc_console
*
console
);
extern
int
lxc_console_cb_con
(
int
fd
,
uint32_t
events
,
void
*
data
,
struct
lxc_epoll_descr
*
descr
);
#endif
#endif
src/lxc/mainloop.c
View file @
a529bc25
...
@@ -40,12 +40,11 @@ struct mainloop_handler {
...
@@ -40,12 +40,11 @@ struct mainloop_handler {
int
lxc_mainloop
(
struct
lxc_epoll_descr
*
descr
,
int
timeout_ms
)
int
lxc_mainloop
(
struct
lxc_epoll_descr
*
descr
,
int
timeout_ms
)
{
{
int
i
,
nfds
;
int
i
,
nfds
,
ret
;
struct
mainloop_handler
*
handler
;
struct
mainloop_handler
*
handler
;
struct
epoll_event
events
[
MAX_EVENTS
];
struct
epoll_event
events
[
MAX_EVENTS
];
for
(;;)
{
for
(;;)
{
nfds
=
epoll_wait
(
descr
->
epfd
,
events
,
MAX_EVENTS
,
timeout_ms
);
nfds
=
epoll_wait
(
descr
->
epfd
,
events
,
MAX_EVENTS
,
timeout_ms
);
if
(
nfds
<
0
)
{
if
(
nfds
<
0
)
{
if
(
errno
==
EINTR
)
if
(
errno
==
EINTR
)
...
@@ -54,13 +53,13 @@ int lxc_mainloop(struct lxc_epoll_descr *descr, int timeout_ms)
...
@@ -54,13 +53,13 @@ int lxc_mainloop(struct lxc_epoll_descr *descr, int timeout_ms)
}
}
for
(
i
=
0
;
i
<
nfds
;
i
++
)
{
for
(
i
=
0
;
i
<
nfds
;
i
++
)
{
handler
=
handler
=
events
[
i
].
data
.
ptr
;
(
struct
mainloop_handler
*
)
events
[
i
].
data
.
ptr
;
/* If the handler returns a positive value, exit
/* If the handler returns a positive value, exit the
the mainloop */
* mainloop. */
if
(
handler
->
callback
(
handler
->
fd
,
events
[
i
].
events
,
ret
=
handler
->
callback
(
handler
->
fd
,
events
[
i
].
events
,
handler
->
data
,
descr
)
>
0
)
handler
->
data
,
descr
);
if
(
ret
==
LXC_MAINLOOP_CLOSE
)
return
0
;
return
0
;
}
}
...
...
src/lxc/mainloop.h
View file @
a529bc25
...
@@ -27,6 +27,9 @@
...
@@ -27,6 +27,9 @@
#include <stdint.h>
#include <stdint.h>
#include "list.h"
#include "list.h"
#define LXC_MAINLOOP_CONTINUE 0
#define LXC_MAINLOOP_CLOSE 1
struct
lxc_epoll_descr
{
struct
lxc_epoll_descr
{
int
epfd
;
int
epfd
;
struct
lxc_list
handlers
;
struct
lxc_list
handlers
;
...
...
src/lxc/start.h
View file @
a529bc25
...
@@ -138,5 +138,5 @@ extern int __lxc_start(const char *, struct lxc_handler *,
...
@@ -138,5 +138,5 @@ extern int __lxc_start(const char *, struct lxc_handler *,
struct
lxc_operations
*
,
void
*
,
const
char
*
,
bool
);
struct
lxc_operations
*
,
void
*
,
const
char
*
,
bool
);
extern
int
resolve_clone_flags
(
struct
lxc_handler
*
handler
);
extern
int
resolve_clone_flags
(
struct
lxc_handler
*
handler
);
#endif
#endif
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