-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdialdevdraw.c
More file actions
98 lines (75 loc) · 1.56 KB
/
dialdevdraw.c
File metadata and controls
98 lines (75 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <u.h>
#include <libc.h>
#include <thread.h>
void
usage()
{
fprint(2, "usage: %s command\n", argv0);
threadexitsall("usage");
}
void
threadmain(int argc, char **argv)
{
int p[2], fd[3], pid[2];
char *a[4], *devdraw;
ARGBEGIN{}ARGEND
if(argc != 1)
usage();
// Make sure we don't kill our parent whilst killing
// our children.
setsid();
if(pipe(p) < 0)
sysfatal("pipe: %r");
fd[0] = dup(p[0], -1);
fd[1] = dup(p[0], -1);
fd[2] = dup(2, -1);
a[0] = "rc";
a[1] = "-c";
a[2] = argv[0];
a[3] = nil;
if((pid[0] = threadspawn(fd, a[0], a)) < 0)
sysfatal("threadspawn: %r");
fd[0] = dup(p[1], -1);
fd[1] = dup(p[1], -1);
fd[2] = dup(2, -1);
putenv("NOLIBTHREADDAEMONIZE", "1");
devdraw = getenv("DEVDRAW");
if(devdraw == nil)
devdraw = "devdraw";
if((pid[1] = threadspawnl(fd, devdraw, devdraw, "(devdraw)", nil)) < 0)
sysfatal("threadspawnl: %r");
close(p[0]);
close(p[1]);
recvp(threadwaitchan());
postnote(PNGROUP, pid[0], "hangup");
postnote(PNGROUP, pid[1], "hangup");
//recvp(threadwaitchan());
threadexitsall("");
/*
if ((pid = fork()) < 0)
sysfatal("fork: %r");
switch(pid){
case 0:
close(p[0]);
dup(p[1], 0);
dup(p[1], 1);
a[0] = "rc";
a[1] = "-c";
a[2] = argv[0];
a[3] = nil;
if(exec("rc", a) < 0)
sysfatal("execl: %r");
default:
close(p[1]);
dup(p[0], 0);
dup(p[0], 1);
putenv("NOLIBTHREADDAEMONIZE", "1");
devdraw = getenv("DEVDRAW");
if(devdraw == nil)
devdraw = "devdraw";
if(execl(devdraw, devdraw, "(devdraw)", nil) < 0)
sysfatal("execl: %r");
}
exits(0);
*/
}