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     char *console_names = "pv, serial, vuart";
31 
32     SWITCH_FOREACH_OPT(opt, "n:t:", NULL, "console", 1) {
33     case 't':
34         if (!strcmp(optarg, "pv"))
35             type = LIBXL_CONSOLE_TYPE_PV;
36         else if (!strcmp(optarg, "serial"))
37             type = LIBXL_CONSOLE_TYPE_SERIAL;
38         else if (!strcmp(optarg, "vuart"))
39             type = LIBXL_CONSOLE_TYPE_VUART;
40         else {
41             fprintf(stderr, "console type supported are: %s\n", console_names);
42             return EXIT_FAILURE;
43         }
44         break;
45     case 'n':
46         num = atoi(optarg);
47         break;
48     }
49 
50     domid = find_domain(argv[optind]);
51     if (!type)
52         libxl_primary_console_exec(ctx, domid, -1);
53     else
54         libxl_console_exec(ctx, domid, num, type, -1);
55     fprintf(stderr, "Unable to attach console\n");
56     return EXIT_FAILURE;
57 }
58 
main_vncviewer(int argc,char ** argv)59 int main_vncviewer(int argc, char **argv)
60 {
61     static const struct option opts[] = {
62         {"autopass", 0, 0, 'a'},
63         {"vncviewer-autopass", 0, 0, 'a'},
64         COMMON_LONG_OPTS
65     };
66     uint32_t domid;
67     int opt, autopass = 0;
68 
69     SWITCH_FOREACH_OPT(opt, "a", opts, "vncviewer", 1) {
70     case 'a':
71         autopass = 1;
72         break;
73     }
74 
75     domid = find_domain(argv[optind]);
76 
77     libxl_vncviewer_exec(ctx, domid, autopass);
78 
79     return EXIT_FAILURE;
80 }
81 
82 /* Channel is just a console in disguise, so put it here */
main_channellist(int argc,char ** argv)83 int main_channellist(int argc, char **argv)
84 {
85     int opt;
86     libxl_device_channel *channels;
87     libxl_channelinfo channelinfo;
88     int nb, i;
89 
90     SWITCH_FOREACH_OPT(opt, "", NULL, "channel-list", 1) {
91         /* No options */
92     }
93 
94     /*      Idx BE state evt-ch ring-ref connection params*/
95     printf("%-3s %-2s %-5s %-6s %8s %-10s %-30s\n",
96            "Idx", "BE", "state", "evt-ch", "ring-ref", "connection", "");
97     for (argv += optind, argc -= optind; argc > 0; --argc, ++argv) {
98         uint32_t domid = find_domain(*argv);
99         channels = libxl_device_channel_list(ctx, domid, &nb);
100         if (!channels)
101             continue;
102         for (i = 0; i < nb; ++i) {
103             if (!libxl_device_channel_getinfo(ctx, domid, &channels[i],
104                 &channelinfo)) {
105                 printf("%-3d %-2d ", channels[i].devid, channelinfo.backend_id);
106                 printf("%-5d ", channelinfo.state);
107                 printf("%-6d %-8d ", channelinfo.evtch, channelinfo.rref);
108                 printf("%-10s ", libxl_channel_connection_to_string(
109                        channels[i].connection));
110                 switch (channels[i].connection) {
111                     case LIBXL_CHANNEL_CONNECTION_PTY:
112                         printf("%-30s ", channelinfo.u.pty.path);
113                         break;
114                     default:
115                         break;
116                 }
117                 printf("\n");
118                 libxl_channelinfo_dispose(&channelinfo);
119             }
120             libxl_device_channel_dispose(&channels[i]);
121         }
122         free(channels);
123     }
124     return 0;
125 }
126 
127 /*
128  * Local variables:
129  * mode: C
130  * c-basic-offset: 4
131  * indent-tabs-mode: nil
132  * End:
133  */
134