… | |
… | |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | *----------------------------------------------------------------------*/ |
21 | *----------------------------------------------------------------------*/ |
22 | |
22 | |
23 | #include "../config.h" |
23 | #include "../config.h" |
24 | #include "rxvtdaemon.h" |
24 | #include "rxvtdaemon.h" |
|
|
25 | #include "fdpass.h" |
25 | |
26 | |
26 | #include "rxvt.h" |
27 | #include "rxvt.h" |
27 | |
28 | |
28 | #include <cstdio> |
29 | #include <cstdio> |
29 | #include <cstdlib> |
30 | #include <cstdlib> |
30 | #include <cstring> |
31 | #include <cstring> |
|
|
32 | #include <csignal> |
31 | |
33 | |
32 | #include <unistd.h> |
34 | #include <unistd.h> |
33 | #include <signal.h> |
|
|
34 | #include <sys/socket.h> |
35 | #include <sys/socket.h> |
35 | #include <sys/un.h> |
36 | #include <sys/un.h> |
36 | |
37 | |
37 | struct client : rxvt_connection { |
38 | struct client : rxvt_connection { |
38 | client (); |
39 | client (); |
… | |
… | |
63 | |
64 | |
64 | int |
65 | int |
65 | main (int argc, const char *const *argv) |
66 | main (int argc, const char *const *argv) |
66 | { |
67 | { |
67 | client c; |
68 | client c; |
68 | char buf[PATH_MAX]; |
|
|
69 | |
|
|
70 | { |
69 | { |
71 | sigset_t ss; |
70 | sigset_t ss; |
72 | |
71 | |
73 | sigemptyset (&ss); |
72 | sigemptyset (&ss); |
74 | sigaddset (&ss, SIGHUP); |
73 | sigaddset (&ss, SIGHUP); |
75 | sigprocmask (SIG_BLOCK, &ss, 0); |
74 | sigprocmask (SIG_BLOCK, &ss, 0); |
76 | } |
75 | } |
77 | |
76 | |
78 | c.send ("NEW"); |
77 | c.send ("NEW"); |
|
|
78 | |
79 | // instead of getcwd we could opendir (".") and pass the fd for fchdir *g* |
79 | // instead of getcwd we could opendir (".") and pass the fd for fchdir *g* |
80 | c.send ("CWD"), c.send (getcwd (buf, sizeof (buf))); |
80 | char cwd[PATH_MAX]; |
81 | |
81 | |
|
|
82 | if (!getcwd (cwd, sizeof (cwd))) |
|
|
83 | { |
|
|
84 | perror ("unable to determine current working directory"); |
|
|
85 | exit (EXIT_FAILURE); |
|
|
86 | } |
|
|
87 | |
|
|
88 | c.send ("CWD"), c.send (cwd); |
|
|
89 | |
82 | for (char **var = environ; *environ; environ++) |
90 | for (char **var = environ; *var; var++) |
83 | c.send ("ENV"), c.send (*environ); |
91 | c.send ("ENV"), c.send (*var); |
84 | |
92 | |
85 | const char *base = strrchr (argv[0], '/'); |
93 | const char *base = strrchr (argv[0], '/'); |
86 | base = base ? base + 1 : argv[0]; |
94 | base = base ? base + 1 : argv[0]; |
87 | c.send ("ARG"), c.send (strcmp (base, RXVTNAME "c") ? base : RXVTNAME); |
95 | c.send ("ARG"), c.send (strcmp (base, RXVTNAME "c") ? base : RXVTNAME); |
88 | |
96 | |
… | |
… | |
90 | c.send ("ARG"), c.send (argv[i]); |
98 | c.send ("ARG"), c.send (argv[i]); |
91 | |
99 | |
92 | c.send ("END"); |
100 | c.send ("END"); |
93 | |
101 | |
94 | auto_str tok; |
102 | auto_str tok; |
|
|
103 | int cint; |
95 | |
104 | |
96 | for (;;) |
105 | for (;;) |
97 | if (!c.recv (tok)) |
106 | if (!c.recv (tok)) |
98 | { |
107 | { |
99 | fprintf (stderr, "protocol error: unexpected eof from server.\n"); |
108 | fprintf (stderr, "protocol error: unexpected eof from server.\n"); |
100 | break; |
109 | break; |
101 | } |
110 | } |
102 | else if (!strcmp (tok, "MSG") && c.recv (tok)) |
111 | else if (!strcmp (tok, "MSG") && c.recv (tok)) |
103 | fprintf (stderr, "%s", (const char *)tok); |
112 | fprintf (stderr, "%s", (const char *)tok); |
|
|
113 | #if ENABLE_FRILLS && HAVE_UNIX_FDPASS |
|
|
114 | else if (!strcmp (tok, "GETFD") && c.recv (cint)) |
|
|
115 | { |
|
|
116 | if (rxvt_send_fd (c.fd, cint) < 0) |
|
|
117 | { |
|
|
118 | fprintf (stderr, "unable to send fd %d: ", cint); perror (0); |
|
|
119 | exit (EXIT_FAILURE); |
|
|
120 | } |
|
|
121 | } |
|
|
122 | #endif |
104 | else if (!strcmp (tok, "END")) |
123 | else if (!strcmp (tok, "END")) |
105 | { |
124 | { |
106 | int success; |
125 | int success; |
|
|
126 | |
107 | if (c.recv (success)) |
127 | if (c.recv (success)) |
108 | exit (success ? EXIT_SUCCESS : EXIT_FAILURE); |
128 | exit (success ? EXIT_SUCCESS : EXIT_FAILURE); |
109 | } |
129 | } |
110 | else |
130 | else |
111 | { |
131 | { |
112 | fprintf (stderr, "protocol error: received illegal token '%s'.\n", (const char *)tok); |
132 | fprintf (stderr, "protocol error: received unsupported token '%s'.\n", (const char *)tok); |
113 | break; |
133 | break; |
114 | } |
134 | } |
115 | |
135 | |
116 | return EXIT_FAILURE; |
136 | return EXIT_FAILURE; |
117 | } |
137 | } |