BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | process main { |
2 | call("dbus_start", {{"--session", "--nopidfile"}}) dbus_start; |
||
3 | |||
4 | println("Got dbus: ", dbus_start.dbus_address); |
||
5 | rprintln("Lost dbus"); |
||
6 | } |
||
7 | |||
8 | template dbus_start { |
||
9 | alias("_arg0") dbus_args; |
||
10 | |||
11 | var("false") retrying; |
||
12 | |||
13 | backtrack_point() retry_point; |
||
14 | If (retrying) { |
||
15 | println("dbus_start: retrying in one second"); |
||
16 | sleep("1000", "0"); |
||
17 | }; |
||
18 | |||
19 | retrying->set("true"); |
||
20 | |||
21 | listfrom({"/usr/bin/dbus-daemon"}, dbus_args, {"--print-address"}) dbus_command; |
||
22 | |||
23 | sys.start_process(dbus_command, "r") proc; |
||
24 | If (proc.is_error) { |
||
25 | println("dbus_start: error starting process"); |
||
26 | retry_point->go(); |
||
27 | }; |
||
28 | |||
29 | var("") dbus_address; |
||
30 | blocker() finished_blocker; |
||
31 | |||
32 | process_manager() mgr; |
||
33 | mgr->start("dbus_start__waiter", {}); |
||
34 | mgr->start("dbus_start__reader", {}); |
||
35 | |||
36 | finished_blocker->use(); |
||
37 | } |
||
38 | |||
39 | template dbus_start__waiter { |
||
40 | alias("_caller.proc") proc; |
||
41 | alias("_caller.retry_point") retry_point; |
||
42 | |||
43 | proc->wait(); |
||
44 | println("dbus_start: process terminated"); |
||
45 | retry_point->go(); |
||
46 | } |
||
47 | |||
48 | template dbus_start__reader { |
||
49 | alias("_caller.proc") proc; |
||
50 | alias("_caller.retry_point") retry_point; |
||
51 | alias("_caller.dbus_address") dbus_address; |
||
52 | alias("_caller.finished_blocker") finished_blocker; |
||
53 | |||
54 | proc->read_pipe() rpipe; |
||
55 | If (rpipe.is_error) { |
||
56 | println("dbus_start: read pipe error"); |
||
57 | retry_point->go(); |
||
58 | }; |
||
59 | |||
60 | value("") buffer; |
||
61 | |||
62 | backtrack_point() read_point; |
||
63 | rpipe->read() data; |
||
64 | |||
65 | If (data.not_eof) { |
||
66 | buffer->append(data); |
||
67 | |||
68 | explode("\n", buffer, "2") exp; |
||
69 | value(exp) exp; |
||
70 | |||
71 | num_greater(exp.length, "1") found; |
||
72 | If (found) { |
||
73 | exp->get("0") address; |
||
74 | dbus_address->set(address); |
||
75 | finished_blocker->up(); |
||
76 | }; |
||
77 | |||
78 | read_point->go(); |
||
79 | }; |
||
80 | |||
81 | println("dbus_start: read pipe eof"); |
||
82 | } |