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
ba03fa64
Commit
ba03fa64
authored
Apr 13, 2016
by
Serge Hallyn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #970 from brauner/2016-04-13/lxc_attach_log
lxc-attach: error on -L/--pty-log + redirection
parents
e4be55c4
804bd6e3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
27 deletions
+45
-27
lxc_attach.c
src/lxc/lxc_attach.c
+36
-20
lxc-test-lxc-attach
src/tests/lxc-test-lxc-attach
+9
-7
No files found.
src/lxc/lxc_attach.c
View file @
ba03fa64
...
@@ -21,7 +21,8 @@
...
@@ -21,7 +21,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
#define _GNU_SOURCE
#include "config.h"
#include <assert.h>
#include <assert.h>
#include <errno.h>
#include <errno.h>
#include <fcntl.h>
#include <fcntl.h>
...
@@ -38,7 +39,6 @@
...
@@ -38,7 +39,6 @@
#include "attach.h"
#include "attach.h"
#include "arguments.h"
#include "arguments.h"
#include "caps.h"
#include "caps.h"
#include "config.h"
#include "confile.h"
#include "confile.h"
#include "console.h"
#include "console.h"
#include "log.h"
#include "log.h"
...
@@ -254,7 +254,7 @@ static int get_pty_on_host(struct lxc_container *c, struct wrapargs *wrap, int *
...
@@ -254,7 +254,7 @@ static int get_pty_on_host(struct lxc_container *c, struct wrapargs *wrap, int *
INFO
(
"Trying to allocate a pty on the host"
);
INFO
(
"Trying to allocate a pty on the host"
);
if
(
!
isatty
(
args
->
ptyfd
))
{
if
(
!
isatty
(
args
->
ptyfd
))
{
ERROR
(
"
stdin is not a tty
"
);
ERROR
(
"
Standard file descriptor does not refer to a pty
\n
.
"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -324,28 +324,40 @@ err1:
...
@@ -324,28 +324,40 @@ err1:
return
ret
;
return
ret
;
}
}
static
int
stdfd_is_pty
(
void
)
{
if
(
isatty
(
STDIN_FILENO
))
return
STDIN_FILENO
;
if
(
isatty
(
STDOUT_FILENO
))
return
STDOUT_FILENO
;
if
(
isatty
(
STDERR_FILENO
))
return
STDERR_FILENO
;
return
-
1
;
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
ret
=
-
1
;
int
ret
=
-
1
,
r
;
int
wexit
=
0
;
int
wexit
=
0
;
pid_t
pid
;
pid_t
pid
;
lxc_attach_options_t
attach_options
=
LXC_ATTACH_OPTIONS_DEFAULT
;
lxc_attach_options_t
attach_options
=
LXC_ATTACH_OPTIONS_DEFAULT
;
lxc_attach_command_t
command
=
(
lxc_attach_command_t
){.
program
=
NULL
};
lxc_attach_command_t
command
=
(
lxc_attach_command_t
){.
program
=
NULL
};
r
et
=
lxc_caps_init
();
r
=
lxc_caps_init
();
if
(
r
et
)
if
(
r
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
r
et
=
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
);
r
=
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
);
if
(
r
et
)
if
(
r
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
if
(
!
my_args
.
log_file
)
if
(
!
my_args
.
log_file
)
my_args
.
log_file
=
"none"
;
my_args
.
log_file
=
"none"
;
r
et
=
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
r
=
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]);
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]);
if
(
r
et
)
if
(
r
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_log_options_no_override
();
lxc_log_options_no_override
();
...
@@ -388,19 +400,23 @@ int main(int argc, char *argv[])
...
@@ -388,19 +400,23 @@ int main(int argc, char *argv[])
command
.
argv
=
(
char
**
)
my_args
.
argv
;
command
.
argv
=
(
char
**
)
my_args
.
argv
;
}
}
if
(
isatty
(
STDIN_FILENO
)
||
isatty
(
STDOUT_FILENO
)
||
isatty
(
STDERR_FILENO
))
{
struct
wrapargs
wrap
=
(
struct
wrapargs
){
struct
wrapargs
wrap
=
(
struct
wrapargs
){
.
command
=
&
command
,
.
command
=
&
command
,
.
options
=
&
attach_options
.
options
=
&
attach_options
};
};
if
(
isatty
(
STDIN_FILENO
))
wrap
.
ptyfd
=
STDIN_FILENO
;
wrap
.
ptyfd
=
stdfd_is_pty
();
else
if
(
isatty
(
STDOUT_FILENO
))
if
(
wrap
.
ptyfd
>=
0
)
{
wrap
.
ptyfd
=
STDOUT_FILENO
;
if
((
!
isatty
(
STDOUT_FILENO
)
||
!
isatty
(
STDERR_FILENO
))
&&
my_args
.
console_log
)
{
else
if
(
isatty
(
STDERR_FILENO
))
fprintf
(
stderr
,
"-L/--pty-log can only be used when stdout and stderr refer to a pty.
\n
"
);
wrap
.
ptyfd
=
STDERR_FILENO
;
goto
out
;
}
ret
=
get_pty_on_host
(
c
,
&
wrap
,
&
pid
);
ret
=
get_pty_on_host
(
c
,
&
wrap
,
&
pid
);
}
else
{
}
else
{
if
(
my_args
.
console_log
)
{
fprintf
(
stderr
,
"-L/--pty-log can only be used when stdout and stderr refer to a pty.
\n
"
);
goto
out
;
}
if
(
command
.
program
)
if
(
command
.
program
)
ret
=
c
->
attach
(
c
,
lxc_attach_run_command
,
&
command
,
&
attach_options
,
&
pid
);
ret
=
c
->
attach
(
c
,
lxc_attach_run_command
,
&
command
,
&
attach_options
,
&
pid
);
else
else
...
...
src/tests/lxc-test-lxc-attach
View file @
ba03fa64
...
@@ -190,14 +190,16 @@ fi
...
@@ -190,14 +190,16 @@ fi
rm
-f
$out
$err
rm
-f
$out
$err
# Test whether logging pty output to a file works.
if
[
$allocate_pty
=
"pty"
]
;
then
trap
"rm -f /tmp/ptylog"
EXIT INT QUIT PIPE
# Test whether logging pty output to a file works.
lxc-attach
-n
busy
-L
/tmp/ptylog
--
hostname
||
FAIL
"to allocate or setup pty"
trap
"rm -f /tmp/ptylog"
EXIT INT QUIT PIPE
if
[
$allocate_pty
==
"pty"
]
&&
[
!
-s
/tmp/ptylog
]
;
then
lxc-attach
-n
busy
-L
/tmp/ptylog
--
hostname
||
FAIL
"to allocate or setup pty"
FAIL
"lxc-attach -n busy -L /tmp/ptylog -- hostname"
if
[
!
-s
/tmp/ptylog
]
;
then
fi
FAIL
"lxc-attach -n busy -L /tmp/ptylog -- hostname"
fi
rm
-f
/tmp/ptylog
rm
-f
/tmp/ptylog
fi
lxc-destroy
-n
busy
-f
lxc-destroy
-n
busy
-f
...
...
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