|
|
1 | #include "../config.h" |
1 | #include "rxvtdaemon.h" |
2 | #include "rxvtdaemon.h" |
|
|
3 | |
|
|
4 | #include "rxvt.h" |
2 | |
5 | |
3 | #include <cstdio> |
6 | #include <cstdio> |
4 | #include <cstdlib> |
7 | #include <cstdlib> |
5 | |
8 | |
6 | #include <unistd.h> |
9 | #include <unistd.h> |
… | |
… | |
34 | } |
37 | } |
35 | |
38 | |
36 | extern char **environ; |
39 | extern char **environ; |
37 | |
40 | |
38 | int |
41 | int |
39 | main(int argc, const char *const *argv) |
42 | main (int argc, const char *const *argv) |
40 | { |
43 | { |
41 | client c; |
44 | client c; |
42 | char buf[PATH_MAX]; |
45 | char buf[PATH_MAX]; |
43 | |
46 | |
44 | { |
47 | { |
… | |
… | |
48 | sigaddset (&ss, SIGHUP); |
51 | sigaddset (&ss, SIGHUP); |
49 | sigprocmask (SIG_BLOCK, &ss, 0); |
52 | sigprocmask (SIG_BLOCK, &ss, 0); |
50 | } |
53 | } |
51 | |
54 | |
52 | c.send ("NEW"); |
55 | c.send ("NEW"); |
53 | // instead of getcwd we could opendir(".") and pass the fd for fchdir *g* |
56 | // instead of getcwd we could opendir (".") and pass the fd for fchdir *g* |
54 | c.send ("CWD"), c.send (getcwd (buf, sizeof (buf))); |
57 | c.send ("CWD"), c.send (getcwd (buf, sizeof (buf))); |
55 | |
58 | |
56 | for (char **var = environ; *environ; environ++) |
59 | for (char **var = environ; *environ; environ++) |
57 | c.send ("ENV"), c.send (*environ); |
60 | c.send ("ENV"), c.send (*environ); |
58 | |
61 | |
59 | for (int i = 0; i < argc; i++) |
62 | for (int i = 0; i < argc; i++) |
60 | c.send ("ARG"), c.send (argv[i]); |
63 | c.send ("ARG"), c.send (argv[i]); |
61 | |
64 | |
62 | c.send ("END"); |
65 | c.send ("END"); |
|
|
66 | |
|
|
67 | auto_str tok; |
|
|
68 | |
|
|
69 | for (;;) |
|
|
70 | if (!c.recv (tok)) |
|
|
71 | { |
|
|
72 | fprintf (stderr, "protocol error: unexpected eof from server.\n"); |
|
|
73 | break; |
|
|
74 | } |
|
|
75 | else if (!strcmp (tok, "MSG") && c.recv (tok)) |
|
|
76 | fprintf (stderr, "%s", (const char *)tok); |
|
|
77 | else if (!strcmp (tok, "END")) |
|
|
78 | { |
|
|
79 | int success; |
|
|
80 | if (c.recv (success)) |
|
|
81 | exit (success ? EXIT_SUCCESS : EXIT_FAILURE); |
|
|
82 | } |
|
|
83 | else |
|
|
84 | { |
|
|
85 | fprintf (stderr, "protocol error: received illegal token '%s'.\n", (const char *)tok); |
|
|
86 | break; |
|
|
87 | } |
|
|
88 | |
|
|
89 | return EXIT_FAILURE; |
63 | } |
90 | } |
64 | |
91 | |