… | |
… | |
2 | |
2 | |
3 | #include <cstdio> |
3 | #include <cstdio> |
4 | #include <cstdlib> |
4 | #include <cstdlib> |
5 | |
5 | |
6 | #include <unistd.h> |
6 | #include <unistd.h> |
|
|
7 | #include <signal.h> |
7 | #include <sys/socket.h> |
8 | #include <sys/socket.h> |
8 | #include <sys/un.h> |
9 | #include <sys/un.h> |
9 | |
10 | |
10 | struct client : rxvt_connection { |
11 | struct client : rxvt_connection { |
11 | client (); |
12 | client (); |
… | |
… | |
13 | |
14 | |
14 | client::client () |
15 | client::client () |
15 | { |
16 | { |
16 | if ((fd = socket (PF_LOCAL, SOCK_STREAM, 0)) < 0) |
17 | if ((fd = socket (PF_LOCAL, SOCK_STREAM, 0)) < 0) |
17 | { |
18 | { |
18 | perror ("unable to create listening socket"); |
19 | perror ("unable to create communications socket"); |
19 | exit (EXIT_FAILURE); |
20 | exit (EXIT_FAILURE); |
20 | } |
21 | } |
21 | |
22 | |
|
|
23 | char *sockname = rxvt_connection::unix_sockname (); |
22 | sockaddr_un sa; |
24 | sockaddr_un sa; |
23 | |
|
|
24 | sa.sun_family = AF_UNIX; |
25 | sa.sun_family = AF_UNIX; |
25 | strcpy (sa.sun_path, rxvt_connection::unix_sockname ()); |
26 | strcpy (sa.sun_path, sockname); |
|
|
27 | free (sockname); |
26 | |
28 | |
27 | if (connect (fd, (sockaddr *)&sa, sizeof (sa))) |
29 | if (connect (fd, (sockaddr *)&sa, sizeof (sa))) |
28 | { |
30 | { |
29 | perror ("unable to bind listening socket"); |
31 | perror ("unable to connect to rxvtd"); |
30 | exit (EXIT_FAILURE); |
32 | exit (EXIT_FAILURE); |
31 | } |
33 | } |
32 | } |
34 | } |
|
|
35 | |
|
|
36 | extern char **environ; |
33 | |
37 | |
34 | int |
38 | int |
35 | main(int argc, const char *const *argv) |
39 | main(int argc, const char *const *argv) |
36 | { |
40 | { |
37 | client c; |
41 | client c; |
38 | char buf[PATH_MAX]; |
42 | char buf[PATH_MAX]; |
39 | |
43 | |
|
|
44 | { |
|
|
45 | sigset_t ss; |
|
|
46 | |
|
|
47 | sigaddset (&ss, SIGHUP); |
|
|
48 | sigprocmask (SIG_BLOCK, &ss, 0); |
|
|
49 | } |
|
|
50 | |
40 | c.send ("NEW"); |
51 | c.send ("NEW"); |
41 | c.send ("DISPLAY"); c.send (getenv ("DISPLAY")); |
|
|
42 | // instead of getcwd we could opendir(".") and pass the fd for fchdir *g* |
52 | // instead of getcwd we could opendir(".") and pass the fd for fchdir *g* |
43 | c.send ("CWD"); c.send (getcwd (buf, sizeof (buf))); |
53 | c.send ("CWD"), c.send (getcwd (buf, sizeof (buf))); |
44 | |
54 | |
45 | c.send ("ARGV"); c.send (argc); |
55 | for (char **var = environ; *environ; environ++) |
|
|
56 | c.send ("ENV"), c.send (*environ); |
|
|
57 | |
46 | for (int i = 0; i < argc; i++) |
58 | for (int i = 0; i < argc; i++) |
47 | c.send (argv[i]); |
59 | c.send ("ARG"), c.send (argv[i]); |
|
|
60 | |
48 | c.send ("END"); |
61 | c.send ("END"); |
49 | } |
62 | } |
50 | |
63 | |