1 /*
2 * Copyright 2009-2017 Citrix Ltd and other contributors
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; version 2.1 only. with the special
7 * exception on linking described in file LICENSE.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 */
14
15 #include <stdlib.h>
16
17 #include <libxl.h>
18 #include <libxl_utils.h>
19 #include <libxlutil.h>
20
21 #include "xl.h"
22 #include "xl_utils.h"
23 #include "xl_parse.h"
24
main_console(int argc,char ** argv)25 int main_console(int argc, char **argv)
26 {
27 uint32_t domid;
28 int opt = 0, num = 0;
29 libxl_console_type type = 0;
30 const char *console_names = "pv, serial, vuart";
31 char* escape_character = NULL;
32
33 SWITCH_FOREACH_OPT(opt, "n:t:e:", NULL, "console", 1) {
34 case 't':
35 if (!strcmp(optarg, "pv"))
36 type = LIBXL_CONSOLE_TYPE_PV;
37 else if (!strcmp(optarg, "serial"))
38 type = LIBXL_CONSOLE_TYPE_SERIAL;
39 else if (!strcmp(optarg, "vuart"))
40 type = LIBXL_CONSOLE_TYPE_VUART;
41 else {
42 fprintf(stderr, "console type supported are: %s\n", console_names);
43 return EXIT_FAILURE;
44 }
45 break;
46 case 'n':
47 num = atoi(optarg);
48 break;
49 case 'e':
50 escape_character = optarg;
51 break;
52 }
53
54 domid = find_domain(argv[optind]);
55 if (!type)
56 libxl_primary_console_exec(ctx, domid, -1, escape_character);
57 else
58 libxl_console_exec(ctx, domid, num, type, -1, escape_character);
59 fprintf(stderr, "Unable to attach console\n");
60 return EXIT_FAILURE;
61 }
62
main_vncviewer(int argc,char ** argv)63 int main_vncviewer(int argc, char **argv)
64 {
65 static const struct option opts[] = {
66 {"autopass", 0, 0, 'a'},
67 {"vncviewer-autopass", 0, 0, 'a'},
68 COMMON_LONG_OPTS
69 };
70 uint32_t domid;
71 int opt, autopass = 0;
72
73 SWITCH_FOREACH_OPT(opt, "a", opts, "vncviewer", 1) {
74 case 'a':
75 autopass = 1;
76 break;
77 }
78
79 domid = find_domain(argv[optind]);
80
81 libxl_vncviewer_exec(ctx, domid, autopass);
82
83 return EXIT_FAILURE;
84 }
85
86 /* Channel is just a console in disguise, so put it here */
main_channellist(int argc,char ** argv)87 int main_channellist(int argc, char **argv)
88 {
89 int opt;
90 libxl_device_channel *channels;
91 libxl_channelinfo channelinfo;
92 int nb, i;
93
94 SWITCH_FOREACH_OPT(opt, "", NULL, "channel-list", 1) {
95 /* No options */
96 }
97
98 /* Idx BE state evt-ch ring-ref connection params*/
99 printf("%-3s %-2s %-5s %-6s %8s %-10s %-30s\n",
100 "Idx", "BE", "state", "evt-ch", "ring-ref", "connection", "");
101 for (argv += optind, argc -= optind; argc > 0; --argc, ++argv) {
102 uint32_t domid = find_domain(*argv);
103 channels = libxl_device_channel_list(ctx, domid, &nb);
104 if (!channels)
105 continue;
106 for (i = 0; i < nb; ++i) {
107 if (!libxl_device_channel_getinfo(ctx, domid, &channels[i],
108 &channelinfo)) {
109 printf("%-3d %-2d ", channels[i].devid, channelinfo.backend_id);
110 printf("%-5d ", channelinfo.state);
111 printf("%-6d %-8d ", channelinfo.evtch, channelinfo.rref);
112 printf("%-10s ", libxl_channel_connection_to_string(
113 channels[i].connection));
114 switch (channels[i].connection) {
115 case LIBXL_CHANNEL_CONNECTION_PTY:
116 printf("%-30s ", channelinfo.u.pty.path);
117 break;
118 default:
119 break;
120 }
121 printf("\n");
122 libxl_channelinfo_dispose(&channelinfo);
123 }
124 libxl_device_channel_dispose(&channels[i]);
125 }
126 free(channels);
127 }
128 return 0;
129 }
130
131 /*
132 * Local variables:
133 * mode: C
134 * c-basic-offset: 4
135 * indent-tabs-mode: nil
136 * End:
137 */
138