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