… | |
… | |
37 | |
37 | |
38 | #define STATUS_SUCCESS 0 |
38 | #define STATUS_SUCCESS 0 |
39 | #define STATUS_FAILURE 1 |
39 | #define STATUS_FAILURE 1 |
40 | #define STATUS_CONNECTION_FAILED 2 |
40 | #define STATUS_CONNECTION_FAILED 2 |
41 | |
41 | |
42 | struct client : rxvt_connection { |
42 | struct client : rxvt_connection |
|
|
43 | { |
43 | client (); |
44 | client (); |
44 | }; |
45 | }; |
45 | |
46 | |
46 | client::client () |
47 | client::client () |
47 | { |
48 | { |
48 | sockaddr_un sa; |
49 | sockaddr_un sa; |
49 | char *sockname = rxvt_connection::unix_sockname (); |
50 | char *sockname = rxvt_connection::unix_sockname (); |
50 | |
51 | |
51 | if (strlen(sockname) >= sizeof(sa.sun_path)) |
52 | if (strlen(sockname) >= sizeof(sa.sun_path)) |
52 | { |
53 | { |
53 | fputs ("socket name too long, aborting.\n", stderr); |
54 | fputs ("socket name too long, aborting.\n", stderr); |
54 | exit (STATUS_FAILURE); |
55 | exit (STATUS_FAILURE); |
55 | } |
56 | } |
56 | |
57 | |
57 | if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) |
58 | if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) |
58 | { |
59 | { |
59 | perror ("unable to create communications socket"); |
60 | perror ("unable to create communications socket"); |
60 | exit (STATUS_FAILURE); |
61 | exit (STATUS_FAILURE); |
61 | } |
62 | } |
… | |
… | |
74 | extern char **environ; |
75 | extern char **environ; |
75 | |
76 | |
76 | int |
77 | int |
77 | main (int argc, const char *const *argv) |
78 | main (int argc, const char *const *argv) |
78 | { |
79 | { |
79 | client c; |
|
|
80 | { |
|
|
81 | sigset_t ss; |
|
|
82 | |
|
|
83 | sigemptyset (&ss); |
|
|
84 | sigaddset (&ss, SIGHUP); |
|
|
85 | sigprocmask (SIG_BLOCK, &ss, 0); |
|
|
86 | } |
|
|
87 | |
|
|
88 | c.send ("NEW"); |
|
|
89 | |
|
|
90 | // instead of getcwd we could opendir (".") and pass the fd for fchdir *g* |
80 | // instead of getcwd we could opendir (".") and pass the fd for fchdir *g* |
91 | char cwd[PATH_MAX]; |
81 | char cwd[PATH_MAX]; |
92 | |
82 | |
93 | if (!getcwd (cwd, sizeof (cwd))) |
83 | if (!getcwd (cwd, sizeof (cwd))) |
94 | { |
84 | { |
95 | perror ("unable to determine current working directory"); |
85 | perror ("unable to determine current working directory"); |
96 | exit (STATUS_FAILURE); |
86 | exit (STATUS_FAILURE); |
97 | } |
87 | } |
98 | |
88 | |
|
|
89 | client c; |
|
|
90 | |
|
|
91 | { |
|
|
92 | sigset_t ss; |
|
|
93 | |
|
|
94 | sigemptyset (&ss); |
|
|
95 | sigaddset (&ss, SIGHUP); |
|
|
96 | sigaddset (&ss, SIGPIPE); |
|
|
97 | sigprocmask (SIG_BLOCK, &ss, 0); |
|
|
98 | } |
|
|
99 | |
|
|
100 | c.send ("NEW"); |
99 | c.send ("CWD"), c.send (cwd); |
101 | c.send ("CWD"), c.send (cwd); |
100 | |
102 | |
101 | for (char **var = environ; *var; var++) |
103 | for (char **var = environ; *var; var++) |
102 | c.send ("ENV"), c.send (*var); |
104 | c.send ("ENV"), c.send (*var); |
103 | |
105 | |