xl console: Add interactive option
PATCH 1/1 xl console: Add interactive option
Added an interactive option to the 'xl console'-command that forwards the input stream of the console to the underlying pty.
Made corresponding changes to libxl, xl and xenconsole.
--- tools/console/client/main.c | 4 ++++ tools/libxl/libxl.h | 5 +++-- tools/libxl/libxl_console.c | 19 ++++++++++++++----- tools/xl/xl_console.c | 11 +++++++---- tools/xl/xl_vmcontrol.c | 2 +- 5 files changed, 29 insertions(+), 12 deletions(-)
tools/console/client/main.c +4 -0
@@ -334,6 +334,7 @@ int main(int argc, char **argv) { "num", 1, 0, 'n' }, { "help", 0, 0, 'h' }, { "start-notify-fd", 1, 0, 's' }, + { "pipe", 0, 0, 'p' }, { 0 }, };
@@ -370,6 +371,9 @@ int main(int argc, char **argv)case 's' : start_notify_fd =atoi (optarg);break ; +case 'p' : + interactive =1 ; +break ;default :fprintf (stderr,"Invalid argument\n" ); fprintf(stderr, "Try `%s --help' for more information.\n",
tools/libxl/libxl.h +3 -2
@@ -1499,7 +1499,8 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass);* the caller that it has connected to the guest console. */ int libxl_console_exec (libxl_ctx *ctx,uint32_t domid,int cons_num, -libxl_console_type type,int notify_fd); +libxl_console_type type,int notify_fd, +int interactive);/* libxl_primary_console_exec finds the domid and console number * corresponding to the primary console of the given vm, then calls * libxl_console_exec with the right arguments (domid might be different
@@ -1511,7 +1512,7 @@ int libxl_console_exec(libxl_ctx *ctx, uint32_t domid, int cons_num,* the caller that it has connected to the guest console. */ int libxl_primary_console_exec (libxl_ctx *ctx,uint32_t domid_vm, -int notify_fd); +int notify_fd,int interactive);#if defined(LIBXL_API_VERSION ) &&LIBXL_API_VERSION <0x040800
tools/libxl/libxl_console.c +14 -5
@@ -51,7 +51,8 @@ out: }int libxl_console_exec (libxl_ctx *ctx,uint32_t domid,int cons_num, -libxl_console_type type,int notify_fd) +libxl_console_type type,int notify_fd, +int interactive) {GC_INIT (ctx);char *p =GCSPRINTF ("%s/xenconsole" ,libxl__private_bindir_path ());
@@ -59,6 +60,7 @@ int libxl_console_exec(libxl_ctx *ctx, uint32_t domid, int cons_num,char *cons_num_s =GCSPRINTF ("%d" , cons_num);char *notify_fd_s;char *cons_type_s; +char interactive_str[] ="--pipe" ;switch (type) {case LIBXL_CONSOLE_TYPE_PV :
@@ -71,13 +73,18 @@ int libxl_console_exec(libxl_ctx *ctx, uint32_t domid, int cons_num, goto out; } +if (!interactive) { + interactive_str[0 ] ='\0' ; + } +if (notify_fd !=-1 ) { notify_fd_s =GCSPRINTF ("%d" , notify_fd);execl (p, p, domid_s,"--num" , cons_num_s,"--type" , cons_type_s, -"--start-notify-fd" , notify_fd_s, (void *)NULL ); +"--start-notify-fd" , notify_fd_s, interactive_str, + (void *)NULL ); }else {execl (p, p, domid_s,"--num" , cons_num_s,"--type" , cons_type_s, - (void *)NULL ); + interactive_str, (void *)NULL ); } out:
@@ -151,7 +158,8 @@ out:return rc; } -int libxl_primary_console_exec (libxl_ctx *ctx,uint32_t domid_vm,int notify_fd) +int libxl_primary_console_exec (libxl_ctx *ctx,uint32_t domid_vm, +int notify_fd,int interactive) {uint32_t domid;int cons_num;
@@ -160,7 +168,8 @@ int libxl_primary_console_exec(libxl_ctx *ctx, uint32_t domid_vm, int notify_fd) rc =libxl__primary_console_find (ctx, domid_vm, &domid, &cons_num, &type);if ( rc )return rc; -return libxl_console_exec (ctx, domid, cons_num, type, notify_fd); +return libxl_console_exec (ctx, domid, cons_num, type, notify_fd, + interactive); } int libxl_primary_console_get_tty(libxl_ctx *ctx, uint32_t domid_vm,
tools/xl/xl_console.c +7 -4
@@ -25,10 +25,10 @@int main_console (int argc,char **argv) {uint32_t domid; -int opt =0 , num =0 ; +int opt =0 , num =0 , interactive =0 ;libxl_console_type type =0 ; - SWITCH_FOREACH_OPT(opt, "n:t:", NULL, "console", 1) { + SWITCH_FOREACH_OPT(opt, "n:t:i", NULL, "console", 1) {case 't' :if (!strcmp (optarg,"pv" )) type =LIBXL_CONSOLE_TYPE_PV ;
@@ -42,13 +42,16 @@ int main_console(int argc, char **argv)case 'n' : num =atoi (optarg);break ; +case 'i' : + interactive =1 ; +break ; } domid =find_domain (argv[optind]);if (!type) -libxl_primary_console_exec (ctx, domid,-1 ); +libxl_primary_console_exec (ctx, domid,-1 , interactive);else -libxl_console_exec (ctx, domid, num, type,-1 ); +libxl_console_exec (ctx, domid, num, type,-1 , interactive);fprintf (stderr,"Unable to attach console\n" );return EXIT_FAILURE ; }
tools/xl/xl_vmcontrol.c +1 -1
@@ -632,7 +632,7 @@ static void autoconnect_console(libxl_ctx *ctx_ignored,postfork ();sleep (1 ); -libxl_primary_console_exec (ctx, bldomid, notify_fd); +libxl_primary_console_exec (ctx, bldomid, notify_fd,0 );/* Do not return. xl continued in child process */ perror ("xl: unable to exec console client" );_exit (1 );
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 27 lines · Felix Schmoll
Added an interactive option to the 'xl console'-command that forwards the input stream of the console to the underlying pty.
Made corresponding changes to libxl, xl and xenconsole.
Signed-off-by Felix Schmoll <[email protected]>--- tools/console/client/main.c | 4 ++++ tools/libxl/libxl.h | 5 +++-- tools/libxl/libxl_console.c | 19 ++++++++++++++----- tools/xl/xl_console.c | 11 +++++++---- tools/xl/xl_vmcontrol.c | 2 +- 5 files changed, 29 insertions(+), 12 deletions(-)tools/console/client/main.c +1
-0@@ -334,6 +334,7 @@ int main(int argc, char **argv) { "num", 1, 0, 'n' }, { "help", 0, 0, 'h' }, { "start-notify-fd", 1, 0, 's' }, + { "pipe", 0, 0, 'p' }, { 0 }, };
tools/console/client/main.c int main(int argc, char **argv) · line 376
Quoted 6 lines
tools/console/client/main.c +3
-0@@ -370,6 +371,9 @@ int main(int argc, char **argv)case 's' : start_notify_fd =atoi (optarg);break ; +case 'p' : + interactive =1 ; +break ;
Indentation is wrong.
And I believe some more changes are needed. Currently interactive also changes the terminal attributes via tcsetattr. Since now STDIN isn't really a tty, we need to skip that.
I think you need to introduce a new flag, not reusing interactive.
Quoted 8 lines
tools/console/client/main.c +0
-0default :fprintf (stderr,"Invalid argument\n" ); fprintf(stderr, "Try `%s --help' for more information.\n",tools/libxl/libxl.h +0
-0
tools/libxl/libxl.h int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass); · line 1503
Quoted 6 lines
tools/libxl/libxl.h +2
-1@@ -1499,7 +1499,8 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass);* the caller that it has connected to the guest console. */ int libxl_console_exec (libxl_ctx *ctx,uint32_t domid,int cons_num, -libxl_console_type type,int notify_fd); +libxl_console_type type,int notify_fd, +int interactive);
If we're to change libxl API, we need to provide compatibility implementation for older version of this API. See the surrounding code.
And I think using "pipe" is better.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel