annotate ie-virsh.c @ 50:7a02dee972c4

easy fix randomUUID
author kono
date Tue, 30 Jan 2018 22:13:22 +0900
parents b8887c40f8b8
children e45676e6b6cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdlib.h>
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <unistd.h>
43
3eb0b5edad30 Support kernel debug without random port
atton
parents: 42
diff changeset
4 #include <stdbool.h>
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include <stdio.h>
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #include <sys/types.h>
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #include <unistd.h>
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 #include <signal.h>
2
1a35a6cb23dd fix commands, include
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
10 #include <string.h>
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
11 #include <regex.h>
39
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
12 #include <pwd.h>
46
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
13 #include <sys/socket.h>
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
14 #include <netinet/in.h>
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
15 #include <arpa/inet.h>
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
16 #include <time.h>
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
17
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
18 /* Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License */
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
20 #define command "/usr/bin/virsh"
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
21 /* #define command "/usr/local/bin/virsh" */
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
22 #define list_command "/usr/bin/virsh list --all"
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
23 /* #define list_command "/usr/local/bin/virsh list --all" */
2
1a35a6cb23dd fix commands, include
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
24 #define start_command "start"
3
203445eb53a8 add xml generator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
25 #define stop_command "destroy"
6
25c14d1144a8 add xml generation and define
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
26 #define define_command "define"
9
ea51e779b381 error message
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
27 #define undefine_command "undefine"
4
349bbbd3fbd5 added dumpxml command
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
28 #define dumpxml_command "dumpxml"
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
29 #define console_command "console"
32
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
30 #define debug_command "debug"
43
3eb0b5edad30 Support kernel debug without random port
atton
parents: 42
diff changeset
31 #define define_gdb_command "define-gdb"
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
32
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
33
50
7a02dee972c4 easy fix randomUUID
kono
parents: 49
diff changeset
34 const char *guests[] = {"145165B"};
34
ccac5d8090f6 Fix guest/managers accounts
atton
parents: 32
diff changeset
35 const char *managers[] = {"atton"};
40
984f31ae74d5 Fix student identifier
atton
parents: 39
diff changeset
36 const char *students_identifier = "student";
39
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
37 const char *teachers_identifier = "teacher";
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
38 const char *students_sym = "students";
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
39 const char *teachers_sym = "teachers";
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
40 const char *managers_sym = "managers";
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
41 const char *guests_sym = "guests";
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
42 const char *delimiter = "_";
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
43
32
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
44 static char bad_name[] = "Bad vmname. Try 01 or 02 ... 04\n";
9
ea51e779b381 error message
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
45
41
517f130f301a Fix template name
atton
parents: 40
diff changeset
46 const char newvm_command[] = "/usr/local/bin/newvm.py -c /etc/libvirt/qemu/ie-virsh-template.xml -n ";
35
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
47
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
48 enum {
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
49 NAME_LENGTH = 50,
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
50 VM_NAME_LENGTH = 50
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
51 };
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
52
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
53 enum {
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
54 STUDENTS,
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
55 GUESTS,
39
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
56 MANAGERS,
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
57 TEACHERS
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
58 };
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
59
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
60 #define VMNAME_MAX (512)
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
61
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
62 typedef struct vmlist {
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
63 char name[VMNAME_MAX];
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
64 struct vmlist *next;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
65 } VMLIST, *VMLISTPTR;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
66
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
67 #define NEW(type) ((type*)malloc(sizeof(type)))
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
68
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 /* Define global variables */
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
71 VMLISTPTR
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
72 get_vmlist(char *list_pattern_str)
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
73 {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
74 regex_t *list_pattern = NEW(regex_t);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
75 if (regcomp(list_pattern, list_pattern_str, 0) != 0) {
3b8858a63694 Refactor
atton
parents: 36
diff changeset
76 exit(0);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
77 }
3b8858a63694 Refactor
atton
parents: 36
diff changeset
78
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
79 VMLISTPTR list = NEW(VMLIST);
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
80 VMLISTPTR p = list ;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
81 p->name[0] = 0;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
82 p->next = 0;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
83 FILE *fp = popen(list_command,"r");
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
84 while(fgets(p->name,VMNAME_MAX,fp)!=NULL) {
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
85 if (regexec(list_pattern, p->name, (size_t) 0, NULL, 0)) continue;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
86 p->next = NEW(VMLIST);
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
87 p = p->next;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
88 }
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
89 p->name[0] = 0;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
90 pclose(fp);
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
91 regfree(list_pattern);
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
92 return list;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
93 }
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
94
36
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
95 void
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
96 print_vmlist(VMLISTPTR list)
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
97 {
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
98 for(;list && list->name[0]; list=list->next) {
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
99 fprintf(stdout, " %s\n",list->name);
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
100 }
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
101 }
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
102
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
103 void
3b8858a63694 Refactor
atton
parents: 36
diff changeset
104 check_vmlist_name(VMLISTPTR list, char * name)
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
105 {
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
106 for(;list && list->name[0]; list=list->next) {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
107 if (strstr(list->name, name)!=0) return;
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
108 }
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
109
3b8858a63694 Refactor
atton
parents: 36
diff changeset
110 fprintf(stderr, bad_name);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
111 print_vmlist(list);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
112 exit(1);
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
113 }
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114
27
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
115 void
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
116 change_delimiter_to_slash(char *name)
27
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
117 {
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
118 long size = sizeof(char) * VM_NAME_LENGTH;
27
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
119 int i = 0;
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
120 for (; i < size; i++) {
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
121 if (name[i] == '_') {
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
122 name[i] = '/';
27
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
123 }
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
124 }
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
125 }
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
126
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
127 int
6
25c14d1144a8 add xml generation and define
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
128 check_name(const char *p)
25c14d1144a8 add xml generation and define
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
129 {
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
130 if (!p) return 1;
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
131 for(;*p;p++) {
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
132 char c = *p;
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
133 if (c<=' ') return 1;
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
134 if (('a'<=c && c<='z') ||
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
135 ('0'<=c && c<='9') ||
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
136 ('/'==c ) ||
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
137 ('-'==c )) continue;
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
138 return 1;
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
139 printf("%c", c);
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
140 }
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
141 return 0;
6
25c14d1144a8 add xml generation and define
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
142 }
25c14d1144a8 add xml generation and define
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
143
36
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
144 void
3
203445eb53a8 add xml generator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
145 usage()
203445eb53a8 add xml generator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
146 {
49
b8887c40f8b8 vncdisplay
mir3636
parents: 46
diff changeset
147 printf("Usage: COMMAND [define|define-gdb|list|start|destroy|dumpxml|vncdisplay|undefine|console] [vm-name]\n");
32
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
148 printf(" vm-name should be 01 - 04\n");
3
203445eb53a8 add xml generator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
149 }
203445eb53a8 add xml generator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
150
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
151 int
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
152 check_user_name(const char *account_name)
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
153 {
39
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
154 const char *home = getpwuid(getuid())->pw_dir;
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
155
39
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
156 if (strstr(home, students_identifier) != NULL) {
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
157 return STUDENTS;
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
158 } else if (strstr(home, teachers_identifier) != NULL) {
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
159 return TEACHERS;
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
160 }
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
161
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
162 const int managers_num = sizeof(managers) / sizeof(managers[0]);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
163 int i = 0;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
164 for (; i < managers_num; i++) {
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
165 if (strncmp(account_name, managers[i], NAME_LENGTH) == 0) {
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
166 return MANAGERS;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
167 }
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
168 }
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
169
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
170 const int guests_num = sizeof(guests) / sizeof(guests[0]);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
171 int j = 0;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
172 for (; j < guests_num; j++) {
50
7a02dee972c4 easy fix randomUUID
kono
parents: 49
diff changeset
173 if (strncmp(account_name, guests[j], NAME_LENGTH) == 0) { return GUESTS;
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
174 }
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
175 }
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
176
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
177 return -1;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
178 }
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
179
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
180 void
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
181 bind_name(char *name, const char *first, const char *second)
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
182 {
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
183 strncat(name, first, VM_NAME_LENGTH);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
184 strncat(name, delimiter, VM_NAME_LENGTH);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
185 strncat(name, second, VM_NAME_LENGTH);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
186 strncat(name, delimiter, VM_NAME_LENGTH);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
187 return;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
188 }
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
189
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
190 void
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
191 make_vm_name(char *vm_name, const int account_type, const char *account_name, const char *vm_num)
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
192 {
36
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
193 const char *regex = "0[1-4]";
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
194 regex_t *num_pattern = NEW(regex_t);
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
195
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
196 if (regcomp(num_pattern, regex, REG_EXTENDED|REG_NEWLINE) != 0) {
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
197 exit(0);
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
198 }
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
199
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
200 int ret = regexec(num_pattern, vm_num, (size_t) 0, NULL, 0);
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
201 regfree(num_pattern);
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
202
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
203 if (ret){
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
204 fprintf(stderr, "This name is invalid number: %s\n", vm_num);
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
205 exit(0);
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
206 }
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
207
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
208 switch(account_type) {
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
209 case STUDENTS:
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
210 strncat(vm_name, students_sym, VM_NAME_LENGTH);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
211 strncat(vm_name, delimiter, VM_NAME_LENGTH);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
212 strncat(vm_name, account_name, 3);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
213 strncat(vm_name, delimiter, VM_NAME_LENGTH);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
214 strncat(vm_name, account_name, VM_NAME_LENGTH);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
215 strncat(vm_name, delimiter, VM_NAME_LENGTH);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
216 break;
39
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
217 case TEACHERS:
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
218 strncat(vm_name, teachers_sym, VM_NAME_LENGTH);
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
219 strncat(vm_name, delimiter, VM_NAME_LENGTH);
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
220 strncat(vm_name, account_name, VM_NAME_LENGTH);
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
221 strncat(vm_name, delimiter, VM_NAME_LENGTH);
6e385ccc40bf Support teacher account
atton
parents: 37
diff changeset
222 break;
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
223 case GUESTS:
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
224 bind_name(vm_name, guests_sym, account_name);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
225 break;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
226 case MANAGERS:
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
227 bind_name(vm_name, managers_sym, account_name);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
228 break;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
229 default :
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
230 fprintf(stderr, "Error: no registered type name.");
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
231 return;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
232 }
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
233
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
234 strncat(vm_name, vm_num, VM_NAME_LENGTH);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
235 }
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
236
46
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
237 int
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
238 get_kernel_debug_port(void){
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
239 struct sockaddr_in addr;
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
240 memset(&addr, 0, sizeof(addr));
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
241 addr.sin_family = AF_INET;
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
242 addr.sin_addr.s_addr = htonl(INADDR_ANY);
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
243 int socket_fd = socket(AF_INET, SOCK_STREAM, 0);
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
244
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
245 int i;
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
246 srand(time(NULL));
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
247 for (i = 0; i < 10; i++) {
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
248 addr.sin_port = htons((rand() % 20000) + 10000);
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
249
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
250 if ((bind(socket_fd, (struct sockaddr *)&addr, sizeof(struct sockaddr) ) == 0) && (listen(socket_fd, 1) == 0)) {
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
251 printf("Port %d was allocated for your kernel debug.\n", ntohs(addr.sin_port));
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
252 close(socket_fd);
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
253 return ntohs(addr.sin_port);
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
254 } else {
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
255 printf("Port %d was used. Trying another port...\n", ntohs(addr.sin_port));
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
256 }
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
257 }
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
258 printf("Cannot allocate debug port.\n");
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
259 exit(EXIT_FAILURE);
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
260 }
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
261
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
262 void
44
546504699402 Generate xml which enabled kernel debug. but needs reload in virsh
atton
parents: 43
diff changeset
263 create_new_vm(const char const *name, const char const *vm_name, char* xml_name, bool debug_kernel){
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
264 if (check_name(name)) {
3b8858a63694 Refactor
atton
parents: 36
diff changeset
265 fprintf(stderr, bad_name);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
266 exit(0);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
267 }
3b8858a63694 Refactor
atton
parents: 36
diff changeset
268 char *vm_path = (char *)malloc(sizeof(char) * VM_NAME_LENGTH);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
269 strncpy(vm_path, vm_name, VM_NAME_LENGTH);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
270 change_delimiter_to_slash(vm_path);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
271 char exec[1024];
43
3eb0b5edad30 Support kernel debug without random port
atton
parents: 42
diff changeset
272 if (debug_kernel) {
46
6b1dddd65d7c Generate kernel debug port randomly between 10000 to 30000
atton
parents: 44
diff changeset
273 snprintf(exec, 1024, "%s %s -d %d", newvm_command, vm_path, get_kernel_debug_port());
42
09fe50fc0629 try to fix debug mode
innparusu
parents: 41
diff changeset
274 } else {
43
3eb0b5edad30 Support kernel debug without random port
atton
parents: 42
diff changeset
275 snprintf(exec, 1024, "%s %s", newvm_command, vm_path);
42
09fe50fc0629 try to fix debug mode
innparusu
parents: 41
diff changeset
276 }
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
277 fprintf(stdout, "excuting %s\n",exec );
3b8858a63694 Refactor
atton
parents: 36
diff changeset
278 system(exec);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
279 strncpy(xml_name, vm_path,900);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
280 strncat(xml_name,".xml",1000);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
281 free(vm_path);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
282 }
3b8858a63694 Refactor
atton
parents: 36
diff changeset
283
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 /* main(int argc, char **argv) - main process loop */
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 int main(int argc, char **argv)
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 {
35
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
288 /* Set euid and egid to actual user */
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
289 int uid = getuid();
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
290 int gid = getgid();
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
291 char *name = getlogin();
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
293 printf("uid %d gid %d name %s\n", uid,gid,name);
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
294 setegid(getgid());
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
295 seteuid(getuid());
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296
27
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
297 int account_type = check_user_name(name);
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
298 if (account_type < 0) {
30
2888c7ec9013 can't define vm name is not number.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 29
diff changeset
299 fprintf(stderr, "Parmission denied. :%s\n", name);
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
300 exit(1);
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
301 }
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
302
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
303
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
304 /* Confirm user is in GROUP(999) group */
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
306 /*
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
307 if ( gid != 999 ) {
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
308 printf("User Not Authorized! Exiting...\n");
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
309 exit(1);
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
310 }
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
311 */
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312
35
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
313 if (argc<2) {
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
314 usage();
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
315 exit(0);
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
316 }
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
317
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
318 /* Set uid, gid, euid and egid to root */
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
319
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
320 setegid(0);
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
321 seteuid(0);
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
322 setgid(0);
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
323 setuid(0);
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
324
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
325 char *vm_name = (char *)malloc(sizeof(char) * VM_NAME_LENGTH);
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
326 vm_name[0] = '\0';
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
327 if ((argc > 2) && (strncmp(argv[1], list_command, 4) != 0)) { make_vm_name(vm_name, account_type, name, argv[2]); }
6
25c14d1144a8 add xml generation and define
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
328
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
329 VMLISTPTR vmlist = get_vmlist(name);
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
330
36
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
331
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
332 /* Check argv for proper arguments and run
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
333 * the corresponding script, if invoked.
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
334 */
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
336 if (argv[1]==0 || strncmp(argv[1], "list", 4) == 0 ) {
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
337 print_vmlist(vmlist);
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
338 } else if (strncmp(argv[1], start_command, 5) == 0) {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
339 if (argc<3) {usage(); exit(1);}
3b8858a63694 Refactor
atton
parents: 36
diff changeset
340 check_vmlist_name(vmlist, argv[2]);
28
554085aec682 fix exec command.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
341 if (execl(command, command, start_command, vm_name, NULL) < 0) {
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
342 perror("Execl:");
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
343 }
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
344 } else if ( strncmp(argv[1], stop_command, 4) == 0 ) {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
345 if (argc<3) {usage(); exit(1);}
3b8858a63694 Refactor
atton
parents: 36
diff changeset
346 check_vmlist_name(vmlist, argv[2]);
28
554085aec682 fix exec command.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
347 if (execl(command, command, stop_command, vm_name, NULL) < 0) {
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
348 perror("Execl:");
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
349 }
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
350 } else if ( strncmp(argv[1], dumpxml_command, 7) == 0 ) {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
351 if (argc<3) {usage(); exit(1);}
3b8858a63694 Refactor
atton
parents: 36
diff changeset
352 check_vmlist_name(vmlist, argv[2]);
28
554085aec682 fix exec command.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
353 if (execl(command, command, dumpxml_command, vm_name, NULL) < 0) {
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
354 perror("Execl:");
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
355 }
49
b8887c40f8b8 vncdisplay
mir3636
parents: 46
diff changeset
356 } else if ( strncmp(argv[1], "vncdisplay", 10) == 0 ) {
b8887c40f8b8 vncdisplay
mir3636
parents: 46
diff changeset
357 if (argc<3) {usage(); exit(1);}
b8887c40f8b8 vncdisplay
mir3636
parents: 46
diff changeset
358 check_vmlist_name(vmlist, argv[2]);
b8887c40f8b8 vncdisplay
mir3636
parents: 46
diff changeset
359 if (execl(command, command, "vncdisplay", vm_name, NULL) < 0) {
b8887c40f8b8 vncdisplay
mir3636
parents: 46
diff changeset
360 perror("Execl:");
b8887c40f8b8 vncdisplay
mir3636
parents: 46
diff changeset
361 }
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
362 } else if ( strncmp(argv[1], console_command, 8) == 0 ) {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
363 if (argc<3) {usage(); exit(1);}
3b8858a63694 Refactor
atton
parents: 36
diff changeset
364 check_vmlist_name(vmlist, argv[2]);
28
554085aec682 fix exec command.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
365 if (execl(command, command, console_command, vm_name, NULL) < 0) {
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
366 perror("Execl:");
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
367 }
44
546504699402 Generate xml which enabled kernel debug. but needs reload in virsh
atton
parents: 43
diff changeset
368 } else if (strcmp(argv[1], define_command) == 0 ) {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
369 if (argc<3) {usage(); exit(1);}
3b8858a63694 Refactor
atton
parents: 36
diff changeset
370 char xml_name[1024];
3b8858a63694 Refactor
atton
parents: 36
diff changeset
371 xml_name[0] = 0;
43
3eb0b5edad30 Support kernel debug without random port
atton
parents: 42
diff changeset
372 create_new_vm(argv[2], vm_name, xml_name, false);
42
09fe50fc0629 try to fix debug mode
innparusu
parents: 41
diff changeset
373 /* chdir("/usr/local/etc/libvirt/qemu"); */
09fe50fc0629 try to fix debug mode
innparusu
parents: 41
diff changeset
374 chdir("/etc/libvirt/qemu");
09fe50fc0629 try to fix debug mode
innparusu
parents: 41
diff changeset
375 if (execl(command, command, define_command, xml_name, NULL) < 0) {
09fe50fc0629 try to fix debug mode
innparusu
parents: 41
diff changeset
376 perror("Execl:");
09fe50fc0629 try to fix debug mode
innparusu
parents: 41
diff changeset
377 }
43
3eb0b5edad30 Support kernel debug without random port
atton
parents: 42
diff changeset
378 } else if (strcmp(argv[1], define_gdb_command) == 0 ) {
42
09fe50fc0629 try to fix debug mode
innparusu
parents: 41
diff changeset
379 if (argc<3) {usage(); exit(1);}
09fe50fc0629 try to fix debug mode
innparusu
parents: 41
diff changeset
380 char xml_name[1024];
09fe50fc0629 try to fix debug mode
innparusu
parents: 41
diff changeset
381 xml_name[0] = 0;
43
3eb0b5edad30 Support kernel debug without random port
atton
parents: 42
diff changeset
382 create_new_vm(argv[2], vm_name, xml_name, true);
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
383 /* chdir("/usr/local/etc/libvirt/qemu"); */
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
384 chdir("/etc/libvirt/qemu");
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
385 if (execl(command, command, define_command, xml_name, NULL) < 0) {
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
386 perror("Execl:");
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
387 }
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
388 } else if ( strncmp(argv[1], undefine_command, 8) == 0 ) {
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
389 /* chdir("/usr/local/etc/libvirt/qemu"); */
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
390 chdir("/etc/libvirt/qemu");
28
554085aec682 fix exec command.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
391 if (execl(command, command, undefine_command, vm_name, NULL) < 0) {
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
392 perror("Execl:");
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
393 }
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
394 } else {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
395 printf("%s is invalid command.\n", argv[1]);
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
396 usage();
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
397 exit(1);
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
398 }
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
399 free(vm_name);
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
400 exit(0);
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 }
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
402
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
403 /* end */