annotate ie-virsh.c @ 38:16840a2375ae

Adapt to CentOS7
author atton
date Fri, 06 Nov 2015 21:51:43 +0900
parents 3b8858a63694
children 6e385ccc40bf
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>
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include <stdio.h>
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include <sys/types.h>
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #include <unistd.h>
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #include <signal.h>
2
1a35a6cb23dd fix commands, include
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
9 #include <string.h>
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
2
1a35a6cb23dd fix commands, include
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1
diff changeset
11 #include <sys/types.h>
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
12 #include <regex.h>
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
13
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
14 /* 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
15
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
16 #define command "/usr/bin/virsh"
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
17 /* #define command "/usr/local/bin/virsh" */
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
18 #define list_command "/usr/bin/virsh list --all"
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
19 /* #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
20 #define start_command "start"
3
203445eb53a8 add xml generator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
21 #define stop_command "destroy"
6
25c14d1144a8 add xml generation and define
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
22 #define define_command "define"
9
ea51e779b381 error message
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
23 #define undefine_command "undefine"
4
349bbbd3fbd5 added dumpxml command
Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
parents: 3
diff changeset
24 #define dumpxml_command "dumpxml"
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
25 #define console_command "console"
32
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
26 #define debug_command "debug"
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
27
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
28
34
ccac5d8090f6 Fix guest/managers accounts
atton
parents: 32
diff changeset
29 const char *guests[] = {};
ccac5d8090f6 Fix guest/managers accounts
atton
parents: 32
diff changeset
30 const char *managers[] = {"atton"};
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
31 const char students_sym[] = "students";
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
32 const char managers_sym[] = "managers";
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
33 const char guests_sym[] = "guests";
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
34 const char delimiter[] = "_";
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
35
32
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
36 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
37
35
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
38 const char newvm_command[] = "/usr/local/bin/newvm.py -c /etc/libvirt/qemu/fedora23.xml -n ";
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
39
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
40 enum {
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
41 NAME_LENGTH = 50,
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
42 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
43 };
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
44
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
45 enum {
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
46 STUDENTS,
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
47 GUESTS,
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
48 MANAGERS
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
49 };
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
50
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
51 #define VMNAME_MAX (512)
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
52
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
53 typedef struct vmlist {
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
54 char name[VMNAME_MAX];
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
55 struct vmlist *next;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
56 } VMLIST, *VMLISTPTR;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
57
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
58 #define NEW(type) ((type*)malloc(sizeof(type)))
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
59
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 /* Define global variables */
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
62 VMLISTPTR
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
63 get_vmlist(char *list_pattern_str)
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
64 {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
65 regex_t *list_pattern = NEW(regex_t);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
66 if (regcomp(list_pattern, list_pattern_str, 0) != 0) {
3b8858a63694 Refactor
atton
parents: 36
diff changeset
67 exit(0);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
68 }
3b8858a63694 Refactor
atton
parents: 36
diff changeset
69
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
70 VMLISTPTR list = NEW(VMLIST);
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
71 VMLISTPTR p = list ;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
72 p->name[0] = 0;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
73 p->next = 0;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
74 FILE *fp = popen(list_command,"r");
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
75 while(fgets(p->name,VMNAME_MAX,fp)!=NULL) {
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
76 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
77 p->next = NEW(VMLIST);
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
78 p = p->next;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
79 }
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
80 p->name[0] = 0;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
81 pclose(fp);
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
82 regfree(list_pattern);
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
83 return list;
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
84 }
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
85
36
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
86 void
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
87 print_vmlist(VMLISTPTR list)
1
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 for(;list && list->name[0]; list=list->next) {
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
90 fprintf(stdout, " %s\n",list->name);
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
91 }
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
92 }
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
93
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
94 void
3b8858a63694 Refactor
atton
parents: 36
diff changeset
95 check_vmlist_name(VMLISTPTR list, char * name)
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
96 {
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
97 for(;list && list->name[0]; list=list->next) {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
98 if (strstr(list->name, name)!=0) return;
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
99 }
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
100
3b8858a63694 Refactor
atton
parents: 36
diff changeset
101 fprintf(stderr, bad_name);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
102 print_vmlist(list);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
103 exit(1);
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
104 }
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
27
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
106 void
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
107 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
108 {
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
109 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
110 int i = 0;
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
111 for (; i < size; i++) {
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
112 if (name[i] == '_') {
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
113 name[i] = '/';
27
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
114 }
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
115 }
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
116 }
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
117
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
118 int
6
25c14d1144a8 add xml generation and define
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
119 check_name(const char *p)
25c14d1144a8 add xml generation and define
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
120 {
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
121 if (!p) return 1;
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
122 for(;*p;p++) {
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
123 char c = *p;
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
124 if (c<=' ') return 1;
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
125 if (('a'<=c && c<='z') ||
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
126 ('0'<=c && c<='9') ||
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
127 ('/'==c ) ||
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
128 ('-'==c )) continue;
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
129 return 1;
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
130 printf("%c", c);
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
131 }
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
132 return 0;
6
25c14d1144a8 add xml generation and define
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
133 }
25c14d1144a8 add xml generation and define
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 5
diff changeset
134
36
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
135 void
3
203445eb53a8 add xml generator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
136 usage()
203445eb53a8 add xml generator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
137 {
36
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
138 printf("Usage: COMMAND [define|list|start|destroy|dumpxml|undefine|console] [vm-name]\n");
32
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
139 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
140 }
203445eb53a8 add xml generator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 2
diff changeset
141
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
142 int
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
143 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
144 {
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
145 const char *regex = "[ek]([0-9]{6})";
36
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
146
28
554085aec682 fix exec command.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
147 regex_t *pattern = NEW(regex_t);
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
148 int ret = 1;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
149
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
150 if (regcomp(pattern, regex, REG_EXTENDED|REG_NEWLINE) != 0) {
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
151 exit(0);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
152 }
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
153
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
154 ret = regexec(pattern, account_name, (size_t) 0, NULL, 0);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
155 regfree(pattern);
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
156
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
157 if (!ret){
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
158 return STUDENTS;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
159 }
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 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
162 int i = 0;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
163 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
164 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
165 return MANAGERS;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
166 }
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 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
170 int j = 0;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
171 for (; j < guests_num; j++) {
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
172 if (strncmp(account_name, guests[j], NAME_LENGTH) == 0) {
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
173 return GUESTS;
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;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
217 case GUESTS:
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
218 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
219 break;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
220 case MANAGERS:
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
221 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
222 break;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
223 default :
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
224 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
225 return;
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
226 }
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
227
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
228 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
229 }
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
230
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
231 void
3b8858a63694 Refactor
atton
parents: 36
diff changeset
232 create_new_vm(const char const *name, const char const *vm_name, char* xml_name){
3b8858a63694 Refactor
atton
parents: 36
diff changeset
233 if (check_name(name)) {
3b8858a63694 Refactor
atton
parents: 36
diff changeset
234 fprintf(stderr, bad_name);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
235 exit(0);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
236 }
3b8858a63694 Refactor
atton
parents: 36
diff changeset
237 char *vm_path = (char *)malloc(sizeof(char) * VM_NAME_LENGTH);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
238 strncpy(vm_path, vm_name, VM_NAME_LENGTH);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
239 change_delimiter_to_slash(vm_path);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
240 char exec[1024];
3b8858a63694 Refactor
atton
parents: 36
diff changeset
241 strncpy(exec, newvm_command ,900);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
242 strncat(exec, vm_path,1000);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
243 fprintf(stdout, "excuting %s\n",exec );
3b8858a63694 Refactor
atton
parents: 36
diff changeset
244 printf("%s\n", vm_path);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
245 system(exec);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
246 strncpy(xml_name, vm_path,900);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
247 strncat(xml_name,".xml",1000);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
248 free(vm_path);
3b8858a63694 Refactor
atton
parents: 36
diff changeset
249 }
3b8858a63694 Refactor
atton
parents: 36
diff changeset
250
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 /* main(int argc, char **argv) - main process loop */
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 int main(int argc, char **argv)
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 {
35
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
255 /* Set euid and egid to actual user */
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
256 int uid = getuid();
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
257 int gid = getgid();
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
258 char *name = getlogin();
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
260 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
261 setegid(getgid());
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
262 seteuid(getuid());
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263
27
b731ce75cd35 add change_delimiter function that change '_' to '/'
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
264 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
265 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
266 fprintf(stderr, "Parmission denied. :%s\n", name);
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
267 exit(1);
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
268 }
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
269
26
76bd473f3b78 change how to define and be used name
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
270
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
271 /* Confirm user is in GROUP(999) group */
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
273 /*
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
274 if ( gid != 999 ) {
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
275 printf("User Not Authorized! Exiting...\n");
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
276 exit(1);
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
277 }
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
278 */
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279
35
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
280 if (argc<2) {
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
281 usage();
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
282 exit(0);
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
283 }
f01dc83040a9 Change mount point and template xml
atton
parents: 34
diff changeset
284
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
285 /* Set uid, gid, euid and egid to root */
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
286
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
287 setegid(0);
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
288 seteuid(0);
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
289 setgid(0);
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
290 setuid(0);
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
291
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
292 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
293 vm_name[0] = '\0';
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
294 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
295
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
296 VMLISTPTR vmlist = get_vmlist(name);
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
297
36
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
298
ebeeb6c20d0a Fix SEGV when argument is empty and invalid command
atton
parents: 35
diff changeset
299 /* Check argv for proper arguments and run
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
300 * the corresponding script, if invoked.
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
301 */
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
303 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
304 print_vmlist(vmlist);
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
305 } else if (strncmp(argv[1], start_command, 5) == 0) {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
306 if (argc<3) {usage(); exit(1);}
3b8858a63694 Refactor
atton
parents: 36
diff changeset
307 check_vmlist_name(vmlist, argv[2]);
28
554085aec682 fix exec command.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
308 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
309 perror("Execl:");
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
310 }
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
311 } else if ( strncmp(argv[1], stop_command, 4) == 0 ) {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
312 if (argc<3) {usage(); exit(1);}
3b8858a63694 Refactor
atton
parents: 36
diff changeset
313 check_vmlist_name(vmlist, argv[2]);
28
554085aec682 fix exec command.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
314 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
315 perror("Execl:");
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
316 }
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
317 } else if ( strncmp(argv[1], dumpxml_command, 7) == 0 ) {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
318 if (argc<3) {usage(); exit(1);}
3b8858a63694 Refactor
atton
parents: 36
diff changeset
319 check_vmlist_name(vmlist, argv[2]);
28
554085aec682 fix exec command.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
320 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
321 perror("Execl:");
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
322 }
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
323 } else if ( strncmp(argv[1], console_command, 8) == 0 ) {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
324 if (argc<3) {usage(); exit(1);}
3b8858a63694 Refactor
atton
parents: 36
diff changeset
325 check_vmlist_name(vmlist, argv[2]);
28
554085aec682 fix exec command.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
326 if (execl(command, command, console_command, vm_name, NULL) < 0) {
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
327 perror("Execl:");
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
328 }
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
329 } else if (strncmp(argv[1], define_command, 6) == 0 ) {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
330 if (argc<3) {usage(); exit(1);}
3b8858a63694 Refactor
atton
parents: 36
diff changeset
331 char xml_name[1024];
3b8858a63694 Refactor
atton
parents: 36
diff changeset
332 xml_name[0] = 0;
3b8858a63694 Refactor
atton
parents: 36
diff changeset
333 create_new_vm(argv[2], vm_name, xml_name);
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
334 /* chdir("/usr/local/etc/libvirt/qemu"); */
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
335 chdir("/etc/libvirt/qemu");
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
336 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
337 perror("Execl:");
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
338 }
22
daa7279b0d78 fix indent
taiki
parents: 21
diff changeset
339 } 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
340 /* chdir("/usr/local/etc/libvirt/qemu"); */
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
341 chdir("/etc/libvirt/qemu");
28
554085aec682 fix exec command.
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
342 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
343 perror("Execl:");
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
344 }
32
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
345 } else if (strncmp(argv[1], debug_command, 5) == 0) {
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
346 char *user_name = (char *)malloc(sizeof(char) * VM_NAME_LENGTH);
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
347 strncpy(user_name, "\0", 1);
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
348 make_vm_name(user_name, account_type, name, debug_command);
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
349
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
350 char str_uid[1024];
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
351 sprintf(str_uid, "%d", uid);
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
352
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
353 char debug_exec[1026];
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
354 sprintf(debug_exec, "/usr/local/bin/debugvm.py --name %s --uid %s --config %s", user_name, str_uid, "/etc/libvirt/qemu/debugvm.xml");
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
355 free(user_name);
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
356
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
357 printf("debug_exec::%s \n", debug_exec);
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
358
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
359 char gdb_exec[1024];
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
360 strncpy(gdb_exec, "/usr/bin/gdb",900);
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
361 // strncat(gdb_exec, " /usr/lib/debug/lib/modules/3.17.4-200.fc20.x86_64/vmlinux", 900);
4bd7d676e608 add debugvm.py to method for manage port.
taiki
parents: 30
diff changeset
362 // system(gdb_exec);
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
363 } else {
37
3b8858a63694 Refactor
atton
parents: 36
diff changeset
364 printf("%s is invalid command.\n", argv[1]);
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
365 usage();
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
366 exit(1);
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
367 }
29
cfa197bad124 fix bug
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
368 free(vm_name);
21
13646e64d98b fix indent
taiki <taiki@cr.ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
369 exit(0);
0
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 }
7785dd06c62f Virsh Wrapper initial version
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
371
1
1a8257a34493 no compile errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
372 /* end */