2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 * number of running guests
27 static int running
= 0;
30 * Guest invocation callback
32 static pid_t
invoke(void *vte
, guest_t
*guest
,
33 char *args
[], int argc
)
37 args
[argc
] = "con0=xterm";
43 dup2(open("/dev/null", 0), 1);
44 dup2(open("/dev/null", 0), 2);
45 execvp(args
[0], args
);
48 fprintf(stderr
, "starting guest '%s' failed\n", guest
->get_name(guest
));
51 printf("started guest '%s', pid: %d\n", guest
->get_name(guest
), pid
);
58 * main routine, parses args and reads from console
60 int main(int argc
, char *argv
[])
63 enumerator_t
*enumerator
;
65 bridge_t
*switch0
, *switch1
, *switch2
;
72 dumm
= dumm_create(NULL
);
74 switch0
= dumm
->create_bridge(dumm
, "switch0");
75 switch1
= dumm
->create_bridge(dumm
, "switch1");
76 switch2
= dumm
->create_bridge(dumm
, "switch2");
78 if (switch0
&& switch1
&& switch2
)
80 enumerator
= dumm
->create_guest_enumerator(dumm
);
81 while (enumerator
->enumerate(enumerator
, &guest
))
83 if (!guest
->start(guest
, invoke
, NULL
, NULL
))
87 if (streq(guest
->get_name(guest
), "alice"))
89 iface
= guest
->create_iface(guest
, "eth0");
92 switch1
->connect_iface(switch1
, iface
);
94 iface
= guest
->create_iface(guest
, "eth1");
97 switch0
->connect_iface(switch0
, iface
);
100 else if (streq(guest
->get_name(guest
), "moon") ||
101 streq(guest
->get_name(guest
), "sun"))
103 iface
= guest
->create_iface(guest
, "eth0");
106 switch0
->connect_iface(switch0
, iface
);
108 iface
= guest
->create_iface(guest
, "eth1");
111 switch1
->connect_iface(switch1
, iface
);
114 else if (streq(guest
->get_name(guest
), "bob"))
116 iface
= guest
->create_iface(guest
, "eth0");
119 switch2
->connect_iface(switch2
, iface
);
122 else if (streq(guest
->get_name(guest
), "venus"))
124 iface
= guest
->create_iface(guest
, "eth0");
127 switch1
->connect_iface(switch1
, iface
);
130 else if (streq(guest
->get_name(guest
), "carol") ||
131 streq(guest
->get_name(guest
), "winnetou") ||
132 streq(guest
->get_name(guest
), "dave"))
134 iface
= guest
->create_iface(guest
, "eth0");
137 switch0
->connect_iface(switch0
, iface
);
141 enumerator
->destroy(enumerator
);
144 sigaddset(&set
, SIGINT
);
145 sigaddset(&set
, SIGHUP
);
146 sigaddset(&set
, SIGTERM
);
147 sigaddset(&set
, SIGCHLD
);
148 sigprocmask(SIG_SETMASK
, &set
, NULL
);
151 if (sigwaitinfo(&set
, &info
) == SIGCHLD
)
153 enumerator
= dumm
->create_guest_enumerator(dumm
);
154 while (enumerator
->enumerate(enumerator
, &guest
))
156 if (guest
->get_pid(guest
) == info
.si_pid
)
159 guest
->sigchild(guest
);
163 enumerator
->destroy(enumerator
);