… | |
… | |
14 | |
14 | |
15 | client::client () |
15 | client::client () |
16 | { |
16 | { |
17 | if ((fd = socket (PF_LOCAL, SOCK_STREAM, 0)) < 0) |
17 | if ((fd = socket (PF_LOCAL, SOCK_STREAM, 0)) < 0) |
18 | { |
18 | { |
19 | perror ("unable to create listening socket"); |
19 | perror ("unable to create communications socket"); |
20 | exit (EXIT_FAILURE); |
20 | exit (EXIT_FAILURE); |
21 | } |
21 | } |
22 | |
22 | |
|
|
23 | char *sockname = rxvt_connection::unix_sockname (); |
23 | sockaddr_un sa; |
24 | sockaddr_un sa; |
24 | |
|
|
25 | sa.sun_family = AF_UNIX; |
25 | sa.sun_family = AF_UNIX; |
26 | strcpy (sa.sun_path, rxvt_connection::unix_sockname ()); |
26 | strcpy (sa.sun_path, sockname); |
|
|
27 | free (sockname); |
27 | |
28 | |
28 | if (connect (fd, (sockaddr *)&sa, sizeof (sa))) |
29 | if (connect (fd, (sockaddr *)&sa, sizeof (sa))) |
29 | { |
30 | { |
30 | perror ("unable to bind listening socket"); |
31 | perror ("unable to connect to rxvtd"); |
31 | exit (EXIT_FAILURE); |
32 | exit (EXIT_FAILURE); |
32 | } |
33 | } |
33 | } |
34 | } |
34 | |
35 | |
35 | extern char **environ; |
36 | extern char **environ; |
36 | |
37 | |
37 | int |
38 | int |
38 | main(int argc, const char *const *argv) |
39 | main (int argc, const char *const *argv) |
39 | { |
40 | { |
40 | client c; |
41 | client c; |
41 | char buf[PATH_MAX]; |
42 | char buf[PATH_MAX]; |
42 | |
43 | |
43 | { |
44 | { |
44 | sigset_t ss; |
45 | sigset_t ss; |
45 | |
46 | |
|
|
47 | sigemptyset (&ss); |
46 | sigaddset (&ss, SIGHUP); |
48 | sigaddset (&ss, SIGHUP); |
47 | sigprocmask (SIG_BLOCK, &ss, 0); |
49 | sigprocmask (SIG_BLOCK, &ss, 0); |
48 | } |
50 | } |
49 | |
51 | |
50 | c.send ("NEW"); |
52 | c.send ("NEW"); |
51 | // instead of getcwd we could opendir(".") and pass the fd for fchdir *g* |
53 | // instead of getcwd we could opendir (".") and pass the fd for fchdir *g* |
52 | c.send ("CWD"), c.send (getcwd (buf, sizeof (buf))); |
54 | c.send ("CWD"), c.send (getcwd (buf, sizeof (buf))); |
53 | |
55 | |
54 | for (char **var = environ; *environ; environ++) |
56 | for (char **var = environ; *environ; environ++) |
55 | c.send ("ENV"), c.send (*environ); |
57 | c.send ("ENV"), c.send (*environ); |
56 | |
58 | |