… | |
… | |
25 | |
25 | |
26 | #include "rxvt.h" |
26 | #include "rxvt.h" |
27 | |
27 | |
28 | #include <cstdio> |
28 | #include <cstdio> |
29 | #include <cstdlib> |
29 | #include <cstdlib> |
|
|
30 | #include <cstring> |
|
|
31 | #include <csignal> |
30 | |
32 | |
31 | #include <unistd.h> |
33 | #include <unistd.h> |
32 | #include <signal.h> |
|
|
33 | #include <sys/socket.h> |
34 | #include <sys/socket.h> |
34 | #include <sys/un.h> |
35 | #include <sys/un.h> |
35 | |
36 | |
36 | struct client : rxvt_connection { |
37 | struct client : rxvt_connection { |
37 | client (); |
38 | client (); |
… | |
… | |
51 | strcpy (sa.sun_path, sockname); |
52 | strcpy (sa.sun_path, sockname); |
52 | free (sockname); |
53 | free (sockname); |
53 | |
54 | |
54 | if (connect (fd, (sockaddr *)&sa, sizeof (sa))) |
55 | if (connect (fd, (sockaddr *)&sa, sizeof (sa))) |
55 | { |
56 | { |
56 | perror ("unable to connect to rxvtd"); |
57 | perror ("unable to connect to the rxvt-unicode daemon"); |
57 | exit (EXIT_FAILURE); |
58 | exit (EXIT_FAILURE); |
58 | } |
59 | } |
59 | } |
60 | } |
60 | |
61 | |
61 | extern char **environ; |
62 | extern char **environ; |
62 | |
63 | |
63 | int |
64 | int |
64 | main (int argc, const char *const *argv) |
65 | main (int argc, const char *const *argv) |
65 | { |
66 | { |
66 | client c; |
67 | client c; |
67 | char buf[PATH_MAX]; |
|
|
68 | |
|
|
69 | { |
68 | { |
70 | sigset_t ss; |
69 | sigset_t ss; |
71 | |
70 | |
72 | sigemptyset (&ss); |
71 | sigemptyset (&ss); |
73 | sigaddset (&ss, SIGHUP); |
72 | sigaddset (&ss, SIGHUP); |
74 | sigprocmask (SIG_BLOCK, &ss, 0); |
73 | sigprocmask (SIG_BLOCK, &ss, 0); |
75 | } |
74 | } |
76 | |
75 | |
77 | c.send ("NEW"); |
76 | c.send ("NEW"); |
|
|
77 | |
78 | // instead of getcwd we could opendir (".") and pass the fd for fchdir *g* |
78 | // instead of getcwd we could opendir (".") and pass the fd for fchdir *g* |
79 | c.send ("CWD"), c.send (getcwd (buf, sizeof (buf))); |
79 | char cwd[PATH_MAX]; |
80 | |
80 | |
81 | for (char **var = environ; *environ; environ++) |
81 | if (!getcwd (cwd, sizeof (cwd))) |
82 | c.send ("ENV"), c.send (*environ); |
82 | { |
|
|
83 | perror ("unable to determine current working directory"); |
|
|
84 | exit (EXIT_FAILURE); |
|
|
85 | } |
83 | |
86 | |
|
|
87 | c.send ("CWD"), c.send (cwd); |
|
|
88 | |
|
|
89 | for (char **var = environ; *var; var++) |
|
|
90 | c.send ("ENV"), c.send (*var); |
|
|
91 | |
|
|
92 | const char *base = strrchr (argv[0], '/'); |
|
|
93 | base = base ? base + 1 : argv[0]; |
|
|
94 | c.send ("ARG"), c.send (strcmp (base, RXVTNAME "c") ? base : RXVTNAME); |
|
|
95 | |
84 | for (int i = 0; i < argc; i++) |
96 | for (int i = 1; i < argc; i++) |
85 | c.send ("ARG"), c.send (argv[i]); |
97 | c.send ("ARG"), c.send (argv[i]); |
86 | |
98 | |
87 | c.send ("END"); |
99 | c.send ("END"); |
88 | |
100 | |
89 | auto_str tok; |
101 | auto_str tok; |